-
- You Are Here
-
- cambo
- Junior Boarder
-
- Posts:31
- Karma: 0
Hi, wondering if anyone can offer some code guidance on how to receive data packets from different sources? So a scenario might be:
Incoming data from an XRF every minute.
Incoming data from an RFM12B every minute.
Incoming data from an XRF every five minutes.
I guess I'm wondering how to wait for different packets from different sources at varying frequencies?
Incoming data from an XRF every minute.
Incoming data from an RFM12B every minute.
Incoming data from an XRF every five minutes.
I guess I'm wondering how to wait for different packets from different sources at varying frequencies?
-
- CisecoDev
- Administrator
-
- Posts:670
- Karma: 23
I wouldn't worry about the message frequencies, the main thing to get right is to ensure that messages from the XRFs do not interleave. This is best done by setting the packet length such that a message always fits into one packet, you will always receive a packet intact. It is best to have a common message structure with a unique and easily identified start of message, e.g. for LLAP you can use (in the loop function)
if (Serial.available() >= 12) {
if (Serial.read() == 'a') {
// we have a message - process it
}
}
The rest of the problem is merely a matter of checking for a message (from RFM12B or from XRF) in the loop and acting on it if one is received. The Jeelabs example RF12demo copes with this.
if (Serial.available() >= 12) {
if (Serial.read() == 'a') {
// we have a message - process it
}
}
The rest of the problem is merely a matter of checking for a message (from RFM12B or from XRF) in the loop and acting on it if one is received. The Jeelabs example RF12demo copes with this.
