Thanks for your thorough answer!
Your solution checks if there is serial data. If not, it returns immediately. You have no idea how long the serial buffer has been empty. Maybe that's OK. Maybe not.
If there is as-yet-unread serial data, it records how much, and waits the entire amount of time defined.
That's okay. As I empty the Serial as the first thing in my loop() (see reply #4 in this thread).
If any data arrives during that time, it again waits the entire amount of time before checking whether new data has arrived.
Between when that function ends and the next function gets called, to actually send the data, more data could have arrived.
That's true - but your method wouldn't catch that either. That's why I choose to wait and then check again, before start sending if new data was received since the buffer was emptied.
Nothing else can happen during those delays (and, yes I recognize that they are short).
Mine, on the other hand, checks on every pass through loop, and records when there is a change in the amount of data.
The delays only occur when there is data to send. My function waits only if there has been activity on the bus, and as soon as the bus has been idle long enough starts to send data.
You cannot know if data has been received between the first check in the loop() function and the call to the sendmessage() function (the lastSerial variable would still contain the time stamp we polled for serial data, not the time the last data was received). And that's the issue here! Both yours and my solution are workarounds. The *right* way would be to subscribe to a interrupt that fires when a byte is received - and then update a time stamp. That way a method as shown in my opening post could be used, which is a mix between yours and my attempt to make the workaround
Thanks for your contribution so far! When I find the right solution (for me that is) I'll post an update to this thread!