I have a sensor network at home using Ardiunos and series 1 Xbees with the mesh software installed on them. The one unsolved problem I have is that if two sensors send data at the same time, the data (in this case json) from the sensors is intermingled.
So, what should look like this
arrives like this
One way to handle this is to poll the sensors, but some of them run on batteries and spend the majority of their time asleep, so I can't do that.
Any suggestion on ways to fix this appreciated
UPDATE: Think I found a solution. The data was being written out as it was read from the sensors, which was inserting delays in sending the data to the serial port. Also the Packetization Timeout on the Xbee was the default of 3, which is the time to send 3 characters (approx 200us at 57600). The combination meant that the json messages were being sent as 2 or 3 packets as the timeout occured while waiting for the sensor to respond. The solution was to read all the data from the sensors, then send the json message, in a single Serial.println(). And set the Packetization Delay to 10 to make quite sure it didn't timeout.