void button_ButtonPressed(Button sender, Button.ButtonState state) { sensorState = (sensorState.Equals("0")) ? "1" : "0"; Debug.Print(sensorState); PUTContent emptyPut = new PUTContent(); Gadgeteer.Networking.HttpRequest req = HttpHelper.CreateHttpPutRequest("http://" + rpi + ":9090/gadgeteer/state/" + sensorState + "/", emptyPut, null); req.SendRequest(); }
/// <summary> /// Make an asynchronous (non-blocking) request for a web page. Use the ResponseReceived event of the returned /// HttpRequest object to obtain the actual web page. /// </summary> /// <param name="url">Url of the web page to get</param> /// <returns>An HttpRequest object on success, null otherwise</returns> public static HttpRequest GetFromWeb(string url) { HttpRequest request = HttpHelper.CreateHttpGetRequest(url); if (request != null) { if (Proxy != null) { request.Proxy = Proxy; } request.SendRequest(); } return(request); }
void pollState() { while (true) { String newState = (pir.SensorStillActive) ? "1" : "0"; if (!newState.Equals(sensorState)) { sensorState = newState; Debug.Print(sensorState); PUTContent emptyPut = new PUTContent(); Gadgeteer.Networking.HttpRequest req = HttpHelper.CreateHttpPutRequest("http://" + rpi + ":9090/gadgeteer/state/" + sensorState + "/", emptyPut, null); req.SendRequest(); } Thread.Sleep(1000); } }
void pollLight() { while (true) { double lightPercent = lightSensor.ReadLightSensorPercentage(); Debug.Print(lightPercent.ToString()); String newState = (lightPercent >= 50) ? "1" : "0"; Debug.Print(newState); if (!sensorState.Equals(newState)) { sensorState = newState; Debug.Print(sensorState); PUTContent emptyPut = new PUTContent(); Gadgeteer.Networking.HttpRequest req = HttpHelper.CreateHttpPutRequest("http://" + rpi + ":9090/gadgeteer/state/" + sensorState + "/", emptyPut, null); req.SendRequest(); } Thread.Sleep(1000); } }