WeMos D1 - All time disconnecting

Hello,
I have buy WeMos D1 board, but I can’t understand why it is periodical disconnecting. Disconnecting interval is about 1 - 3 seconds, then it reconnecting and disconnecting again. Like that is all time. I think code is simple as possible.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>



char auth[] = ".....................................................";

char ssid[] = "TP-LINK_HOME";
char pass[] = "samtenes";









void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}



 BLYNK_READ(V1)
    {
    // STATUS SEND Start
         count = count +1;
        if (count > 5)
           count  = 0;
      

      if (count == 0)
         Blynk.virtualWrite(1, "<   ");
      if (count == 1)
         Blynk.virtualWrite(1, "  ( ");
      if (count == 2)
         Blynk.virtualWrite(1, "   )");
      if (count == 3)
         Blynk.virtualWrite(1, "    >");
      if (count == 4)
         Blynk.virtualWrite(1, "   )");
      if (count == 5)
         Blynk.virtualWrite(1, "  ( ");
    // STATUS SEND End
    }





    void loop()
    {
    Blynk.run();
    }

Let me check on similar hardware…

1 Like

Usually the Wemos boards are pretty stable (I use them all the time). So it could be something else. When it connects, does it actually work? It could be a firewall issue, bad wifi connection maybe? The integrated antenna of the Wemos is after all, pretty small. Interference from the neighbours (try setting your Wifi point to a different channel).

I just run your code on my NodeMCU - and it works stable for 15 minutes already.
Maybe you have bad connection/weak signal. Try using another board or router (possibly).

BTW, This is a very good example code :wink:

Hi Janis
I copied your code into the Arduino IDE but get
‘count’ was not declared in this scope

So haven’t been able to test your code

I have 3 Wemos D1 boards and they all stay logged on without any issues though

It is very strange, I live in place where neighbors is 300m away, so there is clear from any signals and this board I test near the router, there can’t be week signal. I also was try both, external power supply and power supply from USB (same lost connection). I have two WeMos boards, I have tested both - the same. If I use this simple connection see test then board longest connection time is 15sec usualy it is 2-3 sec. If I load more complicated code, then it was reconnecting every single read (read set to 1sec).

As there can see connection is not lost until I turn on my phone and start to read value evey one second.

[10317] Connected to WiFi
[10317] IP: 192.168.1.113
[10317] Blynk v0.4.0 on Arduino
[10317] Connecting to blynk-cloud.com:8442
[10438] Ready (ping: 1ms).
[127349] Login timeout
[127350] Connecting to blynk-cloud.com:8442
[127448] Ready (ping: 1ms).
[133665] Login timeout
[133668] Connecting to blynk-cloud.com:8442
[133765] Ready (ping: 2ms).
[139703] Login timeout
[139706] Connecting to blynk-cloud.com:8442
[139806] Ready (ping: 2ms).
[146633] Login timeout
[146634] Connecting to blynk-cloud.com:8442
[146736] Ready (ping: 3ms).
[153730] Login timeout
[153730] Connecting to blynk-cloud.com:8442
[153830] Ready (ping: 0ms).
[159778] Login timeout
[159780] Connecting to blynk-cloud.com:8442
[159890] Ready (ping: 0ms).
[166734] Login timeout
[166735] Connecting to blynk-cloud.com:8442
[166835] Ready (ping: 1ms).
[172700] Login timeout
[172702] Connecting to blynk-cloud.com:8442
[172803] Ready (ping: 1ms).
[180763] Login timeout
[180766] Connecting to blynk-cloud.com:8442
[180894] Ready (ping: 1ms).
[186811] Login timeout
[186813] Connecting to blynk-cloud.com:8442
[186917] Ready (ping: 0ms).
[192736] Login timeout
[192738] Connecting to blynk-cloud.com:8442
[192839] Ready (ping: 2ms).

More complicated is looks like this:
In first tab is my room light control, and in this what you see is is my pellet burner control in stove. It is read data from arduino what control stove. Its send room temperature, stove temperature, fire sensor 1 and 2 in % and others…

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "db39dc4630404f06afcaa25cac1f61b8";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TP-LINK_HOME";
char pass[] = "samtenes";



int var;
int count;

int x;
int c;

//Variables for Serial receive<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
bool start = false;
bool end = false;
int inData[27]; // Leave plenty of room
char inDataChar[27]; // Leave plenty of room
byte index1;
byte SerialMem;
String inString_1;
String inString_2;
String inString_3;
String inString_4;
String inString_5;
String inString_6;
String inString_7;
String inString_8;
String inString_9;
String inString_10;

//Variables
int Room_t;
int Stove_t;
int Fire_1;
int Fire_2;
int Mode;
int AutoManual;
int Auger;
int Starter;
int Vent;
int value_x;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int temp;
int temp2;


SimpleTimer timer;



WidgetLED led7(V7);
WidgetLED led8(V8);
WidgetLED led9(V9);
WidgetLED led10(V10);
WidgetLED led11(V11);





void setup()
{
//  Wire.begin();
  Serial.begin(115200);
 // Blynk.begin(auth, ssid, pass);
  // Or specify server using one of those commands:
  //Blynk.begin(auth, ssid, pass, "server.org", 8442);
 Blynk.begin(auth, ssid, pass);

timer.setInterval(1500L, myTimerEvent);
//timer.setInterval(2000L, myTimerEvent2);
}





BLYNK_READ(V1)
{
// STATUS SEND SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
     count = count +1;
    if (count > 5)
       count  = 0;
  
  // Usually, you will need to respond with a virtual pin value.
  if (count == 0)
     Blynk.virtualWrite(1, "<   ");
  if (count == 1)
     Blynk.virtualWrite(1, "  ( ");
  if (count == 2)
     Blynk.virtualWrite(1, "   )");
  if (count == 3)
     Blynk.virtualWrite(1, "    >");
  if (count == 4)
     Blynk.virtualWrite(1, "   )");
  if (count == 5)
     Blynk.virtualWrite(1, "  ( ");
// STATUS SEND SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
}





void myTimerEvent()
{
SerialReceive(); //there is reading Serial info at speed 115200 from another arduino
}


void myTimerEvent2()
{
//led ###########################################
if (AutoManual == 1) //0 = manual / 1 = AUTO
   {
   led8.off();
   led7.on();
   }
   else 
   {
   led8.on();
   led7.off();
   } 

if (Auger == 1) //Auger
   led9.on();
   else
   led9.off();

if (Starter == 1) //starter - 1=on
   led10.on();
   else
   led10.off();  

if (Vent == 1) //vent - 1=on
   led11.on();
   else
   led11.off();  

}



BLYNK_WRITE(12)
{
  BLYNK_LOG("Got a value: %s", param.asInt());
  if(param.asInt() == 1)
    Serial.print("<F>");
}


BLYNK_WRITE(13)
{
  BLYNK_LOG("Got a value: %s", param.asInt());
 if(param.asInt() == 1)
   Serial.print("<B>");
}


BLYNK_WRITE(14)
{
  BLYNK_LOG("Got a value: %s", param.asInt());
 if(param.asInt() == 1)
   Serial.print("<C>");
}


BLYNK_WRITE(15)
{
  BLYNK_LOG("Got a value: %s", param.asInt());
  if(param.asInt() == 1)
    Serial.print("<D>");
    else
    Serial.print("<d>");
}



BLYNK_WRITE(16)
{
  BLYNK_LOG("Got a value: %s", param.asInt());
  Serial.print("<E>");
}



BLYNK_WRITE(17)
{
  BLYNK_LOG("Got a value: %s", param.asInt());
 if(param.asInt() == 1)
   Serial.print("<A>");
}





BLYNK_READ(V2)
{

String str;
char result[5];
result[0]=(Room_t/100)+'0';
result[1]=((Room_t/10)%10)+'0';
result[2]='.';
result[3]=(Room_t%10)+'0';
result[4]='\0';
str +=result;
str +="℃";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(2,buf);

}



BLYNK_READ(V3)
{
String str2;
//char result2[4];
//result2[0]=(temp2/100)+'0';
//result2[1]=((temp2/10)%10)+'0';
//result2[2]=(temp2%10)+'0';
//result2[3]='\0';
str2 +=Stove_t;
str2 +="℃";
//char buf[str.length()+1];
char buf2[8];
str2.toCharArray(buf2,sizeof(buf2));
Blynk.virtualWrite(3,buf2);  
}




BLYNK_READ(V4)
{
Blynk.virtualWrite(4,Fire_1);     
}



BLYNK_READ(V5)
{ 
Blynk.virtualWrite(5,Fire_2);   
}



BLYNK_READ(V6)
{
if (Mode == 0) // mode 0 = 90>..  / 1 = STOP / 2 = keep t
   {
   Blynk.virtualWrite(6,"90>.."); 
   }
if (Mode == 1)
   {
   Blynk.virtualWrite(6,"ASTOP"); 
   }
if (Mode == 2)
   {
    Blynk.virtualWrite(6,"KEEPT"); 
   }  
}









void loop()
{
  Blynk.run();
 
}

There is what is in Serial read:

void SerialReceive ()
{
while (Serial.available() > 0 && SerialMem == 0) //SerialMem - read only then is already done something with received data or it is first time to read.
  {
    int aChar = Serial.read();

  if (aChar == '<') // Start of packet marker read
     {    
     index1 = 0;
     start = true;
     end = false;
     }
     else if (aChar == '>') // End of packet marker read
             {    
             end = true;
             break; // Done reading serial data for now
             }
             else
                 {
                 if (index1 < 27) // Make sure there is room
                    {
                    inData[index1] = aChar; // Add char to array
                    index1++;
                    }
                 }
   }








  // When we get here, there is no more serial data to read,
  // or we have read an end-of-packet marker
  if (start && end)
     {
     SerialMem = 1;
     // We've seen both markers - do something with the data here

     //Print all data array
     for (int index1 = 0; index1 < 25; index1++) //for (int index1 = 0; index1 < 7; index1++)
         {
         inDataChar[index1] = inData[index1]; //convert from int to char, for example int 49 = char 1
         Serial.write(inDataChar[index1]);
         }



         
    inString_1 = ""; //Reset string
    for (int index1 = 0; index1 < 3; index1++)
        {
        if (isDigit(inData[index1]))
        inString_1 += inDataChar[index1]; //add 3 first incoming data to string
        else Serial.println("Data received incorectly,data 1 is NOT DIGIT"); 
        }



    inString_2 = ""; //Reset string
    for (int index1 = 4; index1 < 7; index1++)
        {
        if (isDigit(inData[index1]))
        inString_2 += inDataChar[index1]; //add 3 second incoming data to string
        else Serial.println("Data received incorectly,data 2 is NOT DIGIT"); 
        }


    inString_3 = ""; //Reset string
    for (int index1 = 8; index1 < 11; index1++)
        {
        if (isDigit(inData[index1]))
        inString_3 += inDataChar[index1]; //add 3 third incoming data to string
        else Serial.println("Data received incorectly,data 3 is NOT DIGIT"); 
        }


    inString_4 = ""; //Reset string
    for (int index1 = 12; index1 < 15; index1++)
        {
        if (isDigit(inData[index1]))
        inString_4 += inDataChar[index1]; //add 3 fourth incoming data to string
        else Serial.println("Data received incorectly,data 4 is NOT DIGIT"); 
        }



    inString_5 = ""; //Reset string
    inString_6 = ""; //Reset string
    inString_7 = ""; //Reset string
    inString_8 = ""; //Reset string
    inString_9 = ""; //Reset string
    inString_10 = ""; //Reset string

    if (inData[3] == ',') // Check if 4 data is "," and only then asign string to Value(int)
       {
       Room_t = inString_1.toInt(); //Seperated values_1
       Stove_t = inString_2.toInt(); //Seperated values_2
       Fire_1 = inString_3.toInt(); //Seperated values_3
       Fire_2 = inString_4.toInt(); //Seperated values_4


     
       if (isDigit(inData[16]))
          {        
          inString_5 += inDataChar[16]; //char to string to int
          Mode = inString_5.toInt();
          }
          else Serial.println("Data received incorectly,data 16 is NOT DIGIT"); 

       if (isDigit(inData[18]))
          {
          inString_6 += inDataChar[18]; //char to string to int
          AutoManual = inString_6.toInt();
          }
          else Serial.println("Data received incorectly,data 18 is NOT DIGIT"); 


       if (isDigit(inData[20]))
          {
          inString_7 += inDataChar[20]; //char to string to int
          Auger = inString_7.toInt();
          }
          else Serial.println("Data received incorectly,data 20 is NOT DIGIT"); 


       if (isDigit(inData[22]))
          {
          inString_8 += inDataChar[22]; //char to string to int
          Starter = inString_8.toInt();
          }
          else Serial.println("Data received incorectly,data 22 is NOT DIGIT"); 


       if (isDigit(inData[24]))
          {
          inString_9 += inDataChar[24]; //char to string to int
          Vent = inString_9.toInt();
          }
          else Serial.println("Data received incorectly,data 24 is NOT DIGIT"); 


       if (isDigit(inData[26]))
          {
          inString_10 += inDataChar[26]; //char to string to int
          value_x = inString_10.toInt();
          }
          else Serial.println("Data received incorectly,data 26 is NOT DIGIT"); 
       
       } else Serial.println("Data received incorectly, WITHOUT , SEPERATOR");

/*
    Serial.print(" ");
    Serial.print(Room_t);
    Serial.print(" ");
    Serial.print(Stove_t);
    Serial.print(" ");
    Serial.print(Fire_1);
    Serial.print(" ");
    Serial.print(Fire_2);
    Serial.print(" ");
    Serial.print(Mode);
    Serial.print(" ");
    Serial.print(AutoManual);
    Serial.print(" ");
    Serial.print(Auger);
    Serial.print(" ");
    Serial.print(Starter);
    Serial.print(" ");
    Serial.print(Vent);
    Serial.print(" ");
    Serial.print(value_x); 
    */ 
    Serial.println();

    start = false;
    end = false;
    SerialMem = 0;
    }
 
}

I have previously run this example on my expensive Arduino WiFi module for an year it was working perfectly, but after update to blynk version 0.4.0 I can’t get connection with internet with this module (May be you can help me there too). It is why I buy WeMos D1 to test how it works with blynk, (I planing to use it in future to automatize all) because it is more times cheaper too. But now too no luck :pensive:

I use this board. I see that there on market is diferent look WeMos boards. May be mine is bad one chaise? Or may be there is need some hardware version update? It is just guess.

That doesn’t look like a WeMos board. Suggest you buy a WeMos from their store on AliExpress https://www.aliexpress.com/store/product/WeMos-D1-WiFi-uno-based-ESP8266-for-arduino-Compatible/1331105_32455782552.html

http://www.banggood.com/search/wemos.html

Hi Janis
I’m using Rev2 boards
Check out the pictures on the Banggood site
There is a Rev 1 board that’s obsolete now
Then a Rev 2 board (that’s the ones I have)
Then a Rev 2.1 board which probably is not much different

Can I ask a few things first
Did your code compile and upload to your board using the Arduino IDE ?
Could you try some other code say one of the examples ?
There is a Blynk example sketch where you could just monitor millis on pin 5 if I remember correctly

If you tried that then you could see if your WeMos is working or not

Something like this https://codebender.cc/example/BlynkSimpleEthernet/GettingStarted:PushData#PushData.ino
Just change the include libraries to suit I think

That disconnect is so consistent it is like you are telling it to do it.

Try running the Blynk debug to see deeper…

It might be the case though that you wrote your project some time ago and Blynk changes to the server mean you are not connecting
Are the Blynk libraries up to date I had to replace the old ones with the new when reviving an older project from last year

Hi Janis
I think reads every one second might be causing the log offs you could try shifting that to once every 10 or more secs to check
I would think if it was the same when you were using the Arduino it should work but I would try it anyway
I have a project on here with 10 temp sensors being displayed in Blynk and I had to keep the displayed values read rate down to avoid being logged off
It still looks to me though that you are not getting logged on to the Blynk server

Set all app widgets to PUSH frequency!

2 Likes

Wherever you source your WeMos’ from I would suggest you only buy where you see the WeMos logo.

I don’t know what WeMos translates to in Chinese but the WeMos business seems to be able to protect their logo much better than the word WeMos.

So http://www.banggood.com/WeMos-D1-WiFi-UNO-ESP-12E-Based-ESP8266-Shield-For-Arduino-Compatible-p-1087347.html and D1 r2 v2.1.0 wifi module based esp8266 module geekcreit for arduino - products that work with official arduino boards Sale - Banggood.com sold out-arrival notice look like they might be genuine products and D1 r2 wifi esp8266 development board compatible uno program by ide Sale - Banggood.com looks to be fake.

Personally I wouldn’t buy from Banggood as WeMos’ official website only provide one link to their store and that is with AliExpress.

@Janis WeMos charge $6.50 plus delivery for their D1 boards with little or no discount for bulk purchases. They are also considered to one of the cheapest suppliers around. So you are highly unlikely to see a real WeMos D1 board on Ebay for $4.50 including delivery.

That said, many of the fakes do function reasonably well from what I have read.

Ignoring your full sketch and turning to your basic test sketch @Dave1829 is right you should look to use a PUSH frequency and SimpleTimer. 1000ms intervals are no problem for Blynk and even down to 10ms shouldn’t normally be a problem but most projects don’t need intervals below 1000ms.

Most regular Blynkers only use PUSH frequencies and they have their reasons for this.

This is the defacto example you should use to test your “WeMos” (but change the Ethernet libraries to ESP etc) and it appears in the Arduno IDE https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino

If this fails to stay connected then I think you can put the “WeMos” in the bin. If it does stay connected let us know and we might be able to find the problems in your full sketch. If your full sketch is not using PUSH frequency for all applicable widgets you should consider changing them.

Good point Costas
Regards buying a Wemos
All the pictures of the boards are on the same webpage at Banggood so it was just to help identify the board I haven’t heard of a Rev3 although there may be one

Thank you all for help! I have set all data to push and use Simple timer, and now it works fine. I have find also that can’t be pushed data for 4 led at once, then it disconnecting again. I have usetimer.restartTimer(); to separate all data to not push all data at once but in different times with step of 150 milliseconds. And now it works fine!

There is part of code.

int SerialReceive_reset;
int led1Push_reset;
int led2Push_reset;
int value1Push_reset;
int value2Push_reset;



void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
 
timer.setInterval(1000L, Connection_timer);
SerialReceive_reset = timer.setInterval(1000L, SerialReceive_timer);
led1Push_reset = timer.setInterval(1000L, led1Push_timer);
led2Push_reset = timer.setInterval(1000L, led2Push_timer);
value1Push_reset = timer.setInterval(1500L, value1Push_timer);
value2Push_reset = timer.setInterval(1000L, value2Push_timer);

timer.setTimeout(150, OnceOnlyTask1); //Serial receive  delay for start
timer.setTimeout(300, OnceOnlyTask2); //led 1 2 3   delay for start
timer.setTimeout(450, OnceOnlyTask3); //led 4 5     delay for start
timer.setTimeout(600, OnceOnlyTask4); //value 1 2   delay for start
timer.setTimeout(750, OnceOnlyTask4); //value 3 4   delay for start
}




void OnceOnlyTask1() 
{
timer.restartTimer(SerialReceive_reset);
}

void OnceOnlyTask2() 
{
timer.restartTimer(led1Push_reset);
}

void OnceOnlyTask3() 
{
timer.restartTimer(led2Push_reset);
}

void OnceOnlyTask4() 
{
timer.restartTimer(value1Push_reset);
}

void OnceOnlyTask5() 
{
timer.restartTimer(value2Push_reset);
}

Well done Janis and thanks for coming back with the solution