Hi friends. when I reboot my wifi router the nodemcu connection lost and cannot be reconnecting to server but it connected to the wifi router. the code is blow:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SI7021.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <BH1750.h>
BH1750 lightMeter;
char auth[] = "fe5078fcb5f04f5384ac70cb9ab91697"; //Put your blink token
char ssid[] = "MikroTik Tesla"; //Put your SSID of your connection
char pass[] = "12345678"; //Put your Password of your connection
char server[] = "10.5.50.18";
SI7021 sensor;
SimpleTimer timer;
#define I2C_SCL 12 //D6
#define I2C_SDA 13 //D7
Adafruit_BMP085 bmp;
#define ledPin 15
#define pirPin 14
float dst, bt, bp, ba, q;
char dstmp[20], btmp[20], bprs[20], balt[20];
bool bmp085_present = true;
void setup()
{
WiFi.mode(WIFI_STA);
Serial.begin(115200); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass, server, 8080); //insert here your SSID and password
Wire.begin(I2C_SDA, I2C_SCL);
delay(10);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
//while (1) {}
}
timer.setInterval(1000L, sendUptime);
timer.setInterval(1000L, PIRval);
timer.setInterval(1000L, pir);
timer.setInterval(1000L, dozd);
timer.setInterval(1000L, sendWifi);
lightMeter.begin();
//sensor.begin(SDA,SCL);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
}
int pirState;
int val;
int x;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0){
x = param.asInt();
}
void PIRval()
{
val = digitalRead(pirPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
void pir()
{
if (x == 1){
if (digitalRead(pirPin) == HIGH){
Blynk.notify("??? ??? ???? ??");
}
}
}
void sendUptime()
{
float temperature = sensor.getCelsiusHundredths();
Blynk.virtualWrite(5, (float)temperature/100);
float humidity = sensor.getHumidityPercent();
Blynk.virtualWrite(6, humidity); // virtual pin
uint16_t lux = lightMeter.readLightLevel();
Blynk.virtualWrite(4, lux);
float bp = bmp.readPressure();
Blynk.virtualWrite(9,(float)bp/100);
float ba = bmp.readAltitude();
Blynk.virtualWrite(7, ba);
float bt = bmp.readTemperature();
Blynk.virtualWrite(12, bt);
float dst = bmp.readSealevelPressure(520)/100;
Blynk.virtualWrite(13, dst);
float q = analogRead(A0);
Blynk.virtualWrite(2, q);
}
void dozd()
{
float val = digitalRead(pirPin);
Blynk.virtualWrite(3, val);
}
void sendWifi()
{
Blynk.virtualWrite(15, map(WiFi.RSSI(), -105, -40, 0, 100) );
}
void loop()
{
Blynk.run();
timer.run();
}
All this time in the Blynk forum and you are still using Blynk.begin() when all other reconnection topics refer to Blynk.config() and proper watchdog type timers, reconnection routines and so on
Perhaps more time spent searching and reading all the reconnection topics
Not without taking more time than I want to… sorry. Whatever your issue is, it is resolvable with a bit of debugging on your part.
But I would start by staggering your timers… they are all trying to run at the exact same time… another common topic/issue that I am surprised you haven’t read about
set timers like that
timer.setInterval(1000L, sendUptime);
timer.setInterval(1100L, PIRval);
timer.setInterval(1200L, pir);
timer.setInterval(1300L, dozd);
timer.setInterval(1400L, sendWifi);
Try timing your sendUpTime… maybe it takes longer than 400ms to finish so that could be the problem…
Put unsigned long currentMillis = millis(); at the beginning of the function and another unsigned long currentMillis2 = millis(); at the end and print them out and you’ll now if the problem is there…
void StartOfTestingFunction()
{
unsigned long temp;
temp = millis();
// your function is here
functionDuration = millis() - temp;
// print with you convenient way the functionDuration to serial or to terminal widget etc
|
and remove slash one by one
I think you have a sensor that needs more time …
I have had the same issue with DHT11 sensor when I tried my first blynk project
…or, you could use setTimeout -> check this post: [SOLVED] Timer.setinterval - best use?
If you set it this way you will not need to take in consideration how long does a function run so there will be no collisions…
You will need to change your functions a little bit though…