Difference between revisions of "Mqtt notes"

From Wiki at Neela Nurseries
Jump to: navigation, search
m (Nordic Devzone help and reference to LTE modem parameters TAU, AT, iDRX, cDRX, RRC idle.)
(^ Tau and AT, iDRX and cDRX parameters: - 3GPP document.)
Line 21: Line 21:
 
<ul>
 
<ul>
 
*  https://devzone.nordicsemi.com/power/w/opp/4/user-guide-lte
 
*  https://devzone.nordicsemi.com/power/w/opp/4/user-guide-lte
 +
</ul>
 +
Searching for reference document "3GPP":
 +
<ul>
 +
*  https://www.3gpp.org/technologies/keywords-acronyms/98-lte
 
</ul>
 
</ul>
  

Revision as of 21:45, 21 December 2021

Overview

Notes on MQTT

2021-12-20 - On devzone.nordicsemi.com creating public forum post with title "aws_iot MQTT subscriber keep alive", following suggested posts as solutions come up:


^ Tau and AT, iDRX and cDRX parameters

In response to post on Nordic Devzone:

Searching for reference document "3GPP":


^ MQTT Persistent Sessions References


^ aws_iot Run-time Message Excerpts

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 }
z4-sandbox-kionix-work/nrf/subsys/net/lib/aws_iot/src$ grep -n 'struct mqtt_topic' ./*.*
451:	const struct mqtt_topic aws_iot_rx_list[] = {
546:			.list = (struct mqtt_topic *)&aws_iot_rx_list,
952:	static struct mqtt_topic last_will_topic = {

edit point


./zephyr/include/net/mqtt.h:178:struct mqtt_topic {



/** @brief Abstracts UTF-8 encoded strings. */
struct mqtt_utf8 {
        const uint8_t *utf8;       /**< Pointer to UTF-8 string. */
        uint32_t size;             /**< Size of UTF string, in bytes. */
};


/** @brief Abstracts MQTT UTF-8 encoded topic that can be subscribed
 *         to or published.
 */
struct mqtt_topic {
        /** Topic on to be published or subscribed to. */
        struct mqtt_utf8 topic;

        /** Quality of service requested for the subscription.
         *  @ref mqtt_qos for details.
         */
        uint8_t qos;
};


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


^ successful publish to hello/world topic

Created JSON message but not publishing to AWS IoT broker,
- 1110 DEV - new file scoped flag for aws_iot holds 0,
message is: {
        "version":      "512",
        "deviceType":   "PulseV2",
        "deviceSerialNumber":   "352656101125105",
        "state":        {
                "reported":     {
                        "ts":   1639641106680,
                        "vrms": "0.406",
                        "alert_vrms_threshhold_1":      "no_alert",
                        "latitude":     "45.40494423760174",
                        "longitude":    "-122.5310215439456",
                        "altitude":     "0.0"
                }
        }
}
RRC mode: Connected
- 1108 DEV - aws_iot event handler called,
AWS_IOT_EVT_DATA_RECEIVED
Data received from AWS IoT console:
Topic: hello/world
Message: {
        "version":      "513",
        "note": "test 010",
        "KEYNAME001":   "*** **** *** **** ***",
        "KEYNAME002":   "*** **** *** **** ***",
        "KEYNAME003":   "*** **** *** **** ***"
}
adm: power_time_domain=0.003, power_freq_domain=0.002, diff=0.001, ratio=1.604
- 1105 - calculated VRMS of 0.000000


- MARK 7 - at every 100 CLI loop iterations
button press count at 0
adm: power_time_domain=0.002, power_freq_domain=0.001, diff=0.001, ratio=1.631
- 1105 - calculated VRMS of 0.798562


RRC mode: Idle