Hi everyone!
I was happy to use BLYNK last 5 years and it completely fine. As regards this year we forced to use new version. I adapted my code and successfully run device, but have following issue: as I’m in Ukraine and because of russian invasion we have no any more reliable internet and electricity, my project suppose to be able work with different WIFI accesspoints. Blynk 1.0 worked just fine in such conditions using esp8266wifimulti.h library and switching automatically, but BLYNK 2.0 don’t. Device starting, running, connecting to BLYNK in run on main wifi access points, but on another not connecting to BLYNK server after short time reboot. My code is below. Please help - I’m amateur and coding it’s just hobby.
#define BLYNK_TEMPLATE_ID "TMP___________Z"
#define BLYNK_DEVICE_NAME "home"
#define BLYNK_AUTH_TOKEN "KP9-Lt2o_a____________________"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
#include <ESP8266WiFiMulti.h>
#include "GyverTimer.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D5
OneWire oneWire (ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>
#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, SDA, SCL);
#include "DHT.h"
#define DHTPIN D6
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define RELEY D3
#define potent_pin A0
GTimer myTimer(MS);
GTimer myTimer2(MS, 600);
GTimer myTimer3(MS);
int valBase = 6;
int target;
int potent;
int INET;
bool valueR;
boolean value4;
int delta = 2;
int addr_targ = 101;
int addr_reley = 102;
int addr_up = 103;
int addr_Time = 104;
int pinValue;
int pinValue_up;
int tempUP;
ESP8266WiFiMulti wifiMulti;
const uint32_t connectTimeoutMs = 5000;
void WIFIconnect(){
wifiMulti.addAP("AKTA_G****", "******");
wifiMulti.addAP("Vill***iFi", "******");
wifiMulti.addAP("Redmi", "r********75");
wifiMulti.addAP("Pilot", "Pil*******");
wifiMulti.addAP("Virus", "******2004");
wifiMulti.addAP("TP-LINK_E10A6C", "1**********9");
WiFi.mode(WIFI_STA);
wifiMulti.run();
if (wifiMulti.run(5000) == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println(WiFi.SSID());
BlynkEdgent.begin();
}
if (WiFi.status() != WL_CONNECTED) {
unsigned long millis(120000);
Serial.println("No Conncetion");
WiFi.disconnect();
Blynk.disconnect(); }
}
/*void MAINtask(){
}*/
BLYNK_WRITE(V11) {
int pinValue = param.asInt();
Serial.println("inet: " + String(pinValue));
INET = pinValue;
}
void setup()
{
Serial.begin(115200);
delay(100);
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
dht.begin();
sensors.begin();
pinMode (RELEY, OUTPUT);
EEPROM.begin(512);
EEPROM.put(addr_targ, valBase );
myTimer.setInterval(30000);
myTimer2.setInterval(21600000); //6 годин до перезапуску
myTimer3.setInterval(40000);
Serial.println("BEGIN");
WIFIconnect();
//BlynkEdgent.begin();
}
void loop() {
float TEMPin = dht.readTemperature();
float Hymidin = dht.readHumidity();
float TEMPout = sensors.getTempCByIndex(0);
potent = analogRead(potent_pin); // запомнить показания с потенциометра
potent = map(potent, 0, 1023, 5, 30); // перевести в диапазон 0.. 10
potent = constrain(potent, 5, 30);
Serial.println("Potent: "+String(potent));
if (potent >= INET) {
target = potent; }
else if (potent <= INET) {
target = INET; }
Serial.println("Target: " + String(target));
if (TEMPin <= target - delta) {
digitalWrite(RELEY, HIGH);
bool valueR = HIGH;
Serial.println("STATUS: " + String(valueR));
}
else if (TEMPin >= target) {
digitalWrite(RELEY, LOW);
bool valueR = LOW;
Serial.println("STATUS: " + String(valueR)); }
Blynk.virtualWrite(V6, TEMPin);
Serial.println("tempin: " + String(TEMPin));
Blynk.virtualWrite(V7, Hymidin);
Blynk.virtualWrite(V8, TEMPout);
Blynk.virtualWrite(V3, valueR);
Blynk.syncAll();
unsigned long millis(200);
if (myTimer2.isReady()) {
Serial.println("RESTART ");
ESP.restart();}
display.clear();
display.display();
display.drawString(0, 0, "TEMP.inside: " + String(TEMPin));
display.drawString(0, 10, "Hymid.inside:" + String(Hymidin));
display.drawString(0, 20, "TEMP.outside:" + String(TEMPout));
display.drawString(0, 30, "ZADANO V RUCHNU:" +String(potent));
display.drawString(0, 40, "TEMP.targrt I-NET:" +String(INET));
display.drawString(0, 50, "Connected:" +WiFi.SSID());
display.display();
BlynkEdgent.run();
Blynk.syncAll();
}