I have a couple of Node JS Modules that I'm now having problems locally debugging. Local debug was working a few weeks ago and I'm not sure what has changed.
Error message:
[UnauthorizedError: mqtt.js returned Failure on first connection (Not authorized): Connection refused: Not authorized error] {
transportError: Error: Failure on first connection (Not authorized): Connection refused: Not authorized
at C:\Users[Truncated]\node_modules\azure-iot-device-mqtt\dist\mqtt.js:235:104
I'm using VSCode.
Steps to replicate:
Command: Azure IoT Edge: Setup IoT Edge Simulator
Command: Azure IoT Edge: Start IoT Edge Simulator for Single Module
From Debug, select the Local Debug (Node.js) for the appropriate module.
Snippet of my code:
const Transport = require('azure-iot-device-mqtt').Mqtt;
const Client = require('azure-iot-device').ModuleClient;
Client.fromEnvironment(Transport, (err, client) => {
if (err) {
throw err;
} else {
client.on('error', function (err) {
throw err;
});
// connect to the Edge instance
client.open(onConnect);
}
});
When I debug, I can see the connection string in module_client.js being set to:
HostName=[my-hub].azure-devices.net;GatewayHostName=localhost;DeviceId=[correct device id];ModuleId=target;SharedAccessKey=LIm[Truncated]k=
This ties in with the connection string I get from the portal - only difference being the "GatewayHostName=localhost;" which doesn't exist on the portal one.
Edit: I checked this again and the SharedAccessKey doesn't tie in with the ones (primary & secondary) in the portal. It's different. I could have sworn it was the same the first time I checked but I might be wrong. Should it be the SharedAccessKey from the portal. I tried overriding while in debug and it didn't seem to improve matters. Still getting the "Not authorised error".
Additional info: I have a few edge devices. I am having the same issue on both of them.
Anything else I can check? Any suggestions?
