-
• #2
Hi tage
Use a variable where you count the received bytes. Use a timer (setTimer, setInterval) to check every N seconds the counter.
Sacha
-
• #3
Or something like this
var timer function callWhenBytesReceived() { if (timer) {clearTimeout(timer); timer=0;} timer=setTimeout("onDisconnect()",3000) }
-
• #4
Thanks,
I tried Sacha's suggestion and it worked. I did try DrAzzy's method but did not manage to get it to work yet, will try again tomorrow if I find the time. -
• #5
Personally I think Sacha's method is a little more efficient if you have a lot of data coming in - otherwise it won't matter...
-
• #6
Yeah, it probably is.
I am working on a project where I am using my Espruino board to monitor Serial1. With regular intervals there are a couple of bytes arriving. The message contains status information, and I have to take action depending on the status bits. The action can be to turn on some LEDs that show status and fault information.
I have figured out how to read the status bytes by converting them to decimal numbers, but I am struggling with how to detect if the communication suddenly stops. For example, the gadget that I am monitoring goes silent because there is a power interruption. How can you detect that there has been no communication for 3 seconds, for example?