예제 #1
0
        /// <summary>
        /// Main page constructor
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();

            InitGPIO();

            // Hard coding guid for sensors. Not an issue for this particular application which is meant for testing and demos
            List<ConnectTheDotsSensor> sensors = new List<ConnectTheDotsSensor>
            {
                new ConnectTheDotsSensor(),
            };
            //!!!请修改这里,填上相应的值,前四个为必要的修改的值,否则无法连上Event Hub
            ctdHelper = new ConnectTheDotsHelper(
               serviceBusNamespace: "这个是Service Bus的命名空间名称",
               eventHubName: "Event Hub的名字",
               keyName: "在Event Hub配置的规则名称(如Send)",
               key: "在Event Hub配置的相应规则的密钥",
               displayName: "SmartLift",
               organization: "Microsoft",
               location: "Beijing",
               sensorList: sensors);

            // Start Timer every 1 seconds
            ReadSensorTimer = new DispatcherTimer();
            ReadSensorTimer.Interval = TimeSpan.FromMilliseconds(1000);
            ReadSensorTimer.Tick += Timer_Tick;
            ReadSensorTimer.Start();

            Unloaded += MainPage_Unloaded;

            //InitializeSensor(DATA_PIN, SCK_PIN);

            // Initialize and Start HTTP Server
            HttpServer WebServer = new HttpServer();

            WebServer.RecivedMeg += (meg, eve) =>
            {
                this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    tbmeg.Text = meg.ToString();
                }).AsTask();

            };

            var asyncAction = ThreadPool.RunAsync((w) => { WebServer.StartServer(); });
        }
예제 #2
0
        /// <summary>
        /// Main page constructor
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();

            InitGPIO();

            // Hard coding guid for sensors. Not an issue for this particular application which is meant for testing and demos
            List<ConnectTheDotsSensor> sensors = new List<ConnectTheDotsSensor>
            {
                new ConnectTheDotsSensor(),
            };

            ctdHelper = new ConnectTheDotsHelper(
               serviceBusNamespace: "iotwin10msg-ns",
               eventHubName: "ioteventhub",
               keyName: "SendRule",
               key: "OxJ8Nmw3oJBmpZH/S/aXOWT2s5mE2YuRko7OJ+yziec=",
               displayName: "YOUR_DEVICE_NAME",
               organization: "YOUR_ORGANIZATION_OR_SELF",
               location: "YOUR_LOCATION",
               sensorList: sensors);

            // Start Timer every 1 seconds
            ReadSensorTimer = new DispatcherTimer();
            ReadSensorTimer.Interval = TimeSpan.FromMilliseconds(500);
            ReadSensorTimer.Tick += Timer_Tick;
            ReadSensorTimer.Start();

            Unloaded += MainPage_Unloaded;

            InitializeSensor(DATA_PIN, SCK_PIN);

            // Initialize and Start HTTP Server
            HttpServer WebServer = new HttpServer();

            WebServer.RecivedMeg += (meg, eve) =>
            {
                this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    tbmeg.Text = meg.ToString();
                }).AsTask();

            };

            var asyncAction = ThreadPool.RunAsync((w) => { WebServer.StartServer(); });
            getip();
        }