Hello everybody, I'm using an Arduino Ethernet and I'm trying to learn something about it. I've recently played around with some example for the UDP communication and I've found out something which I can't understand.
This is my code:
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#define localPort 7400
#define PACKET_SIZE 384
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0xE5};
IPAddress ip(192, 168, 1, 177);
EthernetUDP Udp;
char packetBuffer[PACKET_SIZE];
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
}
void loop()
{
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("The incoming packet is ");
Serial.print(packetSize);
Serial.println(" bytes long");
Serial.println("It contains the following characters:");
Udp.read(packetBuffer, PACKET_SIZE);
Serial.println(packetBuffer, PACKET_SIZE);
}
}
Pretty easy, it seems a lot like the one in the tutorial but has less functions. Mine should print the size of the packet and its contents (that's exactly what it does).
The problems with the output are:
- why if I send a string (I use MAX/MSP to do so) composed by the characters "abcde" (with no " obviously) the Arduino says that the string is 12 bytes long? That's not true , it should be 5 bytes long unless I'm missing something.
- I'd like to send bytes/integer numbers instead of strings but I can't because when I do so (i.e. I send the number 255 with MAX) I obtain the following message: It contains the following characters: int
For the 2nd I probably need to create a new function into the EthernetUDP class but I have no idea about the first issue. Thanks for your help