void getVersion_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = "<html><body><h1>Version 1.0!</h1>" + getCaptureMode() + "</body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = "<html><body><h1>Hello World!!</h1></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void test_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { Debug.Print("Hello world"); string content = "<html><body><h1>Hosted on .NET Gadgteer!!</h1><a href=\"http://169.254.120.154/seepicture\">http://169.254.120.154/seepicture</a></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void TakePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { GT.Picture jpeg = new GT.Picture(picture.PictureData, Gadgeteer.Picture.PictureEncoding.JPEG); if (picture != null) { responder.Respond(jpeg); } }
void sketch_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { Bitmap bitmap = background.Bitmap; byte[] buff = new byte[bitmap.Width * bitmap.Height * 3 + 54]; Util.BitmapToBMPFile(bitmap.GetBitmap(), bitmap.Width, bitmap.Height, buff); GT.Picture picture = new GT.Picture(buff, GT.Picture.PictureEncoding.BMP); responder.Respond(picture); }
void seePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (pic != null) { responder.Respond(pic); } else { responder.Respond("Take picture first"); } }
/// <summary> /// handler di defalut /// TODO Testare che la pagina venga visualizzata correttamente (con i css) /// </summary> void DefaultEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string str = Resources.GetString(Resources.StringResources.index); byte[] HTML = System.Text.Encoding.UTF8.GetBytes(str); // We always send the same page back responder.Respond(HTML, "index/html;charset=utf-8"); // If a button was clicked if (method == WebServer.HttpMethod.POST) { Debug.Print("Path: " + path); } }
/// <summary> /// Raises the <see cref="WebEventReceived"/> event. /// </summary> /// <param name="responder">Contains request data sent by the the client and functionality to respond to the request.</param> /// <param name="method">The incoming http method. </param> /// <param name="path">The path of the requested resource.</param> internal virtual void OnWebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (onWebEventReceived == null) { onWebEventReceived = new ReceivedWebEventHandler(OnWebEventReceived); } if (_WebEventReceived == null || noHandlerSet) { responder.SendResponse(); } else if (Program.CheckAndInvoke(_WebEventReceived, onWebEventReceived, path, method, responder)) { _WebEventReceived(path, method, responder); } }
void webEvent_dispatcher(string path, WebServer.HttpMethod method, Responder responder) { if (method.Equals(WebServer.HttpMethod.PUT)) { string firstURLParam = path.Substring(0, path.IndexOf("/")); #if DEBUG Debug.Print("Called PUT " + path); Debug.Print("URL starts with " + firstURLParam); #endif switch (firstURLParam) { case "lights": #if DEBUG Debug.Print("Called PUT the lights " + path.Substring(path.LastIndexOf("/"))); #endif putLightsManager(path.Substring(path.IndexOf("/") + 1)); break; case "automatic_light": putAutomaticLightsManager(path.Substring(path.IndexOf("/") + 1)); break; case "automatic_heather": putAutomaticHeatherManager(path.Substring(path.IndexOf("/") + 1)); break; case "heather": putHeatherManager(path.Substring(path.IndexOf("/") + 1)); break; default: lock (board.lokcker) { responder.Respond(Encoding.UTF8.GetBytes("\"KO\""), "text/json"); } return; } } lock (board) { responder.Respond(Encoding.UTF8.GetBytes("\"OK\""), "text/json"); } }
void seePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (pic != null) { Bitmap b = new Bitmap(320, 240); b.DrawLine(Colors.Red, 20, 0, 0, 319, 239); byte[] buff = new byte[320 * 240 * 3 + 54]; GHIElectronics.NETMF.System.Util.BitmapToBMPFile(b.GetBitmap(), 320, 240, buff); GT.Picture picture = new GT.Picture(buff, GT.Picture.PictureEncoding.BMP); responder.Respond(picture); } else { responder.Respond("Take picture first"); } }
void toggleCapture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { captureOn = !(captureOn); string content = "<html><body><h1>" + getCaptureMode() + "</h1></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); if (captureOn) { multicolorLed.BlinkRepeatedly(GT.Color.Red); } else { multicolorLed.BlinkRepeatedly(GT.Color.Green); } }
// secure reception of wifi credentials over wifi network - secured by receiving secret void CredentialsWebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (responder.UrlParameters == null || !responder.UrlParameters.Contains("ssid") || !responder.UrlParameters.Contains("setupauthcode")) { responder.Respond("ERROR::Syntax: " + path + "?ssid=SSID&setupauthcode=SETUPAUTHCODE[&key=WIFIKEY]"); return; } if (((string)responder.UrlParameters["setupauthcode"]) != SetupAuthCode) { responder.Respond("ERROR::Incorrect setupauthcode"); return; } var ssid = responder.UrlParameters["ssid"] as string; if (ssid == null || ssid == "") { responder.Respond("ERROR::Invalid SSID"); return; } var key = ""; if (responder.UrlParameters.Contains("key")) { key = responder.UrlParameters["key"] as string; } Debug.Print("Received (via web event) credentials for network " + ssid); bool newcreds = ReceivedCredentials(ssid, key); if (newcreds) { responder.Respond("OK::Got new credentials"); SaveData(); Thread.Sleep(10); WebServer.StopLocalServer(); currentAP = null; SetLed(); SetScreen(); wifi.Interface.Disconnect(); } else { responder.Respond("OK::Already had those"); } }
void collectData_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { /*EXAMPLE: path = "data?currentLatitude=XX.XXXXXXX¤tLongitude=XX.XXXXXXX&destinationLatitude=XX.XXXXXXX&destinationLongitude=XX.XXXXXXX";*/ Debug.Print(path.ToString()); //Debug.Print(receivedContent.ToString()); // process data /*currentLatitude = path; * currentLongitude = path; * destinationLatitude = path; * destinationLongitude = path;*/ // send information back string respondContent = "HTTP/1.1 200 OK"; // this can be anything (HTML etc..) byte[] HeaderData = new System.Text.UTF8Encoding().GetBytes(respondContent); responder.Respond(HeaderData, "text/plain"); }
/// <summary> /// Extracts data from the header and fills in corresponding properties. /// </summary> protected void ProcessHeader() { // Process Header string request = new string(Encoding.UTF8.GetChars(_headerData)); char[] delimiters = new char[] { '\r', '\n' }; string[] splittedRequest = request.Split(delimiters); for (int i = 0; i < splittedRequest.Length; i++) { string line = splittedRequest[i]; line.Trim(); if (line.Length > 0 && !line.Equals(" ")) { // used for identifying body part // ******************************************************* // prepare request values // ******************************************************* // differ between different cases // generally, first parameter is GET, PUT, POST, DELETE, followed by the URL and HTTP Version // seperated by if (i == 0) { string[] httpFirstLineParameters = line.Split(' '); MethodAsString = httpFirstLineParameters[0]; if (MethodAsString.Equals("GET")) { contentLength = 0; _httpMethod = WebServer.HttpMethod.GET; } else if (MethodAsString.Equals("POST")) { _httpMethod = WebServer.HttpMethod.POST; } else if (MethodAsString.Equals("PUT")) { _httpMethod = WebServer.HttpMethod.PUT; } else if (MethodAsString.Equals("DELETE")) { contentLength = 0; _httpMethod = WebServer.HttpMethod.DELETE; } // Debug.Print("HttpMethod " + HttpMethod); string path = httpFirstLineParameters[1]; // get the path and check for parameters path = path.Substring(1, path.Length - 1); if (_httpMethod == WebServer.HttpMethod.DELETE || HttpMethod == WebServer.HttpMethod.GET) { string[] array = path.Split('?'); if (array.Length == 2) { _path = array[0]; string[] parameterTuples = array[1].Split('&'); UrlParameters = new Hashtable(); for (int t = 0; t < parameterTuples.Length; t++) { string[] parameterData = ((string)parameterTuples[t]).Split('='); if (parameterData.Length == 2) { UrlParameters.Add(parameterData[0], parameterData[1]); } else { throw new Exception("Malformed URL request"); } } } else { _path = path; } } else { _path = path; } _httpVersion = httpFirstLineParameters[2]; } else { // put all other valuse into a hashtable for further computations, if necessary string[] nextLine = line.Split(':'); headerFields.Add(nextLine[0], nextLine[1]); if (nextLine[0].ToLower().Equals("content-length")) { contentLength = int.Parse(nextLine[1]); // Debug.Print("content-Length found " + contentLength); } } } } }
/// <summary> /// HTTP request handler /// </summary> /// <param name="path"></param> /// <param name="method"></param> /// <param name="responder"></param> void DefaultEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { // We always send the same page back responder.Respond(HTML, "text/html;charset=utf-8"); }
void hello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { Debug.Print("Hello world"); responder.Respond("Hello world"); }
void empty_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond("This is a RoboHome module and should be accessed using the API"); }
void state_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond(sensorState); }
void takePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond("Taking picture"); camera.TakePicture(); }