Fetching data from Node.Js Server

I want to fetch the JSON data(time and date) from Node.Js Server to ESP8266-01 using http GET method.

I have used Software serial definition as
#include<SoftwareSerial.h>
SoftwareSerial ser(A8,A9); // Connect TX and RX of ESP8266 (A8 for TX A9 for RX) of ATMEGA2560.

In the code i have written

ser.print(String("GET ") + “/details HTTP/1.1/\r\n” +
“192.168.1.11”+ “\r\n” +
“Connection: close\r\n\r\n”);

// Read all the lines of the reply from server and print them to Serial
Serial.println(“Respond:”);
while(ser.available()){
String line = ser.readStringUntil(’\r’);
Serial.print(line);
}

Serial.println();
Serial.println(“closing connection”);

where ser is defined function for ESP8266-01
192.168.1.11 is Local server IP address from where i have to fetch the JSON data(data and time in my case).

But i am not able to fetch date and time data.

Thank you.

What is your REST Service url defined in Node js?

Post the whole code, if the code contains other logics then create a new code only to show the issue.

Sir,I have no clue about Server side. only thing i know about Server is We are using Node.Js Server.

You dont have to know the server side, but you should know the REST api, the service exposes you to consume.

Ok.I have posted the ESP8266 wifi function which does the communication between Arduino and Server.

void esp_8266() { // String cmd = "AT+CIPSTART=\"TCP\",\""; // AT cammand for TCP/IP connection // cmd += "192.168.1.11"; // api.thingspeak.com IP adress // cmd += "\",5000"; // HTTP port no. // // ser.println(cmd); // Sending AT cammand // p=1; // if(p == 1) // { // if(ser.find("Linked")) // Serching for responce from ESP8266 // { // // Serial.println("Connection Made for Sending data"); // z=0; // } // // p=0; // } // // /String getStr = "GET /update?api_key="; // Generating String to Send Data at Thingspeak // getStr += apiKey; // Placing the Channel API // getStr +="&field1="; // Slecting Field 1 // getStr += DHT.temperature; // Place the Sensor reding // getStr +="&field2="; // Slecting Field 2 // getStr += DHT.humidity; // Place the Sensor reding // getStr +="&field3="; // Slecting Field 3 // getStr += temp; // Place the Sensor reding // getStr +="&field4="; // Slecting Field 4 // getStr += set_temp; // Place the Sensor reding // getStr +="&field5="; // Slecting Field 5 // getStr += Relay1; // Place the Sensor reding // getStr +="&field6="; // Slecting Field 6 // getStr += Relay2; // Place the Sensor reding // getStr +="&field7="; // Slecting Field 7 // getStr += Relay3; // Place the Sensor reding // getStr +="&field8="; // Slecting Field 7 // getStr += m; // Place the Sensor reding // getStr += "\r\n\r\n";/ ////Serial.print(getStr); // Serial Print to view string on serial monitor // // /* String getStr = "GET /log/"; // //getStr += "&field1="; // getStr += "12"; // getStr += "/"; // getStr += "12:30"; // getStr += "/"; // getStr += "0"; // getStr += "/"; // //getStr += "/"; // getStr += DHT.temperature; // // Serial.print(getStr);/ // // // String getStr = "GET /log/deviceid/time/status/"; // / getStr += "deviceid"; // getStr += "time"; // getStr += "status";*/ // getStr += DHT.temperature; // getStr += "/"; // getStr += DHT.humidity; // getStr += "\r\n\r\n"; // // // // // // // // // cmd = "AT+CIPSEND="; // AT command to send Data at TCP server // cmd += String(getStr.length()); // send data length // ser.println(cmd); // Wrighting the AT command to ESP8622 // // if(ser.find(">")) // Serching for responce to send data from ESP8266 // { // // ser.print(getStr); // Printing the string with sensor data to send on ESP8266 module // // // // } // //delay (100);

String cmd = "AT+CIPSTART=\"TCP\",\""; // AT cammand for TCP/IP connection cmd += "192.168.1.11"; // api.thingspeak.com IP adress cmd += "\",5000"; // HTTP port no.

ser.println(cmd); // Sending AT cammand p=1; if(p == 1) { if(ser.find("Linked")) // Serching for responce from ESP8266 {

Serial.println("Connection Made for Receiving data"); z=0; }

p=0; }

int deviceid = serialNumber; String getStr = "GET /log/345/12/status/"; /getStr += "deviceid"; getStr += "time"; // getStr += "status";/ getStr += DHT.temperature; getStr += "/"; getStr += DHT.humidity; getStr += "\r\n\r\n";

cmd = "AT+CIPSEND="; // AT command to send Data at TCP server cmd += String(getStr.length()); // send data length ser.println(cmd); // Wrighting the AT command to ESP8622

if(ser.find(">")) // Serching for responce to send data from ESP8266 {

ser.print(getStr); // Printing the string with sensor data to send on ESP8266 module // int det = ser.print(getStr); // Serial.print(det); //

}

delay (100);

//String url = "/details"; //Serial.print("Requesting URL: "); //Serial.println(url); ser.print(String("GET ") + "/details HTTP/1.1/\r\n" + "192.168.1.11"+ "\r\n" + "Connection: close\r\n\r\n");

// Read all the lines of the reply from server and print them to Serial Serial.println("Respond:"); while(ser.available()){ String line = ser.readStringUntil('\r'); Serial.print(line); }

Serial.println(); Serial.println("closing connection");

//String getStr = "GET /log/getFullYear/getMonth/getDate/getHours/getMinutes/getSeconds/getDay/";

/*else { ser.println("AT+CIPCLOSE"); // Close the TCP/UDP connection

Serial.println("AT+CIPCLOSE"); // alert user on Serial monitor } */ }

see for a newbie blynk may be a better option...

Ok.Thank you.