For decades embedded software developers worked on products that were stand-alone and did not require any internet access. Over the past decade or so, the number of products that are connected to the internet has grown exponentially and with it, embedded developers have been forced to learn the underlying technologies required to communicate in a connected world such as various internet protocols and messaging technologies. While developers have traditionally transmitted encoded binary communication streams, the internet often uses human readable JSON messages. In this post, we will examine what JSON is and how developers can use it in their embedded systems.
“isAlive” : true
The “isAlive” portion of the message is the attribute and the “true” portion is the value that is paired with the attribute. JSON messages can include more than a single attribute/value pair. For example:
“isAlive” : true,
“DeviceID” = 1234,
“DeviceName” = “MyProduct”
You’ll notice that reading the JSON message is actually quite simple for a human and beats having to look-up which bits or bytes are associated with a variable.
JSON’s Impact on Embedded System Development
As you might suspect, the use of string messages to transfer information between devices puts an additional strain on embedded systems developers. We always used to use encoded and binary data because it is more efficient to transfer and requires less processing power to parse. Now, we need to parse string messages! I suspect most developers aren’t as familiar with the C string library which adds yet another wrinkle to using JSON.
There are several different ways to parse JSON messages in C which we will be discussing over the next few blogs. One way is to use an online library such as one of the following:
Any developer working on an IoT device will need to understand JSON and more importantly how to parse these messages. In the next post, we will take a look at how developers can use the built-in C library function strstr to parse JSON messages.