Skip to main content

Publishing a message

As discussed in the device configuration section, in order to publish any message you need to know the device configuration associated to the entity used to communicate.

Using Connhex Control#

  • Enter the device or edge detail
  • Open the Control tab
  • Use the Send a message section to send a message to the selected device.

Connhex Control: sending a message

Please note that this will send a SenML message, as specified here.

HTTP#

To send a sample message via HTTP protocol, we will use curl.

curl -s -S -i -X POST -H "Content-Type: application/json" -H "Authorization: <device_key>" http://<server_ip_address>/http/channels/<channel_id>/messages -d '[{ "n": "sample-device-name", "v": 3.6, "u": "V" }]'
  • <device_key>: key (password) of the device that publish the message;
  • <server_ip_address>: IP address of the server in which Connhex is running;
  • <channel_id>: unique identifier of the channel associated to the device that publish the message.

MQTT#

To publish test messages over MQTT we'll use Mosquitto tools as follows:

mosquitto_pub -u <device_id> -P <device_key> -t channels/<channel_id>/messages -h <server_ip_address> -m '[{ "n": "sample-device-name", "v": 3.6, "u": "V" }]'
  • <device_id>: unique identifier of the device that publish the message;
  • <device_key>: key (password) of the device that publish the message;
  • <server_ip_address>: IP address of the server in which Connhex is running.

You can subscribe to a given topic and receive all the published messages with the following command:

mosquitto_sub -u <device_id> -P <device_key> -t channels/<channel_id>/messages -h <server_ip_address>
MQTT Topic

The standard MQTT topic is channels/<channel_id>/messages.