Skip to content
Snippets Groups Projects
Commit 08890404 authored by Zbigniew Bodek's avatar Zbigniew Bodek
Browse files

Initial commit. Import mqtt_publisher application

Code imported from:
repo: https://github.com/zephyrproject-rtos/zephyr


cid: 730acbd6ed85a5ee30d66f305cfc159b24643468
path: samples/net/mqtt_publisher/

Signed-off-by: default avatarZbigniew Bodek <zbigniew.bodek@huawei.com>
parents
No related branches found
No related tags found
No related merge requests found
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mqtt_publisher)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
Kconfig 0 → 100644
# Config options for mqtt_publisher sample application
# Copyright (c) 2020 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
mainmenu "Networking mqtt_publisher sample application"
config NET_SAMPLE_APP_MAX_ITERATIONS
int "Number of times to Publish sample MQTT messages"
default 500
help
Send sample MQTT messages this many times in a MQTT connection
before exiting. A value of zero means that the messages are sent
forever.
config NET_SAMPLE_APP_MAX_CONNECTIONS
int "Number of times to connect to the MQTT server"
default 0
help
Number of times to connect to the MQTT server. With each connection
send NET_SAMPLE_APP_MAX_ITERATIONS amount of MQTT sample messages.
A value of zero means to continue forever.
source "Kconfig.zephyr"
.. _mqtt-publisher-sample:
MQTT Publisher
##############
Overview
********
`MQTT <http://mqtt.org/>`_ (MQ Telemetry Transport) is a lightweight
publish/subscribe messaging protocol optimized for small sensors and
mobile devices.
The Zephyr MQTT Publisher sample application is a MQTT v3.1.1
client that sends MQTT PUBLISH messages to a MQTT broker.
See the `MQTT V3.1.1 spec`_ for more information.
.. _MQTT V3.1.1 spec: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.html
The source code of this sample application can be found at:
:zephyr_file:`samples/net/mqtt_publisher`.
Requirements
************
- Linux machine
- Freedom Board (FRDM-K64F)
- Mosquitto server: any version that supports MQTT v3.1.1. This sample
was tested with mosquitto 1.3.4.
- Mosquitto subscriber
- LAN for testing purposes (Ethernet)
Build and Running
*****************
Currently, this sample application only supports static IP addresses.
Open the :file:`src/config.h` file and set the IP addresses according
to the LAN environment.
Alternatively, set the IP addresses in the :file:`prj.conf` file.
The file :file:`src/config.h` also contains some variables that may be changed:
MQTT broker TCP port:
.. code-block:: c
#define SERVER_PORT 1883
Application sleep time:
.. code-block:: c
#define APP_SLEEP_MSECS 500
Max number of connection tries:
.. code-block:: c
#define APP_CONNECT_TRIES 10
MQTT Client Identifier:
.. code-block:: c
#define MQTT_CLIENTID "zephyr_publisher"
This sample application supports the IBM Bluemix Watson topic format that can
be enabled by changing the default value of APP_BLUEMIX_TOPIC from 0 to 1:
.. code-block:: c
#define APP_BLUEMIX_TOPIC 1
The Bluemix topic may include some parameters like device type, device
identifier, event type and message format. This application uses the
following macros to specify those values:
.. code-block:: c
#define BLUEMIX_DEVTYPE "sensor"
#define BLUEMIX_DEVID "carbon"
#define BLUEMIX_EVENT "status"
#define BLUEMIX_FORMAT "json"
Max number of MQTT PUBLISH iterations is defined in Kconfig:
.. code-block:: c
CONFIG_NET_SAMPLE_APP_MAX_ITERATIONS 5
On your Linux host computer, open a terminal window, locate the source code
of this sample application (i.e., :zephyr_file:`samples/net/mqtt_publisher`) and type:
.. zephyr-app-commands::
:zephyr-app: samples/net/mqtt_publisher
:board: frdm_k64f
:goals: build flash
:compact:
Open another terminal window and type:
.. code-block:: console
$ sudo mosquitto -v -p 1883
Open another terminal window and type:
.. code-block:: console
$ mosquitto_sub -t sensors
Connecting securely using TLS
=============================
While it is possible to set up a local secure MQTT server and update the
sample to connect to it, it does require some work on the user's part to
create the certificates and to set them up with the server.
Alternatively, a `publicly available Mosquitto MQTT server/broker
<https://test.mosquitto.org/>`_ is available to quickly and easily
try this sample with TLS enabled, by following these steps:
- Download the server's CA certificate file in DER format from
https://test.mosquitto.org
- In :file:`src/test_certs.h`, set ``ca_certificate[]`` using the certificate
contents (or set it to its filename if the socket offloading feature is
enabled on your platform and :option:`CONFIG_TLS_CREDENTIAL_FILENAMES` is
set to ``y``).
- In :file:`src/config.h`, set SERVER_ADDR to the IP address to connect to,
i.e., the IP address of test.mosquitto.org ``"37.187.106.16"``
- In :file:`src/main.c`, set TLS_SNI_HOSTNAME to ``"test.mosquitto.org"``
to match the Common Name (CN) in the downloaded certificate.
- Build the sample by specifying ``-DOVERLAY_CONFIG=overlay-tls.conf``
when running ``west build`` or ``cmake`` (or refer to the TLS offloading
section below if your platform uses the offloading feature).
- Flash the binary onto the device to run the sample:
.. code-block:: console
$ ninja flash
TLS offloading
==============
For boards that support this feature, TLS offloading is used by
specifying ``-DOVERLAY_CONFIG=overlay-tls-offload.conf`` when running ``west
build`` or ``cmake``.
Using this overlay enables TLS without bringing in mbedtls.
SOCKS5 proxy support
====================
It is also possible to connect to the MQTT broker through a SOCKS5 proxy.
To enable it, use ``-DOVERLAY_CONFIG=overlay-socks5.conf`` when running ``west
build`` or ``cmake``.
By default, to make the testing easier, the proxy is expected to run on the
same host as the MQTT broker.
To start a proxy server, ``ssh`` can be used.
Use the following command to run it on your host with the default port:
.. code-block: console
$ ssh -N -D 0.0.0.0:1080 localhost
To connect to a proxy server that is not running under the same IP as the MQTT
broker or uses a different port number, modify the following values:
.. code-block:: c
#define SOCKS5_PROXY_ADDR SERVER_ADDR
#define SOCKS5_PROXY_PORT 1080
Running on cc3220sf_launchxl
============================
Offloading on cc3220sf_launchxl also provides DHCP services, so the sample
uses dynamic IP addresses on this board.
By default, the sample is set up to connect to the broker at the address
specified by SERVER_ADDR in config.h. If the broker is secured using TLS, users
should enable TLS offloading, upload the server's certificate
authority file in DER format to the device filesystem using TI Uniflash,
and name it "ca_cert.der".
In addition, TLS_SNI_HOSTNAME in main.c should be defined to match the
Common Name (CN) in the certificate file in order for the TLS domain
name verification to succeed.
See the note on Provisioning and Fast Connect in :ref:`cc3220sf_launchxl`.
The Secure Socket Offload section has information on programming the
certificate to flash.
Proceed to test as above.
Sample output
=============
This is the output from the FRDM UART console, with:
.. code-block:: c
CONFIG_NET_SAMPLE_APP_MAX_ITERATIONS 5
.. code-block:: console
[dev/eth_mcux] [INF] eth_0_init: Enabled 100M full-duplex mode.
[dev/eth_mcux] [DBG] eth_0_init: MAC 00:04:9f:3e:1a:0a
[publisher:233] network_setup: 0 <OK>
[publisher:258] mqtt_init: 0 <OK>
[connect_cb:81] user_data: CONNECTED
[try_to_connect:212] mqtt_tx_connect: 0 <OK>
[publisher:276] try_to_connect: 0 <OK>
[publisher:285] mqtt_tx_pingreq: 0 <OK>
[publisher:290] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBACK> packet id: 1888, user_data: PUBLISH
[publisher:295] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBREC> packet id: 16356, user_data: PUBLISH
[publish_cb:149] <MQTT_PUBCOMP> packet id: 16356, user_data: PUBLISH
[publisher:300] mqtt_tx_publish: 0 <OK>
[publisher:285] mqtt_tx_pingreq: 0 <OK>
[publisher:290] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBACK> packet id: 45861, user_data: PUBLISH
[publisher:295] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBREC> packet id: 53870, user_data: PUBLISH
[publish_cb:149] <MQTT_PUBCOMP> packet id: 53870, user_data: PUBLISH
[publisher:300] mqtt_tx_publish: 0 <OK>
[publisher:285] mqtt_tx_pingreq: 0 <OK>
[publisher:290] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBACK> packet id: 60144, user_data: PUBLISH
[publisher:295] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBREC> packet id: 6561, user_data: PUBLISH
[publish_cb:149] <MQTT_PUBCOMP> packet id: 6561, user_data: PUBLISH
[publisher:300] mqtt_tx_publish: 0 <OK>
[publisher:285] mqtt_tx_pingreq: 0 <OK>
[publisher:290] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBACK> packet id: 38355, user_data: PUBLISH
[publisher:295] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBREC> packet id: 60656, user_data: PUBLISH
[publish_cb:149] <MQTT_PUBCOMP> packet id: 60656, user_data: PUBLISH
[publisher:300] mqtt_tx_publish: 0 <OK>
[publisher:285] mqtt_tx_pingreq: 0 <OK>
[publisher:290] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBACK> packet id: 28420, user_data: PUBLISH
[publisher:295] mqtt_tx_publish: 0 <OK>
[publish_cb:149] <MQTT_PUBREC> packet id: 49829, user_data: PUBLISH
[publish_cb:149] <MQTT_PUBCOMP> packet id: 49829, user_data: PUBLISH
[publisher:300] mqtt_tx_publish: 0 <OK>
[disconnect_cb:101] user_data: DISCONNECTED
[publisher:304] mqtt_tx_disconnect: 0 <OK>
Bye!
The line:
.. code-block:: console
[try_to_connect:220] mqtt_connect: -5 <ERROR>
means that an error was detected and a new connect message will be sent.
The MQTT API is asynchronous, so messages are displayed as the callbacks are
executed.
This is the information that the subscriber will receive:
.. code-block:: console
$ mosquitto_sub -t sensors
DOORS:OPEN_QoS0
DOORS:OPEN_QoS1
DOORS:OPEN_QoS2
DOORS:OPEN_QoS0
DOORS:OPEN_QoS1
DOORS:OPEN_QoS2
DOORS:OPEN_QoS0
DOORS:OPEN_QoS1
DOORS:OPEN_QoS2
DOORS:OPEN_QoS0
DOORS:OPEN_QoS1
DOORS:OPEN_QoS2
DOORS:OPEN_QoS0
DOORS:OPEN_QoS1
DOORS:OPEN_QoS2
This is the output from the MQTT broker:
.. code-block:: console
$ sudo mosquitto -v
1485663791: mosquitto version 1.3.4 (build date 2014-08-17 00:14:52-0300) starting
1485663791: Using default config.
1485663791: Opening ipv4 listen socket on port 1883.
1485663791: Opening ipv6 listen socket on port 1883.
1485663797: New connection from 192.168.1.101 on port 1883.
1485663797: New client connected from 192.168.1.101 as zephyr_publisher (c1, k0).
1485663797: Sending CONNACK to zephyr_publisher (0)
1485663798: Received PINGREQ from zephyr_publisher
1485663798: Sending PINGRESP to zephyr_publisher
1485663798: Received PUBLISH from zephyr_publisher (d0, q0, r0, m0, 'sensors', ... (15 bytes))
1485663799: Received PUBLISH from zephyr_publisher (d0, q1, r0, m1888, 'sensors', ... (15 bytes))
1485663799: Sending PUBACK to zephyr_publisher (Mid: 1888)
1485663799: Received PUBLISH from zephyr_publisher (d0, q2, r0, m16356, 'sensors', ... (15 bytes))
1485663799: Sending PUBREC to zephyr_publisher (Mid: 16356)
1485663799: Received PUBREL from zephyr_publisher (Mid: 16356)
1485663799: Sending PUBCOMP to zephyr_publisher (Mid: 16356)
1485663800: Received PINGREQ from zephyr_publisher
1485663800: Sending PINGRESP to zephyr_publisher
1485663800: Received PUBLISH from zephyr_publisher (d0, q0, r0, m0, 'sensors', ... (15 bytes))
1485663801: Received PUBLISH from zephyr_publisher (d0, q1, r0, m45861, 'sensors', ... (15 bytes))
1485663801: Sending PUBACK to zephyr_publisher (Mid: 45861)
1485663801: Received PUBLISH from zephyr_publisher (d0, q2, r0, m53870, 'sensors', ... (15 bytes))
1485663801: Sending PUBREC to zephyr_publisher (Mid: 53870)
1485663801: Received PUBREL from zephyr_publisher (Mid: 53870)
1485663801: Sending PUBCOMP to zephyr_publisher (Mid: 53870)
1485663802: Received PINGREQ from zephyr_publisher
1485663802: Sending PINGRESP to zephyr_publisher
1485663802: Received PUBLISH from zephyr_publisher (d0, q0, r0, m0, 'sensors', ... (15 bytes))
1485663803: Received PUBLISH from zephyr_publisher (d0, q1, r0, m60144, 'sensors', ... (15 bytes))
1485663803: Sending PUBACK to zephyr_publisher (Mid: 60144)
1485663803: Received PUBLISH from zephyr_publisher (d0, q2, r0, m6561, 'sensors', ... (15 bytes))
1485663803: Sending PUBREC to zephyr_publisher (Mid: 6561)
1485663803: Received PUBREL from zephyr_publisher (Mid: 6561)
1485663803: Sending PUBCOMP to zephyr_publisher (Mid: 6561)
1485663804: Received PINGREQ from zephyr_publisher
1485663804: Sending PINGRESP to zephyr_publisher
1485663804: Received PUBLISH from zephyr_publisher (d0, q0, r0, m0, 'sensors', ... (15 bytes))
1485663805: Received PUBLISH from zephyr_publisher (d0, q1, r0, m38355, 'sensors', ... (15 bytes))
1485663805: Sending PUBACK to zephyr_publisher (Mid: 38355)
1485663805: Received PUBLISH from zephyr_publisher (d0, q2, r0, m60656, 'sensors', ... (15 bytes))
1485663805: Sending PUBREC to zephyr_publisher (Mid: 60656)
1485663805: Received PUBREL from zephyr_publisher (Mid: 60656)
1485663805: Sending PUBCOMP to zephyr_publisher (Mid: 60656)
1485663806: Received PINGREQ from zephyr_publisher
1485663806: Sending PINGRESP to zephyr_publisher
1485663806: Received PUBLISH from zephyr_publisher (d0, q0, r0, m0, 'sensors', ... (15 bytes))
1485663807: Received PUBLISH from zephyr_publisher (d0, q1, r0, m28420, 'sensors', ... (15 bytes))
1485663807: Sending PUBACK to zephyr_publisher (Mid: 28420)
1485663807: Received PUBLISH from zephyr_publisher (d0, q2, r0, m49829, 'sensors', ... (15 bytes))
1485663807: Sending PUBREC to zephyr_publisher (Mid: 49829)
1485663807: Received PUBREL from zephyr_publisher (Mid: 49829)
1485663807: Sending PUBCOMP to zephyr_publisher (Mid: 49829)
1485663808: Received DISCONNECT from zephyr_publisher
# Networking Config:
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_NATIVE=n
CONFIG_TEST_RANDOM_GENERATOR=y
# Enable SimpleLink WiFi Driver and Socket Offload
CONFIG_WIFI=y
CONFIG_WIFI_SIMPLELINK=y
CONFIG_NET_SOCKETS_OFFLOAD=y
# Enable TLS credential filenames for secure socket offload
CONFIG_TLS_CREDENTIAL_FILENAMES=y
# Disable unneeded settings from the base prj.conf:
CONFIG_DNS_RESOLVER=n
CONFIG_NET_CONFIG_SETTINGS=n
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
# Debugging
CONFIG_NET_LOG=y
CONFIG_WIFI_LOG_LEVEL_DBG=y
CONFIG_DEBUG=y
CONFIG_ASSERT=y
# Networking Config:
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_NATIVE=n
CONFIG_TEST_RANDOM_GENERATOR=y
# Enable SimpleLink WiFi Driver and Socket Offload
CONFIG_WIFI=y
CONFIG_WIFI_SIMPLELINK=y
CONFIG_NET_SOCKETS_OFFLOAD=y
# Enable TLS credential filenames for secure socket offload
CONFIG_TLS_CREDENTIAL_FILENAMES=y
# Disable unneeded settings from the base prj.conf:
CONFIG_DNS_RESOLVER=n
CONFIG_NET_CONFIG_SETTINGS=n
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
# Debugging
CONFIG_NET_LOG=y
CONFIG_WIFI_LOG_LEVEL_DBG=y
CONFIG_DEBUG=y
CONFIG_CC3235SF_DEBUG=y
CONFIG_ASSERT=y
CONFIG_MODEM=y
CONFIG_MODEM_HL7800=y
# Copyright (c) 2020 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
if [ -z "$RUNNING_FROM_MAIN_SCRIPT" ]; then
echo "Do not run this script directly!"
echo "Run $ZEPHYR_BASE/scripts/net/run-sample-tests.sh instead."
exit 1
fi
echo "Starting MQTT test"
start_configuration || return $?
start_docker \
"/usr/local/sbin/mosquitto -v -c /usr/local/etc/mosquitto/mosquitto.conf" || return $?
start_zephyr -DOVERLAY_CONFIG=overlay-sample.conf "$overlay"
wait_zephyr
result=$?
if [ $result -ne 0 ]; then
return $result
fi
stop_docker
# test TLS
echo "Starting MQTT TLS test"
start_docker \
"/usr/local/sbin/mosquitto -v -c /usr/local/etc/mosquitto/mosquitto-tls.conf" || return $?
start_zephyr -DOVERLAY_CONFIG="overlay-tls.conf overlay-sample.conf" "$overlay"
wait_zephyr
result=$?
if [ $result -ne 0 ]; then
return $result
fi
stop_docker
return $result
# FIXME: proxy test does not work as expected
# TLS and SOCKS5, mosquitto TLS is already running
echo "Starting MQTT TLS + proxy test"
start_docker "/usr/sbin/danted" || return $?
start_zephyr -DOVERLAY_CONFIG="overlay-tls.conf overlay-sample.conf overlay-socks5.conf" "$overlay" || return $?
wait_zephyr
result=$?
stop_docker
CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
CONFIG_BT_DEVICE_NAME="Zephyr MQTT"
CONFIG_NET_L2_BT=y
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=y
CONFIG_NET_CONFIG_BT_NODE=y
CONFIG_NET_CONFIG_NEED_IPV6=y
CONFIG_NET_CONFIG_NEED_IPV4=n
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
# Lower values used for testing
CONFIG_NET_SAMPLE_APP_MAX_ITERATIONS=3
CONFIG_NET_SAMPLE_APP_MAX_CONNECTIONS=3
CONFIG_SOCKS=y
CONFIG_MQTT_LIB_TLS=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_MQTT_LIB_TLS=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
# TLS configuration
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=30000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048
CONFIG_WEBSOCKET_CLIENT=y
CONFIG_MQTT_LIB_WEBSOCKET=y
CONFIG_HEAP_MEM_POOL_SIZE=1500
prj.conf 0 → 100644
CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_TCP=y
CONFIG_NET_LOG=y
CONFIG_NET_IPV6_RA_RDNSS=y
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=2
CONFIG_PRINTK=y
CONFIG_STDOUT_CONSOLE=y
# Enable IPv6 support
CONFIG_NET_IPV6=n
# Enable IPv4 support
CONFIG_NET_IPV4=y
# Enable the MQTT Lib
CONFIG_MQTT_LIB=y
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_MAIN_STACK_SIZE=2048
# For IPv6
CONFIG_NET_BUF_DATA_SIZE=256
CONFIG_NET_SHELL=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
sample:
description: MQTT publisher sample application
name: MQTT publisher
common:
harness: net
tags: net mqtt
tests:
sample.net.mqtt_publisher:
platform_allow: frdm_k64f qemu_x86 pinnacle_100_dvk
sample.net.mqtt_publisher.userspace:
platform_allow: frdm_k64f qemu_x86
extra_args: CONFIG_USERSPACE=y
sample.net.mqtt_publisher.bt:
platform_allow: 96b_nitrogen
tags: net mqtt bluetooth
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __CONFIG_H__
#define __CONFIG_H__
#ifdef CONFIG_NET_CONFIG_SETTINGS
#ifdef CONFIG_NET_IPV6
#define ZEPHYR_ADDR CONFIG_NET_CONFIG_MY_IPV6_ADDR
#define SERVER_ADDR CONFIG_NET_CONFIG_PEER_IPV6_ADDR
#else
#define ZEPHYR_ADDR CONFIG_NET_CONFIG_MY_IPV4_ADDR
#define SERVER_ADDR CONFIG_NET_CONFIG_PEER_IPV4_ADDR
#endif
#else
#ifdef CONFIG_NET_IPV6
#define ZEPHYR_ADDR "2001:db8::1"
#define SERVER_ADDR "2001:db8::2"
#else
#define ZEPHYR_ADDR "192.168.1.101"
#define SERVER_ADDR "192.168.1.10"
#endif
#endif
#if defined(CONFIG_SOCKS)
#define SOCKS5_PROXY_ADDR SERVER_ADDR
#define SOCKS5_PROXY_PORT 1080
#endif
#ifdef CONFIG_MQTT_LIB_TLS
#ifdef CONFIG_MQTT_LIB_WEBSOCKET
#define SERVER_PORT 9001
#else
#define SERVER_PORT 8883
#endif /* CONFIG_MQTT_LIB_WEBSOCKET */
#else
#ifdef CONFIG_MQTT_LIB_WEBSOCKET
#define SERVER_PORT 9001
#else
#define SERVER_PORT 1883
#endif /* CONFIG_MQTT_LIB_WEBSOCKET */
#endif
#define APP_CONNECT_TIMEOUT_MS 2000
#define APP_SLEEP_MSECS 500
#define APP_CONNECT_TRIES 10
#define APP_MQTT_BUFFER_SIZE 128
#define MQTT_CLIENTID "zephyr_publisher"
/* Set the following to 1 to enable the Bluemix topic format */
#define APP_BLUEMIX_TOPIC 0
/* These are the parameters for the Bluemix topic format */
#if APP_BLUEMIX_TOPIC
#define BLUEMIX_DEVTYPE "sensor"
#define BLUEMIX_DEVID "carbon"
#define BLUEMIX_EVENT "status"
#define BLUEMIX_FORMAT "json"
#endif
#endif
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <logging/log.h>
LOG_MODULE_REGISTER(net_mqtt_publisher_sample, LOG_LEVEL_DBG);
#include <zephyr.h>
#include <net/socket.h>
#include <net/mqtt.h>
#include <random/rand32.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#if defined(CONFIG_USERSPACE)
#include <app_memory/app_memdomain.h>
K_APPMEM_PARTITION_DEFINE(app_partition);
struct k_mem_domain app_domain;
#define APP_BMEM K_APP_BMEM(app_partition)
#define APP_DMEM K_APP_DMEM(app_partition)
#else
#define APP_BMEM
#define APP_DMEM
#endif
/* Buffers for MQTT client. */
static APP_BMEM uint8_t rx_buffer[APP_MQTT_BUFFER_SIZE];
static APP_BMEM uint8_t tx_buffer[APP_MQTT_BUFFER_SIZE];
#if defined(CONFIG_MQTT_LIB_WEBSOCKET)
/* Making RX buffer large enough that the full IPv6 packet can fit into it */
#define MQTT_LIB_WEBSOCKET_RECV_BUF_LEN 1280
/* Websocket needs temporary buffer to store partial packets */
static APP_BMEM uint8_t temp_ws_rx_buf[MQTT_LIB_WEBSOCKET_RECV_BUF_LEN];
#endif
/* The mqtt client struct */
static APP_BMEM struct mqtt_client client_ctx;
/* MQTT Broker details. */
static APP_BMEM struct sockaddr_storage broker;
#if defined(CONFIG_SOCKS)
static APP_BMEM struct sockaddr socks5_proxy;
#endif
static APP_BMEM struct zsock_pollfd fds[1];
static APP_BMEM int nfds;
static APP_BMEM bool connected;
#if defined(CONFIG_MQTT_LIB_TLS)
#include "test_certs.h"
#define TLS_SNI_HOSTNAME "localhost"
#define APP_CA_CERT_TAG 1
#define APP_PSK_TAG 2
static APP_DMEM sec_tag_t m_sec_tags[] = {
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(CONFIG_NET_SOCKETS_OFFLOAD)
APP_CA_CERT_TAG,
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
APP_PSK_TAG,
#endif
};
static int tls_init(void)
{
int err = -EINVAL;
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(CONFIG_NET_SOCKETS_OFFLOAD)
err = tls_credential_add(APP_CA_CERT_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
ca_certificate, sizeof(ca_certificate));
if (err < 0) {
LOG_ERR("Failed to register public certificate: %d", err);
return err;
}
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
err = tls_credential_add(APP_PSK_TAG, TLS_CREDENTIAL_PSK,
client_psk, sizeof(client_psk));
if (err < 0) {
LOG_ERR("Failed to register PSK: %d", err);
return err;
}
err = tls_credential_add(APP_PSK_TAG, TLS_CREDENTIAL_PSK_ID,
client_psk_id, sizeof(client_psk_id) - 1);
if (err < 0) {
LOG_ERR("Failed to register PSK ID: %d", err);
}
#endif
return err;
}
#endif /* CONFIG_MQTT_LIB_TLS */
static void prepare_fds(struct mqtt_client *client)
{
if (client->transport.type == MQTT_TRANSPORT_NON_SECURE) {
fds[0].fd = client->transport.tcp.sock;
}
#if defined(CONFIG_MQTT_LIB_TLS)
else if (client->transport.type == MQTT_TRANSPORT_SECURE) {
fds[0].fd = client->transport.tls.sock;
}
#endif
fds[0].events = ZSOCK_POLLIN;
nfds = 1;
}
static void clear_fds(void)
{
nfds = 0;
}
static int wait(int timeout)
{
int ret = 0;
if (nfds > 0) {
ret = zsock_poll(fds, nfds, timeout);
if (ret < 0) {
LOG_ERR("poll error: %d", errno);
}
}
return ret;
}
void mqtt_evt_handler(struct mqtt_client *const client,
const struct mqtt_evt *evt)
{
int err;
switch (evt->type) {
case MQTT_EVT_CONNACK:
if (evt->result != 0) {
LOG_ERR("MQTT connect failed %d", evt->result);
break;
}
connected = true;
LOG_INF("MQTT client connected!");
break;
case MQTT_EVT_DISCONNECT:
LOG_INF("MQTT client disconnected %d", evt->result);
connected = false;
clear_fds();
break;
case MQTT_EVT_PUBACK:
if (evt->result != 0) {
LOG_ERR("MQTT PUBACK error %d", evt->result);
break;
}
LOG_INF("PUBACK packet id: %u", evt->param.puback.message_id);
break;
case MQTT_EVT_PUBREC:
if (evt->result != 0) {
LOG_ERR("MQTT PUBREC error %d", evt->result);
break;
}
LOG_INF("PUBREC packet id: %u", evt->param.pubrec.message_id);
const struct mqtt_pubrel_param rel_param = {
.message_id = evt->param.pubrec.message_id
};
err = mqtt_publish_qos2_release(client, &rel_param);
if (err != 0) {
LOG_ERR("Failed to send MQTT PUBREL: %d", err);
}
break;
case MQTT_EVT_PUBCOMP:
if (evt->result != 0) {
LOG_ERR("MQTT PUBCOMP error %d", evt->result);
break;
}
LOG_INF("PUBCOMP packet id: %u",
evt->param.pubcomp.message_id);
break;
case MQTT_EVT_PINGRESP:
LOG_INF("PINGRESP packet");
break;
default:
break;
}
}
static char *get_mqtt_payload(enum mqtt_qos qos)
{
#if APP_BLUEMIX_TOPIC
static APP_BMEM char payload[30];
snprintk(payload, sizeof(payload), "{d:{temperature:%d}}",
(uint8_t)sys_rand32_get());
#else
static APP_DMEM char payload[] = "DOORS:OPEN_QoSx";
payload[strlen(payload) - 1] = '0' + qos;
#endif
return payload;
}
static char *get_mqtt_topic(void)
{
#if APP_BLUEMIX_TOPIC
return "iot-2/type/"BLUEMIX_DEVTYPE"/id/"BLUEMIX_DEVID
"/evt/"BLUEMIX_EVENT"/fmt/"BLUEMIX_FORMAT;
#else
return "sensors";
#endif
}
static int publish(struct mqtt_client *client, enum mqtt_qos qos)
{
struct mqtt_publish_param param;
param.message.topic.qos = qos;
param.message.topic.topic.utf8 = (uint8_t *)get_mqtt_topic();
param.message.topic.topic.size =
strlen(param.message.topic.topic.utf8);
param.message.payload.data = get_mqtt_payload(qos);
param.message.payload.len =
strlen(param.message.payload.data);
param.message_id = sys_rand32_get();
param.dup_flag = 0U;
param.retain_flag = 0U;
return mqtt_publish(client, &param);
}
#define RC_STR(rc) ((rc) == 0 ? "OK" : "ERROR")
#define PRINT_RESULT(func, rc) \
LOG_INF("%s: %d <%s>", (func), rc, RC_STR(rc))
static void broker_init(void)
{
#if defined(CONFIG_NET_IPV6)
struct sockaddr_in6 *broker6 = (struct sockaddr_in6 *)&broker;
broker6->sin6_family = AF_INET6;
broker6->sin6_port = htons(SERVER_PORT);
zsock_inet_pton(AF_INET6, SERVER_ADDR, &broker6->sin6_addr);
#if defined(CONFIG_SOCKS)
struct sockaddr_in6 *proxy6 = (struct sockaddr_in6 *)&socks5_proxy;
proxy6->sin6_family = AF_INET6;
proxy6->sin6_port = htons(SOCKS5_PROXY_PORT);
zsock_inet_pton(AF_INET6, SOCKS5_PROXY_ADDR, &proxy6->sin6_addr);
#endif
#else
struct sockaddr_in *broker4 = (struct sockaddr_in *)&broker;
broker4->sin_family = AF_INET;
broker4->sin_port = htons(SERVER_PORT);
zsock_inet_pton(AF_INET, SERVER_ADDR, &broker4->sin_addr);
#if defined(CONFIG_SOCKS)
struct sockaddr_in *proxy4 = (struct sockaddr_in *)&socks5_proxy;
proxy4->sin_family = AF_INET;
proxy4->sin_port = htons(SOCKS5_PROXY_PORT);
zsock_inet_pton(AF_INET, SOCKS5_PROXY_ADDR, &proxy4->sin_addr);
#endif
#endif
}
static void client_init(struct mqtt_client *client)
{
mqtt_client_init(client);
broker_init();
/* MQTT client configuration */
client->broker = &broker;
client->evt_cb = mqtt_evt_handler;
client->client_id.utf8 = (uint8_t *)MQTT_CLIENTID;
client->client_id.size = strlen(MQTT_CLIENTID);
client->password = NULL;
client->user_name = NULL;
client->protocol_version = MQTT_VERSION_3_1_1;
/* MQTT buffers configuration */
client->rx_buf = rx_buffer;
client->rx_buf_size = sizeof(rx_buffer);
client->tx_buf = tx_buffer;
client->tx_buf_size = sizeof(tx_buffer);
/* MQTT transport configuration */
#if defined(CONFIG_MQTT_LIB_TLS)
#if defined(CONFIG_MQTT_LIB_WEBSOCKET)
client->transport.type = MQTT_TRANSPORT_SECURE_WEBSOCKET;
#else
client->transport.type = MQTT_TRANSPORT_SECURE;
#endif
struct mqtt_sec_config *tls_config = &client->transport.tls.config;
tls_config->peer_verify = TLS_PEER_VERIFY_REQUIRED;
tls_config->cipher_list = NULL;
tls_config->sec_tag_list = m_sec_tags;
tls_config->sec_tag_count = ARRAY_SIZE(m_sec_tags);
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(CONFIG_NET_SOCKETS_OFFLOAD)
tls_config->hostname = TLS_SNI_HOSTNAME;
#else
tls_config->hostname = NULL;
#endif
#else
#if defined(CONFIG_MQTT_LIB_WEBSOCKET)
client->transport.type = MQTT_TRANSPORT_NON_SECURE_WEBSOCKET;
#else
client->transport.type = MQTT_TRANSPORT_NON_SECURE;
#endif
#endif
#if defined(CONFIG_MQTT_LIB_WEBSOCKET)
client->transport.websocket.config.host = SERVER_ADDR;
client->transport.websocket.config.url = "/mqtt";
client->transport.websocket.config.tmp_buf = temp_ws_rx_buf;
client->transport.websocket.config.tmp_buf_len =
sizeof(temp_ws_rx_buf);
client->transport.websocket.timeout = 5 * MSEC_PER_SEC;
#endif
#if defined(CONFIG_SOCKS)
mqtt_client_set_proxy(client, &socks5_proxy,
socks5_proxy.sa_family == AF_INET ?
sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6));
#endif
}
/* In this routine we block until the connected variable is 1 */
static int try_to_connect(struct mqtt_client *client)
{
int rc, i = 0;
while (i++ < APP_CONNECT_TRIES && !connected) {
client_init(client);
rc = mqtt_connect(client);
if (rc != 0) {
PRINT_RESULT("mqtt_connect", rc);
k_sleep(K_MSEC(APP_SLEEP_MSECS));
continue;
}
prepare_fds(client);
if (wait(APP_CONNECT_TIMEOUT_MS)) {
mqtt_input(client);
}
if (!connected) {
mqtt_abort(client);
}
}
if (connected) {
return 0;
}
return -EINVAL;
}
static int process_mqtt_and_sleep(struct mqtt_client *client, int timeout)
{
int64_t remaining = timeout;
int64_t start_time = k_uptime_get();
int rc;
while (remaining > 0 && connected) {
if (wait(remaining)) {
rc = mqtt_input(client);
if (rc != 0) {
PRINT_RESULT("mqtt_input", rc);
return rc;
}
}
rc = mqtt_live(client);
if (rc != 0 && rc != -EAGAIN) {
PRINT_RESULT("mqtt_live", rc);
return rc;
} else if (rc == 0) {
rc = mqtt_input(client);
if (rc != 0) {
PRINT_RESULT("mqtt_input", rc);
return rc;
}
}
remaining = timeout + start_time - k_uptime_get();
}
return 0;
}
#define SUCCESS_OR_EXIT(rc) { if (rc != 0) { return 1; } }
#define SUCCESS_OR_BREAK(rc) { if (rc != 0) { break; } }
static int publisher(void)
{
int i, rc, r = 0;
LOG_INF("attempting to connect: ");
rc = try_to_connect(&client_ctx);
PRINT_RESULT("try_to_connect", rc);
SUCCESS_OR_EXIT(rc);
i = 0;
while (i++ < CONFIG_NET_SAMPLE_APP_MAX_ITERATIONS && connected) {
r = -1;
rc = mqtt_ping(&client_ctx);
PRINT_RESULT("mqtt_ping", rc);
SUCCESS_OR_BREAK(rc);
rc = process_mqtt_and_sleep(&client_ctx, APP_SLEEP_MSECS);
SUCCESS_OR_BREAK(rc);
rc = publish(&client_ctx, MQTT_QOS_0_AT_MOST_ONCE);
PRINT_RESULT("mqtt_publish", rc);
SUCCESS_OR_BREAK(rc);
rc = process_mqtt_and_sleep(&client_ctx, APP_SLEEP_MSECS);
SUCCESS_OR_BREAK(rc);
rc = publish(&client_ctx, MQTT_QOS_1_AT_LEAST_ONCE);
PRINT_RESULT("mqtt_publish", rc);
SUCCESS_OR_BREAK(rc);
rc = process_mqtt_and_sleep(&client_ctx, APP_SLEEP_MSECS);
SUCCESS_OR_BREAK(rc);
rc = publish(&client_ctx, MQTT_QOS_2_EXACTLY_ONCE);
PRINT_RESULT("mqtt_publish", rc);
SUCCESS_OR_BREAK(rc);
rc = process_mqtt_and_sleep(&client_ctx, APP_SLEEP_MSECS);
SUCCESS_OR_BREAK(rc);
r = 0;
}
rc = mqtt_disconnect(&client_ctx);
PRINT_RESULT("mqtt_disconnect", rc);
LOG_INF("Bye!");
return r;
}
static int start_app(void)
{
int r = 0, i = 0;
while (!CONFIG_NET_SAMPLE_APP_MAX_CONNECTIONS ||
i++ < CONFIG_NET_SAMPLE_APP_MAX_CONNECTIONS) {
r = publisher();
if (!CONFIG_NET_SAMPLE_APP_MAX_CONNECTIONS) {
k_sleep(K_MSEC(5000));
}
}
return r;
}
#if defined(CONFIG_USERSPACE)
#define STACK_SIZE 2048
#if IS_ENABLED(CONFIG_NET_TC_THREAD_COOPERATIVE)
#define THREAD_PRIORITY K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1)
#else
#define THREAD_PRIORITY K_PRIO_PREEMPT(8)
#endif
K_THREAD_DEFINE(app_thread, STACK_SIZE,
start_app, NULL, NULL, NULL,
THREAD_PRIORITY, K_USER, -1);
static K_HEAP_DEFINE(app_mem_pool, 1024 * 2);
#endif
void main(void)
{
#if defined(CONFIG_MQTT_LIB_TLS)
int rc;
rc = tls_init();
PRINT_RESULT("tls_init", rc);
#endif
#if defined(CONFIG_USERSPACE)
struct k_mem_partition *parts[] = {
#if Z_LIBC_PARTITION_EXISTS
&z_libc_partition,
#endif
&app_partition
};
k_mem_domain_init(&app_domain, ARRAY_SIZE(parts), parts);
k_mem_domain_add_thread(&app_domain, app_thread);
k_thread_heap_assign(app_thread, &app_mem_pool);
k_thread_start(app_thread);
k_thread_join(app_thread, K_FOREVER);
#else
exit(start_app());
#endif
}
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __TEST_CERTS_H__
#define __TEST_CERTS_H__
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
/* By default only certificates in DER format are supported. If you want to use
* certificate in PEM format, you can enable support for it in Kconfig.
*/
#if defined(CONFIG_TLS_CREDENTIAL_FILENAMES)
static const unsigned char ca_certificate[] = "ca_cert.der";
#else
static const unsigned char ca_certificate[] = {
#include "ca_cert.der.inc"
};
#endif
#else
#include <mbedtls/ssl_ciphersuites.h>
#if defined(MBEDTLS_X509_CRT_PARSE_C)
/* This byte array can be generated by
* "cat ca.crt | sed -e '1d;$d' | base64 -d |xxd -i"
*/
static const unsigned char ca_certificate[] = {
0x30, 0x82, 0x02, 0xfb, 0x30, 0x82, 0x01, 0xe3,
0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
0xee, 0x10, 0x1f, 0xc1, 0xf2, 0x30, 0xe9, 0x11,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30,
0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55,
0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61,
0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x1e, 0x17,
0x0d, 0x31, 0x37, 0x30, 0x36, 0x32, 0x36, 0x31,
0x30, 0x35, 0x36, 0x31, 0x30, 0x5a, 0x17, 0x0d,
0x34, 0x34, 0x31, 0x31, 0x31, 0x31, 0x31, 0x30,
0x35, 0x36, 0x31, 0x30, 0x5a, 0x30, 0x14, 0x31,
0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03,
0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68,
0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30,
0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
0x82, 0x01, 0x01, 0x00, 0xc6, 0x00, 0x7b, 0x0d,
0xd1, 0x17, 0x43, 0x6b, 0xa9, 0xa7, 0x79, 0x9c,
0x0f, 0x8d, 0x77, 0x91, 0xd2, 0xf7, 0x47, 0x35,
0xb3, 0x17, 0xe2, 0xdd, 0xed, 0x6d, 0x01, 0xf9,
0xb1, 0x92, 0xc9, 0x48, 0x80, 0xe0, 0x1f, 0xcf,
0xb7, 0xa4, 0x5f, 0xf0, 0x36, 0xea, 0xbf, 0xe1,
0x33, 0xf8, 0xa9, 0xc5, 0xe6, 0xd4, 0x19, 0x8b,
0x82, 0x25, 0xd9, 0x19, 0x74, 0x70, 0x79, 0xec,
0xc6, 0x68, 0xc9, 0xef, 0xce, 0x1a, 0xa9, 0xf0,
0xb7, 0x01, 0x35, 0x91, 0xff, 0xd3, 0x75, 0x6e,
0x02, 0xba, 0x06, 0x9a, 0x2a, 0xac, 0xcf, 0x22,
0xbf, 0x2b, 0x1f, 0xc1, 0x72, 0x38, 0x22, 0x35,
0xea, 0xda, 0x6f, 0xdd, 0x67, 0xa2, 0x2b, 0x19,
0x38, 0x19, 0x0e, 0x44, 0xd1, 0x71, 0x38, 0xb4,
0x6d, 0x26, 0x85, 0xd6, 0xc6, 0xbe, 0xc1, 0x6f,
0x3c, 0xee, 0xaf, 0x94, 0x3c, 0x05, 0x56, 0x4e,
0xad, 0x53, 0x81, 0x8b, 0xd4, 0x23, 0x31, 0x69,
0x72, 0x27, 0x93, 0xb4, 0x3a, 0xac, 0x23, 0xe8,
0x10, 0xae, 0xf5, 0x9f, 0x0b, 0xa6, 0x6e, 0xd3,
0x73, 0xca, 0x18, 0x11, 0xca, 0xbe, 0x71, 0x00,
0x56, 0x29, 0x34, 0x54, 0xcc, 0xda, 0x29, 0x5b,
0x26, 0x29, 0x99, 0x4d, 0x5f, 0xa1, 0xa6, 0xb9,
0xcb, 0x2b, 0xb2, 0x0f, 0x10, 0x00, 0x04, 0xa9,
0x11, 0x2c, 0x48, 0xb1, 0x99, 0xa5, 0xca, 0x7c,
0x67, 0xa5, 0xbe, 0x14, 0x20, 0x12, 0xb7, 0x3b,
0x7a, 0x4f, 0xdc, 0xc7, 0xd5, 0x2d, 0x04, 0x66,
0xbb, 0xf5, 0x0c, 0xcd, 0xf1, 0x32, 0x39, 0xd7,
0x51, 0x9b, 0xba, 0xdb, 0xf1, 0xa7, 0xfe, 0x2d,
0x9a, 0xe6, 0x9c, 0x6b, 0x54, 0xda, 0xf1, 0xdd,
0x48, 0xf9, 0xd7, 0xf0, 0x35, 0x7c, 0x8e, 0x24,
0x7e, 0x44, 0x2f, 0xf3, 0xbf, 0x39, 0x0e, 0x96,
0xab, 0xe1, 0x45, 0x03, 0x8b, 0x54, 0xdc, 0xe1,
0xb6, 0x11, 0x81, 0x21, 0x02, 0x03, 0x01, 0x00,
0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06,
0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
0xa4, 0xef, 0x6d, 0xdc, 0x9b, 0x23, 0xc5, 0x3a,
0xdd, 0x34, 0xd9, 0x01, 0x1c, 0x68, 0x03, 0x53,
0xae, 0x92, 0xc2, 0xc9, 0x30, 0x1f, 0x06, 0x03,
0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
0x14, 0xa4, 0xef, 0x6d, 0xdc, 0x9b, 0x23, 0xc5,
0x3a, 0xdd, 0x34, 0xd9, 0x01, 0x1c, 0x68, 0x03,
0x53, 0xae, 0x92, 0xc2, 0xc9, 0x30, 0x0c, 0x06,
0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x67,
0x65, 0xbf, 0x93, 0x89, 0xde, 0x4f, 0x71, 0xff,
0x1c, 0x93, 0x68, 0xa0, 0x64, 0x09, 0x5e, 0x95,
0x94, 0xf5, 0xd5, 0xf4, 0x6b, 0x20, 0x32, 0xd8,
0x04, 0x80, 0xac, 0xf8, 0x52, 0x36, 0x7a, 0x38,
0x83, 0xae, 0xab, 0x29, 0x22, 0x42, 0x71, 0x7e,
0xea, 0xe5, 0x4f, 0x71, 0xac, 0x44, 0x3f, 0x9e,
0x5e, 0x49, 0x22, 0x05, 0xee, 0xa6, 0x7b, 0xab,
0x56, 0x2e, 0xb3, 0x9a, 0x35, 0x1a, 0x88, 0xc3,
0x54, 0x9b, 0xfd, 0xac, 0x65, 0x54, 0xaf, 0x21,
0xa7, 0xe0, 0xdd, 0x62, 0x29, 0x8c, 0xae, 0x26,
0x0b, 0x84, 0x1f, 0x69, 0x78, 0x84, 0xc6, 0x7e,
0xcf, 0xc8, 0xf5, 0x92, 0x8c, 0x05, 0xa8, 0x13,
0x38, 0xcd, 0x0b, 0x98, 0x53, 0xfb, 0xdd, 0x8d,
0x51, 0x90, 0xa8, 0x51, 0xfa, 0x52, 0xbe, 0x28,
0xd4, 0x71, 0x50, 0x73, 0x1f, 0xb0, 0xb6, 0x0e,
0x45, 0xb1, 0x47, 0x41, 0x06, 0xd9, 0x1d, 0x7a,
0x34, 0xe7, 0x80, 0x2e, 0x0c, 0x02, 0x50, 0x97,
0xde, 0xa8, 0x7a, 0x84, 0x2c, 0x1d, 0xf4, 0x51,
0x56, 0xa5, 0x52, 0xb5, 0x04, 0x2e, 0xcb, 0xdd,
0x8b, 0x2e, 0x16, 0xc6, 0xde, 0xc8, 0xe9, 0x8d,
0xee, 0x5e, 0xb6, 0xa0, 0xe0, 0x2b, 0x85, 0x2a,
0x89, 0x7b, 0xba, 0x68, 0x80, 0x2b, 0xfb, 0x6e,
0x2e, 0x80, 0xe7, 0x7a, 0x97, 0x09, 0xb5, 0x2f,
0x20, 0x8e, 0xed, 0xbc, 0x98, 0x6f, 0x95, 0xd5,
0x5b, 0x3d, 0x26, 0x19, 0x26, 0x14, 0x39, 0x82,
0xa8, 0xa8, 0x42, 0x46, 0xab, 0x59, 0x93, 0x47,
0x83, 0xf7, 0x79, 0xbf, 0x73, 0xb5, 0x5d, 0x5d,
0x78, 0xfe, 0x62, 0xac, 0xed, 0xb7, 0x1e, 0x4a,
0xad, 0xc3, 0x99, 0x39, 0x7d, 0x3e, 0x30, 0x21,
0x26, 0x1d, 0x66, 0xdb, 0x0d, 0xf3, 0xba, 0x87,
0x46, 0xf0, 0x04, 0xfc, 0xc3, 0xbe, 0x84, 0x85,
0x3c, 0x01, 0xef, 0xe0, 0x68, 0x65, 0xee,
};
#endif /* MBEDTLS_X509_CRT_PARSE_C */
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
/* Avoid leading zero in psk because there's a potential issue of mosquitto
* that leading zero of psk will be skipped and it leads to TLS handshake
* failure
*/
const unsigned char client_psk[] = {
0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
const char client_psk_id[] = "Client_identity";
#endif
#endif /* CONFIG_NET_SOCKETS_OFFLOAD */
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment