Blynk Login Issue (memory)

Something in Blynk is going south when leftover memory (after compile) hits
the 766 byte arena. Find below a simple sketch and monitor window results. The
first results are successful and the second, no so much. I turned on BLYNK_DEBUG
for more info. The blynk app just has a couple of value widgets being updated in
a manual timer loop (trying to minimize library involvement). Memory is the issue
but why? What are the local memory requirements needed by Blynk to run wifi?

Here are the board/connection particulars:

  1. UNO with ESP8266, here is the AT+GMR dump for the ESP
    AT version: 8 2015 14:45:58)
    SDK version:1.3.0
    Ai-Thinker Technology Co.,Ltd.
    Build: Sep 11 2015 11:48:04

  2. ESP using AltSoftSerial on pins 8&9. The tx (from uno) has a divider network and the
    ESP is powered by a separate +3.3V supply, common ground. Note: This library works very
    well. I’ve ran tests at 57600 while having a background timer (100ms callback, printing chars),
    plus i/o pin 13 toggling and did not capture garbage characters (serial monitor window).
    Program has ports set at 19200.

  3. The only modification to the program is done with global variable z (right above loop()).
    I just sub/add a dimension to change the memory requirements. This in turn results in connect
    and no connect.

  4. I’ve used Blynk.begin with the same results. The code below forces a disconnect from the AP
    first then reconnects. This ensures a consistent starting point prior to blynk login. I pass
    the wifi and auth off to blynk.config and then try a connect. Note: serial port cleanup done

  5. After the login fault in Blynk, I can still drop to the command prompt and ping
    the ESP. This clearly shows the ESP is connected to the AP on my network.


 #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
 #define BLYNK_DEBUG
 #include <ESP8266_Lib.h>
 #include <BlynkSimpleShieldEsp8266.h>
 #include <AltSoftSerial.h> \\uses timer2

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

// Your WiFi credentials.
// Set password to "" for open networks.
 char ssid[] =  "xx";
 char pass[] =  "xx";

// This is for the ESP8266 Wifi Adapter
 AltSoftSerial EspSerial(8, 9); // RX, TX
// ESP8266 baud rate:
 #define ESP8266_BAUD 19200
// Attach Serial to Wifi
 ESP8266 wifi(&EspSerial);

  void myTimerEvent()
     Serial.println("Inside Timer Loop");
     Blynk.virtualWrite(V0,  millis() / 1000);
     Blynk.virtualWrite(V2,  (millis() / 1000)+1);

void setup() {
  // put your setup code here, to run once:

  char c;
  // Set console baud rate
  // Set ESP8266 baud rate

  Serial.println("Clearing Ports");
  while (EspSerial.available())
   while (Serial.available())
  Serial.println("Forcing ESP Disconnect");
  //Force ESP8266 to disconnect from wireless end point
  while (EspSerial.available())
// Login to wifi
  while (EspSerial.available())
  Serial.println("\nBefore Blynk Connect=" + String(Blynk.connected()));
// Pass wifi and auth info to blynk
// Try login to blynk
//  Blynk.begin(auth, wifi, ssid, pass);
  while (!Blynk.connected())
    if (Blynk.connect(3000))
      BLYNK_LOG("Reconnect Passed");
      BLYNK_LOG("Reconnect Failed");
  Serial.println("After Blynk Connect=" + String(Blynk.connected()));
 //Should be good IP
  Serial.println("Wifi Connected At: " + wifi.getLocalIP());

bool firstrun=true;
String z[14]={a};
void loop() {
  // put your main code here, to run repeatedly:
  static unsigned long lastmillis=millis();;
  if (firstrun)
    Serial.println("Inside Loop()");
    firstrun = false;
  // Run timer loop every sec 
  if (Blynk.connected() && (millis()-lastmillis) >= 1000)
      Serial.println("Inside Timer Loop, Blynk Connect=" + String(Blynk.connected()));
Memory after compile (FAIL MODE):
Sketch uses 18,472 bytes (57%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,282 bytes (62%) of dynamic memory, leaving 766 bytes for
local variables. Maximum is 2,048 bytes.
Before Blynk Connect=0
[146] Blynk v0.4.0 on Arduino Uno
[7362] <[02|00|01|00] 817daae420d6466d900c1b0b5bf8c4fa
[7522] >[00|00|01|00|C8]
[7522] Ready (ping: 19ms).
[7523] <[11|00|01|00]fver[00]0.4.0[00]h-beat[00]10[00]buff-in[00]256[00]dev
[17596] Cmd error
[22606] Login timeout
.[37798] <[02|00|01|00] 817daae420d6466d900c1b0b5bf8c4fa
[37940] Reconnect Failed
.[40979] Reconnect Failed
Memory after compile (PASS MODE):
Sketch uses 18,472 bytes (57%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,276 bytes (62%) of dynamic memory, leaving 772 bytes for 
local variables. Maximum is 2,048 bytes.
Before Blynk Connect=0
[139] Blynk v0.4.0 on Arduino Uno
[7363] <[02|00|01|00] 817daae420d6466d900c1b0b5bf8c4fa
[7524] >[00|00|01|00|C8]
[7524] Ready (ping: 19ms).
[7525] <[11|00|01|00]fver[00]0.4.0[00]h-beat[00]10[00]buff-in[00]256[00]dev
[7739] <[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]ESP8266[00]
[7884] <build[00]Nov  1 2016 15:31:10[00]
After Blynk Connect=1
Wifi Connected At: +CIFSR:STAIP,""
[8107] >[00|00|01|00|C8]
Inside Loop()
Inside Timer Loop
[9100] <[14|00|02|00|06]vw[00]0[00]9
[9324] <[14|00|03|00|07]vw[00]2[00]10
Inside Timer Loop, Blynk Connect=1
Inside Timer Loop
[10458] <[14|00|04|00|07]vw[00]0[00]10
[10589] <[14|00|05|00|07]vw[00]2[00]11
Inside Timer Loop, Blynk Connect=1

Are you able to post your full code and formatted by highlighting the code and pressing the </> button?

Thanks for detailed report.
Please note that I edited your post for better formatting. Next time, please do it yourself :wink:

Blynk runs mostly on stack, which is actually very good for performance and stability.
Note that Arduino IDE reports only static part of allocated memory (only global variables).
During sketch execution, more memory is used.
Old Arduinos have very limited resources to run a decent IoT-enabled project, so I suggest you to switch to some more capable hardware.

For example, you can run your code directly on ESP8266 chip (standalone mode)

Thanks for confirming my suspicions. Unfortunately, this issue took some time to figure out by process of elimination. At first, my thinking was library contentions since I was also using Wire.h, LiquidCrystal_I2C.h and EEPROM.h. I would add a line of code and wifi/blynk issues would start. Take it out and change some items, back working. A real hair puller…My current application requires more i/o than I’ve seen on the ESP flavors. I do plan on looking down this path in the future. My plan is to switch to the Mega2560 (8K ram vs 2K, 256K flash vs 32K).

You can expand esp8266 gpio using some chips, or even consider using arduino as as slave device of ESP.

Multiplexing is very do-able with an ESP. It can get you plenty of ports to choose from. I use a Mega for my homedomotic system, but I’m still not 100% satisfied with it’s performance. I’m thinking the cpu is just too weak to keep up with what I want.