示例#1
0
        private async void Setup()
        {
            try
            {
                rootPage.NotifyUser("Establishing sensor connectivity", NotifyType.StatusMessage);

                this.mainboard = await GT.Module.CreateAsync <GTMB.FEZCream>();

                this.lightSensor = await GT.Module.CreateAsync <GTMO.LightSense>(this.mainboard.GetProvidedSocket(6));

                this.tempSensor = await GT.Module.CreateAsync <GTMO.TempHumidSI70>(this.mainboard.GetProvidedSocket(8));

                // serial connection via XBee modules
                arduinoConnection = new UsbSerial("0403", "6001");

                //Begin connection
                arduinoConnection.begin(57600, SerialConfig.SERIAL_8N1);

                //Attach event handlers
                arduinoConnection.ConnectionEstablished += ArduinoConnectionEstablished;
                arduinoConnection.ConnectionFailed      += ArduinoConnectionFailed;

                // instantiate remote device
                arduino = new RemoteDevice(arduinoConnection);
                arduino.StringMessageReceived += ArduinoStringMessageReceived;
                rootPage.NotifyUser("Sensors connected successfully!", NotifyType.StatusMessage);
            }
            catch (Exception e)
            {
                rootPage.NotifyUser("Error connecting to sensors", NotifyType.ErrorMessage);
            }
        }
示例#2
0
        private async void Setup()
        {
            this.mainboard = await GT.Module.CreateAsync <GTMB.FEZCream>();

            this.temphumid = await GT.Module.CreateAsync <GTMO.TempHumidSI70>(this.mainboard.GetProvidedSocket(3));

            this.gas = await GT.Module.CreateAsync <GTMO.GasSense>(this.mainboard.GetProvidedSocket(6));

            this.light = await GT.Module.CreateAsync <GTMO.LightSense>(this.mainboard.GetProvidedSocket(5));

            this.relay = await GT.Module.CreateAsync <GTMO.RelayX1>(this.mainboard.GetProvidedSocket(4));

            //mqtt
            if (client == null)
            {
                // create client instance
                MQTT_BROKER_ADDRESS = "gravicodeservices.cloudapp.net";
                client = new MqttClient(MQTT_BROKER_ADDRESS);
                string clientId = Guid.NewGuid().ToString();
                client.Connect(clientId, "mifmasterz", "123qweasd");
                SubscribeMessage();
            }

            this.timer          = new DispatcherTimer();
            this.timer.Interval = TimeSpan.FromMilliseconds(2000);
            this.timer.Tick    += this.OnTick;
            this.timer.Start();
        }