Pages: [1]   Go Down
Author Topic: EthernetUdp Sending Sensor Data  (Read 183 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 137
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

I have a couple of sensors that I am trying to send out over a UDP socket to processing but I am having trouble concatenating a string together and sending it out.

For example, I am trying to read in Analogs 0-3, and concatenating as such:
Code:
String data = "*" + analogRead(0) + "/" + ... + analogRead(3)
But then another problem is that I need to send it over Udp via Udp.write() but that only seems to except character arrays.  So how do I accomplish this?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3732
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The easiest way is to use the String method toCharArray to get your data into a form suited to UDP.write. Better would be to use sprintf to build your char array and get rid of the String object.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 137
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So with toCharArray I can build a string and then write it to the socket as such?
In what format will other side pick it up as? String?
Logged

Pages: [1]   Go Up
Jump to: