Exemplo n.º 1
0
        void wifiC_WifiConnected(object sender, EventArgs e)
        {
            //QUA CI VANNO LE COSE QUANDO E CONNESSO
            Debug.Print("Evento WiFi Connesso Ricevuto");
            #region Check connection
            /*Check connection*/
            //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.it");
            //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //if (response.StatusDescription == " OK")
            //{
            //    Debug.Print("Connect on internet");
            //}
            #endregion

            /*Set Data*/
            RealTimeClock.SetDateTime(Utilità.GetNetworkTime());


            /*Start Timer for syncronize time*/
            Utility.SetLocalTime(Utilità.GetNetworkTime());
            GT.Timer syncClock = new GT.Timer(1000 * 60 * 30);
            if (!syncClock.IsRunning)
            {
                syncClock.Tick += sincronizzazione_clock;
                syncClock.Start();
            }

            //solo prova perchè su mio pc non va broadcast!!!!!!!!!!!!!!!!!!!!
            client = new M2QTT_Wrapper("192.168.43.145", sqldb);
            /*Start Timer for send data*/
            GT.Timer t2min = new GT.Timer(2000 * 60);
            if (!t2min.IsRunning)
            {
                t2min.Tick += send_data;
                t2min.Start();
            }

            //FINO A QUA, DA TOGLIERE

            /*Find Broker IP*/
            //brokerIP broker = new brokerIP();
            //broker.IpObteined += b_IpObteined;
            //Thread scanIP = new Thread(broker.startListening);
            //scanIP.Start();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Synchronize time
 /// </summary>
 /// <param name="timer">Timer</param>
 private void sincronizzazione_clock(GT.Timer timer)
 {
     Utility.SetLocalTime(Utilità.GetNetworkTime());
     Debug.Print("SYNC");
     //RealTimeClock.SetDateTime(DateTime.Now);
 }
        /// <summary>
        /// Read all sensors and validate readings, with specifices
        /// </summary>
        /// <param name="sqldb">Database to insert</param>
        /// <param name="moisture">A moinsture sensor</param>
        public void Read_and_check_values(SQL_Wrapper sqldb, Gadgeteer.Modules.GHIElectronics.Moisture moisture, Gadgeteer.Modules.GHIElectronics.LightSense lightSense)
        {
            /*Read and Print data*/
            Utilità.ReadDHT(dhtSensor);

            if (dhtSensor.Temperature != _last_tm.value || counterTm == 15)
            {
                _last_tm.value = dhtSensor.Temperature;
                TemperatureMisure tm = new TemperatureMisure(dhtSensor.Temperature, "OK");
                //obj_send.addMisure(tm);
                sqldb.insert(tm, 0);
                if (counterTm == 15)
                {
                    counterTm = 0;
                }
            }
            else
            {
                counterTm++;
            }

            if ((dhtSensor.Humidity != _last_hm.value && dhtSensor.Humidity != 0) || counterHm == 15)
            {
                _last_hm.value = dhtSensor.Humidity;
                HumidityMisure hm = new HumidityMisure(dhtSensor.Humidity, "OK");
                //obj_send.addMisure(hm);
                sqldb.insert(hm, 0);
                if (counterHm == 15)
                {
                    counterHm = 0;
                }
            }
            else
            {
                counterHm++;
            }

            float moinstureData = moisture.ReadMoisture();

            Debug.Print("Moinsture      = " + moinstureData);
            if ((moinstureData != _last_mm.value && moinstureData != 0) || counterMm == 15)
            {
                _last_mm.value = moinstureData;
                MoistureMisure mm = new MoistureMisure(moinstureData, "OK");
                //obj_send.addMisure(mm);
                sqldb.insert(mm, 0);
                if (counterMm == 15)
                {
                    counterMm = 0;
                }
            }
            else
            {
                counterMm++;
            }

            Debug.Print(String.Empty);

            double lightDataIll  = lightSense.GetIlluminance();
            double lightDataPro  = lightSense.ReadProportion();
            double lightDataVolt = lightSense.ReadVoltage();

            Debug.Print("LightSenseIll  = " + lightDataIll);
            Debug.Print("LightSensePro  = " + lightDataPro);
            Debug.Print("LightSenseVolt = " + lightDataVolt);
            if (lightDataIll < (_last_ls.value * 0.85) || lightDataIll > (_last_ls.value + _last_ls.value * 0.15) || counterLs == 15)
            {
                _last_ls.value = (float)lightDataIll;
                LightMisure ls = new LightMisure((float)lightDataIll, "OK");
                //obj_send.addMisure(ls);
                sqldb.insert(ls, 0);
                if (counterLs == 15)
                {
                    counterLs = 0;
                }
            }
            else
            {
                counterLs++;
            }
        }