Creating and comparing to a list

Hi there I am trying to get this list to be built and compare data to it. Have values getting sent as a array and need to store them into DeviceID(1-10) or say 1-100 but they come in from set of values RadioData[1]-RadioData[2] ----RadioData[6] it a 6 byte number that need to get store and then compared


 unsigned char radioData[32];//string from the Sensor
retained String Device,Device1,Device2,Device3;
unsigned char DeviceID1,DeviceID2,DeviceID3,DeviceID4,DeviceID5,DeviceID6,DeviceID7,DeviceID8,DeviceID9,DeviceIDA;
void setup() {}
void loop() {
***void DeviceID()***{
   unsigned char *DeviceID[]*={radioData[1],radioData[2],radioData[3],radioData[4],radioData[5],radioData[6]};//This is where the data come in and changes Need to store these into different DeviceID and then compare them later on!!!
      for (int n=0;n<(int)sizeof(DeviceID);n++){

 Device += String::format("%X", DeviceID[n]);
    }
    Serial.print("Device ID :");
   Serial.println(Device);

   if (//?????){ //compare the to Devices 
          unsigned char DeviceID1[]={radioData[1],radioData[2],radioData[3],radioData[4],radioData[5],radioData[6]};
       for (int n=0;n<(int)sizeof(DeviceID1);n++){
            Serial.print("Device ID 1 :");
 Device1 += String::format("%X", DeviceID1[n]);
        }
   }
}
}

Know this will not fully compile have the radio data coming from a radio but the ID look something like this

unsigned char Device1[6]={0xD8, 0x80, 0x39, 0xAD, 0x55, 0x73};
unsigned char Device2[6]={0xD8, 0x80, 0x39, 0xAD, 0xC9, 0x12};
unsigned char Device3[6]={0xD8, 0x80, 0x39, 0xED, 0x80, 0x4C};

Any help in creating this chart, table , data list would be greatly appreciated.

String objects can’t be retained since the actual string is not stored inside the backup RAM space.

If you want to compare C strings strcmp() would be my tool of choice.
For non-strings (e.g. containing 0x00 characters) memcmp() would be the equivalent.

Also what’s that kerfuffle with this?

unsigned char DeviceID1,DeviceID2,DeviceID3,DeviceID4,DeviceID5,DeviceID6,DeviceID7,DeviceID8,DeviceID9,DeviceIDA;

Why not just go with char DeviceID[10]?
A similar thing is true for

retained String Device,Device1,Device2,Device3;

(plus the fact about non-retainable String objects)

And if you have an array that just needs copying over to another of same type you can use memcpy() instead of iterating over the arrays.

3 Likes

Some aspects of what you’re trying to do are unclear to me. How exactly is the data coming in (direct connection, publish, function call)? Does the data come in order, so you get 6 bytes that represent Device1, then 6 bytes for Device2, etc.? How is one set of 6 bytes separated from the next set, or is it just one long stream of bytes for all 10 (or 100) devices?

In the example you show, only the last three bytes of the array are variable. Is that the case for all you data? If so (or even if it’s the last 4 bytes) it might be easier to convert those bytes to an int, and store and compare them.

Hi sorry about the unclear nature the prob. is little hard for me to full grasp at times.
The bytes are coming in from a sensor or Main and the Sensor each have a device Id that trying to get the Main to learn. So there 6 Sensor with different Device Id that all belong to the Main. I need the Main to be able to only get info from those 6 and do nothing with the others that might be on the same radio wave. The device dont have to be in order they just need to know which onces belong to the Main.
The data that come in is all on a string of RadioData[32] but only the first RadioData[6] is the device Id that the information trying to store and compare. This has to work for all device to be add so the 6 byte will all be different.
The String of data that comes in looks like this
03D88039ED804C214F7A83B86800090A05BA06BC06F807C7390072FB02FF106E03FAFBFCFDFEFF03202A05D965
where D88039ED804C is the device ID the rest is other informaton that Break and store as Ints.
I hope this make little bite more clear on what asking, I am lost on how to get this to store and compare
Thanks for the reply

Am I right in assuming then, that you know the DeviceId’s for the 6 devices that you want main to accept data from, and that list of 6 id’s is what you want to construct, and then compare to the incoming data?