Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SensiNact/Bridge MQTT"

Line 16: Line 16:
 
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.
 
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 <code>mosquitto-1.cfg</code>) content is shown below:
+
One example of file (named <code>mqtt-1.cfg</code>) content is shown below:
 
   
 
   
 
<source lang="html4strict">
 
<source lang="html4strict">

Revision as of 12:49, 15 March 2018

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-sb bridge activated (via sensinact -c)
  • A MQTT server

How to use it

Create a file mqtt-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 mqtt-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/cfgs.

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.

You can as well specify the location of the device, this is an optional information, case this information is not provided the location assumes will be the same as the gateway location.

host=127.0.0.1
port=1883
id=counter
topic=/camera
discovery.firstMessage=false
location.latitude=44.5
location.longitude=55.8

Limitations

  • The topic message is considered as String value, although the SNA generic performs automatic conversion to numeric types. It means that even String values can use numeric operators, e.g., "more than", "less than", etc. The conversion will be performed automatically in SNA.

Back to the top