Error handling

PJON is designed to inform the user if an error is detected. A void function has to be defined as the error handler, it receives 2 parameters the first is the error code and the second is 1 byte additional data related to the error.

Error types:

  • PJON_CONNECTION_LOST (value 101), data parameter contains lost packet's index in the packets buffer.
  • PJON_PACKETS_BUFFER_FULL (value 102), data parameter contains buffer length.
  • PJON_CONTENT_TOO_LONG (value 104), data parameter contains content length.
void error_handler(uint8_t code, uint16_t data, void *custom_pointer) {
  if(code == PJON_CONNECTION_LOST) {
    Serial.print("Connection with device ID ");
    Serial.print(bus.packets[data].content[0], DEC);
    Serial.println(" is lost.");
    Serial.print("Packet buffer is full, has now a length of ");
    Serial.println("Possible wrong bus configuration!");
    Serial.println("higher PJON_MAX_PACKETS if necessary.");
  if(code == PJON_CONTENT_TOO_LONG) {
    Serial.print("Content is too long, length: ");

Now inform the instance to call error_handler in case of error:


This document is automatically generated from the github repository. If you have noticed an error or an inconsistency, please report it opening an issue here