Skip to content

Commit e19838d

Browse files
SpontaneousDucknashif
authored andcommitted
net: mqtt-sn: Update MQTT-SN Publisher Sample with Gateway Discovery
Fixes: #78010 This commit adds the "Gateway Advertisement and Discovery" process to the MQTT-SN Publisher Sample application. Signed-off-by: Kenneth Witham <[email protected]>
1 parent cc33fd6 commit e19838d

File tree

7 files changed

+1119
-17
lines changed

7 files changed

+1119
-17
lines changed

samples/net/mqtt_sn_publisher/Kconfig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55

66
mainmenu "MQTT-SN sample application"
77

8+
config NET_SAMPLE_MQTT_SN_STATIC_GATEWAY
9+
bool "Whether to statically define the Gateway. Will use Search procedure if False."
10+
811
config NET_SAMPLE_MQTT_SN_GATEWAY_IP
9-
string "IP of the MQTT-SN gateway"
12+
string "IP of the MQTT-SN gateway. Only used if NET_SAMPLE_MQTT_SN_STATIC_GATEWAY=n."
13+
depends on NET_SAMPLE_MQTT_SN_STATIC_GATEWAY
1014

1115
config NET_SAMPLE_MQTT_SN_GATEWAY_PORT
1216
int "Port of the MQTT-SN gateway"
1317

18+
config NET_SAMPLE_MQTT_SN_BROADCAST_IP
19+
string "IP of the Broadcast address"
20+
21+
config NET_SAMPLE_MQTT_SN_BROADCAST_PORT
22+
int "Port of the MQTT-SN broadcast"
23+
1424
config NET_SAMPLE_MQTT_SN_BUFFER_SIZE
1525
int "Size of the TX and RX buffers"
1626
default 255

samples/net/mqtt_sn_publisher/README.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,30 @@ Requirements
4040
Build and Running
4141
*****************
4242

43-
Currently, this sample application only supports static IP addresses.
44-
Open the :file:`prj.conf` file and set the IP addresses according
45-
to the LAN environment.
43+
This sample application supports both static IP addresses and the Gateway Discovery process.
44+
Open the :zephyr_file:`samples/net/mqtt_sn_publisher/prj.conf` file and set the IP addresses according
45+
to the LAN environment. CONFIG_NET_SAMPLE_MQTT_SN_STATIC_GATEWAY can be used to select the
46+
static IP or Gateway discovery process.
4647

47-
You will also need to start an MQTT-SN gateway. With Paho, you can either
48-
build it from source - see `PAHO MQTT-SN Gateway`_ - or run an unofficial
49-
docker image, like `kyberpunk/paho`_.
48+
You will also need to start an MQTT-SN gateway. A convenience Docker Compose specification file
49+
is provided in :zephyr_file:`samples/net/mqtt_sn_publisher/compose/compose.yaml`.
50+
First, Start the net-tools configuration from[here](https://github.com/zephyrproject-rtos/net-tools)
51+
with:
52+
53+
.. code-block:: console
54+
55+
$ ./net-setup.sh --config docker.conf
56+
57+
Then bring up the Docker environment in a separate terminal window with:
58+
59+
.. code-block:: console
60+
61+
$ cd ./compose
62+
$ docker compose up
63+
64+
You can also set up this environment manually.With Paho, you can either build it
65+
from source - see `PAHO MQTT-SN Gateway`_ - or run an unofficial docker image, l
66+
ike `kyberpunk/paho`_.
5067

5168
.. _PAHO MQTT-SN Gateway: https://www.eclipse.org/paho/index.php?page=components/mqtt-sn-transparent-gateway/index.php
5269
.. _kyberpunk/paho: https://hub.docker.com/r/kyberpunk/paho
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
mosquitto:
3+
image: eclipse-mosquitto:latest
4+
volumes:
5+
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
6+
restart: unless-stopped
7+
networks:
8+
net-tools:
9+
ipv4_address: 192.0.2.3
10+
mqttsn-gateway:
11+
image: kyberpunk/paho
12+
volumes:
13+
- ./gateway.conf:/etc/paho/gateway.conf:ro
14+
restart: unless-stopped
15+
networks:
16+
net-tools:
17+
ipv4_address: 192.0.2.2
18+
networks:
19+
net-tools:
20+
name: net-tools0
21+
external: true
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#**************************************************************************
2+
# Copyright (c) 2016-2021, Tomoaki Yamaguchi
3+
#
4+
# All rights reserved. This program and the accompanying materials
5+
# are made available under the terms of the Eclipse Public License v1.0
6+
# and Eclipse Distribution License v1.0 which accompany this distribution.
7+
#
8+
# The Eclipse Public License is available at
9+
# http://www.eclipse.org/legal/epl-v10.html
10+
# and the Eclipse Distribution License is available at
11+
# http://www.eclipse.org/org/documents/edl-v10.php.
12+
#***************************************************************************
13+
#
14+
# config file of MQTT-SN Gateway
15+
#
16+
17+
GatewayID=1
18+
GatewayName=PahoGateway-01
19+
MaxNumberOfClients=30
20+
KeepAlive=60
21+
#LoginID=your_ID
22+
#Password=your_Password
23+
24+
BrokerName=mosquitto
25+
BrokerPortNo=1883
26+
BrokerSecurePortNo=8883
27+
28+
#
29+
# CertsKey for TLS connections to a broker
30+
#
31+
32+
#RootCAfile=/etc/ssl/certs/ca-certificates.crt
33+
#RootCApath=/etc/ssl/certs/
34+
#CertKey=/path/to/certKey.pem
35+
#PrivateKey=/path/to/privateKey.pem
36+
37+
#
38+
# When AggregatingGateway=YES or ClientAuthentication=YES,
39+
# All clients must be specified by the ClientList File
40+
#
41+
42+
AggregatingGateway=NO
43+
QoS-1=NO
44+
Forwarder=NO
45+
PredefinedTopic=NO
46+
ClientAuthentication=NO
47+
48+
ClientsList=/path/to/your_clients.conf
49+
PredefinedTopicList=/path/to/your_predefinedTopic.conf
50+
51+
52+
#==============================
53+
# SensorNetworks parameters
54+
#==============================
55+
#
56+
# UDP | DTLS
57+
#
58+
59+
GatewayPortNo=10000
60+
MulticastPortNo=1883
61+
MulticastIP=225.1.1.1
62+
MulticastTTL=1
63+
64+
#
65+
# UDP6 | DTLS6
66+
#
67+
68+
GatewayIPv6PortNo=10000
69+
MulticastIPv6PortNo=1883
70+
MulticastIPv6=ff1e:feed:caca:dead::1
71+
MulticastIPv6If=wlp4s0
72+
MulticastHops=1
73+
74+
#
75+
# DTLS | DTLS6
76+
#
77+
78+
DtlsCertsKey=/etc/ssl/certs/gateway.pem
79+
DtlsPrivKey=/etc/ssl/private/privkey.pem
80+
81+
#
82+
# XBee
83+
#
84+
85+
Baudrate=38400
86+
SerialDevice=/dev/ttyUSB0
87+
ApiMode=2
88+
89+
#
90+
# LoRaLink
91+
#
92+
93+
BaudrateLoRaLink=115200
94+
DeviceRxLoRaLink=/dev/loralinkRx
95+
DeviceTxLoRaLink=/dev/loralinkTx
96+
97+
#
98+
# Bluetooth RFCOMM
99+
#
100+
101+
RFCOMMAddress=60:57:18:06:8B:72.*
102+
103+
#
104+
# LOG
105+
#
106+
107+
ShearedMemory=NO

0 commit comments

Comments
 (0)