VSChina / ESP32_AzureIoT_Arduino

The library for ESP32 Azure IoT for Arduino
MIT License
37 stars 43 forks source link

Cannot connect to Iot Hub #8

Open KoRba88 opened 6 years ago

KoRba88 commented 6 years ago

Hi

I have compiled and uploaded "GetStarted" example without errors BUT

Serial monitor shows these messeges

Error: Time:Tue Jul 10 19:48:41 2018 File:C:\Users\Marcin\Documents\Arduino\libraries\ESP32_AzureIoT_Arduino\src\az_iot\c-utility\src\base64.c Func:Base64_Decoder Line:201 Invalid length Base64 string!

Error: Time:Tue Jul 10 19:48:41 2018 File:C:\Users\Marcin\Documents\Arduino\libraries\ESP32_AzureIoT_Arduino\src\az_iot\c-utility\src\sastoken.c Func:construct_sas_token Line:217 Unable to decode the key for generating the SAS.

Error: Time:Tue Jul 10 19:48:41 2018 File:C:\Users\Marcin\Documents\Arduino\libraries\ESP32_AzureIoT_Arduino\src\az_iot\iothub_client\src\iothub_client_authorization.c Func:IoTHubClient_Auth_Get_SasToken Line:389 Failed creating sas_token

Error: Time:Tue Jul 10 19:48:41 2018 File:C:\Users\Marcin\Documents\Arduino\libraries\ESP32_AzureIoT_Arduino\src\az_iot\iothub_client\src\iothubtransport_mqtt_common.c Func:SendMqttConnectMsg Line:1585 failure getting sas token from IoTHubClient_Auth_Get_SasToken.

Info: >>>Re-connect.

Info: Initializing SNTP

assertion "Operating mode must not be set while SNTP client is running" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/lwip/apps/sntp/sntp.c", line 591, function: sntp_setoperatingmode abort() was called at PC 0x400e2cf7 on core 1

Backtrace: 0x40088348:0x3ffd0bd0 0x40088447:0x3ffd0bf0 0x400e2cf7:0x3ffd0c10 0x401135bd:0x3ffd0c40 0x400d3f5e:0x3ffd0c60 0x400d3fba:0x3ffd0c80 0x400d2fa2:0x3ffd0ca0 0x400d32d6:0x3ffd0ce0 0x400d343d:0x3ffd0d00 0x400d2653:0x3ffd0d20 0x401384b4:0x3ffd0e60

Rebooting... ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:956 load:0x40078000,len:0 load:0x40078000,len:13076 entry 0x40078a58 ESP32 Device Initializing...

WiFi Connecting... ....WiFi connected IP address: 192.168.1.74 IoT Hub Info: Initializing SNTP

Info: SNTP initialization complete

Info: IoT Hub SDK for C, version 1.1.23

samisarfraz commented 6 years ago

Its is keep on reconnecting and rebooting ESP 32 device. Having similar issue.

lirenhe commented 6 years ago

From the error, it seems you did not provide the correct device connection string. It failed with the following check

    if ((strlen(source) % 4) != 0)
    {
        /*Codes_SRS_BASE64_06_011: [If the source string has an invalid length for a base 64 encoded string then Base64_Decode shall return NULL.]*/
        LogError("Invalid length Base64 string!");
        result = NULL;
    }

Could you double check the device key in the connection string?

pgrlopes commented 6 years ago

Hello @lirenhe

I have a similar issue. I created a device within my IoT hub in the azure portal and I'm providing the signature string as it is given to me in the device panel, so something like this:

"HostName=;DeviceId=;SharedAccessKey="

It does not work though, saying that my Base64 code has invalid length. By checking a couple of files I can see that the SAS token is retrieved from the key, so I tried changing the SharedAccessKey in the string to SharedAccessSignature. That also does not work, it just says ">>> Connection Status: timeout" and this message is given because the authentication failed in the ConnectionStatusCallback function from the ESP32MQTTClient.cpp file.

Much like OP, im probably doing something trivial very wrong, would appreciate a bit of help understanding the authentication process.

Thank you for your time.

KoRba88 commented 6 years ago

I solved this issue. "HostName=;DeviceId=;SharedAccessKey=" should be written without <> marks. Just directly copy it from azure iot hub account.

lirenhe commented 6 years ago

@pgrlopes , you need to remove '<>' marks in your connection string. Do check this doc: https://blogs.msdn.microsoft.com/iotdev/2017/05/09/understand-different-connection-strings-in-azure-iot-hub/

simf1 commented 5 years ago

Did you resolve this issue?

When my IoTDevKit is connected to the wifi. It repeats a message no-stop (see below).

I fallowed the step-by-step Microsoft Procedure "GetStarted - Connect IoT DevKit AZ3166 to Azure IoT Hub"

I took the ConnectionString from this command:

az iot hub device-identity show-connection-string --hub-name YourIoTHubName --device-id MyNodeDevice --output table I tried with the connection located in Iot Device Explorer... and same result.

And i used this connection string format:

HostName={YourIoTHubName}.azure-devices.net;DeviceId=MyNodeDevice;SharedAccessKey={YourSharedAccessKey} This is the ERROR:

2019-08-28 13:22:04 ERROR: base64_utility.c (ln 201): Invalid length Base64 string! 2019-08-28 13:22:04 ERROR: sastoken.c (ln 217): Unable to decode the key for generating the SAS. 2019-08-28 13:22:04 ERROR: iothub_client_authorization.c (ln 460): Failed creating sas_token 2019-08-28 13:22:04 ERROR: iothubtransport_mqtt_common.c (ln 2169): failure getting sas token from IoTHubClient_Auth_Get_SasToken.

The screen of my IoTDevKit still with the IP Adress and Running... (under that, " > IoT Hub")

Did you have a solution for that?

version DevKitSDK version: 1.6.2

Mico version: 31620002.049

mbed-os version: 5.4.3

mbed TLS version: 2.15.0

WIFI version: wl0: Sep 10 2014 11:28:46 version 5.90.230.10

2019-08-28 09_27_04-Window 2019-08-28 09_21_43-COM5 - PuTTY