A very unusual error for me anyway. Happens in both platform I/O and Arduino
the code compiles with no errors and runs locally within your home subnet for me that is 192.168.1.X
I have setup my router for Port forwarding and checked most of the obvious things.
One interesting aspect is if I run on an earlier version of the Arduino board manager 2.4.0 the program runs fine from a remote site if I upgrade to version 2.4.0 R2 I experience the same error but I cannot connect but locally it works fine.
Very strange I do not know where else to post if this is the incorrect area.
If anyone could show me what I’m doing wrong I would much appreciate it.
Thanking you for your help in advance
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "BTHub5-RKSM";
const char* password = ;
ESP8266WebServer server(80);
const int led = LED_BUILTIN;
IPAddress ip(192, 168, 1, 202); // ip of Client
IPAddress gateway(192,168,1,254); // gateway of your network
IPAddress subnet(255,255,255,0);
IPAddress dns(192, 168, 1, 254);
unsigned long delays=2000;
String theme = "darkly";
long Day=0;
int Hour =0;
int Minute=0;
int Second=0;
int HighMillis=0;
int Rollover=0;
String bmp_stv1,bmp_spv1,bmp_sav1; //BMP sensor string values
float bmp_tv1,bmp_tpv1,bmp_tlv1,bmp_thv1; //BMP temperature sensors float values
float bmp_hv1,bmp_hpv1,bmp_hlv1,bmp_hhv1; //BMP humidity sensor float values
float bmp_av1,bmp_apv1,bmp_alv1,bmp_ahv1; //BMP atmospheric sensor float values
String dht_stv1,dht_shv1; //DHT22 sensor string values
float dht_tv1,dht_tpv1,dht_tlv1,dht_thv1; //DHT22 temperature sensor float values
float dht_hv1,dht_hpv1,dht_hlv1,dht_hhv1; //DHT22 humidity sensor float values
String lightsv1,lightsv2,lightsv3,lightsv4,lightsv5;
int lightv1,lightv2,lightv3,lightv4,lightv5;
int lightpv1,lightpv2,lightpv3,lightpv4,lightpv5;
String etatGpio[5] = {"HOME","Page2","Page3","Page4","Page5"};
const uint8_t GPIOPIN[5] = {1,2,3,4,5};
WiFiClient client;
String getwebPage1();
void handleRoot() {
digitalWrite(led, 1);
server.send ( 200, "text/html", getwebPage1() );
//getwebPage1();
digitalWrite(led, 0);
}
void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
Serial.println("Booting");
WiFi.config(ip, dns, gateway, subnet);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println("HTTP server started");
pinMode(2,OUTPUT);
}
void loop(void){
ArduinoOTA.handle();
server.handleClient();
digitalWrite(led,0);
digitalWrite(2,0);
for (int i=0; i <=10; i++) {
ArduinoOTA.handle();
server.handleClient();
delay(50);}
digitalWrite(led,1);
digitalWrite(2,1);
for (int i=0; i <=10; i++) {
ArduinoOTA.handle();
server.handleClient();
delay(50);}
}
String getwebPage1(){
// Return a string containing the HTML code of the page
String page = "<html charset=UTF-8><head><meta http-equiv='refresh' content='15' name='viewport' content='width=device-width, initial-scale=1'/>";
page += "<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script><script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>";
page += "<link href='https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/";
page += theme;
page += "/bootstrap.min.css' rel='stylesheet'>";
page += "<title>ESP8266 Demo </title></head><body>";
page += "<div class='container-fluid'>";
page += "<div class='row'>";
page += "<div class='col-md-12'>";
page += "<h3>Monitoring Service ESP8266 ";
page += " ";
page += "Up Time: ";
page += Day;
page += " Days ";
page += Hour;
page += " Hours ";
page += Minute;
page += " Minutes ";
page += Second;
page += " Seconds ";
page += "</h1>";
page += "<h3></th><th>Mini station Conservatory</h3>";
page += "<ul class='nav nav-pills'>";
page += "<li class='active'>";
page += "<a href='#'> <span class='badge pull-right'>";
page += dht_tv1;
page += "</span> Temperature</a>";
page += "<li class='active'>";
page += "</li><li>";
page += "<li class='active'>";
page += "<a href='#'> <span class='badge pull-right'>";
page += dht_hv1;
page += "</span> Humidity</a>";
page += "</li><li>";
page += "<li class='active'>";
page += "<a href='#'> <span class='badge pull-right'>";
page += bmp_hv1;
page += "</span> Atmospheric Pressure</a>";//*************
page += "</li><li>";
page += "<li class='active'>";
page += "<a href='#'> <span class='badge pull-right'>";
page += lightv1;
page += "</span> Light Value</a></li>";
page += "</ul>";
page += "<table class='table'>"; // Chart of readings
page += "<thead><tr class='active'><th>Sensor<th>Measurement<th>Value<th>PV<th>Low<th>High</tr></thead>";
page += "<tbody>"; // Table content
page += "<tr><td>DHT22</td><td>Temperature</td><td>"; // First line : temperature
page += dht_tv1;
page += "°C</td><td>";
page += dht_tpv1;
page += "<td>";
page += dht_tlv1;
page += "<td>";
page += dht_thv1;
page += "</td></td>";
page += "<tr><td>DHT22</td><td>Humidity</td><td>"; // 2nd line : humidity *************************<tr class='active'>
page += dht_hv1;
page += "%</td><td>";
page += dht_hpv1;
page += "<td>";
page += dht_hlv1;
page += "<td>";
page += dht_hhv1;
page += "</td></tr>";
page += "<tr><td>BMP280</td><td>Temperature</td><td>"; // 3th line : atmospheric pressure
page += bmp_tv1;
page += "°C</td><td>";
page += bmp_tpv1;
page += "<td>";
page += bmp_tlv1;
page += "<td>";
page += bmp_thv1;
page += "</td></tr>";
page += "<tr><td>BMP280</td><td>Atmospheric Pressure</td><td>"; // 3th line : atmospheric pressure
page += bmp_hv1;
page += "mbar</td><td>";
page += bmp_hpv1;
page += "<td>";
page += bmp_hlv1;
page += "<td>";
page += bmp_hhv1;
/*
page += "</td></tr>";
page += "<tr><td>BMP280</td><td>Approximate altitude</td><td>"; // 3th line : atmospheric pressure
page += bmp_av1;
page += "M</td><td>";
page += bmp_apv1;
page += "<td>";
page += bmp_alv1;
page += "<td>";
page += bmp_ahv1;
*/
page += "</td></tr>";
page += "<tr><td>Photoresistor</td><td>Light </td><td>"; // 4th line : Light
page += lightv1;
page += "%<td>";
page += lightpv1;
page += " %</td><td>";
page += "</tbody></table></div></div>";
page += "<div class='row'>";
page += "<div class='container'>";
page += "</body></html>";
page += "<form action='/' method='POST'><button type='button submit'name='1' value='HOME' class='btn btn-info'><span class='badge'>";
page += etatGpio[0];
page += "</span></button>";
page += "<form action='/' method='POST'><button type='button submit'name='2' value='Page2' class='btn btn-primary'> <span class='badge'>";
page += etatGpio[1];
page += "</span></button>";
page += "<form action='/' method='POST'><button type='button submit'name='3' value='Page3' class='btn btn-success'><span class='badge'>";
page += etatGpio[2];
page += "</span></button>";
page += "<form action='/' method='POST'><button type='button submit'name='4' value='Page4' class='btn btn-warning'><span class='badge'>";
page += etatGpio[3];
page += "</span></button>";
page += "<form action='/' method='POST'><button type='button submit'name='5' value='Page5' class='btn btn-danger'><span class='badge'>";
page += etatGpio[4];
page += "</span></button>";
page += "</div><div>";
return page;
}