private static POSTContent BuildMeasurementsPostBody(Measurement measurement)
        {
            string postContent = "{ ";
            postContent += "\"Field1\" : \"" + measurement.MoistureLevel + "\", ";
            postContent += "\"Field2\" : \"" + measurement.LightLevel + "\", ";
            postContent += "\"Channel\" : \"0\", ";
            postContent += "\"Lite\" : \"true\" ";
            postContent += "}";

            return POSTContent.CreateTextBasedContent(postContent);
        }
        public void PostMeasurements(Measurement measurement)
        {
            Debug.Print("Posting measurements to Tinamous");
            const string url = UrlBase+ "Measurements";
            POSTContent postContent = BuildMeasurementsPostBody(measurement);
            const string contentType = "application/json";

            HttpRequest postRequest = HttpHelper.CreateHttpPostRequest(url, postContent, contentType);
            AddAuthorizationHeaders(postRequest);
            postRequest.ResponseReceived += ResponseReceived;
            postRequest.SendRequest();
        }
        void measurementsTimer_Tick(Timer timer)
        {
            //Debug.Print("Measuring moisture and light levels");

            _currentMeasurement = new Measurement
            {
                MoistureLevel = _moistureSensor.ReadMoisture(),
                LightLevel = _lightSensor.ReadVoltage()
            };

            Debug.Print(_currentMeasurement.ToString());

            PostMeasurement();
        }
        public void PostMeasurements(Measurement measurement)
        {
            if (!IsConnected())
            {
                return;
            }

            Debug.Print("Posting measurements to Tinamous");

            string json = BuildMeasurementsJson(measurement);
            byte[] encoded = Encoding.UTF8.GetBytes(json);

            var response = _client.Publish("/Tinamous/V1/Measurements", encoded);
        }
 public void PostMeasurements(Measurement currentMeasurement)
 { }
        private static string BuildMeasurementsJson(Measurement measurement)
        {
            string postContent = "{ ";
            postContent += "\"Field1\" : \"" + measurement.MoistureLevel + "\", ";
            postContent += "\"Field2\" : \"" + measurement.LightLevel + "\", ";
            postContent += "\"Channel\" : \"0\" ";
            postContent += "}";

            return postContent;
        }
        /// <summary>
        /// Determine if now is a good time to water.
        /// </summary>
        /// <param name="measurement"></param>
        /// <returns></returns>
        /// <remarks>
        /// Checks light level and if it is going to rain
        /// </remarks>
        private bool IsItAGoodTimeToWater(Measurement measurement)
        {
            // If it is going to rain then don't bother watering
            if (IsItGoingToRain())
            {
                return false;
            }

            // Otherwise only water at night.
            return measurement.LightLevel < 0.8D;
        }
 private bool MustWater(Measurement measurement)
 {
     return measurement.MoistureLevel < 250;
 }
 private bool NeedsWatering(Measurement measurement)
 {
     // ~ 1000 is reasonable for watered plant
     // Lower the value the dryer the plant.
     return measurement.MoistureLevel < 750;
 }