Esp8266 Client2
Esp8266 Client2
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp8266-
client-server-wi-fi/
The above copyright notice and this permission notice shall be included
in all
copies or substantial portions of the Software.
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;
String temperature;
String humidity;
String pressure;
String data;
unsigned long previousMillis = 0;
const long interval = 5000;
void setup() {
Serial.begin(115200);
Serial.println();
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
while((WiFiMulti.run() == WL_CONNECTED)) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi");
}
void loop(){
getWeatherData();
sendHumidityToNextion();
sendTemperatureToNextion();
delay(10000);
}
void getWeatherData(){
{
unsigned long currentMillis = millis();
void sendTemperatureToNextion()
{
String command = "temperature.txt=\""+String(temperature)+"\"";
Serial.print(command);
endNextionCommand();
}
void endNextionCommand()
{
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
}
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}