UDP String filtering sections of message from a QLab 4 json

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!

Wireshark Image
Serial Terminal Print out

All help appreciated.....

Serial.print("Contents: ");
    for(int i=0;i<packetSize;i++)    // print contents
      {Serial.print(packetBuffer[i]&0xff,HEX); Serial.print(" "); }

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.

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);
      }
  }

cattledog:

Serial.print("Contents: ");

for(int i=0;i<packetSize;i++)    // print contents
     {Serial.print(packetBuffer[i]&0xff,HEX); Serial.print(" "); }




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!

15:01:20.286 -> Received packet of size 232
15:01:20.286 -> From 10.101.2.1, port 54711
15:01:20.357 -> Contents: 2F 72 65 70 6C 79 2F 63 75 65 5F 69 64 2F 44 36 45 45 30 35 31 36 2D 35 41 31 32 2D 34 35 45 44 2D 39 43 46 33 2D 34 44 32 37 46 39 38 45 46 31 33 46 2F 64 69 73 70 6C 61 79 4E 61 6D 65 0 0 2C 73 0 0 7B 22 73 74 61 74 75 73 22 3A 22 6F 6B 22 2C 22 64 61 74 61 22 3A 22 4F 76 65 72 74 75 72 65 20 36 22 2C 22 77 6F 72 6B 73 70 61 63 65 5F 69 64 22 3A 22 34 30 42 46 32 43 46 30 2D 34 41 46 44 2D 34 30 43 33 2D 41 41 38 35 2D 46 31 41 30 45 46 46 33 43 34 32 32 22 2C 22 61 64 64 72 65 73 73 22 3A 22 5C 2F 63 75 65 5F 69 64 5C 2F 44 36 45 45 30 35 31 36 2D 35 41 31 32 2D 34 35 45 44 2D 39 43 46 33 2D 34 44 32 37 46 39 38 45 46 31 33 46 5C 2F 64 69 73 70 6C 61 79 4E 61 6D 65 22 7D 0 0 0 found
15:01:20.391 -> :

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);
     }
 }

Thank you blh64 - I'll try that!

Cheers guys.

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 :wink: