Difference between revisions of "Mqtt notes"

From Wiki at Neela Nurseries
Jump to: navigation, search
m
m
Line 65: Line 65:
 
</pre>
 
</pre>
  
 +
<pre>
 +
951 #if defined(CONFIG_AWS_IOT_LAST_WILL)
 +
952        static struct mqtt_topic last_will_topic = {
 +
953                .topic.utf8 = CONFIG_AWS_IOT_LAST_WILL_TOPIC,
 +
954                .topic.size = sizeof(CONFIG_AWS_IOT_LAST_WILL_TOPIC) - 1,
 +
955                .qos = MQTT_QOS_0_AT_MOST_ONCE
 +
956        };
 +
957
 +
958        static struct mqtt_utf8 last_will_message = {
 +
959                .utf8 = CONFIG_AWS_IOT_LAST_WILL_MESSAGE,
 +
960                .size = sizeof(CONFIG_AWS_IOT_LAST_WILL_MESSAGE) - 1
 +
961        };
 +
962
 +
963        client->will_topic = &last_will_topic;
 +
964        client->will_message = &last_will_message;
 +
965 #endif
 +
966
 +
967        static sec_tag_t sec_tag_list[] = { CONFIG_AWS_IOT_SEC_TAG };
 +
968        struct mqtt_sec_config *tls_cfg = &(client->transport).tls.config;
 +
969
 +
970        tls_cfg->peer_verify            = 2;
 +
971        tls_cfg->cipher_count          = 0;
 +
972        tls_cfg->cipher_list            = NULL;
 +
973        tls_cfg->sec_tag_count          = ARRAY_SIZE(sec_tag_list);
 +
974        tls_cfg->sec_tag_list          = sec_tag_list;
 +
975        tls_cfg->hostname              = CONFIG_AWS_IOT_BROKER_HOST_NAME;
 +
976        tls_cfg->session_cache = TLS_SESSION_CACHE_DISABLED;
 +
977
 +
978 #if !defined(CONFIG_NRF_MODEM_LIB)
 +
979        err = certificates_provision();
 +
980        if (err) {
 +
981                LOG_ERR("Could not provision certificates, error: %d", err);
 +
982                return err;
 +
983        }
 +
984 #endif /* !defined(CONFIG_NRF_MODEM_LIB) */
 +
985
 +
986        return err;
 +
987 }
 +
</pre>
  
 
A link to review:
 
A link to review:

Revision as of 07:56, 15 December 2021

Notes on MQTT

Looks like in Nordic Semi's aws_iot sample app, the following enumerated events represent a firmware instance receiving subscribed messages from an MQTT broker:

- 1108 DEV - aws_iot event handler called,
AWS_IOT_EVT_READY
- 1108 DEV - aws_iot event handler called,
AWS_IOT_EVT_DATA_RECEIVED

s3://iot-poc/hello/world/

Ah, trouble when attempting to add MQTT topics:

*** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
I: Modem library is not yet initialized, AT commands not sent
I: Configuration of MAGPIO and COEX0 is left to drivers
The AWS IoT sample started, version: v1.0.0
ZZZ
ZZZ
ZZZ
ZZZ - preparing to subscribe to hello/world topic,
ZZZ
ZZZ
ZZZ - calling routine to subscribe to MQTT topics . . .
ZZZ
E: Application subscription list count mismatch
aws_iot_subscription_topics_add, error: -122
ZZZ
ZZZ
ZZZ
ZZZ
Adding application specific topics failed, error: -122
Summary of callback pointers for 'set flag' events:

Appears to come from `./nrf/subsys/net/lib/aws_iot/src/aws_iot.c:1168: LOG_ERR("Application subscription list count mismatch");`

Note 3 - code excert from `nrf/subsys/net/lib/aws_iot/src/aws_iot.c`:

 689                 if (!mqtt_evt->param.connack.session_present_flag ||
 690                     IS_ENABLED(CONFIG_MQTT_CLEAN_SESSION)) {
 691                         err = topic_subscribe();
 692 
 693                         if (err < 0) {
 694                                 aws_iot_evt.type = AWS_IOT_EVT_ERROR;
 695                                 aws_iot_evt.data.err = err;
 696                                 aws_iot_notify_event(&aws_iot_evt);
 697                                 break;
 698                         }
 699                         if (err == 0) {
 700                                 /* There were not topics to subscribe to. */
 701                                 aws_iot_evt.type = AWS_IOT_EVT_READY;
 702                                 aws_iot_notify_event(&aws_iot_evt);
 703                         } /* else: wait for SUBACK */
 704                 } else {
 705                         /* pre-existing session:
 706                          * subscription is already established.
 707                          */
 708                         aws_iot_evt.type = AWS_IOT_EVT_READY;
 709                         aws_iot_notify_event(&aws_iot_evt);
 710 
 711                         if (IS_ENABLED(
 951 #if defined(CONFIG_AWS_IOT_LAST_WILL)
 952         static struct mqtt_topic last_will_topic = {
 953                 .topic.utf8 = CONFIG_AWS_IOT_LAST_WILL_TOPIC,
 954                 .topic.size = sizeof(CONFIG_AWS_IOT_LAST_WILL_TOPIC) - 1,
 955                 .qos = MQTT_QOS_0_AT_MOST_ONCE
 956         };
 957 
 958         static struct mqtt_utf8 last_will_message = {
 959                 .utf8 = CONFIG_AWS_IOT_LAST_WILL_MESSAGE,
 960                 .size = sizeof(CONFIG_AWS_IOT_LAST_WILL_MESSAGE) - 1
 961         };
 962 
 963         client->will_topic = &last_will_topic;
 964         client->will_message = &last_will_message;
 965 #endif
 966 
 967         static sec_tag_t sec_tag_list[] = { CONFIG_AWS_IOT_SEC_TAG };
 968         struct mqtt_sec_config *tls_cfg = &(client->transport).tls.config;
 969 
 970         tls_cfg->peer_verify            = 2;
 971         tls_cfg->cipher_count           = 0;
 972         tls_cfg->cipher_list            = NULL;
 973         tls_cfg->sec_tag_count          = ARRAY_SIZE(sec_tag_list);
 974         tls_cfg->sec_tag_list           = sec_tag_list;
 975         tls_cfg->hostname               = CONFIG_AWS_IOT_BROKER_HOST_NAME;
 976         tls_cfg->session_cache = TLS_SESSION_CACHE_DISABLED;
 977 
 978 #if !defined(CONFIG_NRF_MODEM_LIB)
 979         err = certificates_provision();
 980         if (err) {
 981                 LOG_ERR("Could not provision certificates, error: %d", err);
 982                 return err;
 983         }
 984 #endif /* !defined(CONFIG_NRF_MODEM_LIB) */
 985 
 986         return err;
 987 }

A link to review:


2021-12-14 Tue



2021-12-08

*  https://github.com/aws/aws-iot-device-sdk-embedded-C/blob/main/demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c

+++

*  https://docs.aws.amazon.com/iot/latest/developerguide/topics.html


Unsorted references to MQTT:

# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/net/mqtt_publisher/README.html
# https://www.hivemq.com/blog/mqtt-essentials-part2-publish-subscribe/
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/index.html
# https://www.circuito.io/blog/arduino-code/
# https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages/
# https://www.hivemq.com/blog/mqtt-essentials-part-3-client-broker-connection-establishment/


# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.6.1/nrf/examples.html
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.6.1/nrf/ug_tfm.html#ug-tfm
# https://ci-builds.trustedfirmware.org/static-files/UxIoKYsDyPQ0ojvJOv9EX6-hZNDZd6IPGfcm05Bk1b0xNjM3MTA4NjMxODUxOjk6YW5vbnltb3VzOmpvYi90Zi1tLWJ1aWxkLWRvY3MtbmlnaHRseS9sYXN0U3RhYmxlQnVpbGQvYXJ0aWZhY3Q=/trusted-firmware-m/build/docs/user_guide/html/index.html

Nordic AWS FOTA example:

# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.6.1/nrf/samples/nrf9160/aws_fota/README.html