BlynkProtocol make error with WiFiClient Library on ESP32

On my project I’m using ESP WROOM 32U 240MHz, 4MB Flash.
Communication: WiFi.h and WiFiMulti
Board Version: 1.0.4 (newest are not working good)

  • multithetering

Error: (after 3-6 hour working)

        assertion "pbuf_free: p->ref > 0" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/pbuf.c", line 765, function: pbuf_free
abort() was called at PC 0x4010dcb3 on core 0

Backtrace: 0x4008d09c:0x3ffdc490 0x4008d2cd:0x3ffdc4b0 0x4010dcb3:0x3ffdc4d0 0x4012ac53:0x3ffdc500 0x40123a85:0x3ffdc520 0x40124575:0x3ffdc5a0 0x401245f2:0x3ffdc5d0 0x400d7332:0x3ffdc5f0 0x400d7361:0x3ffdc610 0x400d7716:0x3ffdc630 0x4014c812:0x3ffdc660 0x400dc271:0x3ffdc690 0x400dc29d:0x3ffdc6b0 0x400d2615:0x3ffdc6d0 0x400d2b1b:0x3ffdc730 0x400d2b9c:0x3ffdc770 0x400d2ce8:0x3ffdc7a0 0x400d2d0e:0x3ffdcbe0 0x400da0b0:0x3ffdcc00 0x400da12b:0x3ffdcc20 0x400d1d7f:0x3ffdcc40 0x400897b1:0x3ffdcc70Preformatted text

It’s weird, because WiFi and Blynk Tasks are running on Core 1. But on Core 0 is one function, who are using blynk library and another one to I2C communication.

Decoded Error:

Error
   :63 (discriminator 8):::0x4010dcb3:__assert_func
   0x4008d09c invoke_abort
   0x4008d2cd abort
   0x4012ac53 pbuf_free
   0x40123a85 lwip_recvfrom
   0x40124575 lwip_recvfrom_r
   0x401245f2 lwip_recv_r
   0x400d7332 WiFiClientRxBuffer
   (inlined by) WiFiClientRxBuffer
   0x400d7361 WiFiClientRxBuffer
   0x400d7716 WiFiClient
   0x4014c812 WiFiClient
   0x400dc271 Stream
   0x400dc29d Stream
   0x400d2615 BlynkArduinoClientGen<Client>
   (inlined by) BlynkProtocol<BlynkArduinoClientGen<Client> >
   (inlined by) BlynkProtocol<BlynkArduinoClientGen<Client> >
   0x400d2b1b BlynkProtocol<BlynkArduinoClientGen<Client> >
   0x400d2b9c BlynkProtocol<BlynkArduinoClientGen<Client> >
   0x400d2ce8 void BlynkApi<BlynkProtocol<BlynkArduinoClientGen<Client> > >
   0x400d2d0e WidgetRTC
   0x400da0b0 now()
   0x400da12b year()
   0x400d1d7f timeFun(void*)
   :355 (discriminator 1):::0x400897b1:vPortTaskWrapper
   : ?? ??:0
   : ?? ??:0
   : ?? ??:0

I hope somebody help. Sorry for my bad English.

Without your code, no one could help you :wink:

You all right, my code is to big to publish it all. Here are functions to connect to the Internet:

Core 1:

bool WiFiInitial()
{
	//WiFi.setSleep(false);
	wifiMulti.addAP(ssid, pass);
	//wifiMulti.addAP("B593-5478v2", pass);
	wifiMulti.addAP("B593-5478_5GHz", pass);
	delay(30);
	Serial.println("Connecting Wifi...");

	if (wifiMulti.run() == WL_CONNECTED) {
		Serial.println("");
		Serial.println("WiFi connected");
		Serial.println("IP address: ");
		Serial.println(WiFi.localIP());
		return true;
	}
	else {
		return false;
	}
}

And Blynk tasks:

    void blynkFun(void * param) {

	unsigned long timeToSync = millis() + 10000; 
	Blynk.config(auth);
	delay(1000);

	if (WiFiInitial()) {
		Blynk.connect();
		delay(3000);
	}
	else {
		Serial.println("Problem z polaczeniem WiFi");
	}

	for (;;){
		
		if (Blynk.connected()) {
			Blynk.run();
		}
		else{
			if (wifiMulti.run() == WL_CONNECTED) {
				if (Blynk.connected()) {
					Blynk.run();
				}
				else {
					Serial.println("Wywoluje Blynk.connect();");
					Blynk.connect();
					delay(4000);
					
				}
			}
		}


		if (timeToSync <= millis())
		{
			if (readingServerData && Blynk.connected()){
				Blynk.syncVirtual(osAltana.vPin);
				Blynk.syncVirtual(osPodjazd.vPin);
				Blynk.syncVirtual(osOglSciezka.vPin);
				Blynk.syncVirtual(osSciezka.vPin);
				Blynk.syncVirtual(osOgrod.vPin);
				readingServerData = false;
			}
			else {
				//btnSync
				Serial.println("Synchronizacja BLYNK z ESP");
				Blynk.virtualWrite(osAltana.vPin, osAltana.status);
				Blynk.virtualWrite(osSciezka.vPin, osSciezka.status);
				Blynk.virtualWrite(osOgrod.vPin, osOgrod.status);
				Blynk.virtualWrite(osPodjazd.vPin, osPodjazd.status);
				Blynk.virtualWrite(osOglSciezka.vPin, osOglSciezka.status);
				//sensorsSync
				temp1.blynkWrite();
				temp2.blynkWrite();
			}

			timeToSync = millis() + (1000*100);
		}

		vTaskDelay(50);
	}

	blynkTask = NULL;
	vTaskDelete(NULL);

}

Core 0:

void timeFun(void * param) {
	vTaskDelay(8000);

	for (;;){

		if (Blynk.connected()) {
			localTime.year = year();
			localTime.month = month();
			localTime.day = day();
			localTime.hour = hour();
			localTime.minute = minute();
			Serial.println(localTime.get());
		}

		vTaskDelay(999 * 60); //one minute repeat
	}

	timeTask = NULL;
	vTaskDelete(NULL);
}

It looks like once your code has detected that blynk has connected with Blynk.connected(), it runs Blynk.run(); just once.
For Blynk to work, the run command has to go into your loop function, and hopefully alone. Other code placed inside the loop function, especially delay(); will prevent Blynk from working properly.

Try to move as much of your repeating code into functions below the void loop(), and call these functions from the void loop() when you need them, or directly from an input on the blynk app:

    BLYNK_WRITE(V0) {
     if(param.asInt()) {
      Serial.println("Blynk V0 activated");
      //code that is activated when virtual pin 0 is on.
      }
    }

You can also use a function similar to this to retrieve data from the virtual pin:

  BLYNK_WRITE(V1) {
    yourVariable = param.asInt();
   //code that does something with Virtual pin 1
  }

I’m sure it’s not a reason, because Blynk.connected() return true if hardware is connected to server (not olny one time, but every 50 milisecond) and if board is connected, then execute “Blynk.run()”. This program work well for a few hours, and next is some problem with WiFiClient I think.

EDIT: Task responsible for Blynk has100000 bytes of stack.