public MainPage() { InitializeComponent(); Unloaded += MainPage_Unloaded; //Window.Current.CoreWindow.PointerCursor = null; connection = new RemoteConnection(); connection.OnLedEvent(LedEvent); led = new MulticolorLed(redPinNumber: 18, greenPinNumber: 23, bluePinNumber: 25); humitureSensor = new Dht11HumitureSensor(pinNumber: 4); humitureSensor.RaiseEventsOnUIThread = true; humitureSensor.ReadingChanged += HumitureSensor_ReadingChanged; relay = new Relay(pinNumber: 16); motionDetector = new Sr501PirMotionDetector(pinNumber: 12); motionDetector.RaiseEventsOnUIThread = true; motionDetector.MotionDetected += MotionDetector_MotionDetected; motionDetector.MotionStopped += MotionDetector_MotionStopped; metalTouchSensor = new MetalTouchSensor(pinNumber: 5); metalTouchSensor.RaiseEventsOnUIThread = true; metalTouchSensor.TouchDetected += MetalTouchSensor_TouchDetected; metalTouchSensor.TouchRemoved += MetalTouchSensor_TouchRemoved; flameSensor = new FlameSensor(pinNumber: 26); flameSensor.RaiseEventsOnUIThread = true; flameSensor.FlameDetected += FlameSensor_FlameDetected; flameSensor.FlameExtinguished += FlameSensor_FlameExtinguished; timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(30) }; timer.Tick += Timer_Tick; }
private void init() { Buzzer.init(breakout2.CreatePwmOutput(GT.Socket.Pin.Nine)); StatusLed.led = ledStrip; StatusLed.led.SetLed(0, true); DisplayLCD.lcd = displayTE35; DisplayTimer(); while (!wifi.NetworkInterface.Opened) { try { Debug.Print("Opening Wifi interface"); wifi.NetworkInterface.Open(); Thread.Sleep(1000); } catch (Exception) { Thread.Sleep(1000); continue; } } GeoMessage geomessage = new GeoMessage(wifi.NetworkInterface.Scan()); wifi.NetworkInterface.Close(); RemovableMedia.Insert += (sender, e) => { mountEvent.Set(); Debug.Print("SD Mounted"); }; while (!sdCard.IsCardInserted) { DisplayLCD.addSDInfo(false, 0); Thread.Sleep(1000); Debug.Print("Waiting for sd card"); } while (!sdCard.IsCardMounted) { DisplayLCD.addSDInfo(false, 0); Thread.Sleep(1000); if (!sdCard.IsCardMounted) { sdCard.Mount(); } } //mountEvent.WaitOne(); //byte[] data = Encoding.UTF8.GetBytes("Hello World!"); //sdCard.StorageDevice.WriteFile("measure" + 0, data); //sdCard.StorageDevice.CreateDirectory(@"test"); /*if (VolumeInfo.GetVolumes()[0].IsFormatted) * { * string rootDirectory = * VolumeInfo.GetVolumes()[0].RootDirectory; * string[] files = Directory.GetFiles(rootDirectory); * string[] folders = Directory.GetDirectories(rootDirectory); * * Debug.Print("Files available on " + rootDirectory + ":"); * for (int i = 0; i < files.Length; i++) * { * Debug.Print("Deleted " + files[i]); * sdCard.StorageDevice.Delete(files[i]); * } * Debug.Print("Folders available on " + rootDirectory + ":" + folders.Length); * } * else * { * Debug.Print("Storage is not formatted. " + * "Format on PC with FAT32/FAT16 first!"); * }*/ DisplayLCD.addSDInfo(true, 0); Ethernet eth = new Ethernet(ethernetJ11D); Debug.Print("Ethernet created"); mqtt = eth.MQTT; Debug.Print("Mqtt created"); MeasureOrchestrator.setMqtt(mqtt); MeasureDB.sd = sdCard; Debug.Print("Time updated"); TimeSync.update(); while (!mqtt.isConnected()) { Thread.Sleep(1000); } POSTContent pc = POSTContent.CreateTextBasedContent(GeoMessage.Json(geomessage)); try { HttpRequest wc = HttpHelper.CreateHttpPostRequest("http://52.57.156.220/geolocation", pc, "application/json"); wc.ResponseReceived += wc_ResponseReceived; wc.SendRequest(); } catch (Exception) { mqtt.Publish("cfg", Configuration.Json(new Configuration(45.0631, 7.66004))); } //send a request with GeoMessage.Json(message) and set the configuration FlameSensor flame = new FlameSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Three), "0"); SmokeSensor smoke = new SmokeSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Four), "1"); COSensor co = new COSensor(breakout.CreateAnalogInput(GT.Socket.Pin.Five), "2"); TemperatureSensor temperature = new TemperatureSensor(breakout3.CreateAnalogInput(GT.Socket.Pin.Three), "3"); registerSensor(temperature); registerSensor(smoke); registerSensor(co); registerSensor(flame); pubTimer(3000); pubOldTimer(2000); }