WebHook Locking Up Hardware

There appears to be a problem with the Web Hook Widget. I’ve set it up to https my pager (snpp) service. The browser works fine every time.

My Setup:
Button V9 (push) calls V24 web hook via code on hardware
V24 assigned to web hook and configured: GET text/plain
RUNNNING:
local server:0.37.4
iPhone: 2.21.0
Android: 2.25.1

The application hangs unless:

  1. Another button is pressed. After the button press it calls V24, displays result and continues in loop().
  2. Holding V9 in for a couple of seconds then releasing it will also work and displays result and continues in loop().
    NOTE: ALL PAGES ARE SENT and my pager goes off…Its just the lockup on the hardware side.

Other things tried:

  1. BLYNK_MAX_READBYTES 4096 <- not needed as response is < 56 chars.
  2. webhooks.frequency.user.quota.limit=-1 <- not sending that fast
  3. reviewed blynk.log and it clearly shows the response as 200 when lockup occurs, see below. I opened log file immediately during lock condition to capture results. After that, I pushed another button and it continued in loop(). Re-opened log file and found no more entries.
  4. reviewed web & blynk.cc
  5. I’ve tried put,post,json…etc but the locking still occurs.

I cannot have this widget lock my hardware up until the watchdog kicks off. Not sure what to try or is this a BUG…???

==========================================================================
The below is a debug dump from hardware…Note: WDT is my watch dog flag status and timer value.

Free RAM = 23731
WDT=1,Time=118943
WDT=1,Time=119792

[120906] >[14]=[FF|00|06]
[120907] >vw[00]9[00]1
[120908] Waiting:2
[120911] <[14]=[FF|00|15]vw[00]24[00]test:1529141777
[121042] >[14]*a[00|06]
[121043] >vw[00]9[00]0
WDT=1,Time=121054   <- gets thru V9 code as this is printed in loop()
WDT=1,Time=121925   <- normally locks here unless another button is pressed
                       it will eventually cause watchdog to kick

[147208] >[14|03]x[00]>  <- continues here after button press and calls V24 to print response
[147209] >vw[00]24[00]<html><body>OK: Message Send To 12345678[0D|0A]+IPD,1,12:[14]ud[00]
WDT=1,Time=147226   <- back in loop()
Free RAM = 23731
[147494] >[14]%[0A|00|07]
[147495] >vw[00]15[00]0
WDT=1,Time=147627
WDT=1,Time=148741
WDT=1,Time=149709
WDT=1,Time=150701
[151210] <[06|00]@[00|00]
[151381] >[00|00]@[00|C8]
WDT=1,Time=151755
Free RAM = 23731
==========================================================================
CODE SNIPPETS:
// Fire Web Hook - button
BLYNK_WRITE(V9)
{
	if (param.asInt())
	{
		Blynk.virtualWrite(V24,"test:"+String(now()));
	}
}
// prints web hook data
BLYNK_WRITE(V24)
{
	String webdata = param.asStr();
	SerialUSB.println(webdata);
}
        
==========================================================================
DUMP FROM BLYNK.LOG (ip's and phone changed)
        
14:03:51.809 DEBUG- [id: 0x4ffae266, L:/0.0.0.0:0 - R:xyz.com/0.0.0.0:0] HANDSHAKEN: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
14:03:52.161 DEBUG- 

Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET /sendpage?to=1234567890&msg=test:1529157830 HTTP/1.1
content-type: text/plain; charset=UTF-8
host: xyz.com
accept: */*

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Date: Sat, 16 Jun 2018 19:03:52 GMT
Content-Length: 56

14:03:52.165 DEBUG- Channel Closed: [id: 0x4ffae266, L:/0.0.0.0:0 ! R:xyz.com/0.0.0.0:0] with attribute DISCARD
==========================================================================

On a side note, setting the button state via code also has an issue. Doing something like the below DOES change the button state BUT DOES NOT call the V9 code as done when manually pushing it on the phone.

	static int v9_state = 0;
	v9_state = !v9_state & 0x1;
	Blynk.virtualWrite(V9, v9_state);

Lots of people use the Webhook… probably something in your code? But we need to see all of it, not just a random snippet.

I find it necessary to build up the string combos before sending it out on a virtualWrite()… usually the compiler catches this.

For example, using the email and notifications… see the String body. This will probably work the same for webhook.

BLYNK_WRITE(V55) {
  if (param.asInt()) {
    timeDisplay();
    dateDisplay();
    String emailAddress = "myemail@gmail.com";
    String subject = "Mega CodeShield";
    String body = "Your MEGA CodeShield progect sent this notification at " + String(currentTime) + " on " + String(currentDate);
    Blynk.email(emailAddress.c_str(), subject.c_str(), body.c_str());
    Blynk.notify(body.c_str());
  }
}

Way too much code to upload…I will create a stripped version performing just the minimal functions.

UPDATE:
Here is a scaled down example. I’ve tried using both a pager call (on v24) & logo.txt call (on v54). The results are a delay of ~ 95mS in the loop() will cause a lockup and less than that works. See previous post as well. In both cases, the blynk.log always shows a 200 return.

Just hitting a button (nothing assigned to it on hardware) will unlock it and loop() starts running again.

Furthermore, the code snippet at the end always works BUT is not a desirable way to handle this since the page result can take 1.5s. On a 48Mhz uP, much can be done vs waiting for a response from blynk.

#define ARDUINO_SAMD_ZERO
#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations
#define BLYNK_PRINT SerialUSB    // Comment this out to disable prints and save space. Note:blynk_debug stops as well
//#define BLYNK_DEBUG // comment out to prevent finite blynk execution/error info. Must have blynk_print defined...
#define BLYNK_DEBUG_ALL // BLYNK_DEBUG_ALL must be ON and BLYNK_PRINT to see #pragma messages from BlynkDetectDevice.h

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "EEPROM.h"

ESP8266 WIFI(&Serial);

// prints web hook data Pager
BLYNK_WRITE(V24)
{
	String webdaata = param.asStr();
	SerialUSB.println(webdaata);
}

// prints web hook data logo
BLYNK_WRITE(V54)
{
	String webdaata = param.asStr();
	SerialUSB.println(webdaata);
}

void setup() 
{
	byte cnt=0;
	// clear ram based message record structure
	init_eeprom_msg_record();
	// create all global eeprom class objects to work with the memory
	eeprom_init();
	// read messages into internal ram message structure
	read_eeprom_msg_record(EEPROM53);
	// setup baud rate on controller to PC serial port
	SerialUSB.begin(115200);
	// Set ESP8266 baud rate. 
	Serial.begin(19200);

	// Retrieve EEPROM main record, see struct def in EEPROM.h file.
	read_eeprom_main_record(EEPROM50);
	
	SerialUSB.println(F("Clearing Ports"));
	while (Serial.available())
	{
		SerialUSB.print(char(Serial.read()));
	}
	while (SerialUSB.available())
	{
		SerialUSB.read();
	}

	Blynk.config(WIFI,EEPROM_RECORD.auth, EEPROM_RECORD.blynk_server, atoi(EEPROM_RECORD.blynk_hardware_port));
	while (Blynk.connectWiFi(EEPROM_RECORD.ssid, EEPROM_RECORD.pass) == false)
	{
		delay(1000);
		cnt++;
		if (cnt == 3) NVIC_SystemReset();
	}
	while (Serial.available())
	{
	if (Serial.available()) SerialUSB.print(char(Serial.read()));
	}
	SerialUSB.println();

	// Try login to blynk
	Blynk.connect(15000); // wait no longer than 15 secs trying to connect

	// Verify were connected, if not, loop.
	byte i=0;
	while (!Blynk.connected())
	{
		i++;
		Blynk.connect(30000);
		if (Blynk.connected())
		{
			BLYNK_LOG("Reconnect Passed");
		}
		else
		{
			BLYNK_LOG("Reconnect Failed");
		    if (i == 3) NVIC_SystemReset();
		}
	}
	SerialUSB.println("Exiting Setup()");
}

void loop()
{
	static uint32_t one_sec_timer = millis();
	static uint32_t thirty_sec_timer = millis();
	uint32_t dt = millis();
	static uint8_t reconnect_tries = 0;


	if (millis() - one_sec_timer >= 1000)
	{
		SerialUSB.println("Inside Loop()");
		one_sec_timer = millis();
	}
	if (millis() - thirty_sec_timer >= 5000)
	{
		// pager call
		//Blynk.virtualWrite(24, "Simple Test" + String(millis()));
		// 
		Blynk.virtualWrite(54, "logo.txt");

		thirty_sec_timer = millis();
	}
	// 91mS delay works, >91mS causes lockup (pager call)
	// 95mS delay works, >95mS causes lockup (https://raw.githubusercontent.com/blynkkk/blynk-library/master/extras//pin/)
	dt = millis();
	while (millis() - dt <= 96);

	if (Blynk.connected() == Blynk.CONNECTED)
	{
		Blynk.run();
	}
	// Blynk Not Connected...
	else
	{
		SerialUSB.println(F("Lost Blynk Connection"));
		// Try to re-establish connection with Blynk Server. 
		unsigned long s_t = millis(); // Mark start time before trying to establish connection, see below.
		if (Blynk.connect(10000) != Blynk.CONNECTED)
		{
			if (++reconnect_tries == 3)
			{
				// Cannot Re-Connect...
				SerialUSB.println(F("...RE-BOOTING...\nLost Blynk Communications"));
				NVIC_SystemReset();
			}
			else
			{
				SerialUSB.println(("Tried To Pefrom Blynk.Connect().Try="+ String(reconnect_tries)));
			}
		}
		else
		{
			reconnect_tries = 0;
			SerialUSB.println(F("Had to Pefrom Blynk.Connect(), Back online..."));
			SerialUSB.println("Re-Connect Time: " + String((millis() - s_t) / 1000) + " sec");
		}
	}
}

boolean send_test_page(byte vchan,String send_data)
{    
	// reset flag, see BLYNK_WRITE for webhook
	WEB_HOOK_FIRED = false;
	uint32_t t = millis();
	Blynk.virtualWrite(vchan, send_data);
	// wait no more than 5 secs for response
	while (!WEB_HOOK_FIRED && (millis() - t < 5000))
	{
		Blynk.run();
	}
	return(WEB_HOOK_FIRED);
}

Finally tracked down the lockup to the core size for serial (arm uP).

static void onData(uint8_t mux_id, uint32_t len, void* ptr) inside of:
BlynkSimpleShieldEsp8266.h recieved a len var larger than what the uart buffer had.

Granted, the serial buffer lost chars but blynk will sit in the loop until it receives len chars. There it will sit for eternity or until the watchdog kicks.

You may want to cover this condition as its not very apparent as to what the issue is. Especially since a webhook repsonse can vary. One time it works, next it locks up.

Note: No setting in blynk can override core defines. Really wish the arduino folks implemented this better.

1 Like