Serial Sensor Protocol
Serial Sensor Protocol is a protocol for serial communications between sensors and base stations on a meshed sensor network.
THIS IS A DRAFT
Terminology
- CAN and MAY both mean that it is allowed but not required.
- SHOULD means that it generally should be a certain way but legitimate exceptions may arise; in this case care must be taken not to break compatibility with other aspects of the protocol.
- MUST means that there are no acceptable exceptions to this rule.
Negations both in the form of CAN NOT and CAN'T should be understood canonically.
Transaction block
The basic unit of communications is a transaction block, which consists of:
- Recipient ID (1 byte)
- Sender ID (1 byte)
- Command code (1 byte)
- Payload length in bytes (1 byte)
- (optional) Payload (maximum 255 bytes)
Identification codes
Each sensor MUST have an ID code. These ID codes SHOULD be unique, as ID collisions will render two sensors indistinguishable, but of course there MAY arise situations where this is beneficial; to all other extents there should be no ill effects of collisions.
ID codes 0x00 and 0xFF are reserved.
- 0x00 is a multicast address, which ALL sensors MUST respond to.
- 0xFF is the master address, which is not considered a sensor.
Sensors SHOULD in general address messages to the master unless they have specific reason not to. Sensors SHOULD never use multicast addressing.
Command codes
Code | Function | Returns | Params |
---|---|---|---|
0x00 | No operation | 0x00 | |
0x01 | Read logger memory | @memstruct | |
0x02 | Get logger memory checksum | 2 byte checksum | |
0x03 | Get logger memory entry count | 2 byte entry count | |
0x04 | Get logger time zero | @UTS | |
0x05 | Get logger current time | @UTS | |
0x10 | Clear logger memory | @status | |
0x11 | Set logger time zero | @status | @UTS |
0x12 | Set logger time offset | @status | 2 byte offset |
0x13 | Clear logger time offset | @status | |
0x20 | Get sensor status | @sensorstruct | |
0xE0 | Get network neighbors | @netnodes | |
0xE1 | Get MAC address | 8 byte MAC address | |
0xE2 | Get packets sent | 4 bytes, bytes sent | |
0xE3 | Get packets received | 4 bytes, bytes recvd | |
0xF0 | Get battery status | @status, float |
Command responses
A command response SHOULD address the sender of the comamnd and MUST contain the same command code as was originally posted.
For example:
- Master sends:
01:FF:04:00
- Meaning: Request to Host 0x01 from Master, Get Logger Time Zero, no payload
- Host 0x01 replies:
FF:01:04:04:4A:4B:58:6F
- Meaning: Reply to Master from Host 0x01, Get Logger Time Zero, response: 0x4a4b586f, which in decimal is 1246451823, which is the Unix Time Stamp for Wed, 01 Jul 2009 12:37:03 GMT
Data structures
@UTS
4 byte UNIX time stamp
@memstruct
This contains the measurement data.
- 1 byte signifying number of bytes per structural element.
- 2 bytes number of elements (same as command 0x03).
- repeats:
- 2 bytes time offset
- n bytes structural elements
- 2 bytes checksum (same as command 0x02)
@sensorstruct
This contains information about the sensors, and also provides information about how to parse measurement data.
- 1 byte number of sensors attached
- repeats:
- 1 byte sensor class (@sensorclasses)
- 1 byte status code
- 1 byte memstruct element length in bytes
- 1 byte reserved
@sensorclasses
A table of sensor types, enumerated from 0x00 to 0xFF
- 0x01 Light sensor, IR
- 0x02 Light sensor, visible light
- 0x03 Light sensor, UV
- 0x04 Thermal sensor
- 0x05 Barmoeter
- 0x06 Force sensor
- 0x07 Scales
- 0x10 Accelerometer
- 0x11 Odometer
- 0x12 Tachometer
- 0x20 Button
- 0x21 Switch
- 0xFF Hybrid sensor
@statuscodes
one byte status codes
- 0xE1 OK
- 0xE2 CRC error
- 0xFF Not implemented