DA16200 DA16600 MQTT Programmer Guide UM-WI-010 Abstract This MQTT Programmer Guide intends to assist software developers that implement applications with the DA16200 and DA16600 SDK. A certain degree of reader familiarity with programming environments, debugging tools, and software engineering process in general.
The subscriber function supports DPM mode. TLS is available for message encryption. SDK Build Some source files should be modified in the DA16200 (DA16600) SDK to use the MQTT function. Enable the MQTT function as shown in the example below.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Application Programming Interface Operation APIs The APIs listed in Table 1 are used to create or terminate the MQTT thread, to check the status, and to publish a message. The configuration to execute MQTT protocols is explained in the next section.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide int mqtt_client_unsub_topic(char *topic) 0: Succeeded to unsubscribe. 4: Failed because mqtt is not connected. 3: Failed because the topic is NULL Return 1: Failed because of memory alloc failure Other: Failed due to other cause. See enum “mqtt_client_error_code” to identify the cause.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide void mqtt_sub_disconn_cb_set(void (*user_cb)(void)); Return None Parameter user_cb user callback function to set Register a callback function that is invoked when the MQTT client is Description disconnected void mqtt_sub_disconn2_cb_set(void (*user_cb)(void)); Return None Parameter user_cb user callback function to set...
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Name Description Example da16x_set_config_str(DA16X_CONF_STR Subscriber topic to DA16X_CONF_STR_MQTT_SUB_TOPIC_DEL _MQTT_SUB_TOPIC_DEL, topic); remove. da16x_set_config_str(DA16X_CONF_STR DA16X_CONF_STR_MQTT_PUB_TOPIC Topic to publish. _MQTT_PUB_PUB_TOPIC, “pub_topic”); da16x_set_config_str(DA16X_CONF_STR Username to log in to DA16X_CONF_STR_MQTT_USERNAME _MQTT_USERNAME, “mqtt_id”); a broker. da16x_set_config_str(DA16X_CONF_STR Password to login to a DA16X_CONF_STR_MQTT_PASSWORD _MQTT_PASSWORD, “mqtt_password”);...
Page 10
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Name Description Example TLS peer certificate verification mode: 0 da16x_set_config_int(DA16X_CONF_INT DA16X_CONF_INT_MQTT_TLS_AUTHMODE (not verify), 1 _MQTT_TLS_AUTHMODE, 1) (optional), 2 (required), default is 1 MQTT Clean Session mode (1: clean the da16x_set_config_int(DA16X_CONF_INT DA16X_CONF_INT_MQTT_CLEAN_SESSION previous session, 0: do _MQTT_CLEAN_SESSION, 1);...
Set the configurations for the MQTT broker, publisher topic, and so on when executing power on reset or requiring new MQTT configuration. Call mqtt_client_start() and mqtt_client_send_message() with a message, then DA16200 (DA16600) will temporarily connect to the broker and publish the message.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide MQTT Subscriber Set the configurations for the MQTT broker, subscriber topic, and so on before running the subscriber thread. Call mqtt_client_start() and then the subscriber thread will start. #include "mqtt_client.h" #include "common_config.h" int mqtt_sub_example(void) int status;...
MQTT_PUB_MSG_PERIODIC, MQTT_PUB_MSG_PERIODIC); In DPM mode, for a periodic RTC timer registration, it is registered normally on Power-On-Boot. That means, when the RTC timer is expired, DA16200 wakes up, the callback invoked, and a message is printed on the console as below.
For this test the mosquitto MQTT broker is used, which you can download from the following URL: https://mosquitto.org/download/ If you feel that the broker installation is difficult, Renesas Electronics can provide it so that you can extract and run it on your Windows PC.
Non-QoS Message This section gives an example of publishing a non-QoS message. Figure 2: Publish Non-QoS Message 1. After the DA16200 (DA16600) EVB is connected to an AP, configure the parameters and publish a message. [/DA16200]# net [/DA16200/NET]# mqtt_config broker <Broker IP>...
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide 2. When message transmission -m “Hello!” is successful, you can see the following messages: Hello! (Send, Len: 6, Topic: da16k, Message ID: 1)The following syntax allows to send a message with a new topic: [/DA16200/NET] mqtt_client -m <Message>...
The DA16200 (DA16600) SDK provides a TLS encrypted session for secure MQTT messages. Figure 6: Publish Secure Message NOTE You need to store certificates in the DA16200 (DA16600) EVK to use TLS encryption. This procedure is explained in Section 6. 1. Run a broker with a secure port.
2. Run a broker with a secure port. You need to prepare the configuration file. mosquitto -c <Config File> -p <Port> -v In the mosquitto package provided by Renesas Electronics, file mosq_idpw.conf is used for the <Config File> parameter, and user accounts are registered in file p1.txt.
5.4.2 MQTT over TLS You need to set the current time in the DA16200 (DA16600) EVB to check if the certificate is valid. (If SNTP is auto started during boot, you do not need to do this step.) [/DA16200]# time set <yyyy-mm-dd> <hh:mm:ss>...
[/DA16200/NET]# mqtt_client start >>> MQTT Client connection OK (da16x_FFFE) 2. In the mosquitto package provided by Renesas Electronics, file mosq_idpw.conf is used for the <Config File> parameter and user accounts are registered in file p1.txt. You can add a new account in this file with the following command.
>mosquitto_pub -h 192.168.0.101 -p 1884 --cafile cas.pem --cert wifiuser.pem --key wifiuser.key --tls-version tlsv1 -t da16k --insecure -m “Hello World!!” When the message is received, DA16200 (DA16600) wakes up from DPM Sleep and prints the message. Figure 9: MQTT UC Wakeup...
(and stay active for only a small amount of time to get the job done) when needed. In the Keysight snapshot below, DA16200 (DA16600) was in the Sleep mode until it woke up to post a periodic status message to the broker. Once DA16200 (DA16600) received the response, it enters and stays in Sleep mode until the next Status Message Tx time (the interval depends on application).
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Figure 11: MQTT Communication MQTT CleanSession=0 Test Guide 5.6.1 CleanSession=0 Mode When an MQTT Client (Mqttc onward) establishes a connection with an MQTT Broker (Broker onward), there are two types of session; CleanSession=1 and CleanSession=0.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide CleanSession=0 is enabled) also should retain the state of the unfinished / unacked messages until reconnection. Figure 12: Broker console - CleanSession=1 connection Figure 13: Broker console - CleanSession=0 connection Even with CleanSession=0 connection, the Broker does not maintain session data if Mqttc is disconnected in the following cases.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Search the following compiler options in config_generic_sdk.h. //max payload length of a preserved message #define MQTT_MSG_TBL_PRESVD_MAX_PLAYLOAD_LEN // max number of preserved messages #define MQTT_MSG_TBL_PRESVD_MAX_MSG_CNT ⚫ The following console command is provided to configure CleanSession mode: mqtt_client clean_session <1|0>...
: 3.1 [/DA16200/NET] # mqtt_client start MQTT CleanSession=0 Support Mode enabled. [/DA16200/NET] # >>> MQTT Client connection OK (da16x_D9CC) To activate “CleanSession=0 support mode” in DA16x, QoS should be 1 or 2 and CleanSession option should be set to 0.
[/DA16200/NET] # mqtt_config clean_session 0 [/DA16200/NET] # mqtt_client start MQTT CleanSession=0 Support Mode enabled. [/DA16200/NET] # >>> MQTT Client connection OK (da16x_D9CC) Case 2: Previoius session is CleanSession=0 and you want to do re-test of CleanSession=0. [/DA16200/NET] # mqtt_client stop...
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide 5.6.2.3 PUBLISH Rx Test Test Steps Test steps are as follows under non-DPM and DPM mode. In non-DPM mode: ⚫ DA16x: connect to Broker ⚫ Publisher: send one or two messages ⚫ DA16x: check if the messages are received.
Page 33
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide [PUBACK] (Tx: Msg_ID=3) (Rx: Len=11,Topic=SUB_TOPIC,Msg_ID=4) [PUBACK] (Tx: Msg_ID=4) >>> MQTT Client connection OK (da16x_D9CC) Test Steps - Example 2 (DPM) Below are the test steps for case 18 (DPM mode) (mosquitto broker and mosquitto publisher are used for the test)
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide ⚫ Message length from DA16x should be less than or equal to 100 for case 5 and 6 configuration. Sending longer messages returns failure. For cases other than case 5 or 6, message length limit is 3K.
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Certificate DA16200 (DA16600) provides methods to store certificates in the serial flash with the use of console commands. Certificate Commands 1. Store a CA certificate. [/DA16200/NET]# net [/DA16200/NET]# cert 0 // for SDK v3.2.3.0 or higher, use “cert write ca1”...
Page 39
DA16200 DA16600 MQTT Programmer Guide - Private Key : Empty - DH Parameter: Empty In case you want to remove all the credentials stored: [/DA16200/NET]# cert 3 // in SDK v3.x, use “cert del all” User Manual Revision 1.12 18-Jan-2023...
Page 42
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide // Mosquitto 1.4.14 License Eclipse Distribution License 1.0 Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Page 43
UM-WI-010 DA16200 DA16600 MQTT Programmer Guide Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Page 45
RoHS Compliance Renesas Electronics’ suppliers certify that its products are in compliance with the requirements of Directive 2011/65/EU of the European Parliament on the restriction of the use of certain hazardous substances in electrical and electronic equipment. RoHS certificates from our suppliers are available on request.
Page 46
Renesas disclaims responsibility for, and you will fully indemnify Renesas and its representatives against, any claims, damages, costs, losses, or liabilities arising out of your use of these resources. Renesas' products are provided only subject to Renesas' Terms and Conditions of Sale or other applicable terms agreed to in writing.
Need help?
Do you have a question about the DA16200 and is the answer not in the manual?
Questions and answers