Hey @kennethlimcp – thanks, should have updated the thread/post.
I’ve lowered maxsize, and the code runs, however for some reason it’s having trouble parsing the ArtNet data, and no matter what DMX data is being transmitted, the Spark will always read it as 0, 0, 0.
I’m trying to figure out if this is to do with the apparent issues with the UDP framework for Spark at the moment, maybe there is a better way of parsing the data. I’ve put together the following code to try and find out what the Spark is seeing from the OLA server:
unsigned int localPort = 6454; // local port to listen on
UDP Udp;
const int UDP_TX_PACKET_MAX_SIZE=24;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet
void setup() {
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize > 12) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
}
}
However, the only output I see in the console is:
Received packet of size 191
From 10.0.1.30, port 6454
Contents:
- ArtNet server
Received packet of size 167
From 10.0.1.30, port 6454
Contents:
Received packet of size 143
From 10.0.1.30, port 6454
Contents:
Received packet of size 119
From 10.0.1.30, port 6454
Contents:
A
Received packet of size 95
From 10.0.1.30, port 6454
Contents:
Received packet of size 71
From 10.0.1.30, port 6454
Contents:
Received packet of size 47
From 10.0.1.30, port 6454
Contents:
Received packet of size 23
From 10.0.1.30, port 6454
Contents:
Received packet of size 14
From 10.0.1.30, port 6454
Contents:
Art-Net
The raw packets being broadcast on the network look like this:
I need to have the Spark pick out the packets coming in on port 6454 which have the blue highlighting and purple box in common (header of “Art-Net” and the Opcode “0x5000”) and pull out the red green and blue boxed values, convert to decimals, and apply this decimal to a PWM output.
@bko suggested I use client.read()
instead, however I’m not sure how this works and how to use it to parse raw packet data…