Well you could store the boolean variables for the valves in an array, and use the sensor child id as the index of the variables in the array. You can also use the setSensor setter on the message variable (MSG_V1) to change which sensor child id the message belongs to. That way, you only need to declare one message variable. You can use two setters on the same line like this:
// Set child id 1 to 0 to simplify using it as index in an array
#define CHILD_ID1 0
// Set child id 2 to 1 which is the next index after index 0.
#define CHILD_ID2 1
// Declare an array of type boolean of size 2.
boolean VALVES[2];
// Declare the message with CHILD_ID1.
MyMessage MSG(CHILD_ID1, V_LIGHT);
void setup() {
...
}
...
void incomingMessage(const MyMessage &message) {
if (message.type == V_LIGHT) {
// Set array element at index message.sensor to boolean value from message payload.
VALVES[message.sensor] = message.getBool();
// Set child id to child id of message.sensor and payload to either 1 or 0 for message, and send message.
gw.send(MSG.setSensor(message.sensor).set(message.getBool() ? 1 : 0));
}
}
Sorry... there was a lot of edits. Now I'm done.... :smile: