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
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

[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
[151210] <[06|00]@[00|00]
[151381] >[00|00]@[00|C8]
Free RAM = 23731
// Fire Web Hook - button
	if (param.asInt())
// prints web hook data
	String webdata = param.asStr();
DUMP FROM BLYNK.LOG (ip's and phone changed)
14:03:51.809 DEBUG- [id: 0x4ffae266, L:/ - R:xyz.com/] 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:/ ! R:xyz.com/] 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.

  if (param.asInt()) {
    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());

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

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 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
	String webdaata = param.asStr();

// prints web hook data logo
	String webdaata = param.asStr();

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

	// Retrieve EEPROM main record, see struct def in EEPROM.h file.
	SerialUSB.println(F("Clearing Ports"));
	while (Serial.available())
	while (SerialUSB.available())

	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)
		if (cnt == 3) NVIC_SystemReset();
	while (Serial.available())
	if (Serial.available()) SerialUSB.print(char(Serial.read()));

	// 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())
		if (Blynk.connected())
			BLYNK_LOG("Reconnect Passed");
			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 Not Connected...
		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"));
				SerialUSB.println(("Tried To Pefrom Blynk.Connect().Try="+ String(reconnect_tries)));
			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))

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