embedded - Storing an HTTP request in an array using C -
i trying catch http request , store in array using c . how can possibly ?
the request of following form :
post /box/update http/1.1 accept : application/json content-type : application/x-www-form-urlencoded host:121.158.41.104:1338 content-length : 83 connection : close serial=1234&pin=1234&powestate=true&startstate=true&temperature=11&macadress=113
code have tried far :
/* wifi web server simple web server shows value of analog input pins. using wifi shield. example written network using wpa encryption. wep or wpa, change wifi.begin() call accordingly. circuit: * wifi shield attached * analog inputs attached pins a0 through a5 (optional) created 13 july 2010 dlf (metodo2 srl) modified 31 may 2012 tom igoe */ #include <spi.h> #include <wifi.h> #include <wificlient.h> #include <wifiserver.h> // network name called ssid char ssid[] = "myssid"; // network password char password[] = "mypassword"; // network key index number (needed wep) int keyindex = 0; wifiserver server(mport); int array_number = 3; void setup() { serial.begin(115200); // initialize serial communication pinmode(red_led, output); // set led pin mode // attempt connect wifi network: serial.print("attempting connect network named: "); // print network name (ssid); serial.println(ssid); // connect wpa/wpa2 network. change line if using open or wep network: wifi.begin(ssid, password); while ( wifi.status() != wl_connected) { // print dots while wait connect serial.print("."); delay(300); } serial.println("\nyou're connected network"); serial.println("waiting ip address"); while (wifi.localip() == inaddr_none) { // print dots while wait ip addresss serial.print("."); delay(300); } // you're connected now, print out status printwifistatus(); serial.println("starting webserver on port 80"); server.begin(); // start web server on port 80 serial.println("webserver started!"); } void loop() { // listen incoming clients wificlient client = server.available(); string buffer = ""; string post_str1 = ""; /* int temperatures; string macaddresses; */ string status_message; int status_code; boolean powerstates[3]= {true,true,true}; boolean startstates[3]= {true,true,true}; //int temperatures[3]={11,22,33}; char * macaddresses[3] = {"155","156","157"}; char * temperatures[3] = {"11","22","33"}; // powerstates[3] //startstates[3] /* temperatures = 11; macaddresses = "155"; */ status_code = 1; status_message = "success"; if (client) { serial.println("new client"); // http request ends blank line boolean currentlineisblank = true; int check = 0; while (client.connected()) { if (client.available()) { char c = client.read(); buffer +=c; serial.write(c); // if you've gotten end of line (received newline // character) , line blank, http request has ended, // can send reply //if(c == '\n' && currentlineisblank){ if(buffer.indexof("true")>=0||buffer.indexof("false")>=0){ // you're starting new line client.println("http/1.1 200 ok"); client.println("content-type: application/json"); client.println(); client.print("{\"serial\":\""); client.print("1234"); client.print("\",\"pin\":\""); client.print("1234"); client.print("\",\"powerstates\":"); client.print("[1,1,1]"); client.print(",\"startstates\":"); client.print("[1,1,1]"); client.print(",\"temperatures\":"); client.print("[11,22,33]"); client.print(",\"macaddresses\":"); client.print("[\"125\",\"136\",\"137\"]"); /* client.print("\",\"powerstates\":"); client.print("[\"true\",\"true\",\"true\"]"); client.print(",\"startstates\":"); client.print("[\"false\",\"false\",\"false\"]"); client.print(",\"temperatures\":"); client.print("[\"11\",\"22\",\"33\"]"); client.print(",\"macaddresses\":"); client.print("[\"155\",\"156\",\"157\"]"); */ client.print(",\"status_code\":"); client.print(status_code); client.print(",\"status_message\":\""); client.print(status_message); client.print("\"}"); serial.print("\n\r"); serial.print("{\"serial\":\""); serial.print("1234"); serial.print("\",\"pin\":\""); serial.print("1234"); serial.print("\",\"powerstates\":"); serial.print("[\"true\",\"true\",\"true\"]"); serial.print(",\"startstates\":"); serial.print("[\"true\",\"true\",\"true\"]"); serial.print(",\"temperatures\":"); serial.print("[\"11\",\"22\",\"33\"]"); serial.print(",\"macaddresses\":"); serial.print("[\"155\",\"156\",\"157\"]"); serial.print(",\"status_code\":"); serial.print(status_code); serial.print(",\"status_message\":\""); serial.print(status_message); serial.print("\"}"); serial.print("\n\r"); buffer=""; check==0; break; } if(c == '\n'){ currentlineisblank=true; } else if (c !='\r'){ currentlineisblank=false; } }// carrage }//client avable // give web browser time receive data delay(1); // close connection: client.stop(); serial.println("client disonnected"); }//if client }//while void printwifistatus() { // print ssid of network you're attached to: serial.print("network name: "); serial.println(wifi.ssid()); // print wifi shield's ip address: ipaddress ip = wifi.localip(); serial.print("ip address: "); serial.println(ip); // print received signal strength: long rssi = wifi.rssi(); serial.print("signal strength (rssi):"); serial.print(rssi); serial.println(" dbm"); }
my program requires store each variable , value further use.i have been able read request , output on console , further stuck.
Comments
Post a Comment