I'm trying to figure out how to implement a pretty simple protocol for sending commands + parameters to an arduino board via UDP datagrams.
The part where I send UDP packets is working fine ... My arduino receive the data... But where I need help is to interpret these commands+params.
At the moment my protocol is simple and may become more complex in the future as I wand to be able to add checksum and stuff like that.
For the moment it's like that:
first 3 character is the function number
All the other character excluding the 3 first ones is the parameter
001test will print test to the LCD ...
This 'sort of protocol' works well when I have a command and 1 parameter.. but if I want to send more parameter for the same command or if I would like to add checksumming it start to be more difficult..
here is my actual code:
// Check if new UDP packet arrived
int packetSize = Udp.parsePacket();
Serial.print("[DEBUG] Received packet: [");
Serial.print("] From: ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
if (i < 3)
// read packet
Serial.println("[DEBUG] Looping packet start");
char param[packetSize -2];
for (int i = 0; i < packetSize; i++)
if (i < 3)
command[i] = packetBuffer[i];
command[i+1] = NULL;
param[i-3] = packetBuffer[i];
param[i-2] = NULL;
Serial.println("[DEBUG] Looping packet end");
I would like to have more comments before I continue just to see if there is better way to do it...
I thought about using the cmdMessenger library but I never been able to make it work with UDP messages.
All idea are welcome !