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();
}