This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrF9160 sample aws_fota

I am trying to implement the AWS FOTA sample from SDK V1.4.2.

I have already implemented the AWS IOT sample which works fine.

However, the AWS FOTA fails with mqtt_connect errror -22.

The log is shown below:

*** Booting Zephyr OS build v2.4.0-ncs2  ***


MQTT AWS Jobs FOTA Sample, version: 2.0.0


Initializing bsdlib


Initialized bsdlib


LTE Link Connecting ...


I: PDP Context: AT+CGDCONT=1,"IP","arkessalp.com"


LTE Link Connected!


IPv4 Address 54.154.11.137


client_id: TDG_logger_thing


mqtt_transport_connect FAILED


ERROR: mqtt_connect -22


My prj.cfg file is attached:

5270.prj.conf

Can you point out where it's gone wrong?

  • Hi,

    mqtt_connect -22 is the error EINVAL, which means invalid argument. This is most likely caused because the MQTT configuration is incorrect.

    From your prj.conf I see that you have copied configurations from the AWS IoT sample. The AWS FOTA sample does not use the AWS IoT library, but the AWS FOTA library, which you can see under dependencies in the documentation of the sample. Therefore, you should not use CONFIG_AWS_IOT to configure your sample. Instead, you should configure it as described in the sample, under sample configuration. This description is for how to configure it using menuconfig in SES (SEGGER Embedded Studio), but if you instead want to configure it in prj.conf, which I recommend using instead of SES and menuconfig, you should add the following configs, and switch out the values so they correspond with your values:

    # AWS FOTA
    CONFIG_CLOUD_CERT_SEC_TAG=12345678
    CONFIG_USE_CLOUD_CLIENT_ID=y
    CONFIG_CLOUD_CLIENT_ID="your_client_id"
    CONFIG_MQTT_BROKER_HOSTNAME="your_aws_mqtt_broker_hostname.amazonaws.com"
    CONFIG_MQTT_BROKER_PORT=8883

    The reason I recommend changing configurations in prj.conf and not in menuconfig in SES is because the changes done in menuconfig are only done in your current project, so if you reload the project or close it and open it again, the changes will not be there anymore, as they will be overwritten by prj.conf when you run CMake, which is run when you open a project in SES.

    For later projects, if it is unclear what configs you have to set in prj.conf and the documentation only explains how to configure the project using menuconfig, you can find the configs by doing the following:

    • Open the project in SES
    • Go to Project > Configure nRF Connect SDK Project > menuconfig
    • Press the + next to the project settings to open up the settings (in AWS FOTA this is MQTT FOTA Sample Settings)
    • Select and change the configurations you want to use in your project
    • When you are done select Configure and wait for the configuration to finish
    • There will now be a file in your build folder with the generated configs for your project, in <build_folder>/zephyr/.config, so in the case of the AWS FOTA sample this will be <ncs_folder>/nrf/samples/nrf9160/aws_fota/build/zephyr/.config.
    • You can then copy the relevant configs from the .config file to your prj.conf. The relevant MQTT configs in the case of AWS FOTA can be found under # MQTT FOTA Sample Settings

    Best regards,

    Marte

  • Hi Marte,

    Thanks for your help.

    I have changed the prj.conf file as per your directions and moved things on a bit.

    It does successfully connect to the MQTT broker but I'm not seeing that it is susbcribing to the topic (as per Nordic documentation)

    [mqtt_evt_handler:129] MQTT client connected!
    [00:00:14.106,140] <inf> aws_jobs: Subscribe: $aws/things/nrf-aws-fota/jobs/notify-next

    My topic is:
    $aws/things/TDG_logger_thing/jobs/notify-next
    Here is what I am seeing:
    client_id: TDG_logger_thing
    
    
    
    
    hostname: a3vecosqszzrnz-ats.iot.eu-west-1.amazonaws.com
    
    
    
    
    [mqtt_evt_handler:182] MQTT client connected!
    
    
    [mqtt_evt_handler:235] PUBACK packet id: 50475
    
    
    
    
    [mqtt_evt_handler:245] SUBACK packet id: 2114
    
    
    
    
    [mqtt_evt_handler:193] MQTT client disconnected -128
    
    
    
    
    ERROR: mqtt_input -128
    
    
    
    
    Disconnecting MQTT client...
    
    
    
    
    Could not disconnect MQTT client. Error: -128


    Can you tell me what is wrong here?

    Many thanks

  • Hi,

    Error -128 is ENOTCONN, socket is not connected. The device is being disconnected, but I do not know why. Is the cloud side configured correctly? Did you follow the guide for the sample when creating a thing in AWS IoT and setting up an AWS S3 bucket?

    Could you please take a modem trace? This will help me figure out why you are being disconnected.

    Best regards,

    Marte

  • Hi Marte,

    We did follow the guide for setting up the S2 bucket and creating a thing in AWS IoT - and correctly I think.

    I'm attaching the modem trace.

    I am using nrF9160DK.

    trace-2021-03-17T16-20-13.110Z.bin

    ,Thanks for your help,

    Dermot

  • Hi,

    I will look at the modem trace and come back to you when I find anything.

    Best regards,

    Marte

Related