#include<WiFi.h>#include<HTTPClient.h>constchar*ssid="REPLACE_WITH_YOUR_SSID";constchar*password="REPLACE_WITH_YOUR_PASSWORD";//Your Domain name with URL path or IP address with pathconstchar*serverName="http://192.168.1.106:1880/update-sensor";// the following variables are unsigned longs because the time, measured in// milliseconds, will quickly become a bigger number than can be stored in an int.unsignedlonglastTime=0;// Timer set to 10 minutes (600000)//unsigned long timerDelay = 600000;// Set timer to 5 seconds (5000)unsignedlongtimerDelay=5000;voidsetup(){Serial.begin(115200);WiFi.begin(ssid,password);Serial.println("Connecting");while(WiFi.status()!=WL_CONNECTED){delay(500);Serial.print(".");}Serial.println("");Serial.print("Connected to WiFi network with IP Address: ");Serial.println(WiFi.localIP());Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");}voidloop(){//Send an HTTP POST request every 10 minutesif((millis()-lastTime)>timerDelay){//Check WiFi connection statusif(WiFi.status()==WL_CONNECTED){WiFiClientclient;HTTPClienthttp;// Your Domain name with URL path or IP address with pathhttp.begin(client,serverName);// If you need Node-RED/server authentication, insert user and password below//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");// Specify content-type headerhttp.addHeader("Content-Type","application/x-www-form-urlencoded");// Data to send with HTTP POSTStringhttpRequestData="api_key=tPmAT5Ab3j7F9&sensor=BME280&value1=24.25&value2=49.54&value3=1005.14";// Send HTTP POST requestinthttpResponseCode=http.POST(httpRequestData);// If you need an HTTP request with a content type: application/json, use the following://http.addHeader("Content-Type", "application/json");//int httpResponseCode = http.POST("{\"api_key\":\"tPmAT5Ab3j7F9\",\"sensor\":\"BME280\",\"value1\":\"24.25\",\"value2\":\"49.54\",\"value3\":\"1005.14\"}");// If you need an HTTP request with a content type: text/plain//http.addHeader("Content-Type", "text/plain");//int httpResponseCode = http.POST("Hello, World!");Serial.print("HTTP Response code: ");Serial.println(httpResponseCode);// Free resourceshttp.end();}else{Serial.println("WiFi Disconnected");}lastTime=millis();}}
// Your Domain name with URL path or IP address with pathhttp.begin(serverName);// If you need Node-RED/server authentication, insert user and password below//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");// Specify content-type headerhttp.addHeader("Content-Type","application/x-www-form-urlencoded");// Data to send with HTTP POSTStringhttpRequestData="api_key=tPmAT5Ab3j7F9&sensor=BME280&value1=24.25&value2=49.54&value3=1005.14";// Send HTTP POST requestinthttpResponseCode=http.POST(httpRequestData);