Home Forums EasyTransfer Library Support Forum Suggestion: .end command to complement .begin Reply To: Suggestion: .end command to complement .begin


I played around with this some last night, and I wanted to add to the post I made yesterday.

I created a test setup with a spare Arduino Mega 2560 as a “master” talking to my EnergyMonitor “slave” over serial (Serial1 on the Mega, SoftwareSerial on the slave) with EasyTransfer.

To start, I created the same data structure from the master as I am using in my production system. I then added an integer variable to it, to indicate the mode (1=request for data, 2=data to display).

I have the master first send the structure with the mode variable set to 1, which triggers the slave to take the energy readings, and send the data back using a second data structure (containing only the two energy usage numbers I need). After the master sends its data, it goes into an ET.receive mode, waiting for the data to be returned. It then does a Serial.print of the variables it received. After that, it sends out the structure with mode=2, and the slave doesn’t do anything (because it has a condition on the value of that mode variable).

What I need to figure out (I didn’t have time to test last night) is what happens if the master sends the first structure (the trigger to send back data), but the slave isn’t running (or locks up of something else that causes the data to never come back)? Is the master going to sit there forever waiting for the data, or does it timeout after a certain period of time, and move on?

If I put in a short delay on the master after sending (long enough for the slave to receive the command, capture the latest data, and send it back), and then do an “if(ET.receiveData())”, will that fail if nothing came back, and then move on (I can put an “else” after it to set the expected values to “null,” so the MySQL insert doesn’t fail).

Would that work? Is there a better way to set a timeout on the ET.receiveData() function?