Connection Methods

What are connection methods and how to post data?

There are two ways to post your datapoints in Statstream :

  • Via MQTT connection method.
  • Via HTTP connection method.

How to create a new MQTT connection method

Quick guide to create a new MQTT connection method

  • Click on your Workspace Name to enter within your workspace.

  • Go to -> Administration tab on top right corner.

  • From the left side pane, Go to -> Credentials.

  • Click on New Credential button on the top right side.

  • Enter suitable connection name to connect your device.

  • Choose the Protocol as MQTT from the dropdown list and enter connection description.

  • Click Save & Generate Seceret Key button to get your MQTT server connection details.

  • To get the MQTT server details Go to > Credentials tab and click on Name of the credential.

  • Below screenshot shows an example of your MQTT server details

    MQTT server details

  • Refer to the below YouTube video to help you create a new MQTT connection.

How to create a new HTTP connection method

Quick guide to create a new HTTP connection method

  • Click on your Workspace Name to enter within your workspace.

  • Go to -> Administration tab on top right corner.

  • Click on New Credential button on the top right side.

  • Enter suitable connection name to connect your device.

  • Choose the Protocol as HTTP from the dropdown list and enter connection description.

  • Click Save & Generate Seceret Key button to get your HTTP Post request secret key .

  • To get the HTTP secret key details Go to > Credentials tab and click on Name of the credential.

  • Below screenshot shows an example of your HTTP secret key details

    HTTP connection details

  • Refer to the below YouTube video to help you create a new HTTP connection.

How to post your data using MQTT method

  • Use the following MQTT topic to post the JSON payload of your variables

    • JSON Topic: /v1/device/{DEVICE_ID}
      • example: /v1/device/raspberry_pi
  • You can directly post raw values as well, use the following MQTT topic to post your raw values (example: 24) to a device variable

    • Value Topic: /v1/device/{DEVICE_ID}/variable/{VARIABLE_ID}
      • example: /v1/device/raspberry_pi/variable/INCOMER_B_AMPS
  • The payload must be a JSON object with the following structure :

{
"VARIABLE_ID_1": VALUE,
"VARIABLE_ID_2": VALUE,
"VARIABLE_ID_3": VALUE
}
  • Replace VARIABLE_ID_1,VARIABLE_ID_2 with your actual “VARIABLE_IDs” and VALUE with the actual Value you want to record.
  • You can get VARIABLE_IDs from -> Devices -> Show -> Variables tab.

How to post your data using HTTP method

  • Use the following HTTP URL to post the JSON payload of your variables
    • HTTP:POST request: https://your_account_URL/http/v1/device/{DEVICE_ID}/{SECRET_TOKEN}
      • example: https://acme.statstream.io/http/v1/device/raspberry_pi/d80fc6c38q044c82a01e0dffc0
  • The payload must be a JSON object with the following structure :
{
"VARIABLE_ID_1": VALUE,
"VARIABLE_ID_2": VALUE,
"VARIABLE_ID_3": VALUE
}
  • Replace VARIABLE_ID_1,VARIABLE_ID_2 with your actual “VARIABLE_IDs” and VALUE with the actual Value you want to record.
  • You can get VARIABLE_IDs from -> Devices -> Show -> Variables tab.