TL;DR

Publish data to /tenants/{tenant_id}/devices/{device_id}/events/{stream_name}/jsonarray in JSON array format.

Introduction

The previous section shown us how to connect to bytebeam. It is now time to start pushing some data.

All communication with Bytebeam happens using JSON. On Bytebeam data is organised into Streams. Each stream is mapped to an MQTT topic. Go through the Creating a Stream guide to create a stream.

Every project in bytebeam comes with a default stream called Device Shadow. We will be illustring how to push data using this stream.

MQTT topic and payload structure

Topic structure

To push data to any stream, you need to publish data to the MQTT topic:

/tenants/{tenant_id}/devices/{device_id}/events/{stream_name}/jsonarray

Replace {tenant_id} with your project name and {device_id} with the device id. You can find these in the JSON file downloaded in the previous section.

Say we are on demo project and device id is 1, so in our case, topic for device shadow will be:

/tenants/demo/devices/1/events/device_shadow/jsonarray

Data should be published with QoS 0 or 1 only, QoS 2 is not supported yet.

Payload

The payload must be a jsonarray, which is an array of data point, where data point is just a JSON object with following fields:

  • sequence: an auto incrementing number for each packet
  • timestamp: Timestamp in milliseconds
  • other fields of the stream ( note: Field names are case sensitive )

so example of a payload for our device_shadow which contains field Status will look like:

[
  {
    "sequence": 1,
    "timestamp": 1710760059006,
    "Status": "On"
  }
]
A device should only publish data to the tenant it is connected.
_Device will be disconnected if device connected to tenant demo, tries to publish to other tenant, say mytenant, e.g. /tenants/mytenant/devices/1/events/device_shadow/jsonarray

Batching Data

As the payload that server accepts is a JSON array. If your client is expected to generate a large amount of data it will be more efficient to batch data and send it to the cloud instead of sending a single packet with each message.

For example:

[
  {
    "sequence": 1,
    "timestamp": 1710760059006,
    ...
  },
  {
    "sequence":2,
    "timestamp": 1710775681047,
    ...
  }
]

Compressing Data

If you are sending larger batches of data you can save on data size by sending zlib or lz4 compressed data.

Trying it out with MQTTX

You can try publishing data using MQTTX as shown below. Notice the QoS1 setting:

You should see the Status change on Bytebeam now: