/// <summary> /// Send Database data /// </summary> /// <param name="timer">Timer</param> private void send_data(GT.Timer timer) { if (firstTime == true) { client.sendToBroker(configuration, -1, true); firstTime = false; } if (DateTime.Now.Year != 2011) { if (wifiRS21.IsNetworkConnected && broker != null) { Hashtable packet = new Hashtable(); if ((packet = init.retriveData(sqldb)) != null) { foreach (DictionaryEntry de in packet) { int num = (int)de.Key; string json = (string)de.Value; Debug.Print("sending....!"); client.sendToBroker(json, num, false); Debug.Print("DATA SENDED!"); } } } else { Debug.Print("RECONNECTION"); wifiC = new WiFiConnection(); wifiC.WifiConnected += wifiC_WifiConnected; wifiC.connectToWiFI(wifiRS21, SSID, PASSWORD); } } }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { Debug.Print("Program Started"); #region ForEthernet //ethernetJ11D.UseThisNetworkInterface(); //ethernetJ11D.UseStaticIP("192.168.137.1","255.255.255.0","192.168.137.46"); //ethernetJ11D.NetworkUp += ethernetJ11D_NetworkUp; //ethernetJ11D.NetworkDown += ethernetJ11D_NetworkDown; #endregion /*Inizialized Database for Misure*/ sqldb = new SQL_Wrapper(sdCard); sqldb.setup_database(); /*Create Configuration*/ //Configuration conf = new Configuration(); StreamReader d = new StreamReader(sdCard.StorageDevice.RootDirectory + "\\configuration.json"); configuration = d.ReadToEnd(); /*Inizialized DHT11 sensor*/ init = new InizializeDHT(); /*Start Timer for read sensors*/ GT.Timer t6sec = new GT.Timer(6000); t6sec.Tick += read_sensors; t6sec.Start(); /*Start Timer for Backup DataBase*/ //GT.Timer tBackup = new GT.Timer(1000 * 60 * 7); //7 minuti //tBackup.Tick += BackupDB; //tBackup.Start(); /*Activate WiFi interface*/ WiFiRS9110.NetworkParameters mynet = new WiFiRS9110.NetworkParameters(); if (!wifiRS21.NetworkInterface.Opened) { wifiRS21.NetworkInterface.Open(); } wifiRS21.UseThisNetworkInterface(); #region AdHoc //mynet.Channel= 5; //mynet.Ssid="prova"; //mynet.Key=" "; //mynet.SecurityMode = WiFiRS9110.SecurityMode.Open; //mynet.NetworkType = WiFiRS9110.NetworkType.AdHoc; ////wifiRS21.NetworkInterface.EnableStaticIP("192.168.1.100", "255.255.0.0", "192.168.1.1"); //wifiRS21.NetworkInterface.StartAdHocNetwork(mynet); //Thread.Sleep(2000); //HttpListener l = new HttpListener("http"); //l.Start(); //var contex = l.GetContext(); //var respons = contex.Response; //const string r = "<html><body>Hello world</body></html>"; //var buffer = System.Text.Encoding.UTF8.GetBytes(r); //respons.ContentLength64 = buffer.Length; //var output = respons.OutputStream; //output.Write(buffer, 0, buffer.Length); //output.Close(); #endregion /*Connect to wifi*/ wifiC = new WiFiConnection(); wifiC.WifiConnected += wifiC_WifiConnected; wifiC.connectToWiFI(wifiRS21, SSID, PASSWORD); //setup(); }