Hello guys, this is my first post here, so I hope you can understand what I need advice for.
So, what I have to do is: I need to connect to a WiFi network, through an ESP8266-01, then to connect to an API to take a json file to parse it. So far so good. After I have the json file, or a certain variable I need from that json, I need to send it to the Arduino, in order to print it to and LCD afterwards.
What I have managed to do so far: I managed to program the ESP to take the json, parse it, and print it to the serial monitor in the Arduino IDE. Now I need help in taking the data via serial communication in the Arduino, to print it to the LCD. I have tried with SoftwareSerial, but it doesn't work, maybe i am doing something wrong. I attach here the code that i used to program the ESP.
EDIT: So this is the code i used to program the ESP
#include <HttpClient.h>
#include <ESP8266WiFi.h>
const char* ssid = "MERCUSYS_0392"; //Enter your Wi-Fi SSID
const char* password = "STEAUA123"; //Enter you Wi-Fi Password
String payload; //To store the JSON object as string
const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=Timisoara,ro&APPID=";
const String key = "52ac89c578549fc9806a451e8e66d792";
void setup () {
Serial.begin(9600); //initialise serial monitor to send data to Arduino
WiFi.begin(ssid, password); //connect to the network specified above
while (WiFi.status() != WL_CONNECTED) { //Wait till Wi-Fi is connected
delay(1000);
Serial.print("Connecting.."); //Print Connecting.. till connection is established
}
Serial.println("Connected to the WiFi network");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
//If Wi-Fi connected successfully
HTTPClient http; //start a HTTPClinet as http
http.begin(endpoint + key); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
Serial.println(httpCode);
//Serial.println(payload);
//preluare date fisier JSON
const size_t bufferSize = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + JSON_OBJECT_SIZE(12) + 400;
DynamicJsonBuffer jsonBuffer(bufferSize);
const char* json = "{\"coord\":{\"lon\":21.23,\"lat\":45.75},\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear sky\",\"icon\":\"01n\"}],\"base\":\"stations\",\"main\":{\"temp\":276.16,\"pressure\":1012,\"humidity\":93,\"temp_min\":275.15,\"temp_max\":277.15},\"visibility\":10000,\"wind\":{\"speed\":3.6,\"deg\":290},\"clouds\":{\"all\":0},\"dt\":1544466600,\"sys\":{\"type\":1,\"id\":6926,\"message\":0.3671,\"country\":\"RO\",\"sunrise\":1544421933,\"sunset\":1544453439},\"id\":665087,\"name\":\"Timisoara\",\"cod\":200}";
JsonObject& root = jsonBuffer.parseObject(json);
float coord_lon = root["coord"]["lon"]; // 21.23
float coord_lat = root["coord"]["lat"]; // 45.75
JsonObject& weather0 = root["weather"][0];
int weather0_id = weather0["id"]; // 800
const char* weather0_main = weather0["main"]; // "Clear"
const char* weather0_description = weather0["description"]; // "clear sky"
const char* weather0_icon = weather0["icon"]; // "01n"
const char* base = root["base"]; // "stations"
JsonObject& main = root["main"];
float main_temp = main["temp"]; // 276.16
int main_pressure = main["pressure"]; // 1012
int main_humidity = main["humidity"]; // 93
float main_temp_min = main["temp_min"]; // 275.15
float main_temp_max = main["temp_max"]; // 277.15
int visibility = root["visibility"]; // 10000
float wind_speed = root["wind"]["speed"]; // 3.6
int wind_deg = root["wind"]["deg"]; // 290
int clouds_all = root["clouds"]["all"]; // 0
long dt = root["dt"]; // 1544466600
JsonObject& sys = root["sys"];
int sys_type = sys["type"]; // 1
int sys_id = sys["id"]; // 6926
float sys_message = sys["message"]; // 0.3671
const char* sys_country = sys["country"]; // "RO"
long sys_sunrise = sys["sunrise"]; // 1544421933
long sys_sunset = sys["sunset"]; // 1544453439
long id = root["id"]; // 665087
const char* name = root["name"]; // "Timisoara"
int cod = root["cod"]; // 200
//Print the variables thorugh serial monitor
Serial.print (name);
Serial.print(" ");//send the location details to Arduino
delay(100); //stability delay
Serial.print (main_temp);
Serial.print(" ");//send the temperature details to Arduino
delay(100); //stability delay
}
else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
delay(30000);
}