# Test MQTT topic

## About test&#x20;

Data reading and writing examples here below assumes that you are using the Eclipse Mosquitto client CLI, available at the official page <https://mosquitto.org>

## Code placeholders

Code here follows uses placeholders that must be replaced with the actual values. \
So you should know in advance these variables:

* **\<realm-id>**: identifier of the organization (see [Get organisation-id](https://admin-things5.gitbook.io/things5/integrations/devices-and-provisioning/get-realm-id))
* **\<device\_id>**: identifier of the machine (see [Get device-id](https://admin-things5.gitbook.io/things5/integrations/devices-and-provisioning/get-device-id))

machine ssl certificates names, contained in the zip file (see [Get ssl certificates](https://admin-things5.gitbook.io/things5/integrations/devices-and-provisioning/get-ssl-certificates) )

* **\<certificate\_crt>**: named as xxxxxxxxxxxx-certificate.pem
* **\<private\_key>**: named as xxxxxxxxxxxx-private.pem
* **\<cafile\_crt>**: AmazonRootCA1.pem is the current file name

## Publish data&#x20;

{% hint style="warning" %}
**timestamp** must be expressed in milliseconds\
Sent data by here below snippet are: Cabinet\_probe: 55, Evaporator\_probe: 85

Further about [machine variables](https://admin-things5.gitbook.io/things5/device/manage-firmware/machine-variables) in documentation page.
{% endhint %}

```
mosquitto_pub \
-h mqtt.things5.digital \
-q 1 \
-p 8883 \ 
-t things5-production/v1/devices/<device_id>/data_req \
-i things5-production-machine-<device_id> \
-m "{\"metrics\":[{\"timestamp\":0000000000000,\"data\":[{\"name\":\"Cabinet_probe\",\"value\":"55"},{\"name\":\"Evaporator_probe\",\"value\":"85"}]}]}" \
--cafile <cafile_crt> \
--cert <certificate_crt> \
--key <private_key> 
```

Visit monitoring page at this url (*replace placeholders with their real values*) to see published data

```
https://<realm-id>.things5.digital/machines/<device_id>/monitoring
```

### Data stream monitor

Things5 lets you monitor device-broker-device message exchange as shown in this help section [MQTT Diagnostic](https://admin-things5.gitbook.io/things5/integrations/devices-and-provisioning/mqtt-diagnostic)

## Read configuration

Subscribe this topic to let Things 5 read configuration dataset from device (you'll also have to send the right response as explained in the API documentation)

```
mosquitto_sub \
-h mqtt.things5.digital \
-q 1 \
-p 8883 \ 
-t things5-production/v1/devices/<device_id>/cmd/read_variables_req \
-i things5-production-machine-<device_id> \
-v \
--cafile <cafile_crt> \
--cert <certificate_crt> \
--key <private_key> 
```

Visit configuration page at this url (*replace placeholders with their real values*) to see read data

```
https://<realm-id>.things5.digital/machines/<device_id>/configuration
```
