New strange thing from my nre project…
With no BLYNK_DEBUG my sketch disconnect frquently from my local server… is I enable the BLYNK_DEBUG I have no more disconnections.
I know it’s a very strange fact… so… my hardware is a WeMos D1 mini R2 and this is my code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_DEBUG
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Time.h>
#include <WidgetRTC.h>
#include <Adafruit_NeoPixel.h>
#define NeoPixel_PIN D2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, NeoPixel_PIN, NEO_GRB + NEO_KHZ800);
char auth[] = "2affa38aa6f245d39dff7ff0ff2ec4c7";
WidgetTerminal TERM(V5);
WidgetRTC RTC;
WidgetLCD LCD(V32);
BLYNK_ATTACH_WIDGET(RTC, V0);
SimpleTimer myTimer;
boolean blynkConnected;
float tmin;
float tmax;
float temperature;
float humidity;
float heatindex;
float temperatureArray[4];
float humidityArray[4];
float heatindexArray[4];
byte RGB[3];
void setup() {
blynkConnected = false;
Serial.begin(9600);
pixels.begin();
NeoPixel_Test(0,0,0);
Blynk.begin(auth, "FRITZ!Box Fon WLAN 7390", "4506523768287213", "192.168.1.110", 8442);
myTimer.setInterval(10000, BLYNK_CHECK_CONN);
}
void debugMillis(String myString){
Serial.println("[" + String(millis()) + "] " + myString);
}
void NeoPixel_Test(int R, int G, int B){
if (R >= 0) RGB[0] = R;
if (G >= 0) RGB[1] = G;
if (B >= 0) RGB[2] = B;
pixels.setPixelColor(0, pixels.Color(RGB[0], RGB[1], RGB[2]));
pixels.show();
}
void BLYNK_CHECK_CONN() {
debugMillis(F("BLYNK_CHECK_CONN()"));
if (Blynk.connected()) {
blynkConnected = true;
} else {
blynkConnected = false;
debugMillis(F("Blynk disconnected!"));
}
}
BLYNK_CONNECTED(){
debugMillis(F("BLYNK_CONNECTED()"));
blynkConnected = true;
Blynk.syncVirtual(V0); //RTC
myTimer.setTimeout(10000, BLYNK_CONNECTED_DELAYED);
}
void BLYNK_CONNECTED_DELAYED(){
debugMillis(F("BLYNK_CONNECTED_DELAYED()"));
Blynk.syncVirtual(V3); //T1
delay(100);
Blynk.syncVirtual(V4); //T2
delay(100);
Blynk.syncVirtual(V6); //T3
delay(100);
Blynk.syncVirtual(V7); //T4
delay(100);
Blynk.syncVirtual(V30); //TEMP MIN
delay(100);
Blynk.syncVirtual(V31); //TEMP MAX
}
BLYNK_WRITE(V1){ // Modo: Aut./Man.
debugMillis(F("BLNK_WRITE(V1)"));
}
BLYNK_WRITE(V2){
debugMillis(F("BLNK_WRITE(V2)"));
}
BLYNK_WRITE(V3){ // Timer 1
debugMillis(F("BLNK_WRITE(V3)"));
TimeInputParam t(param);
if (t.hasStartTime()) {
Serial.println(String(F("\tStart: ")) +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
} else if (t.isStartSunrise()) {
Serial.println(F("\tStart at Sunrise"));
} else if (t.isStartSunset()) {
Serial.println(F("\tStart at sSunset"));
} else {
// Do nothing
}
if (t.hasStopTime()) {
Serial.println(String(F("\tStop: ")) +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
} else if (t.isStopSunrise()) {
Serial.println(F("\tStop at Sunrise"));
} else if (t.isStopSunset()) {
Serial.println(F("\tStop at Sunset"));
} else {
// Do nothing: no stop time was set
}
Serial.println(String(F("\tTime zone: ")) + t.getTZ());
Serial.println(String(F("\tTime zone offset: ")) + t.getTZ_Offset());
// Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String(F("\tDay ")) + i + F(" is selected"));
}
}
}
BLYNK_WRITE(V4){ // Timer 2
debugMillis(F("BLNK_WRITE(V4)"));
TimeInputParam t(param);
if (t.hasStartTime()) {
Serial.println(String(F("\tStart: ")) +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
} else if (t.isStartSunrise()) {
Serial.println(F("\tStart at Sunrise"));
} else if (t.isStartSunset()) {
Serial.println(F("\tStart at sSunset"));
} else {
// Do nothing
}
if (t.hasStopTime()) {
Serial.println(String(F("\tStop: ")) +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
} else if (t.isStopSunrise()) {
Serial.println(F("\tStop at Sunrise"));
} else if (t.isStopSunset()) {
Serial.println(F("\tStop at Sunset"));
} else {
// Do nothing: no stop time was set
}
Serial.println(String(F("\tTime zone: ")) + t.getTZ());
Serial.println(String(F("\tTime zone offset: ")) + t.getTZ_Offset());
// Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String(F("\tDay ")) + i + F(" is selected"));
}
}
}
BLYNK_WRITE(V6){ // Timer 3
debugMillis(F("BLNK_WRITE(V6)"));
TimeInputParam t(param);
if (t.hasStartTime()) {
Serial.println(String(F("\tStart: ")) +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
} else if (t.isStartSunrise()) {
Serial.println(F("\tStart at Sunrise"));
} else if (t.isStartSunset()) {
Serial.println(F("\tStart at sSunset"));
} else {
// Do nothing
}
if (t.hasStopTime()) {
Serial.println(String(F("\tStop: ")) +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
} else if (t.isStopSunrise()) {
Serial.println(F("\tStop at Sunrise"));
} else if (t.isStopSunset()) {
Serial.println(F("\tStop at Sunset"));
} else {
// Do nothing: no stop time was set
}
Serial.println(String(F("\tTime zone: ")) + t.getTZ());
Serial.println(String(F("\tTime zone offset: ")) + t.getTZ_Offset());
// Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String(F("\tDay ")) + i + F(" is selected"));
}
}
}
BLYNK_WRITE(V7){ // Timer 4
debugMillis(F("BLNK_WRITE(V7)"));
TimeInputParam t(param);
if (t.hasStartTime()) {
Serial.println(String(F("\tStart: ")) +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
} else if (t.isStartSunrise()) {
Serial.println(F("\tStart at Sunrise"));
} else if (t.isStartSunset()) {
Serial.println(F("\tStart at sSunset"));
} else {
// Do nothing
}
if (t.hasStopTime()) {
Serial.println(String(F("\tStop: ")) +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
} else if (t.isStopSunrise()) {
Serial.println(F("\tStop at Sunrise"));
} else if (t.isStopSunset()) {
Serial.println(F("\tStop at Sunset"));
} else {
// Do nothing: no stop time was set
}
Serial.println(String(F("\tTime zone: ")) + t.getTZ());
Serial.println(String(F("\tTime zone offset: ")) + t.getTZ_Offset());
// Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String(F("\tDay ")) + i + F(" is selected"));
}
}
}
BLYNK_WRITE(V10){ // Stanza 1: Temperatura
debugMillis(F("BLNK_WRITE(V10)"));
temperatureArray[0] = param[0].asFloat();
}
BLYNK_WRITE(V11){ // Stanza 1: Umidità
debugMillis(F("BLNK_WRITE(V11)"));
humidityArray[0] = param[0].asFloat();
}
BLYNK_WRITE(V30){ // T.Min
debugMillis(F("BLNK_WRITE(V30)"));
float tmin = param[0].asFloat();
Serial.println("\tT.MIN: " + String(tmin) + "°C");
}
BLYNK_WRITE(V31){ // T.Max
debugMillis(F("BLNK_WRITE(V31)"));
float tmin = param[0].asFloat();
Serial.println("\tT.MAX: " + String(tmin) + "°C");
}
BLYNK_READ(V33) { // Temp. media
debugMillis(F("BLNK_WRITE(V33)"));
temperature = 0;
byte index = 0;
for (byte i = 0; i < 4; i++) {
if (temperatureArray[i] > 0) {
temperature = temperature + temperatureArray[i];
index++;
}
}
temperature = temperature / index++;
Blynk.virtualWrite(V33, String(temperature,1));
}
BLYNK_READ(V34) { // Umid. media
debugMillis(F("BLNK_WRITE(V34)"));
humidity = 0;
byte index = 0;
for (byte i = 0; i < 4; i++) {
if (humidityArray[i] > 0) {
humidity = humidity + humidityArray[i];
index++;
}
}
humidity = humidity / index++;
Blynk.virtualWrite(V34, String(humidity,1));
}
void loop() {
myTimer.run();
Blynk.run();
if (blynkConnected) {
NeoPixel_Test(0,255,-1);
} else {
NeoPixel_Test(255,0,-1);
}
}
… and this is my serial terminal …
¶HPÙtAHäLØxtHìø[248] Connecting to FRITZ!Box Fon WLAN 7390
[2749] Connected to WiFi
[2749] IP: 192.168.1.186
[2749] Blynk v0.3.9 on Arduino
[5001] Connecting to 192.168.1.110:8442
[5011] <[02|00|01|00] 2affa38aa6f245d39dff7ff0ff2ec4c7
[5017] >[00|00|01|00]È
[5017] Ready (ping: 1ms).
[5022] <[11|00|01|00]Gver[00]0.3.9[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]Arduino[00]build[00]Sep 29 2016 11:42:29[00]
[5158] BLYNK_CONNECTED()
[5180] <[10|00|02|00|04]vr[00]0
[5217] >[14|00|01|00|12]
[5241] >pm[00]5[00]out[00]0[00]in[00]0[00]in
[5289] >[00|00|01|00]È
[5314] >[14|00|02|00|0F]
[5341] >vw[00]0[00]1475149370
[5373] Time sync: OK
[12749] BLYNK_CHECK_CONN()
[13090] >[0F]5o[00|0D]
[13090] >vw[00]10[00]24.0000
[13090] BLNK_WRITE(V10)
[13094] >[0F]5p[00|0D]
[13094] >vw[00]11[00]31.0000
[13095] BLNK_WRITE(V11)
[13122] >[0F]5q[00|0C]
[13147] >vw[00]12[00]23.265
[15217] BLYNK_CONNECTED_DELAYED()
[15217] <[10|00|03|00|04]vr[00]3
[15321] <[10|00|04|00|04]vr[00]4
[15423] <[10|00|05|00|04]vr[00]6
[15562] <[10|00|06|00|04]vr[00]7
[15665] <[10|00|07|00|05]vr[00]30
[15771] <[10|00|08|00|05]vr[00]31
[15778] >[14|00|03|00]-
[15779] >vw[00]3[00]28800[00]32400[00]Africa/Harare[00]1,2,3,4,5[00]7200
[15779] BLNK_WRITE(V3)
Start: 8:0:0
Stop: 9:0:0
Time zone: Africa/Harare
Time zone offset: 7200
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
[15992] >[14|00|04|00]-
[16018] >vw[00]4[00]61200[00]75600[00]Africa/Harare[00]1,2,3,4,5[00]7200
[16094] BLNK_WRITE(V4)
Start: 17:0:0
Stop: 21:0:0
Time zone: Africa/Harare
Time zone offset: 7200
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
[16311] >[14|00|07|00|08]
[16339] >vw[00]30[00]15
[16364] BLNK_WRITE(V30)
T.MIN: 15.00°C
[16409] >[14|00|08|00|08]
[16438] >vw[00]31[00]22
[16463] BLNK_WRITE(V31)
T.MAX: 22.00°C
[22167] >[14]5x[00|05]
[22169] >vr[00]10
[22170] >[14]5y[00|05]
[22170] >vr[00]11
[22170] >[14]5z[00|05]
[22170] >vr[00]12
[22170] >[14]5{[00|05]
[22195] >vr[00]33
[22213] BLNK_WRITE(V33)
[22240] <[14]5{[00|0A]vw[00]33[00]24.0
[22322] >[14]5|[00|05]
[22323] >vr[00]34
[22326] BLNK_WRITE(V34)
[22353] <[14]5|[00|0A]vw[00]34[00]31.0
[22749] BLYNK_CHECK_CONN()
[23149] >[0F]5‚[00|0D]
[23149] >vw[00]10[00]24.0000
[23149] BLNK_WRITE(V10)
[23154] >[0F]5ƒ[00|0D]
[23154] >vw[00]11[00]31.0000
[23154] BLNK_WRITE(V11)
[23181] >[0F]5„[00|0C]
[23206] >vw[00]12[00]23.265
[32398] <[06|00|09|00|00]
[32401] >[00|00|09|00]È
[32749] BLYNK_CHECK_CONN()
[42402] <[06|00|0A|00|00]
[42405] >[00|00|0A|00]È
[42749] BLYNK_CHECK_CONN()
[43262] >[0F]5¡[00|0D]
[43263] >vw[00]10[00]24.0000
[43264] BLNK_WRITE(V10)
[43264] >[0F]5¢[00|0D]
[43264] >vw[00]11[00]31.0000
[43267] BLNK_WRITE(V11)
[43294] >[0F]5£[00|0C]
[43319] >vw[00]12[00]23.265
[52171] >[14]5ª[00|05]
[52172] >vr[00]10
[52173] >[14]5«[00|05]
[52173] >vr[00]11
[52174] >[14]5¬[00|05]
[52174] >vr[00]12
[52174] >[14]5[00|05]
[52198] >vr[00]33
[52217] BLNK_WRITE(V33)
[52244] <[14]5[00|0A]vw[00]33[00]24.0
[52326] >[14]5®[00|05]
[52327] >vr[00]34
[52329] BLNK_WRITE(V34)
[52356] <[14]5®[00|0A]vw[00]34[00]31.0
[52749] BLYNK_CHECK_CONN()
[62330] <[06|00|0B|00|00]
[62333] >[00|00|0B|00]È
[62749] BLYNK_CHECK_CONN()
[63333] >[0F]5Â[00|0D]
[63334] >vw[00]10[00]24.0000
[63334] BLNK_WRITE(V10)
[63334] >[0F]5Ã[00|0D]
[63335] >vw[00]11[00]31.0000
[63338] BLNK_WRITE(V11)
[63365] >[0F]5Ä[00|0C]
[63390] >vw[00]12[00]23.265
[72333] <[06|00|0C|00|00]
[72336] >[00|00|0C|00]È
[72749] BLYNK_CHECK_CONN()
[73212] >[0F]5Ó[00|0D]
[73212] >vw[00]10[00]24.0000
[73213] BLNK_WRITE(V10)
[73217] >[0F]5Ô[00|0D]
[73218] >vw[00]11[00]31.0000
[73218] BLNK_WRITE(V11)
[73244] >[0F]5Õ[00|0C]
[73269] >vw[00]12[00]23.265
[82278] >[14]5Ü[00|05]
[82278] >vr[00]10
[82280] >[14]5Ý[00|05]
[82280] >vr[00]11
[82281] >[14]5Þ[00|05]
[82281] >vr[00]12
[82281] >[14]5ß[00|05]
[82305] >vr[00]33
[82324] BLNK_WRITE(V33)
[82351] <[14]5ß[00|0A]vw[00]33[00]24.0
[82434] >[14]5à[00|05]
[82435] >vr[00]34
[82436] BLNK_WRITE(V34)
[82463] <[14]5à[00|0A]vw[00]34[00]31.0