[SOLVED] [net.en] ERROR: Failed to allocate pbuf

I am getting a strange error message displaying frequently when I am displaying UDP data sent over a network.

0000029659 [net.en] ERROR: Failed to allocate pbuf

I tried searching for this error message but I couldn’t find any clues.

Here is the successful UDP message displayed on the Serial Monitor (*data removed for security) along with the error message described above.

What could be the cause of 0000029659 [net.en] ERROR: Failed to allocate pbuf

Source Code → Particle Argon, deviceOS@3.1.0

#include "Particle.h"

UDP Udp;
char message[128];
const int port = 7234;

long unsigned now = 0;
long unsigned lastTime = 0;
const int INTERVAL = 5000;

SerialLogHandler logHandler(LOG_LEVEL_WARN, {{ "app", LOG_LEVEL_INFO }});

void setup() {
  Udp.begin (port);
}

void loop() {
  now = millis();
  if (now - lastTime > INTERVAL){
    lastTime = now;
    Udp.receivePacket((byte*)message, 127);
    Log.info(message);
  }
}

Corrected Code → No more [net.en] ERROR - Thank you @rickkas7

#include "Particle.h"

UDP Udp;
char message[128];
const int port = 7234;

long unsigned now = 0;
long unsigned lastTime = 0;
const int INTERVAL = 5000;

SerialLogHandler logHandler(LOG_LEVEL_WARN, {{ "app", LOG_LEVEL_INFO }});

void setup() {
  Udp.begin (port);
}

void loop() {
  now = millis();
  Udp.receivePacket((byte*)message, 127); // Updated Location
  if (now - lastTime > INTERVAL){
    lastTime = now;
    Log.info(message);
  }
}

That error message occurs when the Ethernet interface runs out of buffers to hold incoming packets.

I’d first try to solve this by reading a packet on every loop. You’ll then need to figure out what you want to do when too many packets arrive too quickly - either discard them or queue them somewhere else. But by always calling receivePacket on every loop (1000 times per second) you should prevent having the Ethernet interface have to discard packets for you.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.