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"

(Creation of the page)
 
Line 25: Line 25:
 
</source>
 
</source>
  
In order to be taken into account, this file '''MUST''' be deployed in the directory <code>$SENSINACT_HOME/load</code>.
+
In order to be taken into account, this file '''MUST''' be deployed in the directory <code>$SENSINACT_HOME/cfgs</code>.
  
 
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''':
 
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 ;
 
* 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 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.
  
 
<source lang="html4strict">
 
<source lang="html4strict">
Line 38: Line 40:
 
payload.format=json
 
payload.format=json
 
payload.sensorValue=value
 
payload.sensorValue=value
 +
discovery.firstMessage=false
 +
location.latitude=44.5
 +
location.longitude=55.8
 
</source>
 
</source>
  

Revision as of 08:39, 31 May 2017

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/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
payload.format=json
payload.sensorValue=value
discovery.firstMessage=false
location.latitude=44.5
location.longitude=55.8

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 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