firedog1024 / mkr1000-iotc

Connecting an Arduino MKR1000 to Azure IoT Central
MIT License
31 stars 13 forks source link

---> mqtt failed, rc=-2 issue on MKR1000 #3

Closed nahojkj closed 5 years ago

nahojkj commented 5 years ago

Hi!

Having trouble getting this running on an MKR1000.

Using Arduino 1.8.9. Double checked everything is ok in IoT Central. I downgraded the WiFi101 to the version mentioned in readme, but that did nothing. Reuploaded the SSL-certificates. Not sure what to try next...

Serial output is as follows: 16:00:10.758 -> Getting the time from time service: 16:00:10.826 -> Current time: 28. May 2019 - Tuesday 14:00:10 16:00:10.928 -> Getting IoT Hub host from Azure IoT DPS 16:00:11.236 -> ERROR: Couldn't connect AzureIOT DPS endpoint. 16:00:31.231 -> Starting IoT Hub connection 16:00:51.206 -> ---> mqtt failed, rc=-2 ...and so on...

nahojkj commented 5 years ago

Hi again!

It seems that there is some issue with getting the host name from the getHubHostName function.

I changed line 318 in mkr10x0.ino to an actual hostname:

// iothubHost = hostName; iothubHost = "-----------------------------------.azure-devices.net";

That seemed to do the trick! So I made some changes so that getHubHostName is not called, and that the hostname is configured in the config.h:

In configure.h: static char PROGMEM iotc_hostName[] = "-----------------------------------.azure-devices.net"

in mkr10x0.ino: // getHubHostName((char*)iotc_scopeId, (char*)iotc_deviceId, (char*)iotc_deviceKey, hostName); iothubHost = iotc_hostName;

I've got the MKR1000 up and running now, and it works great! I must say that this is one of the clearest and most concise guides and code I have encountered for Azure IoT so far. Like the guides based on the simplesample_MQTT/simplesample_HTTP, for whatever device, are long, confusing, and full of quircks (like mixing C/C++ code). Many thanks for sharing!

firedog1024 commented 5 years ago

Thanks for the kind words, one of the main goals of this project was to make the sample really straight forward and easy to understand, I'll take a look at this issue and see if I can reproduce the error you were seeing. Glad you got it working with some tinkering around but I'd like to understand the root cause here. I'm leaving the issue open for now until I can take a closer look.

firedog1024 commented 5 years ago

Finally got back to this issue. I installed the latest wifi firmware onto the MKR-1000 (WINC1501 Model B (19.6.1)(Arduino/Genuino MKR 1000)). pulled the github repo code and just changed my scope id, device id, and device key, plus added in wifi SSID and password. Running the code on the MKR 1000 I was able to connect to IoT Central vioa DPS without an issue. I rebooted a dozen times without any connection issues. I also tried with the earlier wifi firmware 19.5.4 and again had no issues connecting to IoT Central via DPS. I'm going to close out this issue as I cannot reproduce it. Possibly there was a transient issue with DPS at the time you tried to connect. If you can try again that would be great and if you are still experiencing issues we can re-open the issue and investigate further.

I'll update the readme to include the latest WiFi firmware version, since it's been released after publishing this repo.

zhaodong2013062 commented 5 years ago

I have repro'd this issue. Tried updating to firmware version 19.6.1, and got the same error. I then ran the CheckWiFi101Firmware sketch, and I was told that I needed to be on version 19.4.4. I downgraded to that version, but got the same issue.

Getting the time from time service: 
Current time: 25. June 2019 - Tuesday 22:07:08
Getting IoT Hub host from Azure IoT DPS
ERROR: Error from DPS endpoint

Starting IoT Hub connection
---> mqtt failed, rc=-2
---> mqtt failed, rc=-2
---> mqtt failed, rc=-2
---> mqtt failed, rc=-2
zhaodong2013062 commented 5 years ago

Tried using the Firmware/Certificates uploader tool to upload the SSL certificate for the domain global.azure-devices-provisioning.net:443, but that did not work either.

mgungorchamp commented 2 years ago

Connecting MKR WIFI 1010 to Microsoft Azure IoT Hub with Symmetric key Device option

https://paul-bruffett.medium.com/iot-azure-pipeline-9725ac2b6a00