A Look at Sensor Hub JSON Messaging on WaRP

For WaRP we wanted a simple communication protocol for talking to hardware. Something that would be easy for software developers to use and interact with. Our first requirement was that the messages be human readable for development purposes to avoid trying to decode bit-streams and packets. The second requirement was to allow for variable payloads that could easily be parsed in software.

We choose to use a messaging protocol based on JSON. The lightweight data-interchange format is commonly used in modern programming languages and is portable across platforms. JSON messages are used to send commands and read data back from various peripherals on the Daughterboard.

The messages developed on the Daughterboard are specific to the peripherals on it, but can easily be extended using our protocol.

Viewing  Messages from Daughterboard

A simple way to view the UART data stream coming from the Daughterboard is to cat the UART device /dev/ttymxc2. Performing this operation in the background using the ampersand (&) at the end of the command will cause messages received by the WaRP on ttymxc2 to be printed to the terminal, but still allow typing into the command line.

cat /dev/ttymxc2 &

To kill the background process, use the jobs command to identify the job number and then the kill command to stop it.

root@warp:/ # jobs

[1] + Running   cat /dev/ttymxc2

root@warp:/ # kill %1

Note that interacting with /dev/ttymxc2 from multiple points (e.g. command line and pedometer app or button handler) can cause corruption of the data stream and may result in dropped event signals.

Sending Messages to the Daughterboard

The pedometer example application periodically sends a request for up to date data from the daughterboard by issuing the GET command to the MMA9553L daughterboard device:

{"MMA9553L":"GET"}

While the pedometer app does this programatically, interacting with the daughterboard from the command line is also straight forward. In the terminal simply echo the command to ttymxc2, escaping any special characters as shown below.

Request:

root@warp:/ # echo "{\"MMA9553L\":\"GET\"}" > /dev/ttymxc2

Response:

{"MMA9553L":"Status","data":{"steps":0,"distance":0,"speed":0,"calories":0}}

JSON Messaging Interface

The JSON interface available at release is as follows. Additional functionality can of course be added or exposed by modifying the daughterboard firmware, which is a lesson for another time.

Messages to KL16 from WaRP

Pedometer data request
{“MMA9553L”:”GET”}
Buzzer on/off control
{“BUZZER”:”ON”}
{“BUZZER”:”OFF”}

Messages from KL16 to WaRP

System message from daughterboard
{“SYSMSG”:”System message string”}
Status packet from MMA9553L pedometer
{“MMA9553L”:”Status”,”data”:{“steps”:0,”distance”:0,”speed”:0,”calories”:0}}
Button state messages
{“BTN0”:0}
{“BTN0”:1}
{“BTN1”:0}
{“BTN1”:1}
Push Button 0 Down Event
Push Button 0 Up Event
Push Button 1 Down Event
Push Button 1 Up Event
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *