Skip to content

Commit 85ddcd1

Browse files
authored
Merge pull request #376 from embhorn/sn-workflow
Add MQTT-SN CI tests
2 parents 3b93bdb + b4badfd commit 85ddcd1

File tree

2 files changed

+111
-7
lines changed

2 files changed

+111
-7
lines changed

.github/workflows/mqtt-sn-check.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: MQTT-SN Build Test
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 5
14+
15+
steps:
16+
- name: Install dependencies
17+
run: |
18+
# Don't prompt for anything
19+
export DEBIAN_FRONTEND=noninteractive
20+
sudo apt-get update
21+
# Install mosquitto
22+
sudo apt-get install -y mosquitto bubblewrap
23+
24+
- name: Setup mosquitto broker
25+
run: |
26+
# Disable default broker daemon
27+
sudo service mosquitto stop
28+
sleep 1
29+
mosquitto -v &> ~/broker.log &
30+
sleep 1
31+
32+
- uses: actions/checkout@master
33+
with:
34+
repository: eclipse/paho.mqtt-sn.embedded-c
35+
path: gateway
36+
- name: Build gateway
37+
working-directory: ./gateway/MQTTSNGateway
38+
run: ./build.sh udp -DDEBUG -DDEBUG_NW
39+
- name: Write config to change broker
40+
working-directory: ./gateway/MQTTSNGateway/bin
41+
run: |
42+
printf "GatewayID=1\nGatewayName=PahoGateway-01\nMaxNumberOfClients=30\nKeepAlive=60\nBrokerName=localhost\nBrokerPortNo=1883\nAggregatingGateway=NO\nQoS-1=NO\nForwarder=NO\nPredefinedTopic=NO\nClientAuthentication=NO\nGatewayPortNo=10000\nMulticastPortNo=1883\nMulticastIP=225.1.1.1\nMulticastTTL=1\n" > gateway.conf
43+
- name: Display gateway config
44+
working-directory: ./gateway/MQTTSNGateway/bin
45+
run: more gateway.conf
46+
- name: Run gateway
47+
working-directory: ./gateway/MQTTSNGateway/bin
48+
run: sudo ./MQTT-SNGateway &> ~/gateway.log &
49+
sleep 1
50+
51+
# This is some debug info useful if something goes wrong
52+
- name: Show network status
53+
run: |
54+
sudo ifconfig
55+
sudo route
56+
sudo netstat -tulpan
57+
58+
- uses: actions/checkout@master
59+
with:
60+
repository: wolfssl/wolfssl
61+
path: wolfssl
62+
- name: wolfssl autogen
63+
working-directory: ./wolfssl
64+
run: ./autogen.sh
65+
- name: wolfssl configure
66+
working-directory: ./wolfssl
67+
run: ./configure --enable-enckeys
68+
- name: wolfssl make
69+
working-directory: ./wolfssl
70+
run: make
71+
- name: wolfssl make install
72+
working-directory: ./wolfssl
73+
run: sudo make install
74+
75+
- uses: actions/checkout@master
76+
- name: wolfmqtt autogen
77+
run: ./autogen.sh
78+
79+
- name: wolfmqtt configure with SN Enabled
80+
run: |
81+
export WOLFMQTT_NO_EXTERNAL_BROKER_TESTS=1
82+
./configure --enable-sn
83+
- name: wolfmqtt make
84+
run: make
85+
86+
- name: test SN Client
87+
run: ./examples/sn-client/sn-client -T
88+
89+
# Cleanup
90+
- name: Stop gateway
91+
if: failure() || cancelled()
92+
run: |
93+
sudo kill -2 $(pgrep -f "MQTT-SNGateway")
94+
sleep 3
95+
sudo kill -2 $(pgrep -f "mosquitto")
96+
sleep 1
97+
98+
# capture logs on failure
99+
- name: Show logs on failure
100+
if: failure() || cancelled()
101+
run: |
102+
sudo cat ~/gateway.log
103+
sudo cat ~/broker.log

examples/sn-client/sn-client.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,20 +509,20 @@ int sn_test(MQTTCtx *mqttCtx)
509509
PRINTF("MQTT Waiting for message...");
510510

511511
do {
512-
/* Try and read packet */
513-
rc = SN_Client_WaitMessage(&mqttCtx->client,
514-
mqttCtx->cmd_timeout_ms);
515-
516512
/* check for test mode */
517513
if (mStopRead) {
518514
rc = MQTT_CODE_SUCCESS;
519515
PRINTF("MQTT Exiting...");
520516
break;
521517
}
522518

519+
/* Try and read packet */
520+
rc = SN_Client_WaitMessage(&mqttCtx->client,
521+
mqttCtx->cmd_timeout_ms);
522+
523523
/* check return code */
524524
#ifdef WOLFMQTT_ENABLE_STDIN_CAP
525-
else if (rc == MQTT_CODE_STDIN_WAKE) {
525+
if (rc == MQTT_CODE_STDIN_WAKE) {
526526
XMEMSET(mqttCtx->rx_buf, 0, MAX_BUFFER_SIZE);
527527
if (XFGETS((char*)mqttCtx->rx_buf, MAX_BUFFER_SIZE - 1,
528528
stdin) != NULL)
@@ -556,8 +556,9 @@ int sn_test(MQTTCtx *mqttCtx)
556556
}
557557
}
558558
}
559+
else
559560
#endif
560-
else if (rc == MQTT_CODE_ERROR_TIMEOUT) {
561+
if (rc == MQTT_CODE_ERROR_TIMEOUT) {
561562
/* Keep Alive */
562563
PRINTF("Keep-alive timeout, sending ping");
563564

@@ -743,6 +744,6 @@ int main(int argc, char** argv)
743744
#endif
744745

745746

746-
return (rc == 0) ? 0 : EXIT_FAILURE;
747+
return (rc == MQTT_CODE_SUCCESS) ? 0 : EXIT_FAILURE;
747748
}
748749

0 commit comments

Comments
 (0)