Discussion: Reliable delivery
-
Seems like it is impossible now to distinguish for which message we have received acknowledgement. For example, when you just sent two identical messages. Message should contain message ID field (also called packet id or sequence id, unique for sending side) either in protocol headers (need to change protocol and break compatibility) or in user-defined message body (also breaks compatibility).
-
Seems like it is impossible now to distinguish for which message we have received acknowledgement. For example, when you just sent two identical messages. Message should contain message ID field (also called packet id or sequence id, unique for sending side) either in protocol headers (need to change protocol and break compatibility) or in user-defined message body (also breaks compatibility).
-
@robosensor Yes it is impossible to distinguish between acks for two identical messages. But in which use case is that a problem?
@mfalkvidd for example, to know last actuator state.
Imagine that you are sending three commands:
- ON
- OFF
- ON
Then you receive two confirmations: ON and OFF. For which one ON ack is received? Is current actuator state after receiving two confirmations ON or OFF? How to determine which message (first or third) is lost and what you need to resend?
-
@mfalkvidd for example, to know last actuator state.
Imagine that you are sending three commands:
- ON
- OFF
- ON
Then you receive two confirmations: ON and OFF. For which one ON ack is received? Is current actuator state after receiving two confirmations ON or OFF? How to determine which message (first or third) is lost and what you need to resend?
@robosensor good example. As you said before, there is no way to solve that with the current protocol. However, the example can be made even simpler, it is enough to just send OFF then ON. In-order delivery is not guaranteed so you don't know which message was received last.
-
@robosensor good example. As you said before, there is no way to solve that with the current protocol. However, the example can be made even simpler, it is enough to just send OFF then ON. In-order delivery is not guaranteed so you don't know which message was received last.
@mfalkvidd yes, I understand that this feature will break everything.
Also, message id field can help to filter out duplicate messages on receiving side (due to message acknowledgement is not received by sending side) and can help to re-order incoming messages in right way using increasing message ids.
Even more, sending acknowledgement with only numeric id instead of full message data can help to remove load from MCU (need to parse full message), from RAM (need to store full message), and from 'network' (both wired and wireless, data channel will be busy less time).
-
@mfalkvidd yes, I understand that this feature will break everything.
Also, message id field can help to filter out duplicate messages on receiving side (due to message acknowledgement is not received by sending side) and can help to re-order incoming messages in right way using increasing message ids.
Even more, sending acknowledgement with only numeric id instead of full message data can help to remove load from MCU (need to parse full message), from RAM (need to store full message), and from 'network' (both wired and wireless, data channel will be busy less time).
-
Very cool! Thanks a lot @hek! Can't believe I have read several hundred forum posts about the protocol design and ack problems the last two weeks without realizing that what I needed was already included in the library.
From the discussions I've read it looks like almost no-one else has understood either.
Some ideas to help people understand how to use the built-in features for reliable delivery:
- Add an example that has a complete implementation of end-to-end ack usage. This includes
- setting up timer(s) for re-sending
- storing sent messages so they can be re-sent
- determining which message was acked when an ack message is received (there might be several messages that haven't been acked yet)
- removing acked message from the sent message store and clearing the timer(s)
- re-sending when the timers expire
- Update the documentation for bool send(MyMessage &msg, bool ack); (and similar functions) to explain that the bool returned is the result of the next-hop ack.
- Rename the bool ack parameter to bool end-to-end-ack or something similar to make it clear(er) that there are two types of acks
- In the documentation for send() (and similar functions), refer to the example in (1) for information on how to use end-to-end ack.
- When the example in (1) is good enough, add some of the required code to the MySensors library so people don't need to copy-paste a lot of code into their sketches. Surround the code with ifdefs to make it optional.
(2) and (3) should be quite easy to do. Can it be done with a pull request or how are documentation improvements handled?
I'm willing to do 1 (will post the sketch in the forum for public scrutiny/feedback of course).
4 can be done when the community think the example is "good enough"
5 can wait until the example has been thoroughly vetted.
I got ready to do a PR for this:
- Update the documentation for bool send(MyMessage &msg, bool ack); (and similar functions) to explain that the bool returned is the result of the next-hop ack.
But the code for 1.5.4 already contains this:
@return true Returns true if message reached the first stop on its way to destination.so the problem seems to be the that @return statements didn't make it to http://www.mysensors.org/download/sensor_api_15
@hek: It seems like a PR won't help in this case? -
I got ready to do a PR for this:
- Update the documentation for bool send(MyMessage &msg, bool ack); (and similar functions) to explain that the bool returned is the result of the next-hop ack.
But the code for 1.5.4 already contains this:
@return true Returns true if message reached the first stop on its way to destination.so the problem seems to be the that @return statements didn't make it to http://www.mysensors.org/download/sensor_api_15
@hek: It seems like a PR won't help in this case?@mfalkvidd @return is doxygen formatting info, while the link points to documentation manually written. For 2.0 doxygen is on the agenda, and maybe the manual docs will be replaced by doxygen generated docs. Probably @hek has better insight on the subject.
-
@mfalkvidd @return is doxygen formatting info, while the link points to documentation manually written. For 2.0 doxygen is on the agenda, and maybe the manual docs will be replaced by doxygen generated docs. Probably @hek has better insight on the subject.
-
It's already building, but only @Anticimex has been a good boy adding the correct doxygen comments to his code .
http://ci.mysensors.org/job/MySensorsArduino/branch/development/Doxygen_HTML/ -
Has there been any progress on this guys?
-
Has there been any progress on this guys?
@Mark-Swift thanks for asking. Number 3 and 4 in this post were actually already in place in the code and documentation before this thread was started, but it seems like updating the site to reflect that is quite hard. I don't know how updating the site works unfortunately. The only advice I can give is "Don't look at the online documentation, dig through the source code instead".
number 1 is blocked by me getting enough motivation to do the work required to get the development channel working without screwing up my existing projects. There are so many changes to folder locations and similar that I am unable to compile anything if I switch to the development version and I'm not looking forward to figuring out how to handle that.
-
@Mark-Swift thanks for asking. Number 3 and 4 in this post were actually already in place in the code and documentation before this thread was started, but it seems like updating the site to reflect that is quite hard. I don't know how updating the site works unfortunately. The only advice I can give is "Don't look at the online documentation, dig through the source code instead".
number 1 is blocked by me getting enough motivation to do the work required to get the development channel working without screwing up my existing projects. There are so many changes to folder locations and similar that I am unable to compile anything if I switch to the development version and I'm not looking forward to figuring out how to handle that.
@mfalkvidd said:
Add an example that has a complete implementation of end-to-end ack usage. This includes
setting up timer(s) for re-sending
storing sent messages so they can be re-sent
determining which message was acked when an ack message is received (there might be several messages that haven't been acked yet)
removing acked message from the sent message store and clearing the timer(s)
re-sending when the timers expireAre you referring to this number 1 post?
Does this functionality need to be part of the bool send(MyMessage &msg, bool ack); function or become a layer over the send() function?
Maybe i can have a look one of these days...
-
@mfalkvidd said:
Add an example that has a complete implementation of end-to-end ack usage. This includes
setting up timer(s) for re-sending
storing sent messages so they can be re-sent
determining which message was acked when an ack message is received (there might be several messages that haven't been acked yet)
removing acked message from the sent message store and clearing the timer(s)
re-sending when the timers expireAre you referring to this number 1 post?
Does this functionality need to be part of the bool send(MyMessage &msg, bool ack); function or become a layer over the send() function?
Maybe i can have a look one of these days...
-
I'd love to see some examples of how we can implement a reliable delivery method into critical nodes, especially now 2.0.0 is out in the wild.
-
Any news on this, guys? Do we have some good examples?
-
@hek said:
No, only the findal destination node will answer with a soft ack message.
Note, the (soft) ack message has to be picked up by yourself in your incomingMessage function.
Thanks for explaining. Just checking if my understanding is correct:
bool send(MyMessage &msg, bool ack);will return the result of the hardware ack, regardless if the second parameter is true or false?
So my post above should have been like this:
Hardware ack is always on
- Hardware ack is hop-to-hop acknowledgment
- Sending is a blocking function which returns true if an hardware ack was received, and false if ~70ms passed without receiving an hardware ack.
- Sending hardware ack (when the message has reached the next-hop node) is handled automatically by the library(/radio)
- Receiving an hardware ack is handled automatically by the library, by setting the return value from the send call mentioned above
- Up to 15 tries are made automatically by the library. Further re-send needs to be handled manually in each sketch (a while-loop with a counter counting up to maxRetries and using wait() between each resend seems to be the most common solution)
Software ack is what I get when using send(msg, true) (and is also supported by some other functions like present(), sendSketchInfo() and sendBatteryLevel()
- Software ack is end-to-end acknowledgment
- Sending is a non-blocking function
- Sending ack (when the message has reached its final destination) is handled automatically by the library
- Re-send needs to be handled manually in each sketch (setting up a timer when sending the original message might be a good solution)
- Receiving an ack needs to be handled manually in each sketch (by checking msg.isAck() in incomingMessage and clearing the timer mentioned above)
@mfalkvidd I just came across this post and I am very supprised by the fact that this information is not written anywhere in the documentation ... I believe this is one of the most important stuff everyone should know to actually use MySensors in a real world application - not just diy/hobby project :/ till now I was sure that return value of send funtion (which is NOT explained in the documentation !) is the end-to-end confirmation ...
-
@mfalkvidd I just came across this post and I am very supprised by the fact that this information is not written anywhere in the documentation ... I believe this is one of the most important stuff everyone should know to actually use MySensors in a real world application - not just diy/hobby project :/ till now I was sure that return value of send funtion (which is NOT explained in the documentation !) is the end-to-end confirmation ...