Curiosity PIC32MZEF demo connection problem

Janeu wrote on November 20, 2019:

Hi,

Help needed, my Curiosity PIC32MZEF demo has worked in the past, but for some reason it doesn’t now connect to AWS IoT.

Setup:

  1. Created a thing.
  2. Created certificates (pem.crt and private.perm.key) and activated them.
  3. Attached a very general policy to the certificate.
  4. Attached the thing to the certificate.
  5. Used CertificateConfigurator.html (perm.crt and private.perm.key) to generate aws_clientcredential_keys.h.
  6. Updated aws_clientcredential.h with my endpoint and thing name.
  7. Subscribed “iotdemo/#” in AWS IoT Test page, but no result seen.

Uart log:
7 3258 [iot_thread] [INFO ][DEMO][3258] ---------STARTING DEMO---------
8 3260 [iot_thread] [INFO ][INIT][3260] SDK successfully initialized.
9 3260 [iot_thread] [INFO ][DEMO][3260] Successfully initialized the demo. Network type for the demo: 4
10 3260 [iot_thread] [INFO ][MQTT][3260] MQTT library successfully initialized.
11 3260 [iot_thread] [INFO ][DEMO][3260] MQTT demo client identifier is MyDevice (length 8).
12 5901 [iot_thread] [INFO ][MQTT][5901] Establishing new MQTT connection.
13 5902 [iot_thread] [INFO ][MQTT][5902] Anonymous metrics (SDK language, SDK version) will be provided to AWS IoT. Recompile w14 5902 [iot_thread] [INFO ][MQTT][5902] (MQTT connection 0x80016518, CONNECT operation 0x8000d950) Waiting for operation compl15 10902 [iot_thread] [INFO ][MQTT][10902] (MQTT connection 0x80016518, CONNECT operation 0x8000d950) Wait complete with result16 10902 [iot_thread] [ERROR][MQTT][10902] Failed to establish new MQTT connection, error TIMEOUT.
17 10902 [iot_thread] [WARN ][NET][10902] Failed to close connection.
18 10902 [iot_thread] [INFO ][MQTT][10902] Network connection closed on error.
19 10903 [iot_thread] [INFO ][MQTT][10903] (MQTT connection 0x80016518) Network connection destroyed.
20 10903 [iot_thread] [ERROR][DEMO][10903] MQTT CONNECT returned error TIMEOUT.
21 10903 [iot_thread] [INFO ][MQTT][10903] MQTT library cleanup done.
22 10903 [iot_thread] [ERROR][DEMO][10903] Error running demo.
23 10903 [iot_thread] [INFO ][INIT][10903] SDK cleanup done.
24 10903 [iot_thread] [INFO ][DEMO][10903] -------DEMO FINISHED-------

I don’t know if AWS blocks or incorrect setup in the PIC.
Any idea what to check?

Janeu wrote on November 21, 2019:

Hi Yuki-AWS,

Yes, I’m using Ethernet and IDE.

The Ethernet is included via PIC32_USE_ETHERNET in the Project Properties Preprocessor macros, and seems to work. I’ve check via a breakpoint in defined Ethernet area. As seen it has been given a client IP address by the router. The router is connected to the internet.

In debug mode, I can see that the AWS’s CONNACK is missing from the PIC’s CONNECT try.
The timeout occurs in IotMqtt_Wait().

As I see it, there can be two alternative faults here:

  1. Either in the PIC, ie incorrect setting or so, or
  2. AWS is blocking

The only changes in code are, but I’m not sure if they are correct:

  • #define clientcredentialMQTT_BROKER_ENDPOINT “a…y-ats.iot.eu-west-1.amazonaws.com”
  • #define clientcredentialIOT_THING_NAME “MyDevice”
    Note: Same endpoint as defined in AWS IoT Setting, my AWS region is eu-west-1 and the thing MyDevice is created in the AWS IoT.

Policy used:
{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: “iot:Connect”,
“Resource”: “"
},
{
“Effect”: “Allow”,
“Action”: “iot:Publish”,
“Resource”: "

},
{
“Effect”: “Allow”,
“Action”: “iot:Subscribe”,
“Resource”: “"
},
{
“Effect”: “Allow”,
“Action”: “iot:Receive”,
“Resource”: "

}
]
}

There is a way to check the incoming messages in AWS, such as CONNECT from the PIC? And also the AWS reaction?

Yuki-AWS wrote on November 21, 2019:

Hi Janeu,

From the log, it seems the project is using ethernet. Network type for the demo: 4 And it seems you were not able to connect to IoT core. The expectation for our MQTT demo is it should work out of box, and I’m going to set it up locally to verify the head of aws/amazon-freertos master branch.

Meanwhile,

- You’ve mentioned the demo worked for you. Could you confirm whether it was on WiFi or Ethernet?

- There may exist some difference between IDE and CMake project. If you are using CMake to see this error, could try IDE.

- Since ethernet, may want to check cable… (I know…)

-------- Updated --------
I’ve verified aws/amazon-freertos the HEAD of master branch Microchip PIC32 IDE project on Windows, and MQTT demo was working for me over ethernet. (Log attached, with IoT endpoint commented out.) May try the same code to confirm whether there was a setup issue.

Edited by: Yuki-AWS on Nov 20, 2019 6:20 PM

Janeu wrote on November 21, 2019:

Hi all,

My misstake, I’ve jumped around in different AWS Regions and then forget to perform a Clean before going into the Debug session. Therefore the endpoint was incorrect, and unfortunately it wasn’t seen in the debug UART. I found out via removing the internet connection and got the debug info in clear text about the incorrect endpoint.

After a Clean , my target has the correct endpoint and work as expected!

Lesson learned: Always perform a Clean before a build!

Yuki-AWS wrote on November 21, 2019:

Hi Janeu,

Glad it all sorted out!

(Yes, we don’t log all the settings in UART… Will discuss with team, see if we can make debug easier.)