Hi guys, i recently bought a Wemos D1 ESP8266 for a project of mine, i made the code you see on the bottom of the post, so basically i attached a dht11 sensor to the wemos D1, my goal is posting the data that the sensor constantly read into the IP address (so if i go on internet and type the IP address, humidity and tempereture data are showed in that page) but i have two problems in the code:
-the first one is the IP address, it is not static, depending by the wifi i connect the wemos, the IP changes, and i need the IP address to be static so i can change it whenever i want by the IDE and the IP i write into the IDE will be always that IP for the wemos D1.
-my secondary problem is that i can't read datas onto the IP via internet anyway, even with the IP being dynamic, i made a variable called "i" for humidity and "l" for temperature, so when the sensor reads the data, it writes data under form of l and i in the string you see at the beginning of the code as the string of the page, but it doesn't, it only write l and i when i go and check.
another think is that i can read datas and the connection, for example the IP address, into the serial monitor, so the sensor works, and gives to me every second the data i want.
Please help me out finding my mistackes into the code, i think that i put the ip to be dynamic by calling it "randomSeed" but to be honest i dont know how to put it static if my thoughts are right.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <dht11.h>
dht11 DHT;
#define DHT11_PIN 4
int i = DHT.humidity;
int l = DHT.temperature;
String HeaderPage = "";
String FooterPage = "";
String rootPageBody = "<h2>i , l</h2>"; //here is where datas are showed
String rootWebPage;
const char *wifi_ssid = "WIFI NAME"; //name of the wifi
const char *wifi_password = "WIFI PASSWORD"; //password of the wifi
ESP8266WebServer server(80);
WiFiClient espClient;
void setup() {
Serial.begin(115200);
Serial.println();
setup_wifi();
composeWebPage();
startWebServer();
}
void loop() {
server.handleClient();
int chk;
Serial.print("DHT11, \t");
chk = DHT.read(DHT11_PIN); // READ DATA
switch (chk) {
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum Error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Timeout Error,\t");
break;
default:
Serial.print("Unknown Error,\t");
break;
}
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
delay(1000);
}
void setup_wifi() {
delay(10);
Serial.print("Connecting... ");
Serial.println(wifi_ssid);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
randomSeed(micros());
Serial.println("");
Serial.print("WiFi connect at IP address: ");
Serial.println(WiFi.localIP());
}
void handleRoot() {
server.send(200, "text/html", rootWebPage);
}
void composeWebPage() {
rootWebPage = HeaderPage;
rootWebPage += rootPageBody;
rootWebPage += FooterPage;
}
void startWebServer() {
server.on("/", handleRoot);
server.begin();
Serial.println("SERVER BEGIN!!");
}