I am in search for some examples as to how can one use the AsyncUDPMessage in an Application for sending out UDP packets to a host with specific IP address and Port number from an ESP-WROOM-32 (Olimex ESP32-PoE) module?

The Class for AsyncUDPMessage in arduino-esp32 library inherits from Print.

I want to send sensor measurements to InfluxDB in the Line Protocol (InfluxDB specific).


 imu,location=front,nodeid=node1 status=0.00,liac_x=-1.18,liac_y=0.02,liac_z=9.63,eul_x=0.00,eul_y=-6.81,eul_z=0.25 1538507409930

The above mentioned example is stored in the form of a String and the methods to send information via UDP viz. send() sendTo() all mention usage of AsyncUDPMessage as the first parameter.


Send the above measurement to the particular Device's IP and port

udp.sendTo(Message, IPAddress(192,168,3,11), 8089);

I am currently using broadcastTo(const char * data, port) menthod to send information the InfluxDB instance.


void loop(void) {

  DateTime now_time = rtc.now();

 // create a measurement
  influxMeasurement row("imu");
  row.addTag("location", "front");
  row.addTag("nodeid", "node1");

// get information from BNO055
  imu::Vector<3> li_ac = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
//  Serial.print(li_ac.x());
//  Serial.print(li_ac.y());
  row.addField("status", 0);
  row.addField("liac_x", li_ac.x());
  row.addField("liac_y", li_ac.y());
  row.addField("liac_z", li_ac.z());
  row.addField("eul_x", euler.x());
  row.addField("eul_y", euler.y());
  row.addField("eul_z", euler.z());

  // add timestamp
  row.addTimeStamp_ms(String(now_time.unixtime()) + String(millis()%1000));

  // print the Line Protocol output

  // UDP Sending 
  char buf[2048]; // make buffer for `broadcastTo()`
  row.postString().toCharArray(buf, sizeof(buf)); // string to char array
  // Serial.println(buf);
  udp.broadcastTo(buf ,8089);


I create a Line protocol String, make a buffer, convert the string to char [] and send it out.


  1. how do I use AsyncUDPMessage so I can pass the string to it directly?

  2. I am not sure but will char buf[2048] within a loop is a good idea as every time a buffer allocation might make the ESP32 run out of memory? And if AsyncUDPMessage can avoid this concern?

  • 1
    String has .c_str()
    – Juraj
    Oct 2, 2018 at 17:23
  • the library has AsyncUDPClient example
    – Juraj
    Oct 2, 2018 at 17:25
  • Yes but there is not mention of AsyncUDPMessage. there is only AsyncUDPPacket
    – Shan-Desai
    Oct 2, 2018 at 17:26

1 Answer 1


Use udp.print(row.postString().c_str())

AsyncUDPMessage in AsyncUDP library is only a buffer. It is used only in AsyncUDP send function:

size_t AsyncUDPPacket::send(AsyncUDPMessage &message)
    return write(message.data(), message.length());
  • So just connect once and then print the information will send the udp to the destination porT?
    – Shan-Desai
    Oct 2, 2018 at 18:01
  • udp doesn't connect. only the library takes the server and port parameters in a connect like function. the function can only resolve hostname to IP. but the implementation is hidden in not open source espressif SDK
    – Juraj
    Oct 2, 2018 at 18:25
  • if you don't need nonblocking UDP sending, then you don't need the AsyncUDP library
    – Juraj
    Oct 2, 2018 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.