Reputation: 31
I am using the IoT Agent for Ultralight. I am sending my data via mqtt. My broker uses the mqtts protocol. It works with the json iot agent but not with UL. Apparently I can't set a protocol type like in the json agent. My colleagues stick to the UL agent. So I'd like to use that as well. Does anyone know the right way to connect to a tls mqtt-broker with the UL agent? Is it even possible?
Thanks in advance!
Upvotes: 0
Views: 419
Reputation: 5290
The latest is 1.13.0 Release includes a port the MQTT over SSL support from the JSON IoT Agent over to the Ultralight IoT Agent.
The important changes for secure MQTT support can be found here - the most relevant part is summarized below:
var options = {
protocol: 'mqtt',
host: 'localhost',
port: 1883,
key: fs.readFileSync(mqttConfig.key, 'utf8') : null,
ca: fs.readFileSync(mqttConfig.ca, 'utf8') : null,
cert: fs.readFileSync(mqttConfig.cert, 'utf8') : null,
rejectUnauthorized: true,
username: 'username',
password: 'password',
keepalive: 0,
connectTimeout: 60 * 60 * 1000
};
var mqttClient = mqtt.connect(
options.protocol + '://' + mqttConfig.host + ':' + mqttConfig.port,
options
);
This is merely stuffing the options
available within the standard Node.JS MQTT Client
Since this PR has been merged,it is now possible to use the latest
docker image and supply Docker variables to add username, password, ca authority and so on.
The following new Docker ENV
variables are defined:
| Environment variable | Configuration attribute |
| ---------------------------- | ---------------------- |
| IOTA_MQTT_PROTOCOL | mqtt.protocol |
| IOTA_MQTT_CA | mqtt.ca |
| IOTA_MQTT_CERT | mqtt.cert |
| IOTA_MQTT_KEY | mqtt.key |
| IOTA_MQTT_REJECT_UNAUTHORIZED | mqtt.rejectUnauthorized |
| IOTA_MQTT_USERNAME | mqtt.username |
| IOTA_MQTT_PASSWORD | mqtt.password |
IOTA_MQTT_KEY
, IOTA_MQTT_USERNAME
and IOTA_MQTT_PASSWORD
can be hidden as Docker secrets and alias in the usual manner by adding the _FILE
suffix.
Upvotes: 0