As I said, your "contradicting" scans will work due to the fact that they are mutually exclusively valid, but aren't you making things a bit too complicated for yourself?
You seem to have multiple code bases for (as I assume) rather similar use-cases.
But why not have the same code for both devices, you have the DEVICE_NAME
to distinguish what's meant on the receiving end.
void SendStatus()
{
char data[64];
snprintf(data, sizeof(data), "A%d, B%d", state[A], state[B]);
Particle.publish(DEVICE_NAME, data, PRIVATE);
}
On the receiving side
void handler(const char* event, const char* data) {
int device = -1;
if (strcmp(event, "DeviceX") == 0) device = 0;
else if (strcmp(event, "DeviceY") == 0) device = 1;
if (device >= 0)
sscanf(data, "A%d, B%d", &deviceStateA[device], &deviceStateB[device]);
}
Regarding the task to match the incoming device name against a list of possible options you can have a look at this post where another member asked me to elaborate a bit more about my proposal to use arrays and loops instead of individual variables