Hi again,
i found the fault, hope it is usefull for someone.
Now the board have a static IP.
in this line
WiFi.config(arduino_ip, dns_ip, gateway_ip, subnet_mask);
was “dns_ip” missing.
Here is my code. I test all with no internet, no wifi, no router, all is working.
This system must run a few weeks alone, its possible that the internetline is down or the router is down, but the sytem must keep running. So its very important that the code is running with out connection and only with short breaks for try to connect.
In this sketch i test every minute, later every hour if a connection is true.
But i have some question again.
What can i do better?
When the system is running and than i cut the wifi or router, Blynk.run(); beguin
every second to try a connection, because the variable Connected2Blynk hold true.
#include <ESP8266WiFi.h> //WemosD1R1
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "TP-LINK_AP_B4F2";
char pass[] = "xxxxxxxxxxxxxxx";
char server[] = "blynk-cloud.com"; // URL for Blynk Cloud Server
int port = 80;
byte arduino_mac[] = { 0x5C, 0xCF, 0x7F, 0x0F, 0x63, 0xC0 };
//IPAddress server_ip ( 139, 59, 206, 133); // blynk Server
IPAddress arduino_ip ( 192, 168, 1, 80);
IPAddress dns_ip ( 192, 168, 1, 10);
IPAddress gateway_ip ( 192, 168, 1, 10);
IPAddress subnet_mask( 255, 255, 255, 0);
WiFiClient espClient;
bool Connected2Blynk = false;
unsigned long startCheckConnection;
void setup() {
Serial.begin(115000);
delay(10);
MyWiFi();
}
void MyWiFi() {
int mytimeout = millis() / 1000;
WiFi.config(arduino_ip, dns_ip, gateway_ip, subnet_mask);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
if ((millis() / 1000) > mytimeout + 1) {
break;
}
}
Blynk.config(auth);
Connected2Blynk = Blynk.connect();
mytimeout = millis() / 1000;
while (Blynk.connect() == false) {
if ((millis() / 1000) > mytimeout + 1) {
break;
}
}
}
void CheckConnection() {
if ( millis() > startCheckConnection + 60000) { //now check every minute, later every hour
startCheckConnection = millis();
if (!Connected2Blynk) {
MyWiFi();
}
}
}
void loop() {
CheckConnection();
if (Connected2Blynk) {
Blynk.run();
}
Serial.println("running Code");
}
Thankyou for your patience with me
I learned a lot in the last days.