-->
Communicating using JSON-formatted strings
JSON, IBM IoT and MQTT target communications options use JSON-formatted strings for messages. For more information on JSON format please json.org
- All fields are case-sensitive, and will not work properly if there are any errors in spelling, uppercase vs. lowercase letters, punctuation, etc.
- Use "straight double quotes", not curled “quotes”
- \n (0x0A) is used as a delimiter between objects
- Do not use \n as line ending within the JSON string
- Here's an example of target code (using the Energia Serial library) to send a JSON response to your GUI Application:
- When binding to a property like the Green property in the above example, dot notation is used:
e.g. to bind to the value of the Green LED, use LEDs.Green
- When sending a value to the target, the JSON object will be dynamically created based on the binding value you enter.
where true would be replaced by the value of the checkbox's checked property.
- It is important to note that the type of the widget's property (e.g. boolean) determines what will be sent to the target (e.g. true), and the target is responsible for handling this.
Configuration Dialogs for USB-UART : JSON, IBM IoT and MQTT
'Teach' GUI Composer the JSON strings your target program is sending to enable auto-completion
- You can make it MUCH easier to bind the JSON property/value strings sent by the target to your GUI
applications widgets by using one of the advanced features of the Target Communications configuration dialogs.
-
The Configuration Dialog is displayed when you are creating a New Project and have selected either
"USB-UART : JSON", "IBM IoT" or "MQTT" as the protocol in Target Communications dialog. You may also open it at
any time by clicking on Project : Properties and clicking Next in the pop up dialog.
-
When the Target Communication wizard page is active, click on a particular target communication method in the left side of the tree to choose your target communication method.
This would show settings for that particular data exchange method. You would then click on Connect and then click on Console buttons. GUI Composer will attempt a connection to your device or broker and show the data
that it is receiving in the console. This accomplishes two objectives.
- It verifies that connection can be established successfully
- GUI Composer parses received JSON strings and creates a table of names that can be used when specifying widget bindings. In binding specification dialog you can trigger auto-completion by pressing CTRL + space bar
-
Once you have created your project, you can re-open this dialog at any time by selecting Project / Properties
from the toolbar at the top of the Designer and then clicking Next in the properties wizard.
Leverage aJson Energia library to construct JSON objects in your firmware
- The simplest way to get started publishing JSON objects is to leverage aJson library that is part of Energia tool.
You may download Energia desktop tool from Energia website or use Cloud IDE at dev.ti.com, which has Energia integrated.
We recommend that you use examples that are included in aJson library to get a better understanding of how to use aJson library
in your own project.
-
In Cloud IDE, create a new project, choose your device and scroll down to Energia libraries, expand aJson node and choose one the examples.
-
As an example code below,
- Here are some Gallery examples that provide links to the associated target-side code and demonstrate an alternative low-overhead method of parsing of incoming JSON strings sent by the GUI Application.
The code also periodically sends the LED status information to the GUI Application: