user37223: 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).
Example
 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.
goal
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.
Code
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
  Serial.println(row.postString());

  // 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);
  
  delay(100);
}

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

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

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?



user37622: 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());
}


37223: <p>I am in search for some examples as to how can one use the <code>AsyncUDPMessage</code> in an Application for sending out UDP packets to a host with specific IP address and Port number from an <strong>ESP-WROOM-32</strong> (Olimex ESP32-PoE) module?</p>
<p>The Class for <a href="https://github.com/espressif/arduino-esp32/blob/master/libraries/AsyncUDP/src/AsyncUDP.h#L25" rel="nofollow noreferrer">AsyncUDPMessage in arduino-esp32 library</a> inherits from <code>Print</code>.</p>
<p>I want to send sensor measurements to InfluxDB in the Line Protocol (InfluxDB specific).</p>
<h3>Example</h3>
<pre><code> 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
</code></pre>
<p>The above mentioned example is stored in the form of a <code>String</code> and the methods to send information via UDP viz. <code>send()</code> <code>sendTo()</code> all mention usage of <code>AsyncUDPMessage</code> as the first parameter.</p>
<h3>goal</h3>
<p>Send the above measurement to the particular Device's IP and port</p>
<pre><code>udp.sendTo(Message, IPAddress(192,168,3,11), 8089);
</code></pre>
<p>I am currently using <code>broadcastTo(const char * data, port)</code> menthod to send information the InfluxDB instance.</p>
<h3>Code</h3>
<pre><code>void loop(void) {

  DateTime now_time = rtc.now();

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

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

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

  // print the Line Protocol output
  Serial.println(row.postString());

  // 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);
  
  delay(100);
}
</code></pre>
<h3>method</h3>
<p>I create a Line protocol <code>String</code>, make a buffer, convert the string to <code>char []</code> and send it out.</p>
<h3>Question</h3>
<ol>
<li><p>how do I use <code>AsyncUDPMessage</code> so I can pass the string to it directly?</p>
</li>
<li><p>I am not sure but will <code>char buf[2048]</code> within a <code>loop</code> is a good idea as every time a buffer allocation might make the ESP32 run out of memory? And if <code>AsyncUDPMessage</code> can avoid this concern?</p>
</li>
</ol>
 37622: <p>Use <code>udp.print(row.postString().c_str())</code></p>

<p>AsyncUDPMessage in AsyncUDP library is only a buffer. It is used only in AsyncUDP send function:</p>

<pre><code>size_t AsyncUDPPacket::send(AsyncUDPMessage &amp;message)
{
    return write(message.data(), message.length());
}
</code></pre>
