NATS
Introduction
Section titled “Introduction”NATS is a simple, secure and high performance open source data layer for cloud native applications, IoT messaging, and microservices architectures.
This document serves as a comprehensive guide to the NATS topics and their schemas being used in our system.
It is not intended to be a guide to NATS itself, for that please refer to the NATS documentation.
Use Cases
Section titled “Use Cases”NATS is being used in our system is to provide a simple and reliable messaging layer between Smart Boxes, backend microservices, web applications, and android applications.
The primary use case is to control the Smart Boxes, send commands to them, and receive telemetry data from them.
Topics
Section titled “Topics”Request.$CompanyID.$ZoneTopic.Box
Section titled “Request.$CompanyID.$ZoneTopic.Box”This topic is used to send commands to the Smart Boxes. The commands are sent in JSON format and
the Smart Boxes respond to the commands on the Response.$CompanyID.$ZoneTopic.Box topic.
Schema
Section titled “Schema”{ "Id": "string", "Timestamp": "string", "Type": "number", "NodeIP": "string", "NodeName": "string", "CmdId": "30", "CmdData": { "Address": "number", "Data": ["0-255", "0-255", "0-255", "0 | 1", "0-255"] }}The fields in the schema are as follows:
Id: A unique identifier for the message.Timestamp: The timestamp when the message was sent.Type: The type of the message. Type 0 specifies that light’s color and blink status are being set.NodeIP: The IP address of the Smart Box.NodeName: The name of the Smart Box.CmdId: The command ID. See the Command ID Definitions section for the definition of theCmdIdfield.CmdData: The data for the command. TheCmdDatafield is an object with the following fields:Address: The address of the Smart Box.Data: An array of 5 elements. The first 3 elements are the RGB values of the color. The 4th element is the blink status (0 for off, 1 for on). The 5th element is the brightness of the light.
Response.$CompanyID.$ZoneTopic.Box
Section titled “Response.$CompanyID.$ZoneTopic.Box”This topic is used by the Smart Boxes to respond to the commands sent to them on the
Request.$CompanyID.$ZoneTopic.Box topic.
Schema
Section titled “Schema”{ "Id": "string", "Timestamp": "string", "Type": "number", "NodeIP": "string", "NodeName": "string", "CmdResp": { "Code": "number", "Status": "string", "Description": "string", "CmdData": { "Address": "number", "Data": ["0-255", "0-255", "0-255", "0 | 1", "0-255"] } }}The fields in the schema are as follows:
Id: A unique identifier for the message.Timestamp: The timestamp when the message was sent.Type: The type of the message. Type 0 specifies that the response is for a command.NodeIP: The IP address of the Smart Box.NodeName: The name of the Smart Box.CmdResp: The response data for the command. TheCmdRespfield is an object with the following fields:Code: The response code.Status: The status of the execution of the command.Description: A description the success or failure of the command.CmdData: The data that was sent for the command. TheCmdDatafield is an object with the following fields:Address: The address of the Smart Box.Data: An array of 5 elements. The first 3 elements are the RGB values of the color. The 4th element is the blink status (0 for off, 1 for on). The 5th element is the brightness of the light.
Command ID Definitions
Section titled “Command ID Definitions”| Command ID | Command Name | Description |
|---|---|---|
| 30 | SetLightColor | Set the color of the Smart Box LED. |