Go Down

Topic: Arduino Mega + ESP8266 + Webserver + JSon Response (Read 2700 times) previous topic - next topic

arinmihai

Hello,

I need a little help with a problem.
I want to make a webserver that will reply to a GET request from a page(android app) with a Json format.
The Json will show the values of 3 sensors.

The hardware is like this : Arduino Mega, wifi module ESP8266 connected on serial1.
I need to say that i'm very low on programing but here is what i have done until now :

              strcpy(html,"HTTP/1.1 200 OK");
              strcpy(command,"AT+CIPSEND=0,25\r\n");
              Serial1.print(command);
              getReply( 2000 );         
              Serial1.print(html);
              getReply( 2000 );                     
 
               strcpy(html,"Content-Type: application/json");
              strcpy(command,"AT+CIPSEND=0,50\r\n");
              Serial1.print(command);
              getReply( 2000 );         
              Serial1.print(html);
              getReply( 2000 );   
 
              strcpy(html,"Connection: close");
              strcpy(command,"AT+CIPSEND=0,50\r\n");
              Serial1.print(command);
              getReply( 2000 );         
              Serial1.print(html);
              getReply( 2000 );         
 
              strcpy(html,"");
              strcpy(command,"AT+CIPSEND=0,1\r\n");
              Serial1.print(command);
              getReply( 2000 );         
              Serial1.print(html);
              getReply( 2000 );   
             
              strcpy(html,"{\"StatusALL:\":\"OK\",\"Room1:\":\"100\",\"TEXT:\":\"200\"}");
              strcpy(command,"AT+CIPSEND=0,50\r\n");
              Serial1.print(command);
              getReply( 2000 );         
              Serial1.print(html);
              getReply( 2000 );   
       
             // close the connection
              Serial1.print( "AT+CIPCLOSE=0\r\n" );
              getReply( 1500 );           
 
 On serial monitor i get OK for each line until the line with the json string where i get an error message.
Can you tell me what is wrong ?

I found on the internet a library ESP8266wifi ( made for arduino ) not for the esp8266 (WiFi) but i can not find any examples for creating an webserver with the ESP connected to an AP.

One other way that i found for the Json is with the library ArduinoJson.h but i don't know how to print the result to the esp8266.

The library has something like this : root.printTo(Serial); or : root.prettyPrintTo(Serial);

PLS HELP :)




Ray_Beebe

AT+CIPSEND=0,50 I think the 50 in this command is the actual length of the string you send. You should determine actual length of the string with string.length() or the appropriate one for your data type. Every line in a header needs a "/r/ n" on the end. The last part of the header should have "/r/n/r/n". Not 100% on this but can't hurt to try.

Go Up