256dpi / arduino-mqtt

MQTT library for Arduino
MIT License
1.02k stars 236 forks source link

Added lambda feature for onMessage callback. #220

Closed drzony closed 3 years ago

drzony commented 4 years ago

Version of #175 that works on all platforms

Fixes #147

256dpi commented 4 years ago

Thanks for working on this! Would you mind updating the README and perhaps provided an example for the functional API?

drzony commented 4 years ago

Done, is it enough or should I expand more?

256dpi commented 3 years ago

Unfortunately, the CI build is failing due to an error. It seems it's a known error that is not trivially fixable: https://arduinojson.org/v6/error/macro-min-passed-3-arguments-but-takes-just-2.

Generating function prototypes...
1332/home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10813 -DARDUINO_SAMD_MKRGSM1400 -DARDUINO_ARCH_SAMD -DUSE_ARDUINO_MKR_PIN_LAYOUT -D__SAMD21G18A__ -DUSB_VID=0x2341 -DUSB_PID=0x8052 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino MKR GSM 1400\"" -DUSE_BQ24195L_PMIC -I/home/travis/.arduino15/packages/arduino/tools/CMSIS/4.5.0/CMSIS/Include/ -I/home/travis/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/ -I/home/travis/.arduino15/packages/arduino/hardware/samd/1.8.9/cores/arduino -I/home/travis/.arduino15/packages/arduino/hardware/samd/1.8.9/variants/mkrgsm1400 -I/home/travis/Arduino/libraries/MKRGSM/src -I/home/travis/Arduino/libraries/arduino-mqtt/src /tmp/arduino_build_1999/sketch/ArduinoMKRGSM1400.ino.cpp -o /tmp/arduino_build_1999/preproc/ctags_target_for_gcc_minus_e.cpp -DARDUINO_LIB_DISCOVERY_PHASE
1333In file included from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/bits/char_traits.h:39:0,
1334                 from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/string:40,
1335                 from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/stdexcept:39,
1336                 from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/array:39,
1337                 from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/tuple:39,
1338                 from /home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/functional:54,
1339                 from /home/travis/Arduino/libraries/arduino-mqtt/src/MQTTClient.h:13,
1340                 from /home/travis/Arduino/libraries/arduino-mqtt/src/MQTT.h:4,
1341                 from /home/travis/build/256dpi/arduino-mqtt/examples/ArduinoMKRGSM1400/ArduinoMKRGSM1400.ino:13:
1342/home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
1343     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
1344                                                        ^
1345/home/travis/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/arm-none-eabi/include/c++/7.2.1/bits/stl_algobase.h:265:56: error: macro "max" passed 3 arguments, but takes just 2
1346     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
drzony commented 3 years ago

Now it should work

drzony commented 3 years ago

I've checked on my side and after those 2 fixes all CI builds are successful

brianrho commented 3 years ago

Also, good to keep in mind that not everyone may want to incur the (not-insignificant) cost of using std::functional, or including the standard library in general, whether it's supported by the platform or not. So, people should still have access to the existing simple prototypes, easily configurable.

256dpi commented 3 years ago

Merged in #232.

@brianrho The new API is additional, and if not used should not use any more space.