MKR 1500 BearSSL is failing

Hi everybody,

thanks to this community I got the basic functions of the MKR1500 board running.

Right now I'm trying to connect to Azure using the Azure example and I accounted the following problem:

The connection fails, as the BearSSLClient does not properly read all received bytes. At least, this is what I think the problem is when I follow the code in debug mode:

...

+UUSORD: 0,280
AT+USORD=0,256


+USORD: 

0,256,"receivedBytesHere"
OK

+UUSORD: 0,24
failed to connect
.-2

It stops before reading the last 24 received bytes. What's the problem here?

Thank you,
Andy

Edit: I figured when the NB_SOCKET_BUFFER_SIZE is set to 512, my module suddenly stops working. So I set it down to 256. Then I get an following error in the ssl_hs_client.c file, which is reported by the line

br_ssl_engine_fail(ENG, (int)T0_POPi());

Has anyone any idea how I can make the X509 self-singed authorization process with azure work?

I've got a suggestion for your last question. Perhaps you should start by getting that working first.

Follow this guide
https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-nb-1500-to-azure-iot-hub-af6470

I did and connected first time. You must run the sketch to set up X509.

Thank you for your answer.

I'm following the exact same tutorial. I properly set up the certificate. I didn't modify anything as far as I can tell.

What exactly was your setup when you made it work?

  • SIM-Card?
  • Power source?

Edit:
the -2 means that the connection was refused, but I have no idea what caused that.

My (non-verbose) output is:

Attempting to connect to the cellular network
You're connected to the cellular network

Attempting to connect to MQTT broker: MKRHub.azure-devices.net
failed to connect
.-2

You seem to be close.

I use a Vodafone SIM for NB. Don't know if it is different to the normal ones. But you are connecting to the cellular network so your SIM seems to do the job. Can you run the MKRNB GPRS test OK?

I have a 1200mAh LiPo battery connected. It won't connect without the battery.

Have you pasted the SHA string into your Azure IOT device as a Self Signed key? Your device ID is the same in your sketch as the Azure DeviceID? I'm really just going through all the things you need to set up.

My guess is your sketch setup, key or Azure setup isn't quite right, not your hardware, since you can get to the broker connection step.

Good luck.

Thanks for your help.

I'm using a 1NCE Simcard and cellular connection seems to work so far.

I also tried both a 3.7V battery and a high precision power supply, both won't make it work.

I triple-checked the authentification thing, it should be alright. I'm running out of ideas :frowning:

Also tested on three different MKR1500, one of them was defective from the beginning.

MPQ

If you look in MQTTClient.h you see -2 = MQTT_CONNECTION_REFUSED
Perhaps search on reasons for that.

If you can run the GPRS sketch successfully and you get the MQTT phase of the example program it isn't going to be battery or PSU. You are already successfully connecting.

Have you tried connecting anything else to your IOT Hub? I had been using an ESP2866 Arduino, to connect via wifi, before using the 1500NB. At least you will know the Azure end works.

Yes, connection does not seem to be the problem. The MKR is also connect to a battery pack.

Another thing that seems strange to me: When I leave the variable

#define NB_SOCKET_BUFFER_SIZE 512

my serial output eventually stops with

...
+UUSORD: 0,536
AT+USORD=0,512

+USORD: 0,512,"1603030FA70200004D03035D55091ED36D3176A4CDEAAB3638E1FFD8FA05A3CFCD6D24601FA0A28C70F79520ED270000082BDA0AD4271363256C20E9D3299BFDF5012107310DF8D5F2FD2BCCC027000005FF010001000B000DC5000DC200080430820800308205E8A0030201020213160004A37B883F57C415A40F6800000004A37B300D06092A864886F70D01010B050030818B310B3009060355040613025553311330110603550408130A57617368696E67746F6E3110300E060355040713075265646D6F6E64311E301C060355040A13154D6963726F736F667420436F72706F726174696F6E31153013060355040B130C4D6963726F736F6674204954311E301C060355040313154D6963726F736F667420495420544C532043412034301E170D3139303431323232353934335A170D3230303431323232353934335A301E311C301A06035504030C132A2E617A7572652D646576696365732E6E657430820122300D06092A864886F70D010100503800F03010A282110ED119F954E68F52040F2B706DC815909F7A82BAFFF7B4F64E4A445BBB1D1F2E5D384660C85C8F3159A028485DDABCC5E7C2BF58669A60FBEF4730C63DEED2B665CA509FB95B96A6FB0FE89A8E6491C983A0A62B
OK

+ORD: 024

So it feels like the module crahes.

So I changed it to 256:

#define NB_SOCKET_BUFFER_SIZE 256

Then my output is

...
+USORD: 0,256,"DA009B2AA8F43500E3FD2C3BEDE5159B7F160FC78EC9362094F01D01B91250509981E028422C8E78FFEDC69ED5E4CAE9A0AAB3484FA45FE48B18FF13022D9011361866283A229ADE95F159EE9F6D2A17759350C30512D5DE64B4B6BCDBD77659FEA5D6E556E1FE465C3B8AF8EC0EFBEF129091CE201281BA3C52E37FE340F40C4120668718DA3269E0F6DC8F28F2BD0C000169030018610452F1F9B991DDAE6B720201E72C42D670195FBEC35A88D14F0CAE66B89670058EA0AC7BADD0A55C4F70000AF94B7BA54EA7BDDC2B50F60DA88B64420BD88DEDDD49402D8D584AC1AC3267CC0DAC8CF981EF166F9C1C5EA84EC8D1BB647FD75D3802010100796AFB0E"
OK

+UUSORD: 0,24
failed to connect
.-2

and it seems to work exept for error -2 (failed auth). Maybe someone has an idea what's happening here.

Edit: Maybe found the error: The AT+CCKL returns the default time:
+CCLK: "80/01/06,00:22:24"
which makes the server reject the certificate. How do I set the time/timezone?
CTZU=1 does not work

Any new suggestions?
I have the some problem with the MKR1400.
Should I consider to buy a new one?