Hello! Have got all the UDP to and from simultaneously working on my Uno to and from QLab however trying to decipher and how best to focus on trimming the UDP reply string from QLab 4s JSON reply.
Have been using the examples set out in this forum post, reply 11 but for some reason when I try to get any response I only get the : from between the strings not the next set of data in "" marks. Any and all ideas appreciated tearing my hair out here!
See my current code and see also the Wireshark pull of the same packet - I am only after the section that is "data" as then I need to write that to a variable so I can constantly update my screen with what cue number is coming up!
// if there's data available, read a packet
int packetSize = UdpRecieve.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = UdpRecieve.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(UdpRecieve.remotePort());
// read the packet into packetBufffer
byte packetBuffer[packetSize]={0};
for(int i=0;i<packetSize;i++)
packetBuffer[i]=UdpRecieve.read(); // read the packet into array
Serial.print("Contents: ");
for(int i=0;i<packetSize;i++) // print contents
{Serial.print(packetBuffer[i]&0xff,HEX); Serial.print(" "); }
// search for STATUS
byte * ptr=(byte *)memmem(packetBuffer, sizeof(packetBuffer),"data",4);
if(ptr==NULL)Serial.println("NULL");
else { // if data found print data
Serial.println("found");
do { ptr++; } while(*ptr != '\"'); // search for starting "
while(*(++ptr) != '\"') // print until terminating " found
Serial.print((char)*ptr);
}
}
This is the Wireshark poll of the packet - the code above works but only returns the : between the "data":"overture 6" and I need the overture 6 title part!
You search for the string "data".
You find it
You then start searching for a quote '"'.
You find that at the very next location beyond data
You then start searching for the next quote, printing everything while doing so.
The next character is a ':' so it gets printed.
The next character is a quote so you are done.
The string you are searching for is ....."data":"Overture.....
Your algorithm does not take into account that the word data has quotes around it.
// if there's data available, read a packet
int packetSize = UdpRecieve.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = UdpRecieve.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(UdpRecieve.remotePort());
// read the packet into packetBufffer
byte packetBuffer[packetSize]={0};
for(int i=0;i<packetSize;i++)
packetBuffer[i]=UdpRecieve.read(); // read the packet into array
Serial.print("Contents: ");
for(int i=0;i<packetSize;i++) // print contents
{Serial.print(packetBuffer[i]&0xff,HEX); Serial.print(" "); }
// search for STATUS
byte * ptr=(byte *)memmem(packetBuffer, sizeof(packetBuffer),"data",4);
if(ptr==NULL)Serial.println("NULL");
else { // if data found print data
Serial.println("found");
ptr++; // skip trailing quote on data
do { ptr++; } while(*ptr != '\"'); // search for starting "
while(*(++ptr) != '\"') // print until terminating " found
Serial.print((char)*ptr);
}
}
Can you please show the complete packet buffer received. All the linked serial print out shows is the first few bytes.
Don't link and image, just show the received data in a code tags box.
Yeah sorry its like a 232 byte print but it was set to just print in a line not print on a new line every time!
blh64:
You search for the string "data".
You find it
You then start searching for a quote '"'.
You find that at the very next location beyond data
You then start searching for the next quote, printing everything while doing so.
The next character is a ':' so it gets printed.
The next character is a quote so you are done.
The string you are searching for is ....."data":"Overture.....
Your algorithm does not take into account that the word data has quotes around it.
// if there's data available, read a packet
int packetSize = UdpRecieve.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = UdpRecieve.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(UdpRecieve.remotePort());
// read the packet into packetBufffer
byte packetBuffer[packetSize]={0};
for(int i=0;i<packetSize;i++)
packetBuffer[i]=UdpRecieve.read(); // read the packet into array
Serial.print("Contents: ");
for(int i=0;i<packetSize;i++) // print contents
{Serial.print(packetBuffer[i]&0xff,HEX); Serial.print(" "); }
// search for STATUS
byte * ptr=(byte *)memmem(packetBuffer, sizeof(packetBuffer),"data",4);
if(ptr==NULL)Serial.println("NULL");
else { // if data found print data
Serial.println("found");
ptr++; // skip trailing quote on data
do { ptr++; } while(ptr != '"'); // search for starting "
while((++ptr) != '"') // print until terminating " found
Serial.print((char)*ptr);
}
}
blh64:
You search for the string "data".
You find it
You then start searching for a quote '"'.
You find that at the very next location beyond data
You then start searching for the next quote, printing everything while doing so.
The next character is a ':' so it gets printed.
The next character is a quote so you are done.
The string you are searching for is ....."data":"Overture.....
Your algorithm does not take into account that the word data has quotes around it.
// if there's data available, read a packet
int packetSize = UdpRecieve.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = UdpRecieve.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(UdpRecieve.remotePort());
// read the packet into packetBufffer
byte packetBuffer[packetSize]={0};
for(int i=0;i<packetSize;i++)
packetBuffer[i]=UdpRecieve.read(); // read the packet into array
Serial.print("Contents: ");
for(int i=0;i<packetSize;i++) // print contents
{Serial.print(packetBuffer[i]&0xff,HEX); Serial.print(" "); }
// search for STATUS
byte * ptr=(byte *)memmem(packetBuffer, sizeof(packetBuffer),"data",4);
if(ptr==NULL)Serial.println("NULL");
else { // if data found print data
Serial.println("found");
ptr++; // skip trailing quote on data
do { ptr++; } while(ptr != '"'); // search for starting "
while((++ptr) != '"') // print until terminating " found
Serial.print((char)*ptr);
}
}
Although the problem here is the title will only be Overture once! (unless I call every cue Overture song 4 overture song 98