0

I'm running a forever script sending data from raspberry pi 3 to azure-iot-hub, using the following, root@raspberrypi3:~# forever start /home/pi/azure/iam/ble_azure.js

After working for about 1.5 days, I stopped getting messages at auzre-iot-hub, when I checked forever list I got the following:

root@raspberrypi3:~# forever list
info:    Forever processes running
data:        uid  command         script                          forever pid  id logfile                 uptime         
data:    [0] NWgI /usr/bin/nodejs /home/pi/azure/iam/ble_azure.js 8990    3784    /root/.forever/NWgI.log 0:21:17:38.742 

When I checked the log file I get this error message:

/home/pi/azure/iam/node_modules/applicationinsights/AutoCollection/Exceptions.js:27
                        throw error;
                        ^
NotConnectedError: mqtt.js returned client disconnecting error
    at translateError (/home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-translate-error.js:25:11)
    at MqttTwinReceiver._handleError (/home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:201:42)
    at /home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:64:18
    at MqttClient._checkDisconnecting (/home/pi/azure/iam/node_modules/mqtt/lib/client.js:314:7)
    at MqttClient.subscribe (/home/pi/azure/iam/node_modules/mqtt/lib/client.js:423:12)
    at /home/pi/azure/iam/node_modules/azure-iot-device-mqtt/lib/mqtt-twin-receiver.js:62:22
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
error: Forever detected script exited with code: 7
error: Script restart attempt #34
state has changed poweredOn
started scanning
[IoT hub Client] Connect error: mqtt.js returned premature close error

Through the log file, mqtt error keeps happening multiple times and forever handled it successfully, what I can't understand why after 1.5 days, I get this error:

**error: Forever detected script exited with code: 7
error: Script restart attempt #34**

Also why I keep getting such mqtt error, why it keeps disconnecting?

**NotConnectedError: mqtt.js returned client disconnecting error**


Forever --version 
v0.15.3

root@raspberrypi3:~# uname -a
Linux raspberrypi3 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

Thanks

hardillb
  • 54,545
  • 11
  • 67
  • 105
Ayman
  • 37
  • 1
  • 6

1 Answers1

0

If you're using Client.fromConnectionString to instantiate the client object the SDK disconnects and reconnects every 45 minutes to renew the shared access signature token. (it doesn't happen with AMQP that uses a different authentication mechanism). It might be that when re-establishing the connection the client hits this "premature close" error that we've been tracking in this issue.

There are 2 things that could help limit potential errors linked to disconnecting/reconnecting:

Last but not least, the next release of the SDK (1.2.0) will include a retry/reconnect logic that is way more robust than what was there before. I'll update the issue to point to it when it is released.

  • how shall I get X509 certificate on RPi, using nodejs "JS"? any links – Ayman Oct 25 '17 at 16:41
  • You can refer [Get started on X.509 CA certificate security](https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-security-x509-get-started) to set up X.509 security in your Azure IoT hub. – Michael Xu Oct 26 '17 at 01:30
  • you said that **"Client.fromConnectionString"** will make the client to connect/disconnect every 45min, but today I found that my script kept working for 1day and 18 hrs, it's very strange, I didn't change anything, I didn't manage to try your suggestions above yesterday and kept forever running as it's with the old connectionstring, anyway, now I changed my script to use SAS token using **"Client.fromSharedAccessSignature"**, to see if it will connect/disconnect again, and will update you, thanks for your help. – Ayman Oct 26 '17 at 12:46