Skip to content

NATS

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.

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.

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.

{
"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 the CmdId field.
  • CmdData: The data for the command. The CmdData field 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.

This topic is used by the Smart Boxes to respond to the commands sent to them on the Request.$CompanyID.$ZoneTopic.Box topic.

{
"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. The CmdResp field 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. The CmdData field 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 IDCommand NameDescription
30SetLightColorSet the color of the Smart Box LED.