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:
-
UNO with ESP8266, here is the AT+GMR dump for the ESP
AT version:0.40.0.0(Aug 8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04 -
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. -
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. -
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
throughout. -
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.
- SKETCH
#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
Serial.begin(19200);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Serial.println("Clearing Ports");
while (EspSerial.available())
{
Serial.print(EspSerial.read());
}
while (Serial.available())
{
Serial.read();
}
Serial.println("Forcing ESP Disconnect");
//Force ESP8266 to disconnect from wireless end point
EspSerial.print("AT+CWQAP\r\n");
delay(100);
while (EspSerial.available())
{
Serial.print(EspSerial.read());
}
Serial.println("");
// Login to wifi
EspSerial.print("AT+CWJAP=\"");EspSerial.print(ssid);EspSerial.print("\",\"");EspSerial.print(pass);EspSerial.print("\"\r\n");
while (EspSerial.available())
{
Serial.print(EspSerial.read());
}
Serial.println("");
Serial.println("\nBefore Blynk Connect=" + String(Blynk.connected()));
// Pass wifi and auth info to blynk
Blynk.config(wifi,auth);
// Try login to blynk
Blynk.connect(3000);
// Blynk.begin(auth, wifi, ssid, pass);
while (!Blynk.connected())
{
Serial.print(".");
if (Blynk.connect(3000))
{
BLYNK_LOG("Reconnect Passed");
}
else
{
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 a = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
String z[14]={a};
void loop() {
// put your main code here, to run repeatedly:
static unsigned long lastmillis=millis();
Blynk.run();
if (firstrun)
{
Serial.println("Inside Loop()");
firstrun = false;
}
// Run timer loop every sec
if (Blynk.connected() && (millis()-lastmillis) >= 1000)
{
myTimerEvent();
Serial.println("Inside Timer Loop, Blynk Connect=" + String(Blynk.connected()));
lastmillis=millis();
}
}
*******************************************************************************
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,"192.168.0.72"
+CIFSR:STAMAC,"5c:cf:7f:1c:67:b4"
[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