Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
SensiNact/Bridge MQTT
Description
This bridge allows sensiNact to subscribe to a MQTT topic, and materializes a sensiNact device based on the messages. The devices are displayed just after its configuration (once the .cfg
file is deployed, check below) but the value will be update upon the message arrivals.
Requirements
- MQTT bridge activated (using
sensinact -c
) ; - MQTT server running.
How to use it
Create a file mosquitto-X.cfg
where <codeX</code> is a number that will stand as OSGi service PID (for more details, checks Felix Configuration Manager).
The fields in this file are defined as in a regular property file. The mandatory fields are id and topic. In case any of the other fields host and port are not specified their defaults values are assumed, which are `127.0.0.1` and `1883` respectively.
The id becomes the provider into sensiNact (the name of the sensor), the topic corresponds to the topic in which the provider is attached to. It means that when a new message on the assigned topic is received, the value associated with the device defined in id is updated.
One example of file (named mosquitto-1.cfg
) content is shown below:
host=127.0.0.1 port=1883 id=counter topic=/camera
In order to be taken into account, this file MUST be deployed in the directory $SENSINACT_HOME/load
.
If the message sent to the MQTT does not correspond to clear text, but some other format (e.g., JSON), you can specify two properties, payload.format and payload.sensorValue:
- The payload.format supports the value 'json' at this moment ;
- You MUST specify payload.sensorValue to indicate which element from the JSON you want to use.
host=127.0.0.1 port=1883 id=counter topic=/camera payload.format=json payload.sensorValue=value
Limitations
- One topic is associated with one, and only one, sensiNact provider ;
- The topic message is considered as
String
value, although the SNA generic performs automatic conversion to numeric types. It means that evenString
values can use numeric operators, e.g., "more than", "less than", etc. The conversion will be performed automatically in SNA.