Пример #1
0
 /*********************************************************
 * isValidReading tests values of all measurements
 * returns true if all values are in range
 * opens a MessageBox and returns false if out of range
 *********************************************************/
 public static Boolean isValidReading(SimulatedReading read)
 {
     if (isPositionInRange(read.latitude, read.longitude) &&
         isVoltageInRange(read.battery) &&
         isPhInRange(read.pH) && isTempInRange(read.temperature) &&
         isConductivityInRange(read.conductivity) &&
         isTurbidityInRange(read.turbidity) &&
         isDissolvedSolidsInRange(read.dissolvedSolids))
     {
         return(true);
     }
     else
     {
         MessageBox.Show("Reading has not been/nbroadcast or recorded", "Device Error");
         return(false);
     }
 }
Пример #2
0
        /**********************************************************************************
        * ReadingTimer_TickAsync(object sender, EventArgs e)
        * Creates a reading and sends it to dweet.io
        * Every 240 readings (1 hour) send reading to database
        **********************************************************************************/
        private async void ReadingTimer_TickAsync(object sender, EventArgs e)
        {
            try
            {
                SimulatedReading reading = new SimulatedReading(); // create reading
                SmartBuoyDB      sb      = new SmartBuoyDB();      //for database connection

                int counter = 1;                                   // set counter

                CycleLEDs();                                       // LEDS

                if (RangeValidator.isValidReading(reading))        // validate data
                {
                    indicatorLIVE.Image = SmartBuoySimulator.Properties.Resources.LED_GreenOn;

                    await DweetStream.BroadcastLive(reading); // send to dweet.io

                    indicatorLIVE.Image = SmartBuoySimulator.Properties.Resources.LED_GreenOff;

                    counter++;          // increment counter

                    if (counter == 240) // every 240 readings (1 hour) insert data into database
                    {
                        indicatorSQL.Image = SmartBuoySimulator.Properties.Resources.LED_GreenOn;
                        indicatorSQL.Refresh();

                        // Insert into the database
                        sb.Reading.InsertOnSubmit(reading);
                        sb.SubmitChanges();

                        Thread.Sleep(1000);
                        indicatorSQL.Image = SmartBuoySimulator.Properties.Resources.LED_GreenOff;
                        indicatorSQL.Refresh();

                        counter = 1; // reset counter
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogError(ex);
            }
        }
Пример #3
0
        /**********************************************************************************
        * BroadcastLIVE will take the data reading and send to the Dweet.io
        * hosting service using an HttpClient.
        **********************************************************************************/
        public static async Task BroadcastLive(SimulatedReading sr)
        {
            try
            {
                StringBuilder dweetString = new StringBuilder();

                // build the url string
                dweetString.Append("https://dweet.io/dweet/for/SmartBuoyb97e934d5336e0?DATETIME=");
                dweetString.Append(sr.readingDT);
                dweetString.Append("&VOLTS=");
                dweetString.Append(sr.battery);
                dweetString.Append("&TEMP=");
                dweetString.Append(sr.temperature);
                dweetString.Append("&PH=");
                dweetString.Append(sr.pH);
                dweetString.Append("&EC=");
                dweetString.Append(sr.conductivity);
                dweetString.Append("&TDS=");
                dweetString.Append(sr.dissolvedSolids);
                dweetString.Append("&TURB=");
                dweetString.Append(sr.turbidity);
                dweetString.Append("&LAT=");
                dweetString.Append(sr.latitude);
                dweetString.Append("&LON=");
                dweetString.Append(sr.longitude);

                HttpClient client = new HttpClient();

                var result = await client.GetAsync(dweetString.ToString()); // connect to dweet.io
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Logger.LogError(ex);
            }
        }