Skip to content

Commit

Permalink
Update for compatibility with recent pioarduino versions
Browse files Browse the repository at this point in the history
This adds two new method overrides for classes inheriting from ::Client
* connect(IPAddress ip, uint16_t port, int32_t timeout)
* connect(const char * host, uint16_t port, int32_t timeout)

Changes also include a CI update to build tests with both pioarduino and
the official platformio esp32 platform.
  • Loading branch information
Michael Haberler authored and mlesniew committed Dec 4, 2024
1 parent 82f6413 commit df9d7cb
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 9 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ jobs:
build:
strategy:
matrix:
board:
- d1_mini
- esp32dev
include:
- board: d1_mini
platform_override:
- board: esp32dev
platform_override: [email protected]
- board: esp32dev
platform_override: https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc3/platform-espressif32.zip
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cache/pip
Expand All @@ -39,4 +43,4 @@ jobs:
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Build examples
run: ./build_examples.sh ${{ matrix.board }}
run: PLATFORM_OVERRIDE=${{ matrix.platform_override }} ./build_examples.sh ${{ matrix.board }}
27 changes: 25 additions & 2 deletions build_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ fi

find examples -mindepth 1 -type d | cut -d/ -f2 | sort | while read -r EXAMPLE
do
COMPATIBLE_PLATFORMS="$(grep -hoiE 'platform compatibility:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
DEPENDENCIES="$(grep -hoiE 'dependencies:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
REQUIRED_PLATFORM="$(grep -hoiE 'platform:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1 | tr -d ' ')"
if [ -z "$REQUIRED_PLATFORM" ]
then
COMPATIBLE_PLATFORMS="$(grep -hoiE 'platform compatibility:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
else
COMPATIBLE_PLATFORMS="$(echo $REQUIRED_PLATFORM | cut -d'@' -f1)"
fi
FILESYSTEM="$(grep -hoiE 'filesystem:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1)"
DEPENDENCIES="$(grep -hoiE 'dependencies:.*' "$ROOT_DIR/examples/$EXAMPLE/"* | cut -d: -f2- | head -n1 | xargs -r -n1 printf '\n %s')"
echo "$EXAMPLE:$COMPATIBLE_PLATFORMS"
if [ -n "$COMPATIBLE_PLATFORMS" ] && ! echo "$COMPATIBLE_PLATFORMS" | grep -qFiw "$PLATFORM"
then
Expand All @@ -44,13 +51,29 @@ do
then
echo "lib_deps = $DEPENDENCIES" >> platformio.ini
fi
if [ -n "$PLATFORM_OVERRIDE" ]
then
sed -E -i "s#^platform *=.*#platform = $PLATFORM_OVERRIDE#" platformio.ini
elif [ -n "$REQUIRED_PLATFORM" ]
then
sed -E -i "s#^platform *=.*#platform = $REQUIRED_PLATFORM#" platformio.ini
fi
if [ -n "$FILESYSTEM" ]
then
echo "board_build.filesystem = $FILESYSTEM" >> platformio.ini
fi
fi

ln -s -f -t src/ "$ROOT_DIR/examples/$EXAMPLE/"*
ln -s -f -t lib/ "$ROOT_DIR"
if [ -e "$ROOT_DIR/config.h" ]
then
ln -s -f -t src/ "$ROOT_DIR/config.h"
fi
if [ -d "$ROOT_DIR/examples/$EXAMPLE/data" ]
then
ln -s -f -t ./ "$ROOT_DIR/examples/$EXAMPLE/data"
fi
pio run
popd
done
2 changes: 1 addition & 1 deletion examples/websocket_server/websocket_server.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// dependencies: mlesniew/PicoWebsocket
// dependencies: mlesniew/PicoWebsocket@1.1.0

#include <PicoMQTT.h>
#include <PicoWebsocket.h>
Expand Down
14 changes: 14 additions & 0 deletions src/PicoMQTT/client_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ int ClientWrapper::connect(const char * host, uint16_t port) {
return client.connect(host, port);
}

#ifdef PICOMQTT_EXTRA_CONNECT_METHODS

int ClientWrapper::connect(IPAddress ip, uint16_t port, int32_t timeout) {
TRACE_FUNCTION
return client.connect(ip, port, timeout);
}

int ClientWrapper::connect(const char * host, uint16_t port, int32_t timeout) {
TRACE_FUNCTION
return client.connect(host, port, timeout);
}

#endif

int ClientWrapper::available() {
TRACE_FUNCTION
return client.available();
Expand Down
6 changes: 6 additions & 0 deletions src/PicoMQTT/client_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <WiFiClient.h>

#include "config.h"

namespace PicoMQTT {

class ClientWrapper: public ::Client {
Expand All @@ -18,6 +20,10 @@ class ClientWrapper: public ::Client {
// all of the below call the corresponding method on this->client
virtual int connect(IPAddress ip, uint16_t port) override;
virtual int connect(const char * host, uint16_t port) override;
#ifdef PICOMQTT_EXTRA_CONNECT_METHODS
virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) override;
virtual int connect(const char * host, uint16_t port, int32_t timeout) override;
#endif
virtual int available() override;
virtual void flush() override;
virtual void stop() override;
Expand Down
8 changes: 8 additions & 0 deletions src/PicoMQTT/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <Arduino.h>

#ifndef PICOMQTT_MAX_TOPIC_SIZE
#define PICOMQTT_MAX_TOPIC_SIZE 256
#endif
Expand All @@ -24,6 +26,12 @@
#define PICOMQTT_OUTGOING_BUFFER_SIZE 128
#endif

#ifdef ESP32
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 1, 0)
#define PICOMQTT_EXTRA_CONNECT_METHODS
#endif
#endif

// #define PICOMQTT_DEBUG

// #define PICOMQTT_DEBUG_TRACE_FUNCTIONS
13 changes: 13 additions & 0 deletions src/PicoMQTT/incoming_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ int IncomingPacket::connect(const char * host, uint16_t port) {
return 0;
}


#ifdef PICOMQTT_EXTRA_CONNECT_METHODS
int IncomingPacket::connect(IPAddress ip, uint16_t port, int32_t timeout) {
TRACE_FUNCTION;
return 0;
}

int IncomingPacket::connect(const char * host, uint16_t port, int32_t timeout) {
TRACE_FUNCTION;
return 0;
}
#endif

size_t IncomingPacket::write(const uint8_t * buffer, size_t size) {
TRACE_FUNCTION
return 0;
Expand Down
5 changes: 5 additions & 0 deletions src/PicoMQTT/incoming_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Arduino.h>
#include <Client.h>

#include "config.h"
#include "packet.h"

namespace PicoMQTT {
Expand All @@ -21,6 +22,10 @@ class IncomingPacket: public Packet, public Client {
virtual int available() override;
virtual int connect(IPAddress ip, uint16_t port) override;
virtual int connect(const char * host, uint16_t port) override;
#ifdef PICOMQTT_EXTRA_CONNECT_METHODS
virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) override;
virtual int connect(const char * host, uint16_t port, int32_t timeout) override;
#endif
virtual int peek() override;
virtual int read() override;
virtual int read(uint8_t * buf, size_t size) override;
Expand Down
4 changes: 4 additions & 0 deletions src/PicoMQTT/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class BufferClient: public ::Client {
// these methods are nop dummies
virtual int connect(IPAddress ip, uint16_t port) override final { TRACE_FUNCTION return 0; }
virtual int connect(const char * host, uint16_t port) override final { TRACE_FUNCTION return 0; }
#ifdef PICOMQTT_EXTRA_CONNECT_METHODS
virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) override final { TRACE_FUNCTION return 0; }
virtual int connect(const char * host, uint16_t port, int32_t timeout) override final { TRACE_FUNCTION return 0; }
#endif
virtual size_t write(const uint8_t * buffer, size_t size) override final { TRACE_FUNCTION return 0; }
virtual size_t write(uint8_t value) override final { TRACE_FUNCTION return 0; }
virtual void flush() override final { TRACE_FUNCTION }
Expand Down

0 comments on commit df9d7cb

Please sign in to comment.