Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Connect to MQTT broker at Amazon IoT with fw/examples/c_mqtt

edited November 2016 in Mongoose OS

Hi,

I want to connect my esp8266 to Amazon IoT.
I compiled the firmware (master@0873fe75), used the example c_mqtt code and followed the steps at https://github.com/cesanta/mongoose-iot/tree/master/fw/examples/c_mqtt but can't get a connection to the MQTT broker at AWS IoT.

However, I can connect to my AWS "thing" via mosquitto_sub/pub so the AWS setup seems to work.

I set the log level to DEBUG and here is what I get:

mqtt_global_connect  MQTT connecting to xxxx.iot.eu-central-1.amazonaws.com:8883
set_errno            spiffs error: -10002
set_errno            spiffs error: -10003
set_errno            spiffs error: -10003
set_errno            spiffs error: -10003
set_errno            spiffs error: -10003
set_errno            spiffs error: -10003

No "CONNECT" message, no error message.

Publishing to /device-id/gpio will be received by mosquitto_sub but not by the esp8266.

Pressing the flash button does not trigger a published message. Instead I get
gpio_int_handler Click!

I don't know if the spiffs errors have anything to do with my problem.

Using the new miot aws-iot-setup command did not work as well:

`Error: failed to generate certificate: invalid create certificate response
...
...
...
invalid character 'a' looking for beginning of value`

Has anybody been able to connect to AWS IoT lately?

Thanks,
/Matthias

Comments

  • rojerrojer Dublin, Ireland
    edited November 2016

    aws iot requires certificates, it won't work without successful aws-iot-setup.

    server's response should be included in the error message, can you include it?

  • I tried the manual setup according to the doc on github (c_mqtt) and I uploaded all three certificates to the device.

    I tried using miot aws-iot-setup as an alternative to the manual setup because I wasn't able to connect to aws.

    Regarding the aws-iot-setup error, here is the server's response: http://pastebin.com/6nZPu5JQ

  • rojerrojer Dublin, Ireland
    edited November 2016

    let's focus on aws-iot-setup, that's the easier way - when it works :)
    it looks like server returned ARN + PEM as plain text, not wrapped in JSON.
    response should look like this:

    {
        "certificateArn": "arn:aws:iot:eu-west-1:493820262597:cert/92ec5070fac379e62a887bb3b39904f6281541adca0ffee6f88872eda8c92f5b", 
        "certificatePem": "-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----\n", 
        "certificateId": "92ec5070fac379e62a887bb3b39904f6281541adca0ffee6f88872eda8c92f5b"
    }

    what's your aws CLI version? run aws --version to check.

  • rojerrojer Dublin, Ireland

    btw, you can also skip cert generation with aws-iot-setup - specify --cert-file=mycert.pem --key-file=my-key.pem and it will use them

  • @rojer said:
    it looks like server returned ARN + PEM as plain text, not wrapped in JSON.

    Ah, it was the format. I had to change it from text to json.

    @rojer said:
    btw, you can also skip cert generation with aws-iot-setup - specify --cert-file=mycert.pem --key-file=my-key.pem and it will use them

    That worked like a charm.
    Thank you very much!

    ev_handler           MQTT Connect (1)
    ev_handler           CONNACK: 0
    sub                  Subscribed to /espding/gpio
    ev_handler           Done: [{pin: 5, state: 1}]
    ev_handler           Done: [{pin: 2, state: 0}]
    ev_handler           Done: [{pin: 2, state: 1}]
  • rojerrojer Dublin, Ireland

    i will add --output=json to all the aws commands issued by miot so we don't rely on the default. thanks for reporting!

  • rojerrojer Dublin, Ireland

    btw, what's your use case? what are you building? if you don't mind sharing, of course.

Sign In or Register to comment.