Skip to main content
Skip table of contents

JSON data format in DeviceLink

In the Navixy DeviceLink, the JSON (JavaScript Object Notation) data format is used to structure and encode data for transmission between IoT devices and the Navixy platform across all protocols - MQTT, UDP, TCP, and HTTP.

For example, a GPS tracker might send data like this:

JSON
{
    "deviceID": "1234",
    "timestamp": "2023-06-27T10:00:00Z",
    "location": {
        "latitude": 40.7128,
        "longitude": 74.0060
    },
    "speed": 50,
    "direction": 90
}

Each device packages its data as a UTF-8 encoded JSON object, ensuring universal character representation and backward compatibility with ASCII. Irrespective of the communication protocol used, each message to the Navixy platform contains a single such encoded JSON object.

Grouping related data fields can make the data structure more intuitive and easier to work with. While we don’t enforce specific field names, providing a recommended structure with grouped fields can be helpful for developers.

For example, the payload could look like this:

JSON
{
    "deviceID": "1234",
    "timestamp": "2023-06-27T10:00:00Z",
    "gpsData": {
        "location": {
            "latitude": 40.7128,
            "longitude": 74.0060
        },
        "speed": 50,
        "direction": 90
    },
    "cellularSignal": {
        "strength": -75,
        "networkType": "4G"
    },
    "sensorData": {
        "temperature": 20,
        "humidity": 60
    }
}

In this example, GPS data, cellular signal data, and sensor readings are grouped into their own objects. This makes the payload more organized and the data easier to understand at a glance. Plus, it makes extracting specific sets of related data on the server side simpler. However, this is just a recommendation and as a developer you can structure your JSON data in the way that works best for you.

There are a couple of ways to send binary data in JSON format from an IoT device to the Navixy platform:

1. Base64 encoding

One of the most common ways to include binary data in JSON is to encode the data as a Base64 string. Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. This is a good option if the binary data is not too large, as Base64 increases the size of the binary data by about 33%.

Example:

JSON
{
    "deviceID": "1234",
    "binaryData": "SGVsbG8gd29ybGQ="
}

The binaryData field is a Base64-encoded string that represents the binary data.

2. Hexadecimal encoding

Alternatively, binary data can be encoded as a hexadecimal string. This approach doubles the size of the binary data, but it may be easier to handle in certain cases, as hexadecimal strings only contain digits and the letters A-F.

Example:

JSON
{
    "deviceID": "1234",
    "binaryData": "48656c6c6f20776f726c64"
}

The binaryData field is a hexadecimal string that represents the binary data.

In both cases, the IoT Gateway needs to know that it should decode the string to obtain the original binary data. You should specify this when designing a Data process by using the Retrieve and Set type component. The Navixy IoT Gateway has the functionality to decode these strings back into their original binary format. After decoding, the binary data may be interpreted or processed further, depending on what the data represents. This might involve converting the binary data to a different data type, such as an integer, a float, or a string, or it might involve parsing the binary data in a certain way.

When it comes to sending large volumes of data like images or video clips captured by dash cams, you might need to employ special strategies as these can be quite sizable and could exceed payload limits or result in performance issues. Here are some suggestions:

  • Compression: Before sending the data, consider using a compression algorithm to reduce its size. Be aware, however, that the compression/decompression process can introduce some latency.

  • Chunking: If the data is too large to send in a single message, you might need to break it down into smaller chunks and send each one separately. Each chunk would be sent as a separate message, and you'd need to include some kind of sequence information so that the server can reassemble the chunks in the correct order.

  • Separate endpoint for large data: Consider providing a separate API endpoint in your apps specifically for large data uploads. This would separate the heavy traffic from your regular data flow and ensure that large uploads do not interfere with other data processing.

  • Use TCP or HTTP: For transmitting large volumes of data, TCP or HTTP are generally better suited than MQTT or UDP. TCP, in particular, provides reliable, ordered, and error-checked delivery of a stream of bytes, which is ideal for large data.

  • Offload to cloud storage: Instead of sending the video files or images directly to the Navixy IoT Gateway, you could upload them to a cloud storage service like AWS S3, Google Cloud Storage, or Azure Blob Storage. The device could then send a message to the server with the URL of the uploaded file. This offloads the heavy data handling to a service that's designed for it and can scale as needed.

Remember that any method you use should take into consideration the capacity and capabilities of the IoT devices themselves, as well as the overall network conditions and the capabilities of the server.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.