Hi Everyone,
maybe the below will help people facing random incorrect behaviors.
In sample from december 2016 /mysensors/MySensors/examples/RelayActuator/RelayActuator.ino, there is something which could be seen as a bug.
In my case, I have used that sample to control a lot of relais. I noticed some rare but really annoying errors. From time to time a relay got switched incorrectly.
Annoying and strange as coding was pretty straightforward. All relais are coded to act in pulse mode.
digitalWrite(message.sensor-1+RELAY_1, RELAY_OFF);
wait(1000);
digitalWrite(message.sensor-1+RELAY_1, RELAY_ON);
And this is the reason of the bug.
Explanation.
During that second of wait, a lot of things may occurs. Due to the 'message' declaration, it is possible that the 'message' is getting changed.
Typically a ping may come and as result the 'message' is not anymore the same.
For that reason I would suggest the code to be changed a little bit.
void receive(const MyMessage &message_orig)
{
MyMessage message;
message = message_orig;
This way, the function works with a local copy and you are sure nothing can change during the processing.
Anyway, thanks for the sample it was nevertheless very helpful