diff --git a/.github/workflows/mqtt-sn-check.yml b/.github/workflows/mqtt-sn-check.yml new file mode 100644 index 000000000..4d00dd2b0 --- /dev/null +++ b/.github/workflows/mqtt-sn-check.yml @@ -0,0 +1,103 @@ +name: MQTT-SN 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 + mosquitto -v &> ~/broker.log & + sleep 1 + + - 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 -DDEBUG -DDEBUG_NW + - name: Write config to change broker + working-directory: ./gateway/MQTTSNGateway/bin + run: | + 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 + - name: Display gateway config + working-directory: ./gateway/MQTTSNGateway/bin + run: more gateway.conf + - name: Run gateway + working-directory: ./gateway/MQTTSNGateway/bin + run: sudo ./MQTT-SNGateway &> ~/gateway.log & + 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: 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 + run: | + export WOLFMQTT_NO_EXTERNAL_BROKER_TESTS=1 + ./configure --enable-sn + - name: wolfmqtt make + run: make + + - name: test SN Client + run: ./examples/sn-client/sn-client -T + + # Cleanup + - name: Stop gateway + if: failure() || cancelled() + run: | + sudo kill -2 $(pgrep -f "MQTT-SNGateway") + sleep 3 + sudo kill -2 $(pgrep -f "mosquitto") + sleep 1 + + # capture logs on failure + - name: Show logs on failure + if: failure() || cancelled() + run: | + sudo cat ~/gateway.log + sudo cat ~/broker.log diff --git a/examples/sn-client/sn-client.c b/examples/sn-client/sn-client.c index 15b5a9bf1..31a909603 100644 --- a/examples/sn-client/sn-client.c +++ b/examples/sn-client/sn-client.c @@ -509,10 +509,6 @@ int sn_test(MQTTCtx *mqttCtx) PRINTF("MQTT Waiting for message..."); do { - /* Try and read packet */ - rc = SN_Client_WaitMessage(&mqttCtx->client, - mqttCtx->cmd_timeout_ms); - /* check for test mode */ if (mStopRead) { rc = MQTT_CODE_SUCCESS; @@ -520,9 +516,13 @@ int sn_test(MQTTCtx *mqttCtx) break; } + /* Try and read packet */ + rc = SN_Client_WaitMessage(&mqttCtx->client, + mqttCtx->cmd_timeout_ms); + /* check return code */ #ifdef WOLFMQTT_ENABLE_STDIN_CAP - else if (rc == MQTT_CODE_STDIN_WAKE) { + if (rc == MQTT_CODE_STDIN_WAKE) { XMEMSET(mqttCtx->rx_buf, 0, MAX_BUFFER_SIZE); if (XFGETS((char*)mqttCtx->rx_buf, MAX_BUFFER_SIZE - 1, stdin) != NULL) @@ -556,8 +556,9 @@ int sn_test(MQTTCtx *mqttCtx) } } } + else #endif - else if (rc == MQTT_CODE_ERROR_TIMEOUT) { + if (rc == MQTT_CODE_ERROR_TIMEOUT) { /* Keep Alive */ PRINTF("Keep-alive timeout, sending ping"); @@ -743,6 +744,6 @@ int main(int argc, char** argv) #endif - return (rc == 0) ? 0 : EXIT_FAILURE; + return (rc == MQTT_CODE_SUCCESS) ? 0 : EXIT_FAILURE; }