microchip-pic-avr-solutions / microchip-iot-developer-guides-for-aws

Microchip IoT Developer Guides for AWS is a set of tutorials tailored to get started with your IoT Design, from embedded to cloud. Starting with the sandbox, you can play around with sending and receiving data to the cloud with almost no setup.
34 stars 6 forks source link

AVR-IoT WA is not connecting to AWS #5

Open aquaMatt900 opened 3 years ago

aquaMatt900 commented 3 years ago

I have tried connecting to the sandbox, and connecting to my own AWS account. In both scenarios, the blue LED goes solid blue and then the green LED blinks indefinitely. After a patter of around 20-30 blinks, the green LED stays lit momentarily, then the red error LED will come on for a few seconds and then go off. Then the green LED continues blinking. I also don't see the device connected on the AWS side.

johanlofstad commented 3 years ago

The solid blue LED indicates that it's able to connect to the Wi-Fi, so that's good. Whenever it's connected to AWS, it should show a blinking yellow light, and if I understood you correctly this never happens. You might have a board with outdated firmware. Please try using IoT Provisioning Tool to install the newest firmware, and try connecting to the sandbox again.

Try the following to update the firmware: Download the provisioning tool and extract it. Open a terminal and navigate to the folder you extracted. In my case it's Linux.

cd extracted-iot-prov-folder/linux
./iotprovision-bin -c aws -m sandbox

Please note that the board uses MQTT to communicate with AWS. If you're on a network that blocks port 1883 and 8883 (school, university & office networks often do this), that might also be causing the issue.

If that didn't work, let me know.

aquaMatt900 commented 3 years ago

Thanks for the response. You are correct in understanding the problem; however, I should mention that occasionally the board will have the blinking yellow LED (I can't pinpoint a cause for success), and if I have the board provisioned to access my own AWS account, I can successfully test MQTT messages. If I power cycle the board, though, it very often goes back into the error state.

I tried provisioning back to the sandbox, like you said - still the same problem. I have actually updated the firmware multiple times prior in several different ways (drag and drop .hex to curiosity drive, provisioned to my own AWS, build and program from MPLAB).

I'm on a home network that doesn't block those ports. Actually, this problem has occurred on two different networks that I've tried.

Is there a way (logs or something), to check what is causing the red LED to come on? Is it just a connection timeout, or could it indicate corrupted packets, or something else?

LOSkrebergene commented 3 years ago

The red LED usually indicates errors related to networking or MQTT.

I would try downloading the MPLAB X firmware project and running it directly from MPLAB X. If you run the project in debug mode, you could set some breakpoints wherever the red LED is toggled to see if you can find the problem there. You can find out where the red LED is toggled by searching (Ctrl + Shift + F) for LED_control(&ledParameterRed).

There are also some debug logging available if you connect to the board with a serial terminal (e.g. Tera term) through the COM port. You would also have to enable debug logging in Header Files -> MCC Generated Files -> config -> IoT_Sensor_Node_config.h. Change CFG_DEBUG_PRINT to 1, and rerun the project. When you connect to the serial port with Tera Term, you could also type debug 4, followed by the enter key, to get more detailed debugging information.

aquaMatt900 commented 3 years ago

Ok, I finally had a chance to work on this today. I first ran a debug session and set a breakpoint at "LED_control(&ledParameterRed)" application_manager.c, under "if(shared_networking_params.haveError)". The session halted there. So I set a breakpoint at all lines in the code where shared_networking_params.haveError = 1; The session halted in wifi_service.c, line 211 at "shared_networking_params.haveError = 1;". That was under "if(M2M_SUCCESS != wifiError)". I'm not sure if this is just catching the first try at wifi connection, which may sometimes fail (see debug logs below), or if it's an indication of some other machine to machine connection error. Looking at some other M2M errors, I eventually came to winc_drv_fail being returned on winc_drv_start. This causes M2M_ERROR_INIT to be returned on m2m_wifi_init_start(). Going backward, this led me to finding that false is returned in winc_chip_init(), at the very end of the block, presumably because of a timeout. I'm not sure if that chain of errors is related to the "if(M2M_SUCCESS != wifiError)" causing the red led to come on. That is as far as I got with debugging - didn't have time to do more.

I also went to view debug logs through a serial terminal and the following was returned:

CC5D42B19CF5FE DEBUG ERROR WIFI: wifi error = -1 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud reset timer is set 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Reset task 0123CC5D42B19CF5FE INFO NORMAL CLOUD: reinit 0123CC5D42B19CF5FE INFO NORMAL Connecting to AP with the last used credentials 0123CC5D42B19CF5FE INFO NORMAL CLOUD: Cloud reset timer is deleted 0123CC5D42B19CF5FE DEBUG GOOD wifi_cb: M2M_WIFI_RESP_CON_STATE_CHANGED: CONNECTED 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG GOOD CLOUD: DHCP CONF 0123CC5D42B19CF5FE INFO NORMAL CLOUD: mqttBrokerIP = (3.139.212.254) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: MQTT Connection Timeout 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud Reset 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud reset timer is set 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Reset task 0123CC5D42B19CF5FE INFO NORMAL CLOUD: reinit

second cycle:

0123CC5D42B19CF5FE INFO NORMAL Connecting to AP with the last used credentials 0123CC5D42B19CF5FE DEBUG ERROR WIFI: wifi error = -1 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud reset timer is set 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Reset task 0123CC5D42B19CF5FE INFO NORMAL CLOUD: reinit 0123CC5D42B19CF5FE INFO NORMAL Connecting to AP with the last used credentials 0123CC5D42B19CF5FE INFO NORMAL CLOUD: Cloud reset timer is deleted 0123CC5D42B19CF5FE DEBUG GOOD wifi_cb: M2M_WIFI_RESP_CON_STATE_CHANGED: CONNECTED 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG GOOD CLOUD: DHCP CONF 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE INFO NORMAL CLOUD: mqttBrokerIP = (18.224.122.192) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: MQTT Connection Timeout 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud Reset 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud reset timer is set 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: MQTT Connect 0123CC5D42B19CF5FE DEBUG NORMAL MQTT: sendresult (14) 0123CC5D42B19CF5FE DEBUG NORMAL CLOUD: Connect socket 0123CC5D42B19CF5FE INFO NORMAL ActiveCS bitmap:a000 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Reset task 0123CC5D42B19CF5FE INFO NORMAL CLOUD: reinit 0123CC5D42B19CF5FE INFO NORMAL Connecting to AP with the last used credentials 0123CC5D42B19CF5FE DEBUG ERROR WIFI: wifi error = -1 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Cloud reset timer is set 0123CC5D42B19CF5FE DEBUG ERROR CLOUD: Reset task 0123CC5D42B19CF5FE INFO NORMAL CLOUD: reinit 0123CC5D42B19CF5FE INFO NORMAL Connecting to AP with the last used credentials 0123CC5D42B19CF5FE INFO NORMAL CLOUD: Cloud reset timer is deleted

Which I guess is just indicating a connection timeout.

I'm probably going to call it on this one, since I don't think there is anything wrong with my network/ports/firewalls, etc.. I'll look one more time into the router settings, but I don't think I'll spend more time just trying to get the out-of-box functionality (even just connecting to the sandbox) going on this.