Reputation: 23
Edge Module node client is unable to connect to Edge Hub over MQTT. It throws a cert error - NotConnectedError: unable to get local issuer certificate
.
Cert is set an option for the client,
var certFile = process.env.EdgeModuleCACertificateFile;
var connectionString = process.env.EdgeHubConnectionString
var Protocol = require('azure-iot-device-mqtt').Mqtt;
var Client = require('azure-iot-device').Client;
var client = Client.fromConnectionString(connectionString, Protocol);
var options = {
ca: fs.readFileSync(certFile,'utf-8').toString(),
};
client.setOptions(options,()=>{
console.log('Client transport option set');
});
client.open(connectCallback);
Upvotes: 2
Views: 511
Reputation: 26
I can't help without knowing some details about your environment:
Are you running inside a docker container?
What base image did you use?
How are you starting the container -- are you launching it manually or letting the EdgeAgent launch it for you?
A few things that you can try:
1) Verify that you're using @modules-preview code. NPM makes this easy to get wrong.
PS F:\temp> npm list | findstr "azure-iot"
+-- azure-iot-device-mqtt@1.4.0-modules-preview
| +-- azure-iot-common@1.5.0-modules-preview
| +-- azure-iot-device@1.4.0-modules-preview
| | +-- azure-iot-http-base@1.3.3-modules-preview
| +-- azure-iot-mqtt-base@1.3.3-modules-preview
2) Verify that your connection string is well formed. It needs to have moduleId= and gatewayHostName= values. The gatewayHostName should be referencing your edgeHub host.
3) Verify the cert file referenced in EdgeModuleCACertificateFile exists and looks like a valid PEM file (e.g. text file wrapped in -----BEGIN CERTIFICATE-----/-----END CERTIFICATE---- with a bunch of lines of encoded text in between).
Upvotes: 1