Problem with MQTT on STM32L475IoT

sdt99 wrote on October 18, 2019:

Hi,

I have created an AWS account, created a thing, a group a policy added the thing to the group and linked the policy but MQTT seems to still fail (see bold)

0 522 Tmr Svc WiFi module initialized.
1 1025 Tmr Svc Write certificate…
2 2387 Tmr Svc Device credential provisioning succeeded.
3 8727 Tmr Svc WiFi connected to AP HOME-FF08-2.4.
4 8732 Tmr Svc IP Address acquired 10.0.0.19
5 8736 Tmr Svc WiFi firmware version is: C3.5.2.5.STM
6 8741 Tmr Svc WiFi firmware is up-to-date.
7 8746 iot_thread INFO INIT 8746 SDK successfully initialized.
8 15450 iot_thread INFO DEMO 15449 Successfully initialized the demo. Net
work type for the demo: 1
9 15459 iot_thread INFO MQTT 15459 MQTT library successfully initialized.
10 15466 iot_thread INFO DEMO 15466 MQTT demo client identifier is PersonalSTM32L475IoT (length 20).
11 16850 iot_thread INFO MQTT 16850 Establishing new MQTT connection.
12 16861 iot_thread INFO MQTT 16860 Anonymous metrics (SDK language, SDK version) will be provided to AWS IoT. Recompile with AWS_IOT_MQTT_ENABLE_METRIC1
3 16875 iot_thread INFO MQTT 16875 (MQTT connection 0x100065f0, CONNECT operation 0x10006778) Waiting for operation completion.
14 16960 NetRecv ERROR MQTT 16960 (MQTT connection 0x100065f0) Unknown packet type 01 received.
15 16970 NetRecv ERROR MQTT 16970 (MQTT connection 0x100065f0) Error processing incoming data. Closing connection.
16 16981 NetRecv INFO MQTT 16980 (MQTT connection 0x100065f0) Network connection closed.
17 21887 iot_thread INFO MQTT 21887 (MQTT connection 0x100065f0, CONNECT operation 0x10006778) Wait complete with result TIMEOUT.
18 21899 iot_thread ERROR MQTT 21899 Failed to establish new MQTT connection, error TIMEOUT.
19 21908 iot_thread INFO MQTT 21908 Network connection closed on error.
20 21921 iot_thread INFO MQTT 21921 (MQTT connection 0x100065f0) Network connection destroyed.

I’d greatly appreciate any ideas / pointers that anyone might have

Edited by: sdt99 on Oct 18, 2019 4:08 PM

PrasadV-AWS wrote on October 28, 2019:

Hello,

Thank you for reporting this and sharing logs. Can you provide more information on which Amazon FreeRTOS release you are using and if you had made any changes or trying the MQTT demo?

Are you using the board listed here - https://devices.amazonaws.com/detail/a3G0L00000AANsWUAX/STM32L4-Discovery-Kit-IoT-Node ?

sdt99 wrote on November 07, 2019:

Sorry for the slow reply - I was pulled onto other projects.

I fixed the problem - it was entirely due to my lack of understanding of AWS IoT. The error was in the policy attached to the thing

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“iot:Publish”,
“iot:Subscribe”,
“iot:Connect”,
“iot:Receive”
],
“Resource”: “arn:aws:iot:us-east-2:374120848493:topic/replaceWithATopic
}
]
}

I replaced the bolded text topic/replaceWithATopic with a single asterisk and now the demo completes correctly.

sdt99 wrote on November 07, 2019:

I am using the STM32L475 IoT node - though with what may be an old example of the AWS FreeRTOS demo code. In aws_demo_config.h I replaced the default demo CONFIG_GREENGRASS_DISCOVERY_DEMO_ENABLED with CONFIG_MQTT_DEMO_ENABLED in an attempt to create the simplest possible demo of MQTT connect / publish and subscribe.

  • Amazon FreeRTOS V1.4.7
  • Copyright © 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  • Permission is hereby granted, free of charge, to any person obtaining a copy of
  • this software and associated documentation files (the “Software”), to deal in
  • the Software without restriction, including without limitation the rights to
  • use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  • the Software, and to permit persons to whom the Software is furnished to do so,
  • subject to the following conditions:
  • The above copyright notice and this permission notice shall be included in all
  • copies or substantial portions of the Software.
  • THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  • FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  • COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  • IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  • CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • http://aws.amazon.com/freertos
  • http://www.FreeRTOS.org
    */

#ifndef AWS_DEMO_CONFIG_H
#define AWS_DEMO_CONFIG_H

/* To run a particular demo you need to define one of these.

  • Only one demo can be configured at a time
  •      CONFIG_MQTT_DEMO_ENABLED
    
  •      CONFIG_SHADOW_DEMO_ENABLED
    
  •      CONFIG_GREENGRASS_DISCOVERY_DEMO_ENABLED
    
  •      CONFIG_TCP_ECHO_CLIENT_DEMO_ENABLED
    
  •      CONFIG_DEFENDER_DEMO_ENABLED
    
  •      CONFIG_POSIX_DEMO_ENABLED
    
  •      CONFIG_OTA_UPDATE_DEMO_ENABLED
    
  •      CONFIG_HTTPS_SYNC_DOWNLOAD_DEMO_ENABLED
    
  •      CONFIG_HTTPS_ASYNC_DOWNLOAD_DEMO_ENABLED
    
  • These defines are used in iot_demo_runner.h for demo selection */

//#define CONFIG_GREENGRASS_DISCOVERY_DEMO_ENABLED
#define CONFIG_MQTT_DEMO_ENABLED

sdt99 wrote on November 07, 2019:

Ended up answering my own question - I now understand the policy restricts which MQTT topics a Thing can publish and subscribe to. My policy had a bug - once fixed the demo works.

sdt99 wrote on November 07, 2019:

Just one more observation - with the incorrect policy setting when I look in Things->DeviceName->violations in the AWS IoT console it says:

“This Thing had not violated behaviors for any associated security profile during the selected time duration.”

I would have expected to see a violation here since the Thing was unable to connect MQTT due to policy error.