Skip to content

Commit

Permalink
Add SN client workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
embhorn committed Oct 27, 2023
1 parent 0ba6da7 commit 5e27de9
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 489 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/mqtt-sn-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Ubuntu Build Test

on:
push:
branches: [ 'master', 'main', 'release/**' ]
pull_request:
branches: [ '*' ]

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Install dependencies
run: |
# Don't prompt for anything
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
# Install mosquitto
sudo apt-get install -y mosquitto bubblewrap
- name: Setup mosquitto broker
run: |
# Disable default broker daemon
sudo service mosquitto stop
sleep 1
# This is some debug info useful if something goes wrong
- name: Show network status
run: |
sudo ifconfig
sudo route
sudo netstat -tulpan
- uses: actions/checkout@master
with:
repository: eclipse/paho.mqtt-sn.embedded-c
path: gateway
- name: Build gateway
working-directory: ./gateway/MQTTSNGateway
run: ./build.sh udp
- name: Write config to change broker
working-directory: ./gateway/MQTTSNGateway/bin
run: |
echo -n "GatewayID=1" | cat > gateway.conf
echo -n "GatewayName=PahoGateway-01" | cat >> gateway.conf
echo -n "MaxNumberOfClients=30" | cat >> gateway.conf
echo -n "KeepAlive=60" | cat >> gateway.conf
echo -n "BrokerName=localhost" | cat >> gateway.conf
echo -n "BrokerPortNo=1883" | cat >> gateway.conf
echo -n "AggregatingGateway=NO" | cat >> gateway.conf
echo -n "QoS-1=NO" | cat >> gateway.conf
echo -n "Forwarder=NO" | cat >> gateway.conf
echo -n "PredefinedTopic=NO" | cat >> gateway.conf
echo -n "ClientAuthentication=NO" | cat >> gateway.conf
echo -n "GatewayPortNo=10000" | cat >> gateway.conf
echo -n "MulticastPortNo=1883" | cat >> gateway.conf
echo -n "MulticastIP=225.1.1.1" | cat >> gateway.conf
echo -n "MulticastTTL=1" | cat >> gateway.conf
- name: Run gateway
working-directory: ./gateway/MQTTSNGateway/bin
run: ./MQTT-SNGateway

- uses: actions/checkout@master
with:
repository: wolfssl/wolfssl
path: wolfssl
- name: wolfssl autogen
working-directory: ./wolfssl
run: ./autogen.sh
- name: wolfssl configure
working-directory: ./wolfssl
run: ./configure --enable-enckeys
- name: wolfssl make
working-directory: ./wolfssl
run: make
- name: wolfssl make install
working-directory: ./wolfssl
run: sudo make install

- uses: actions/checkout@master
- name: wolfmqtt autogen
run: ./autogen.sh

- name: wolfmqtt configure with SN Enabled
env:
WOLFMQTT_NO_EXTERNAL_BROKER_TESTS: 1
run: ./configure --enable-sn
- name: wolfmqtt make
run: make
- name: wolfmqtt make check
run: make check
- name: test SN Client
run: ./examples/sn-client/sn-client

# capture logs on failure
- name: Show logs on failure
if: failure() || cancelled()
run: |
cat test-suite.log
22 changes: 15 additions & 7 deletions examples/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ noinst_PROGRAMS += examples/mqttclient/mqttclient \
examples/wiot/wiot \
examples/nbclient/nbclient \
examples/multithread/multithread \
examples/sn-client/sn-client \
examples/sn-client/sn-client_qos-1 \
examples/sn-client/sn-multithread \
examples/pub-sub/mqtt-pub \
examples/pub-sub/mqtt-sub
if BUILD_SN
noinst_PROGRAMS += examples/sn-client/sn-client \
examples/sn-client/sn-client_qos-1 \
examples/sn-client/sn-multithread
endif

noinst_HEADERS += examples/mqttclient/mqttclient.h \
examples/mqttsimple/mqttsimple.h \
Expand All @@ -30,8 +32,10 @@ noinst_HEADERS += examples/mqttclient/mqttclient.h \
examples/mqttport.h \
examples/nbclient/nbclient.h \
examples/multithread/multithread.h \
examples/sn-client/sn-client.h \
examples/pub-sub/mqtt-pub-sub.h
if BUILD_SN
noinst_HEADERS += examples/sn-client/sn-client.h
endif

# MQTT Client Example
examples_mqttclient_mqttclient_SOURCES = examples/mqttclient/mqttclient.c \
Expand Down Expand Up @@ -161,9 +165,11 @@ dist_example_DATA+= examples/mqttnet.c \
examples/wiot/wiot.c
dist_example_DATA+= examples/nbclient/nbclient.c
dist_example_DATA+= examples/multithread/multithread.c
if BUILD_SN
dist_example_DATA+= examples/sn-client/sn-client.c
dist_example_DATA+= examples/sn-client/sn-client_qos-1.c
dist_example_DATA+= examples/sn-client/sn-multithread.c
endif
dist_example_DATA+= examples/pub-sub/mqtt-pub.c
dist_example_DATA+= examples/pub-sub/mqtt-sub.c

Expand All @@ -175,11 +181,13 @@ DISTCLEANFILES+= examples/mqttclient/.libs/mqttclient \
examples/wiot/.libs/wiot \
examples/nbclient/.libs/nbclient \
examples/multithread/.libs/multithread \
examples/sn-client/.libs/sn-client \
examples/sn-client/.libs/sn-client_qos-1 \
examples/sn-client/.libs/sn-multithread \
examples/pub-sub/mqtt-pub \
examples/pub-sub/mqtt-sub
if BUILD_SN
DISTCLEANFILES+= examples/sn-client/.libs/sn-client \
examples/sn-client/.libs/sn-client_qos-1 \
examples/sn-client/.libs/sn-multithread
endif

EXTRA_DIST+= examples/mqttuart.c \
examples/publish.dat \
Expand Down
2 changes: 1 addition & 1 deletion examples/sn-client/sn-client_qos-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <config.h>
#endif

#include "wolfmqtt/mqtt_client.h"
#include "wolfmqtt/mqtt_sn_client.h"

#include "sn-client.h"
#include "examples/mqttnet.h"
Expand Down
2 changes: 1 addition & 1 deletion examples/sn-client/sn-multithread.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <config.h>
#endif

#include "wolfmqtt/mqtt_client.h"
#include "wolfmqtt/mqtt_sn_client.h"

#include "sn-client.h"
#include "examples/mqttnet.h"
Expand Down
6 changes: 3 additions & 3 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static int MqttClient_Publish_ReadPayload(MqttClient* client,
#endif

/* These RespList functions assume caller has locked client->lockClient mutex */
static int MqttClient_RespList_Add(MqttClient *client,
int MqttClient_RespList_Add(MqttClient *client,
MqttPacketType packet_type, word16 packet_id, MqttPendResp *newResp,
void *packet_obj)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ static int MqttClient_RespList_Add(MqttClient *client,
return 0;
}

static void MqttClient_RespList_Remove(MqttClient *client, MqttPendResp *rmResp)
void MqttClient_RespList_Remove(MqttClient *client, MqttPendResp *rmResp)
{
MqttPendResp *tmpResp;

Expand Down Expand Up @@ -252,7 +252,7 @@ static void MqttClient_RespList_Remove(MqttClient *client, MqttPendResp *rmResp)
#endif
}

static int MqttClient_RespList_Find(MqttClient *client,
int MqttClient_RespList_Find(MqttClient *client,
MqttPacketType packet_type, word16 packet_id, MqttPendResp **retResp)
{
int rc = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ int MqttProps_Free(MqttProp *head)

#endif /* WOLFMQTT_V5 */

static int MqttPacket_HandleNetError(MqttClient *client, int rc)
int MqttPacket_HandleNetError(MqttClient *client, int rc)
{
(void)client;
#ifdef WOLFMQTT_DISCONNECT_CB
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt_sn_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <config.h>
#endif

#include "wolfmqtt/mqtt_client.h"
#include "wolfmqtt/mqtt_sn_client.h"

#ifdef WOLFMQTT_SN

Expand Down
4 changes: 2 additions & 2 deletions src/mqtt_sn_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <config.h>
#endif

#include "wolfmqtt/mqtt_client.h"
#include "wolfmqtt/mqtt_packet.h"
#include "wolfmqtt/mqtt_sn_client.h"
#include "wolfmqtt/mqtt_sn_packet.h"

#ifdef WOLFMQTT_SN
const char* SN_Packet_TypeDesc(SN_MsgType packet_type)
Expand Down
3 changes: 1 addition & 2 deletions wolfmqtt/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ nobase_include_HEADERS+= \

if BUILD_SN
nobase_include_HEADERS+= wolfmqtt/mqtt_sn_client.h \
wolfmqtt/mqtt_sn_packet.h \

wolfmqtt/mqtt_sn_packet.h
endif
31 changes: 31 additions & 0 deletions wolfmqtt/mqtt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include "wolfmqtt/mqtt_types.h"
#include "wolfmqtt/mqtt_packet.h"
#include "wolfmqtt/mqtt_socket.h"
#ifdef WOLFMQTT_SN
#include "wolfmqtt/mqtt_sn_packet.h"
#endif

/* This macro allows the disconnect callback to be triggered when
* MqttClient_Disconnect_ex is called. Normally the CB is only used to handle
Expand Down Expand Up @@ -134,6 +137,23 @@ typedef struct _MqttSk {
typedef int (*MqttPropertyCb)(struct _MqttClient* client, MqttProp* head, void* ctx);
#endif


#ifdef WOLFMQTT_SN
/*! \brief Mqtt-SN Register Callback.
* A GW sends a REGISTER message to a client if it wants to
inform that client about the topic name and the assigned topic id that
it will use later on when sending PUBLISH messages of the corresponding
topic name. This callback allows the client to accept and save the new
ID, or reject it if the ID is unknown. If the callback is not defined,
then the regack will contain the "unsupported" return code.
* \param topicId New topic ID value
* \param topicName Pointer to topic name
* \param reg_ctx Pointer to user context
* \return >= 0 Indicates acceptance
*/
typedef int (*SN_ClientRegisterCb)(word16 topicId, const char* topicName, void *reg_ctx);
#endif

/* Client structure */
typedef struct _MqttClient {
word32 flags; /* MqttClientFlags */
Expand Down Expand Up @@ -552,6 +572,17 @@ WOLFMQTT_API const char* MqttClient_ReturnCodeToString(
"not compiled in"
#endif /* WOLFMQTT_NO_ERROR_STRINGS */

/* Internal functions */
WOLFMQTT_LOCAL int MqttClient_RespList_Find(MqttClient *client,
MqttPacketType packet_type, word16 packet_id, MqttPendResp **retResp);
WOLFMQTT_LOCAL void MqttClient_RespList_Remove(MqttClient *client,
MqttPendResp *rmResp);
WOLFMQTT_LOCAL int MqttClient_RespList_Add(MqttClient *client,
MqttPacketType packet_type, word16 packet_id, MqttPendResp *newResp,
void *packet_obj);
WOLFMQTT_LOCAL int MqttPacket_HandleNetError(MqttClient *client, int rc);


#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
Loading

0 comments on commit 5e27de9

Please sign in to comment.