├── .codespellrc ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml ├── stale.yml └── workflows │ ├── auto-github-actions.yml │ ├── report-size-deltas.yml │ └── spell-check.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── Packages_Patches ├── STM32 │ └── hardware │ │ └── stm32 │ │ ├── 1.9.0 │ │ ├── system │ │ │ ├── STM32F4xx │ │ │ │ └── stm32f4xx_hal_conf_default.h │ │ │ └── STM32F7xx │ │ │ │ └── stm32f7xx_hal_conf_default.h │ │ └── variants │ │ │ ├── NUCLEO_F767ZI │ │ │ └── variant.h │ │ │ └── NUCLEO_L053R8 │ │ │ └── variant.h │ │ ├── 2.0.0 │ │ ├── system │ │ │ ├── STM32F4xx │ │ │ │ └── stm32f4xx_hal_conf_default.h │ │ │ └── STM32F7xx │ │ │ │ └── stm32f7xx_hal_conf_default.h │ │ └── variants │ │ │ ├── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ └── variant_NUCLEO_F767ZI.h │ │ │ ├── L052R(6-8)H_L053R(6-8)H │ │ │ └── variant_generic.h │ │ │ ├── STM32F7xx │ │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ │ └── variant_NUCLEO_F767ZI.h │ │ │ └── STM32L0xx │ │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ │ └── variant_generic.h │ │ ├── 2.1.0 │ │ ├── system │ │ │ ├── STM32F4xx │ │ │ │ └── stm32f4xx_hal_conf_default.h │ │ │ └── STM32F7xx │ │ │ │ └── stm32f7xx_hal_conf_default.h │ │ └── variants │ │ │ ├── STM32F7xx │ │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ │ └── variant_NUCLEO_F767ZI.h │ │ │ └── STM32L0xx │ │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ │ └── variant_generic.h │ │ ├── 2.2.0 │ │ ├── system │ │ │ ├── STM32F4xx │ │ │ │ └── stm32f4xx_hal_conf_default.h │ │ │ └── STM32F7xx │ │ │ │ └── stm32f7xx_hal_conf_default.h │ │ └── variants │ │ │ ├── STM32F7xx │ │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ │ └── variant_NUCLEO_F767ZI.h │ │ │ └── STM32L0xx │ │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ │ └── variant_generic.h │ │ └── 2.3.0 │ │ ├── system │ │ ├── STM32F4xx │ │ │ └── stm32f4xx_hal_conf_default.h │ │ └── STM32F7xx │ │ │ └── stm32f7xx_hal_conf_default.h │ │ └── variants │ │ ├── STM32F7xx │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ └── variant_NUCLEO_F767ZI.h │ │ └── STM32L0xx │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ └── variant_generic.h ├── arduino │ └── hardware │ │ └── mbed_portenta │ │ ├── 2.4.1 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ ├── libraries │ │ │ └── SocketWrapper │ │ │ │ └── src │ │ │ │ ├── MbedUdp.cpp │ │ │ │ └── MbedUdp.h │ │ └── portenta_post_install.sh │ │ ├── 2.5.2 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ ├── libraries │ │ │ └── SocketWrapper │ │ │ │ └── src │ │ │ │ ├── MbedUdp.cpp │ │ │ │ └── MbedUdp.h │ │ └── portenta_post_install.sh │ │ ├── 2.6.1 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ ├── libraries │ │ │ └── SocketWrapper │ │ │ │ └── src │ │ │ │ ├── MbedUdp.cpp │ │ │ │ └── MbedUdp.h │ │ └── portenta_post_install.sh │ │ ├── 2.7.2 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ └── portenta_post_install.sh │ │ ├── 2.8.0 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ └── portenta_post_install.sh │ │ ├── 3.0.0 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ └── portenta_post_install.sh │ │ ├── 3.0.1 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ └── portenta_post_install.sh │ │ ├── 3.1.1 │ │ ├── cores │ │ │ └── arduino │ │ │ │ └── mbed │ │ │ │ └── connectivity │ │ │ │ └── lwipstack │ │ │ │ └── include │ │ │ │ └── lwipstack │ │ │ │ └── lwipopts.h │ │ └── portenta_post_install.sh │ │ ├── 3.3.0 │ │ └── portenta_post_install.sh │ │ └── 3.4.1 │ │ └── portenta_post_install.sh └── hardware │ └── teensy │ └── avr │ ├── boards.txt │ └── cores │ ├── teensy │ ├── Stream.cpp │ └── Stream.h │ ├── teensy3 │ ├── Stream.cpp │ └── Stream.h │ └── teensy4 │ ├── Stream.cpp │ └── Stream.h ├── README.md ├── changelog.md ├── docs ├── 1.-Getting-started.md ├── 2.-API-reference.md ├── 3.-Memory-management.md ├── 4.-Limitations-and-known-issues.md ├── 5.-Troubleshooting.md ├── README.md └── index.md ├── examples ├── ESP32 │ ├── AsyncWebServer_MQTT │ │ └── AsyncWebServer_MQTT.ino │ ├── FullyFeaturedSSL_ESP32 │ │ ├── FullyFeaturedSSL_ESP32.ino │ │ └── defines.h │ └── FullyFeatured_ESP32 │ │ ├── FullyFeatured_ESP32.ino │ │ └── defines.h ├── ESP32_ENC │ ├── FullyFeaturedSSL_ESP32_ENC │ │ ├── FullyFeaturedSSL_ESP32_ENC.ino │ │ └── defines.h │ └── FullyFeatured_ESP32_ENC │ │ ├── FullyFeatured_ESP32_ENC.ino │ │ └── defines.h ├── ESP32_W5500 │ ├── FullyFeaturedSSL_ESP32_W5500 │ │ ├── FullyFeaturedSSL_ESP32_W5500.ino │ │ └── defines.h │ └── FullyFeatured_ESP32_W5500 │ │ ├── FullyFeatured_ESP32_W5500.ino │ │ └── defines.h ├── ESP8266 │ ├── FullyFeatured_ESP8266 │ │ ├── FullyFeatured_ESP8266.ino │ │ └── defines.h │ └── FullyFeatured_ESP8266_Ethernet │ │ ├── FullyFeatured_ESP8266_Ethernet.ino │ │ └── defines.h ├── PortentaH7_Ethernet │ └── FullyFeatured_PortentaH7_Ethernet │ │ ├── FullyFeatured_PortentaH7_Ethernet.ino │ │ └── defines.h ├── PortentaH7_WiFi │ └── FullyFeatured_PortentaH7_WiFi │ │ ├── FullyFeatured_PortentaH7_WiFi.ino │ │ └── defines.h ├── QNEthernet │ └── FullyFeatured_QNEthernet │ │ ├── FullyFeatured_QNEthernet.ino │ │ └── defines.h ├── RP2040W │ ├── AsyncWebServer_MQTT_RP2040W │ │ └── AsyncWebServer_MQTT_RP2040W.ino │ └── FullyFeatured_RP2040W │ │ ├── FullyFeatured_RP2040W.ino │ │ └── defines.h ├── STM32 │ └── FullyFeatured_STM32 │ │ ├── FullyFeatured_STM32.ino │ │ └── defines.h ├── STM32_LAN8720 │ └── FullyFeatured_STM32_LAN8720 │ │ ├── FullyFeatured_STM32_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h └── WT32_ETH01 │ ├── FullyFeaturedSSL_WT32_ETH01 │ ├── FullyFeaturedSSL_WT32_ETH01.ino │ └── defines.h │ └── FullyFeatured_WT32_ETH01 │ ├── FullyFeatured_WT32_ETH01.ino │ └── defines.h ├── keywords.txt ├── library.json ├── library.properties ├── pics └── STM32F407VET6.png ├── platformio └── platformio.ini ├── scripts ├── CI │ ├── build_examples_pio.sh │ ├── platformio_esp32.ini │ └── platformio_esp8266.ini └── get-fingerprint │ └── get-fingerprint.py ├── src ├── AsyncMqttClient │ ├── Callbacks.hpp │ ├── DisconnectReasons.hpp │ ├── Errors.hpp │ ├── Flags.hpp │ ├── Helpers.hpp │ ├── MessageProperties.hpp │ ├── Packets │ │ ├── ConnAckPacket.cpp │ │ ├── ConnAckPacket.hpp │ │ ├── Out │ │ │ ├── Connect.cpp │ │ │ ├── Connect.hpp │ │ │ ├── Disconn.cpp │ │ │ ├── Disconn.hpp │ │ │ ├── OutPacket.cpp │ │ │ ├── OutPacket.hpp │ │ │ ├── PingReq.cpp │ │ │ ├── PingReq.hpp │ │ │ ├── PubAck.cpp │ │ │ ├── PubAck.hpp │ │ │ ├── Publish.cpp │ │ │ ├── Publish.hpp │ │ │ ├── Subscribe.cpp │ │ │ ├── Subscribe.hpp │ │ │ ├── Unsubscribe.cpp │ │ │ └── Unsubscribe.hpp │ │ ├── Packet.hpp │ │ ├── PingRespPacket.cpp │ │ ├── PingRespPacket.hpp │ │ ├── PubAckPacket.cpp │ │ ├── PubAckPacket.hpp │ │ ├── PubCompPacket.cpp │ │ ├── PubCompPacket.hpp │ │ ├── PubRecPacket.cpp │ │ ├── PubRecPacket.hpp │ │ ├── PubRelPacket.cpp │ │ ├── PubRelPacket.hpp │ │ ├── PublishPacket.cpp │ │ ├── PublishPacket.hpp │ │ ├── SubAckPacket.cpp │ │ ├── SubAckPacket.hpp │ │ ├── UnsubAckPacket.cpp │ │ └── UnsubAckPacket.hpp │ ├── ParsingInformation.hpp │ └── Storage.hpp ├── AsyncMqttClient_Generic.hpp ├── AsyncMqttClient_Generic_Debug.h ├── AsyncMqttClient_Generic_Impl.h └── AsyncMqtt_Generic.h └── utils ├── astyle_library.conf └── restyle.sh /.codespellrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/codespell-project/codespell#using-a-config-file 2 | [codespell] 3 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 4 | ignore-words-list = , 5 | check-filenames = 6 | check-hidden = 7 | skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the bug 11 | 12 | A clear and concise description of what the bug is. 13 | 14 | ### Steps to Reproduce 15 | 16 | Steps to reproduce the behavior. Including the [MRE](https://stackoverflow.com/help/minimal-reproducible-example) sketches 17 | 18 | ### Expected behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ### Actual behavior 23 | 24 | A clear and concise description of what you expected to happen. 25 | 26 | ### Debug and AT-command log (if applicable) 27 | 28 | A clear and concise description of what you expected to happen. 29 | 30 | ### Screenshots 31 | 32 | If applicable, add screenshots to help explain your problem. 33 | 34 | --- 35 | 36 | ### Information 37 | 38 | Please ensure to specify the following: 39 | 40 | * Arduino IDE version (e.g. 1.8.19) or Platform.io version 41 | * `ESP8266`,`ESP32`, `STM32`, `arduino-pico` or `Teensyduino` Core Version (e.g. ESP8266 core v3.1.1, ESP32 v2.0.6, STM32 v2.4.0, arduino-pico v2.7.1 or Teensyduino v1.57) 42 | * Contextual information (e.g. what you were trying to achieve) 43 | * Simplest possible steps to reproduce 44 | * Anything that might be relevant in your opinion, such as: 45 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 46 | * Network configuration 47 | 48 | 49 | Please be educated, civilized and constructive as you've always been. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted. 50 | 51 | --- 52 | 53 | ### Example 54 | 55 | ``` 56 | Arduino IDE version: 1.8.19 57 | ESP32 Core Version 2.0.6 58 | OS: Ubuntu 20.04 LTS 59 | Linux xy-Inspiron-3593 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux 60 | 61 | Context: 62 | I encountered a crash while using this library 63 | Steps to reproduce: 64 | 1. ... 65 | 2. ... 66 | 3. ... 67 | 4. ... 68 | ``` 69 | 70 | ### Additional context 71 | 72 | Add any other context about the problem here. 73 | 74 | --- 75 | 76 | ### Sending Feature Requests 77 | 78 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 79 | 80 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncMQTT_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 81 | 82 | --- 83 | 84 | ### Sending Pull Requests 85 | 86 | Pull Requests with changes and fixes are also welcome! 87 | 88 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 89 | 90 | 1. Change directory to the library GitHub 91 | 92 | ``` 93 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncMQTT_Generic_GitHub/ 94 | xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$ 95 | ``` 96 | 97 | 2. Issue astyle command 98 | 99 | ``` 100 | xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$ bash utils/restyle.sh 101 | ``` 102 | 103 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Is your feature request related to a problem? Please describe. 11 | 12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 13 | 14 | ### Describe the solution you'd like 15 | 16 | A clear and concise description of what you want to happen. 17 | 18 | ### Describe alternatives you've considered 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | ### Additional context 22 | 23 | Add any other context or screenshots about the feature request here. 24 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file 2 | version: 2 3 | 4 | updates: 5 | # Configure check for outdated GitHub Actions actions in workflows. 6 | # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot 7 | - package-ecosystem: github-actions 8 | directory: / # Check the repository's workflows under /.github/workflows/ 9 | schedule: 10 | interval: daily 11 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | daysUntilStale: 60 4 | daysUntilClose: 14 5 | limitPerRun: 30 6 | staleLabel: stale 7 | exemptLabels: 8 | - pinned 9 | - security 10 | - "to be implemented" 11 | - "for reference" 12 | - "move to PR" 13 | - "enhancement" 14 | 15 | only: issues 16 | onlyLabels: [] 17 | exemptProjects: false 18 | exemptMilestones: false 19 | exemptAssignees: false 20 | 21 | markComment: > 22 | [STALE_SET] This issue has been automatically marked as stale because it has not had 23 | recent activity. It will be closed in 14 days if no further activity occurs. Thank you 24 | for your contributions. 25 | 26 | unmarkComment: > 27 | [STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it opening the future. 28 | 29 | closeComment: > 30 | [STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. 31 | 32 | -------------------------------------------------------------------------------- /.github/workflows/auto-github-actions.yml: -------------------------------------------------------------------------------- 1 | name: auto-github-actions 2 | on: [push] 3 | jobs: 4 | check-bats-version: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v3 8 | - uses: actions/setup-node@v3 9 | with: 10 | node-version: '14' 11 | - run: npm install -g bats 12 | - run: bats -v 13 | -------------------------------------------------------------------------------- /.github/workflows/report-size-deltas.yml: -------------------------------------------------------------------------------- 1 | name: Report Size Deltas 2 | 3 | on: 4 | schedule: 5 | - cron: '*/5 * * * *' 6 | 7 | jobs: 8 | report: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Comment size deltas reports to PRs 13 | uses: arduino/report-size-deltas@v1 14 | with: 15 | # The name of the workflow artifact created by the "Compile Examples" workflow 16 | sketches-reports-source: sketches-reports 17 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | 3 | on: 4 | pull_request: 5 | push: 6 | schedule: 7 | # run every Tuesday at 3 AM UTC 8 | - cron: "0 3 * * 2" 9 | workflow_dispatch: 10 | repository_dispatch: 11 | 12 | jobs: 13 | spellcheck: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | 20 | # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md 21 | - name: Spell check 22 | uses: codespell-project/actions-codespell@master 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to AsyncMQTT_Generic 2 | 3 | ### Reporting Bugs 4 | 5 | Please report bugs in [AsyncMQTT_Generic](https://github.com/khoih-prog/AsyncMQTT_Generic/issues/new) if you find them. 6 | 7 | However, before reporting a bug please check through the following: 8 | 9 | * [Existing Open Issues](https://github.com/khoih-prog/AsyncMQTT_Generic/issues) - someone might have already encountered this. 10 | 11 | If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncMQTT_Generic/issues/new). 12 | 13 | --- 14 | 15 | ### How to submit a bug report 16 | 17 | Please ensure to specify the following: 18 | 19 | * Arduino IDE version (e.g. 1.8.19) or Platform.io version 20 | * `ESP8266`,`ESP32`, `STM32`, `arduino-pico` or `Teensyduino` Core Version (e.g. ESP8266 core v3.1.1, ESP32 v2.0.6, STM32 v2.4.0, arduino-pico v2.7.1 or Teensyduino v1.57) 21 | * Contextual information (e.g. what you were trying to achieve) 22 | * Simplest possible steps to reproduce 23 | * Anything that might be relevant in your opinion, such as: 24 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 25 | * Network configuration 26 | 27 | 28 | Please be educated, civilized and constructive as you've always been. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted. 29 | 30 | --- 31 | 32 | ### Example 33 | 34 | ``` 35 | Arduino IDE version: 1.8.19 36 | ESP32 Core Version 2.0.6 37 | OS: Ubuntu 20.04 LTS 38 | Linux xy-Inspiron-3593 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux 39 | 40 | Context: 41 | I encountered a crash while using this library 42 | 43 | Steps to reproduce: 44 | 1. ... 45 | 2. ... 46 | 3. ... 47 | 4. ... 48 | ``` 49 | 50 | --- 51 | 52 | ### Sending Feature Requests 53 | 54 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 55 | 56 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncMQTT_Generic/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 57 | 58 | --- 59 | 60 | ### Sending Pull Requests 61 | 62 | Pull Requests with changes and fixes are also welcome! 63 | 64 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 65 | 66 | 1. Change directory to the library GitHub 67 | 68 | ``` 69 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncMQTT_Generic_GitHub/ 70 | xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$ 71 | ``` 72 | 73 | 2. Issue astyle command 74 | 75 | ``` 76 | xy@xy-Inspiron-3593:~/Arduino/xy/AsyncMQTT_Generic_GitHub$ bash utils/restyle.sh 77 | ``` 78 | 79 | 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Khoi Hoang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Packages_Patches/STM32/hardware/stm32/1.9.0/variants/NUCLEO_F767ZI/variant.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _VARIANT_ARDUINO_STM32_ 20 | #define _VARIANT_ARDUINO_STM32_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif // __cplusplus 25 | 26 | /*---------------------------------------------------------------------------- 27 | Pins 28 | ----------------------------------------------------------------------------*/ 29 | 30 | #define PG9 0 31 | #define PG14 1 32 | #define PF15 2 33 | #define PE13 3 34 | #define PF14 4 35 | #define PE11 5 36 | #define PE9 6 37 | #define PF13 7 38 | #define PF12 8 39 | #define PD15 9 40 | #define PD14 10 41 | #define PA7 A10 42 | #define PA6 A11 43 | #define PA5 A12 44 | #define PB9 14 45 | #define PB8 15 46 | #define PC6 16 47 | #define PB15 17 48 | #define PB13 18 49 | #define PB12 19 50 | #define PA15 20 51 | #define PC7 21 52 | #define PB5 22 53 | #define PB3 23 54 | #define PA4 A13 55 | #define PB4 25 56 | #define PB6 26 57 | #define PB2 27 58 | #define PD13 28 59 | #define PD12 29 60 | #define PD11 30 61 | #define PE2 31 62 | #define PA0 A14 63 | #define PB0 33 // LED_GREEN 64 | #define PE0 34 65 | #define PB11 35 66 | #define PB10 36 67 | #define PE15 37 68 | #define PE14 38 69 | #define PE12 39 70 | #define PE10 40 71 | #define PE7 41 72 | #define PE8 42 73 | #define PC8 43 74 | #define PC9 44 75 | #define PC10 45 76 | #define PC11 46 77 | #define PC12 47 78 | #define PD2 48 79 | #define PG2 49 80 | #define PG3 50 81 | #define PD7 51 82 | #define PD6 52 83 | #define PD5 53 84 | #define PD4 54 85 | #define PD3 55 86 | // 56 is PE2 (31) 87 | #define PE4 57 88 | #define PE5 58 89 | #define PE6 59 90 | #define PE3 60 91 | #define PF8 A15 92 | #define PF7 A16 93 | #define PF9 A17 94 | #define PG1 64 95 | #define PG0 65 96 | #define PD1 66 97 | #define PD0 67 98 | #define PF0 68 99 | #define PF1 69 100 | #define PF2 70 101 | // 71 is PA7 (11) 102 | // 72 is NC 103 | #define PB7 73 // LED_BLUE 104 | #define PB14 74 // LED_RED 105 | #define PC13 75 // USER_BTN 106 | #define PD9 76 // Serial Rx 107 | #define PD8 77 // Serial Tx 108 | #define PA3 A0 109 | #define PC0 A1 110 | #define PC3 A2 111 | #define PF3 A3 112 | #define PF5 A4 113 | #define PF10 A5 114 | #define PB1 A6 115 | #define PC2 A7 116 | #define PF4 A8 117 | #define PF6 A9 118 | 119 | // This must be a literal 120 | #define NUM_DIGITAL_PINS 88 121 | // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS 122 | #define NUM_ANALOG_INPUTS 18 123 | 124 | // On-board LED pin number 125 | #define LED_BUILTIN PB0 126 | #define LED_GREEN LED_BUILTIN 127 | #define LED_BLUE PB7 128 | #define LED_RED PB14 129 | 130 | // On-board user button 131 | #define USER_BTN PC13 132 | 133 | // Timer Definitions 134 | // Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin 135 | #define TIMER_TONE TIM6 136 | #define TIMER_SERVO TIM7 137 | 138 | // UART Definitions 139 | #define SERIAL_UART_INSTANCE 3 //Connected to ST-Link 140 | 141 | // Serial pin used for console (ex: stlink) 142 | // Rerquired by Firmata 143 | #define PIN_SERIAL_RX PD9 144 | #define PIN_SERIAL_TX PD8 145 | 146 | /* Extra HAL modules */ 147 | #define HAL_DAC_MODULE_ENABLED 148 | #define HAL_ETH_MODULE_ENABLED 149 | 150 | // Last Flash sector used for EEPROM emulation, address/sector depends on single/dual bank configuration. 151 | // By default 2MB single bank 152 | #define FLASH_BASE_ADDRESS 0x081C0000 153 | #define FLASH_DATA_SECTOR 11 154 | 155 | #ifdef __cplusplus 156 | } // extern "C" 157 | #endif 158 | /*---------------------------------------------------------------------------- 159 | Arduino objects - C++ only 160 | ----------------------------------------------------------------------------*/ 161 | 162 | #ifdef __cplusplus 163 | // These serial port names are intended to allow libraries and architecture-neutral 164 | // sketches to automatically default to the correct port name for a particular type 165 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, 166 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. 167 | // 168 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor 169 | // 170 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial 171 | // 172 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library 173 | // 174 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. 175 | // 176 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX 177 | // pins are NOT connected to anything by default. 178 | #define SERIAL_PORT_MONITOR Serial 179 | 180 | // KH mod to add Serial1, for ESP-AT 181 | //#define SERIAL_PORT_HARDWARE Serial 182 | #define SERIAL_PORT_HARDWARE Serial1 183 | #endif 184 | 185 | #endif /* _VARIANT_ARDUINO_STM32_ */ 186 | -------------------------------------------------------------------------------- /Packages_Patches/STM32/hardware/stm32/1.9.0/variants/NUCLEO_L053R8/variant.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _VARIANT_ARDUINO_STM32_ 20 | #define _VARIANT_ARDUINO_STM32_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif // __cplusplus 25 | 26 | /*---------------------------------------------------------------------------- 27 | Pins 28 | ----------------------------------------------------------------------------*/ 29 | 30 | #define PA3 0 31 | #define PA2 1 32 | #define PA10 2 33 | #define PB3 3 34 | #define PB5 4 35 | #define PB4 5 36 | #define PB10 6 37 | #define PA8 7 38 | #define PA9 8 39 | #define PC7 9 40 | #define PB6 10 41 | #define PA7 A6 42 | #define PA6 A7 43 | #define PA5 13 44 | #define PB9 14 45 | #define PB8 15 46 | // ST Morpho 47 | // CN7 Left Side 48 | #define PC10 16 49 | #define PC12 17 50 | // 18 is NC - BOOT0 51 | #define PA13 19 // SWD 52 | #define PA14 20 // SWD 53 | #define PA15 21 54 | #define PB7 22 55 | #define PC13 23 56 | #define PC14 24 57 | #define PC15 25 58 | #define PH0 26 59 | #define PH1 27 60 | #define PC2 A8 61 | #define PC3 A9 62 | // CN7 Right Side 63 | #define PC11 30 64 | #define PD2 31 65 | // CN10 Left Side 66 | #define PC9 32 67 | // CN10 Right side 68 | #define PC8 33 69 | #define PC6 34 70 | #define PC5 A10 71 | #define PA12 36 72 | #define PA11 37 73 | #define PB12 38 74 | #define PB11 39 75 | #define PB2 40 76 | #define PB1 41 77 | #define PB15 42 78 | #define PB14 43 79 | #define PB13 44 80 | #define PC4 A11 81 | #define PA0 A0 82 | #define PA1 A1 83 | #define PA4 A2 84 | #define PB0 A3 85 | #define PC1 A4 86 | #define PC0 A5 87 | 88 | // This must be a literal 89 | #define NUM_DIGITAL_PINS 52 90 | // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS 91 | #define NUM_ANALOG_INPUTS 12 92 | 93 | // On-board LED pin number 94 | #define LED_BUILTIN 13 95 | #define LED_GREEN LED_BUILTIN 96 | 97 | // On-board user button 98 | #define USER_BTN PC13 99 | 100 | // Timer Definitions 101 | // Use TIM6 when possible as servo and tone don't need GPIO output pin 102 | #define TIMER_TONE TIM6 103 | #define TIMER_SERVO TIM2 104 | 105 | // UART Definitions 106 | #define SERIAL_UART_INSTANCE 2 //Connected to ST-Link 107 | // Default pin used for 'Serial' instance (ex: ST-Link) 108 | // Mandatory for Firmata 109 | #define PIN_SERIAL_RX 0 110 | #define PIN_SERIAL_TX 1 111 | 112 | /* Extra HAL modules */ 113 | #define HAL_DAC_MODULE_ENABLED 114 | 115 | #ifdef __cplusplus 116 | } // extern "C" 117 | #endif 118 | /*---------------------------------------------------------------------------- 119 | Arduino objects - C++ only 120 | ----------------------------------------------------------------------------*/ 121 | 122 | #ifdef __cplusplus 123 | // These serial port names are intended to allow libraries and architecture-neutral 124 | // sketches to automatically default to the correct port name for a particular type 125 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, 126 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. 127 | // 128 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor 129 | // 130 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial 131 | // 132 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library 133 | // 134 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. 135 | // 136 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX 137 | // pins are NOT connected to anything by default. 138 | #define SERIAL_PORT_MONITOR Serial 139 | 140 | // KH mod to add Serial1, for ESP-AT 141 | //#define SERIAL_PORT_HARDWARE Serial 142 | #define SERIAL_PORT_HARDWARE Serial1 143 | #endif 144 | 145 | #endif /* _VARIANT_ARDUINO_STM32_ */ 146 | -------------------------------------------------------------------------------- /Packages_Patches/STM32/hardware/stm32/2.0.0/variants/L052R(6-8)H_L053R(6-8)H/variant_generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | Copyright (c) 2020-2021, STMicroelectronics 4 | All rights reserved. 5 | 6 | This software component is licensed by ST under BSD 3-Clause license, 7 | the "License"; You may not use this file except in compliance with the 8 | License. You may obtain a copy of the License at: 9 | opensource.org/licenses/BSD-3-Clause 10 | 11 | ******************************************************************************* 12 | */ 13 | #pragma once 14 | 15 | /*---------------------------------------------------------------------------- 16 | STM32 pins number 17 | ----------------------------------------------------------------------------*/ 18 | #define PA0 PIN_A0 19 | #define PA1 PIN_A1 20 | #define PA2 PIN_A2 21 | #define PA3 PIN_A3 22 | #define PA4 PIN_A4 23 | #define PA5 PIN_A5 24 | #define PA6 PIN_A6 25 | #define PA7 PIN_A7 26 | #define PA8 8 27 | #define PA9 9 28 | #define PA10 10 29 | #define PA11 11 30 | #define PA12 12 31 | #define PA13 13 32 | #define PA14 14 33 | #define PA15 15 34 | #define PB0 PIN_A8 35 | #define PB1 PIN_A9 36 | #define PB2 18 37 | #define PB3 19 38 | #define PB4 20 39 | #define PB5 21 40 | #define PB6 22 41 | #define PB7 23 42 | #define PB8 24 43 | #define PB9 25 44 | #define PB10 26 45 | #define PB11 27 46 | #define PB12 28 47 | #define PB13 29 48 | #define PB14 30 49 | #define PB15 31 50 | #define PC0 PIN_A10 51 | #define PC1 PIN_A11 52 | #define PC2 PIN_A12 53 | #define PC4 PIN_A13 54 | #define PC5 PIN_A14 55 | #define PC6 37 56 | #define PC7 38 57 | #define PC8 39 58 | #define PC9 40 59 | #define PC10 41 60 | #define PC11 42 61 | #define PC12 43 62 | #define PC13 44 63 | #define PC14 45 64 | #define PC15 46 65 | #define PD2 47 66 | #define PH0 48 67 | #define PH1 49 68 | 69 | // Alternate pins number 70 | #define PA2_ALT1 (PA2 | ALT1) 71 | #define PA3_ALT1 (PA3 | ALT1) 72 | 73 | #define NUM_DIGITAL_PINS 50 74 | #define NUM_ANALOG_INPUTS 15 75 | 76 | // On-board LED pin number 77 | #ifndef LED_BUILTIN 78 | #define LED_BUILTIN PNUM_NOT_DEFINED 79 | #endif 80 | 81 | // On-board user button 82 | #ifndef USER_BTN 83 | #define USER_BTN PNUM_NOT_DEFINED 84 | #endif 85 | 86 | // SPI definitions 87 | #ifndef PIN_SPI_SS 88 | #define PIN_SPI_SS PA4 89 | #endif 90 | #ifndef PIN_SPI_SS1 91 | #define PIN_SPI_SS1 PA15 92 | #endif 93 | #ifndef PIN_SPI_SS2 94 | #define PIN_SPI_SS2 PNUM_NOT_DEFINED 95 | #endif 96 | #ifndef PIN_SPI_SS3 97 | #define PIN_SPI_SS3 PNUM_NOT_DEFINED 98 | #endif 99 | #ifndef PIN_SPI_MOSI 100 | #define PIN_SPI_MOSI PA7 101 | #endif 102 | #ifndef PIN_SPI_MISO 103 | #define PIN_SPI_MISO PA6 104 | #endif 105 | #ifndef PIN_SPI_SCK 106 | #define PIN_SPI_SCK PA5 107 | #endif 108 | 109 | // I2C definitions 110 | #ifndef PIN_WIRE_SDA 111 | #define PIN_WIRE_SDA PB7 112 | #endif 113 | #ifndef PIN_WIRE_SCL 114 | #define PIN_WIRE_SCL PB6 115 | #endif 116 | 117 | // Timer Definitions 118 | // Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin 119 | #ifndef TIMER_TONE 120 | #define TIMER_TONE TIM6 121 | #endif 122 | #ifndef TIMER_SERVO 123 | #define TIMER_SERVO TIM21 124 | #endif 125 | 126 | // UART Definitions 127 | #ifndef SERIAL_UART_INSTANCE 128 | #define SERIAL_UART_INSTANCE 2 129 | #endif 130 | 131 | // Default pin used for generic 'Serial' instance 132 | // Mandatory for Firmata 133 | #ifndef PIN_SERIAL_RX 134 | #define PIN_SERIAL_RX PA3 135 | #endif 136 | #ifndef PIN_SERIAL_TX 137 | #define PIN_SERIAL_TX PA2 138 | #endif 139 | 140 | // Extra HAL modules 141 | #if !defined(HAL_DAC_MODULE_DISABLED) 142 | #define HAL_DAC_MODULE_ENABLED 143 | #endif 144 | 145 | /*---------------------------------------------------------------------------- 146 | Arduino objects - C++ only 147 | ----------------------------------------------------------------------------*/ 148 | 149 | #ifdef __cplusplus 150 | // These serial port names are intended to allow libraries and architecture-neutral 151 | // sketches to automatically default to the correct port name for a particular type 152 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, 153 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. 154 | // 155 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor 156 | // 157 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial 158 | // 159 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library 160 | // 161 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. 162 | // 163 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX 164 | // pins are NOT connected to anything by default. 165 | #ifndef SERIAL_PORT_MONITOR 166 | #define SERIAL_PORT_MONITOR Serial 167 | #endif 168 | #ifndef SERIAL_PORT_HARDWARE 169 | // KH mod to add Serial1, for ESP-AT 170 | //#define SERIAL_PORT_HARDWARE Serial 171 | #define SERIAL_PORT_HARDWARE Serial1 172 | #endif 173 | #endif 174 | -------------------------------------------------------------------------------- /Packages_Patches/STM32/hardware/stm32/2.0.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/variant_generic.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | Copyright (c) 2020-2021, STMicroelectronics 4 | All rights reserved. 5 | 6 | This software component is licensed by ST under BSD 3-Clause license, 7 | the "License"; You may not use this file except in compliance with the 8 | License. You may obtain a copy of the License at: 9 | opensource.org/licenses/BSD-3-Clause 10 | 11 | ******************************************************************************* 12 | */ 13 | #pragma once 14 | 15 | /*---------------------------------------------------------------------------- 16 | STM32 pins number 17 | ----------------------------------------------------------------------------*/ 18 | #define PA0 PIN_A0 19 | #define PA1 PIN_A1 20 | #define PA2 PIN_A2 21 | #define PA3 PIN_A3 22 | #define PA4 PIN_A4 23 | #define PA5 PIN_A5 24 | #define PA6 PIN_A6 25 | #define PA7 PIN_A7 26 | #define PA8 8 27 | #define PA9 9 28 | #define PA10 10 29 | #define PA11 11 30 | #define PA12 12 31 | #define PA13 13 32 | #define PA14 14 33 | #define PA15 15 34 | #define PB0 PIN_A8 35 | #define PB1 PIN_A9 36 | #define PB2 18 37 | #define PB3 19 38 | #define PB4 20 39 | #define PB5 21 40 | #define PB6 22 41 | #define PB7 23 42 | #define PB8 24 43 | #define PB9 25 44 | #define PB10 26 45 | #define PB11 27 46 | #define PB12 28 47 | #define PB13 29 48 | #define PB14 30 49 | #define PB15 31 50 | #define PC0 PIN_A10 51 | #define PC1 PIN_A11 52 | #define PC2 PIN_A12 53 | #define PC4 PIN_A13 54 | #define PC5 PIN_A14 55 | #define PC6 37 56 | #define PC7 38 57 | #define PC8 39 58 | #define PC9 40 59 | #define PC10 41 60 | #define PC11 42 61 | #define PC12 43 62 | #define PC13 44 63 | #define PC14 45 64 | #define PC15 46 65 | #define PD2 47 66 | #define PH0 48 67 | #define PH1 49 68 | 69 | // Alternate pins number 70 | #define PA2_ALT1 (PA2 | ALT1) 71 | #define PA3_ALT1 (PA3 | ALT1) 72 | 73 | #define NUM_DIGITAL_PINS 50 74 | #define NUM_ANALOG_INPUTS 15 75 | 76 | // On-board LED pin number 77 | #ifndef LED_BUILTIN 78 | #define LED_BUILTIN PNUM_NOT_DEFINED 79 | #endif 80 | 81 | // On-board user button 82 | #ifndef USER_BTN 83 | #define USER_BTN PNUM_NOT_DEFINED 84 | #endif 85 | 86 | // SPI definitions 87 | #ifndef PIN_SPI_SS 88 | #define PIN_SPI_SS PA4 89 | #endif 90 | #ifndef PIN_SPI_SS1 91 | #define PIN_SPI_SS1 PA15 92 | #endif 93 | #ifndef PIN_SPI_SS2 94 | #define PIN_SPI_SS2 PNUM_NOT_DEFINED 95 | #endif 96 | #ifndef PIN_SPI_SS3 97 | #define PIN_SPI_SS3 PNUM_NOT_DEFINED 98 | #endif 99 | #ifndef PIN_SPI_MOSI 100 | #define PIN_SPI_MOSI PA7 101 | #endif 102 | #ifndef PIN_SPI_MISO 103 | #define PIN_SPI_MISO PA6 104 | #endif 105 | #ifndef PIN_SPI_SCK 106 | #define PIN_SPI_SCK PA5 107 | #endif 108 | 109 | // I2C definitions 110 | #ifndef PIN_WIRE_SDA 111 | #define PIN_WIRE_SDA PB7 112 | #endif 113 | #ifndef PIN_WIRE_SCL 114 | #define PIN_WIRE_SCL PB6 115 | #endif 116 | 117 | // Timer Definitions 118 | // Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin 119 | #ifndef TIMER_TONE 120 | #define TIMER_TONE TIM6 121 | #endif 122 | #ifndef TIMER_SERVO 123 | #define TIMER_SERVO TIM21 124 | #endif 125 | 126 | // UART Definitions 127 | #ifndef SERIAL_UART_INSTANCE 128 | #define SERIAL_UART_INSTANCE 2 129 | #endif 130 | 131 | // Default pin used for generic 'Serial' instance 132 | // Mandatory for Firmata 133 | #ifndef PIN_SERIAL_RX 134 | #define PIN_SERIAL_RX PA3 135 | #endif 136 | #ifndef PIN_SERIAL_TX 137 | #define PIN_SERIAL_TX PA2 138 | #endif 139 | 140 | // Extra HAL modules 141 | #if !defined(HAL_DAC_MODULE_DISABLED) 142 | #define HAL_DAC_MODULE_ENABLED 143 | #endif 144 | 145 | /*---------------------------------------------------------------------------- 146 | Arduino objects - C++ only 147 | ----------------------------------------------------------------------------*/ 148 | 149 | #ifdef __cplusplus 150 | // These serial port names are intended to allow libraries and architecture-neutral 151 | // sketches to automatically default to the correct port name for a particular type 152 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, 153 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. 154 | // 155 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor 156 | // 157 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial 158 | // 159 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library 160 | // 161 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. 162 | // 163 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX 164 | // pins are NOT connected to anything by default. 165 | #ifndef SERIAL_PORT_MONITOR 166 | #define SERIAL_PORT_MONITOR Serial 167 | #endif 168 | #ifndef SERIAL_PORT_HARDWARE 169 | // KH mod to add Serial1, for ESP-AT 170 | //#define SERIAL_PORT_HARDWARE Serial 171 | #define SERIAL_PORT_HARDWARE Serial1 172 | #endif 173 | #endif 174 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.4.1/libraries/SocketWrapper/src/MbedUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | MbedUdp.h - UDP implementation using mbed Sockets 3 | Copyright (c) 2021 Arduino SA. All right reserved. 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | Lesser General Public License for more details. 12 | You should have received a copy of the GNU Lesser General Public 13 | License along with this library; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 | */ 16 | 17 | #ifndef MBEDUDP_H 18 | #define MBEDUDP_H 19 | 20 | #include "Arduino.h" 21 | #include "SocketHelpers.h" 22 | #include "api/Udp.h" 23 | 24 | #include "netsocket/SocketAddress.h" 25 | #include "netsocket/UDPSocket.h" 26 | 27 | #ifndef WIFI_UDP_BUFFER_SIZE 28 | #define WIFI_UDP_BUFFER_SIZE 508 29 | #endif 30 | 31 | namespace arduino 32 | { 33 | 34 | class MbedUDP : public UDP 35 | { 36 | private: 37 | UDPSocket _socket; // Mbed OS socket 38 | SocketAddress _host; // Host to be used to send data 39 | SocketAddress _remoteHost; // Remote host that sent incoming packets 40 | 41 | uint8_t* _packet_buffer; // Raw packet buffer (contains data we got from the UDPSocket) 42 | 43 | // The Arduino APIs allow you to iterate through this buffer, so we need to be able to iterate over the current packet 44 | // these two variables are used to cache the state of the current packet 45 | uint8_t* _current_packet; 46 | size_t _current_packet_size; 47 | 48 | RingBufferN txBuffer; 49 | 50 | protected: 51 | virtual NetworkInterface* getNetwork() = 0; 52 | 53 | public: 54 | MbedUDP(); // Constructor 55 | ~MbedUDP(); 56 | virtual uint8_t begin( 57 | uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 58 | virtual uint8_t beginMulticast(IPAddress, 59 | uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use 60 | virtual void stop(); // Finish with the UDP socket 61 | 62 | // Sending UDP packets 63 | 64 | // Start building up a packet to send to the remote host specific in ip and port 65 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 66 | virtual int beginPacket(IPAddress ip, uint16_t port); 67 | // Start building up a packet to send to the remote host specific in host and port 68 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 69 | virtual int beginPacket(const char* host, uint16_t port); 70 | // Finish off this packet and send it 71 | // Returns 1 if the packet was sent successfully, 0 if there was an error 72 | virtual int endPacket(); 73 | // Write a single byte into the packet 74 | virtual size_t write(uint8_t); 75 | // Write size bytes from buffer into the packet 76 | virtual size_t write(const uint8_t* buffer, size_t size); 77 | 78 | using Print::write; 79 | 80 | // Start processing the next available incoming packet 81 | // Returns the size of the packet in bytes, or 0 if no packets are available 82 | virtual int parsePacket(); 83 | // Number of bytes remaining in the current packet 84 | virtual int available(); 85 | // Read a single byte from the current packet 86 | virtual int read(); 87 | // Read up to len bytes from the current packet and place them into buffer 88 | // Returns the number of bytes read, or 0 if none are available 89 | virtual int read(unsigned char* buffer, size_t len); 90 | // Read up to len characters from the current packet and place them into buffer 91 | // Returns the number of characters read, or 0 if none are available 92 | virtual int read(char* buffer, size_t len) 93 | { 94 | return read((unsigned char*)buffer, len); 95 | }; 96 | // Return the next byte from the current packet without moving on to the next byte 97 | virtual int peek(); 98 | virtual void flush(); // Finish reading the current packet 99 | 100 | // Return the IP address of the host who sent the current incoming packet 101 | virtual IPAddress remoteIP(); 102 | // // Return the port of the host who sent the current incoming packet 103 | virtual uint16_t remotePort(); 104 | 105 | friend class MbedSocketClass; 106 | }; 107 | 108 | } 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.4.1/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.5.2/libraries/SocketWrapper/src/MbedUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | MbedUdp.h - UDP implementation using mbed Sockets 3 | Copyright (c) 2021 Arduino SA. All right reserved. 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | Lesser General Public License for more details. 12 | You should have received a copy of the GNU Lesser General Public 13 | License along with this library; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 | */ 16 | 17 | #ifndef MBEDUDP_H 18 | #define MBEDUDP_H 19 | 20 | #include "Arduino.h" 21 | #include "SocketHelpers.h" 22 | #include "api/Udp.h" 23 | 24 | #include "netsocket/SocketAddress.h" 25 | #include "netsocket/UDPSocket.h" 26 | 27 | #ifndef WIFI_UDP_BUFFER_SIZE 28 | #define WIFI_UDP_BUFFER_SIZE 508 29 | #endif 30 | 31 | namespace arduino 32 | { 33 | 34 | class MbedUDP : public UDP 35 | { 36 | private: 37 | UDPSocket _socket; // Mbed OS socket 38 | SocketAddress _host; // Host to be used to send data 39 | SocketAddress _remoteHost; // Remote host that sent incoming packets 40 | 41 | uint8_t* _packet_buffer; // Raw packet buffer (contains data we got from the UDPSocket) 42 | 43 | // The Arduino APIs allow you to iterate through this buffer, so we need to be able to iterate over the current packet 44 | // these two variables are used to cache the state of the current packet 45 | uint8_t* _current_packet; 46 | size_t _current_packet_size; 47 | 48 | RingBufferN txBuffer; 49 | 50 | protected: 51 | virtual NetworkInterface* getNetwork() = 0; 52 | 53 | public: 54 | MbedUDP(); // Constructor 55 | ~MbedUDP(); 56 | virtual uint8_t begin( 57 | uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 58 | virtual uint8_t beginMulticast(IPAddress, 59 | uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use 60 | virtual void stop(); // Finish with the UDP socket 61 | 62 | // Sending UDP packets 63 | 64 | // Start building up a packet to send to the remote host specific in ip and port 65 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 66 | virtual int beginPacket(IPAddress ip, uint16_t port); 67 | // Start building up a packet to send to the remote host specific in host and port 68 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 69 | virtual int beginPacket(const char* host, uint16_t port); 70 | // Finish off this packet and send it 71 | // Returns 1 if the packet was sent successfully, 0 if there was an error 72 | virtual int endPacket(); 73 | // Write a single byte into the packet 74 | virtual size_t write(uint8_t); 75 | // Write size bytes from buffer into the packet 76 | virtual size_t write(const uint8_t* buffer, size_t size); 77 | 78 | using Print::write; 79 | 80 | // Start processing the next available incoming packet 81 | // Returns the size of the packet in bytes, or 0 if no packets are available 82 | virtual int parsePacket(); 83 | // Number of bytes remaining in the current packet 84 | virtual int available(); 85 | // Read a single byte from the current packet 86 | virtual int read(); 87 | // Read up to len bytes from the current packet and place them into buffer 88 | // Returns the number of bytes read, or 0 if none are available 89 | virtual int read(unsigned char* buffer, size_t len); 90 | // Read up to len characters from the current packet and place them into buffer 91 | // Returns the number of characters read, or 0 if none are available 92 | virtual int read(char* buffer, size_t len) 93 | { 94 | return read((unsigned char*)buffer, len); 95 | }; 96 | // Return the next byte from the current packet without moving on to the next byte 97 | virtual int peek(); 98 | virtual void flush(); // Finish reading the current packet 99 | 100 | // Return the IP address of the host who sent the current incoming packet 101 | virtual IPAddress remoteIP(); 102 | // // Return the port of the host who sent the current incoming packet 103 | virtual uint16_t remotePort(); 104 | 105 | friend class MbedSocketClass; 106 | }; 107 | 108 | } 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.5.2/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.6.1/libraries/SocketWrapper/src/MbedUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | MbedUdp.h - UDP implementation using mbed Sockets 3 | Copyright (c) 2021 Arduino SA. All right reserved. 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | Lesser General Public License for more details. 12 | You should have received a copy of the GNU Lesser General Public 13 | License along with this library; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 | */ 16 | 17 | #ifndef MBEDUDP_H 18 | #define MBEDUDP_H 19 | 20 | #include "Arduino.h" 21 | #include "SocketHelpers.h" 22 | #include "api/Udp.h" 23 | 24 | #include "netsocket/SocketAddress.h" 25 | #include "netsocket/UDPSocket.h" 26 | 27 | #ifndef WIFI_UDP_BUFFER_SIZE 28 | #define WIFI_UDP_BUFFER_SIZE 508 29 | #endif 30 | 31 | namespace arduino 32 | { 33 | 34 | class MbedUDP : public UDP 35 | { 36 | private: 37 | UDPSocket _socket; // Mbed OS socket 38 | SocketAddress _host; // Host to be used to send data 39 | SocketAddress _remoteHost; // Remote host that sent incoming packets 40 | 41 | uint8_t* _packet_buffer; // Raw packet buffer (contains data we got from the UDPSocket) 42 | 43 | // The Arduino APIs allow you to iterate through this buffer, so we need to be able to iterate over the current packet 44 | // these two variables are used to cache the state of the current packet 45 | uint8_t* _current_packet; 46 | size_t _current_packet_size; 47 | 48 | RingBufferN txBuffer; 49 | 50 | protected: 51 | virtual NetworkInterface* getNetwork() = 0; 52 | 53 | public: 54 | MbedUDP(); // Constructor 55 | ~MbedUDP(); 56 | virtual uint8_t begin( 57 | uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 58 | virtual uint8_t beginMulticast(IPAddress, 59 | uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use 60 | virtual void stop(); // Finish with the UDP socket 61 | 62 | // Sending UDP packets 63 | 64 | // Start building up a packet to send to the remote host specific in ip and port 65 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 66 | virtual int beginPacket(IPAddress ip, uint16_t port); 67 | // Start building up a packet to send to the remote host specific in host and port 68 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 69 | virtual int beginPacket(const char* host, uint16_t port); 70 | // Finish off this packet and send it 71 | // Returns 1 if the packet was sent successfully, 0 if there was an error 72 | virtual int endPacket(); 73 | // Write a single byte into the packet 74 | virtual size_t write(uint8_t); 75 | // Write size bytes from buffer into the packet 76 | virtual size_t write(const uint8_t* buffer, size_t size); 77 | 78 | using Print::write; 79 | 80 | // Start processing the next available incoming packet 81 | // Returns the size of the packet in bytes, or 0 if no packets are available 82 | virtual int parsePacket(); 83 | // Number of bytes remaining in the current packet 84 | virtual int available(); 85 | // Read a single byte from the current packet 86 | virtual int read(); 87 | // Read up to len bytes from the current packet and place them into buffer 88 | // Returns the number of bytes read, or 0 if none are available 89 | virtual int read(unsigned char* buffer, size_t len); 90 | // Read up to len characters from the current packet and place them into buffer 91 | // Returns the number of characters read, or 0 if none are available 92 | virtual int read(char* buffer, size_t len) 93 | { 94 | return read((unsigned char*)buffer, len); 95 | }; 96 | // Return the next byte from the current packet without moving on to the next byte 97 | virtual int peek(); 98 | virtual void flush(); // Finish reading the current packet 99 | 100 | // Return the IP address of the host who sent the current incoming packet 101 | virtual IPAddress remoteIP(); 102 | // // Return the port of the host who sent the current incoming packet 103 | virtual uint16_t remotePort(); 104 | 105 | friend class MbedSocketClass; 106 | }; 107 | 108 | } 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.6.1/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.7.2/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.8.0/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/3.0.0/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/3.0.1/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/3.1.1/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/3.3.0/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | portenta_h7_rules () { 4 | echo "" 5 | echo "# Portenta H7 bootloader mode UDEV rules" 6 | echo "" 7 | cat < /etc/udev/rules.d/49-portenta_h7.rules 18 | 19 | # reload udev rules 20 | echo "Reload rules..." 21 | udevadm trigger 22 | udevadm control --reload-rules 23 | -------------------------------------------------------------------------------- /Packages_Patches/hardware/teensy/avr/cores/teensy/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Stream_h 21 | #define Stream_h 22 | 23 | #include 24 | #include "Print.h" 25 | 26 | class Stream : public Print 27 | { 28 | public: 29 | constexpr Stream() : _timeout(1000), read_error(0) {} 30 | virtual int available() = 0; 31 | virtual int read() = 0; 32 | virtual int peek() = 0; 33 | 34 | void setTimeout(unsigned long timeout); 35 | bool find(const char *target); 36 | 37 | bool find(const uint8_t *target) 38 | { 39 | return find ((const char *)target); 40 | } 41 | 42 | bool find(const String &target) 43 | { 44 | return find(target.c_str()); 45 | } 46 | 47 | bool find(const char *target, size_t length); 48 | 49 | bool find(const uint8_t *target, size_t length) 50 | { 51 | return find ((const char *)target, length); 52 | } 53 | 54 | bool find(const String &target, size_t length) 55 | { 56 | return find(target.c_str(), length); 57 | } 58 | 59 | bool findUntil(const char *target, const char *terminator); 60 | 61 | bool findUntil(const uint8_t *target, const char *terminator) 62 | { 63 | return findUntil((const char *)target, terminator); 64 | } 65 | 66 | bool findUntil(const String &target, const char *terminator) 67 | { 68 | return findUntil(target.c_str(), terminator); 69 | } 70 | 71 | bool findUntil(const char *target, const String &terminator) 72 | { 73 | return findUntil(target, terminator.c_str()); 74 | } 75 | 76 | bool findUntil(const String &target, const String &terminator) 77 | { 78 | return findUntil(target.c_str(), terminator.c_str()); 79 | } 80 | 81 | bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); 82 | 83 | bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) 84 | { 85 | return findUntil((const char *)target, targetLen, terminate, termLen); 86 | } 87 | 88 | bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); 89 | bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); 90 | bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); 91 | 92 | long parseInt(); 93 | long parseInt(char skipChar); 94 | 95 | float parseFloat(); 96 | float parseFloat(char skipChar); 97 | 98 | size_t readBytes(char *buffer, size_t length); 99 | 100 | size_t readBytes(uint8_t *buffer, size_t length) 101 | { 102 | return readBytes((char *)buffer, length); 103 | } 104 | 105 | size_t readBytesUntil(char terminator, char *buffer, size_t length); 106 | 107 | size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) 108 | { 109 | return readBytesUntil(terminator, (char *)buffer, length); 110 | } 111 | 112 | //////////////////////////////////////////////////////////// 113 | String readString(size_t max = 512); 114 | String readStringUntil(char terminator, size_t max = 512); 115 | 116 | // KH, to not use String 117 | char* readCharsUntil(char terminator, size_t max = 512); 118 | //////////////////////////////////////////////////////////// 119 | 120 | int getReadError() 121 | { 122 | return read_error; 123 | } 124 | 125 | void clearReadError() 126 | { 127 | setReadError(0); 128 | } 129 | 130 | protected: 131 | void setReadError(int err = 1) 132 | { 133 | read_error = err; 134 | } 135 | 136 | unsigned long _timeout; 137 | 138 | // KH 139 | int timedRead(); 140 | int timedPeek(); 141 | int peekNextDigit(); 142 | ////// 143 | 144 | private: 145 | char read_error; 146 | }; 147 | 148 | #endif 149 | 150 | -------------------------------------------------------------------------------- /Packages_Patches/hardware/teensy/avr/cores/teensy3/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Stream_h 21 | #define Stream_h 22 | 23 | #include 24 | #include "Print.h" 25 | 26 | class Stream : public Print 27 | { 28 | public: 29 | constexpr Stream() : _timeout(1000), read_error(0) {} 30 | virtual int available() = 0; 31 | virtual int read() = 0; 32 | virtual int peek() = 0; 33 | 34 | void setTimeout(unsigned long timeout); 35 | bool find(const char *target); 36 | 37 | bool find(const uint8_t *target) 38 | { 39 | return find ((const char *)target); 40 | } 41 | 42 | bool find(const String &target) 43 | { 44 | return find(target.c_str()); 45 | } 46 | 47 | bool find(const char *target, size_t length); 48 | 49 | bool find(const uint8_t *target, size_t length) 50 | { 51 | return find ((const char *)target, length); 52 | } 53 | 54 | bool find(const String &target, size_t length) 55 | { 56 | return find(target.c_str(), length); 57 | } 58 | 59 | bool findUntil(const char *target, const char *terminator); 60 | 61 | bool findUntil(const uint8_t *target, const char *terminator) 62 | { 63 | return findUntil((const char *)target, terminator); 64 | } 65 | 66 | bool findUntil(const String &target, const char *terminator) 67 | { 68 | return findUntil(target.c_str(), terminator); 69 | } 70 | 71 | bool findUntil(const char *target, const String &terminator) 72 | { 73 | return findUntil(target, terminator.c_str()); 74 | } 75 | 76 | bool findUntil(const String &target, const String &terminator) 77 | { 78 | return findUntil(target.c_str(), terminator.c_str()); 79 | } 80 | 81 | bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); 82 | 83 | bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) 84 | { 85 | return findUntil((const char *)target, targetLen, terminate, termLen); 86 | } 87 | 88 | bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); 89 | bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); 90 | bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); 91 | 92 | long parseInt(); 93 | long parseInt(char skipChar); 94 | 95 | float parseFloat(); 96 | float parseFloat(char skipChar); 97 | 98 | size_t readBytes(char *buffer, size_t length); 99 | 100 | size_t readBytes(uint8_t *buffer, size_t length) 101 | { 102 | return readBytes((char *)buffer, length); 103 | } 104 | 105 | size_t readBytesUntil(char terminator, char *buffer, size_t length); 106 | 107 | size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) 108 | { 109 | return readBytesUntil(terminator, (char *)buffer, length); 110 | } 111 | 112 | //////////////////////////////////////////////////////////// 113 | String readString(size_t max = 512); 114 | String readStringUntil(char terminator, size_t max = 512); 115 | 116 | // KH, to not use String 117 | char* readCharsUntil(char terminator, size_t max = 512); 118 | //////////////////////////////////////////////////////////// 119 | 120 | int getReadError() 121 | { 122 | return read_error; 123 | } 124 | 125 | void clearReadError() 126 | { 127 | setReadError(0); 128 | } 129 | 130 | protected: 131 | void setReadError(int err = 1) 132 | { 133 | read_error = err; 134 | } 135 | 136 | unsigned long _timeout; 137 | 138 | // KH 139 | int timedRead(); 140 | int timedPeek(); 141 | int peekNextDigit(); 142 | ////// 143 | 144 | private: 145 | char read_error; 146 | }; 147 | 148 | #endif 149 | 150 | -------------------------------------------------------------------------------- /Packages_Patches/hardware/teensy/avr/cores/teensy4/Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Stream_h 21 | #define Stream_h 22 | 23 | #include 24 | #include "Print.h" 25 | 26 | class Stream : public Print 27 | { 28 | public: 29 | constexpr Stream() : _timeout(1000), read_error(0) {} 30 | virtual int available() = 0; 31 | virtual int read() = 0; 32 | virtual int peek() = 0; 33 | 34 | void setTimeout(unsigned long timeout); 35 | bool find(const char *target); 36 | 37 | bool find(const uint8_t *target) 38 | { 39 | return find ((const char *)target); 40 | } 41 | 42 | bool find(const String &target) 43 | { 44 | return find(target.c_str()); 45 | } 46 | 47 | bool find(const char *target, size_t length); 48 | 49 | bool find(const uint8_t *target, size_t length) 50 | { 51 | return find ((const char *)target, length); 52 | } 53 | 54 | bool find(const String &target, size_t length) 55 | { 56 | return find(target.c_str(), length); 57 | } 58 | 59 | bool findUntil(const char *target, const char *terminator); 60 | 61 | bool findUntil(const uint8_t *target, const char *terminator) 62 | { 63 | return findUntil((const char *)target, terminator); 64 | } 65 | 66 | bool findUntil(const String &target, const char *terminator) 67 | { 68 | return findUntil(target.c_str(), terminator); 69 | } 70 | 71 | bool findUntil(const char *target, const String &terminator) 72 | { 73 | return findUntil(target, terminator.c_str()); 74 | } 75 | 76 | bool findUntil(const String &target, const String &terminator) 77 | { 78 | return findUntil(target.c_str(), terminator.c_str()); 79 | } 80 | 81 | bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); 82 | 83 | bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) 84 | { 85 | return findUntil((const char *)target, targetLen, terminate, termLen); 86 | } 87 | 88 | bool findUntil(const String &target, size_t targetLen, const char *terminate, size_t termLen); 89 | bool findUntil(const char *target, size_t targetLen, const String &terminate, size_t termLen); 90 | bool findUntil(const String &target, size_t targetLen, const String &terminate, size_t termLen); 91 | 92 | long parseInt(); 93 | long parseInt(char skipChar); 94 | 95 | float parseFloat(); 96 | float parseFloat(char skipChar); 97 | 98 | size_t readBytes(char *buffer, size_t length); 99 | 100 | size_t readBytes(uint8_t *buffer, size_t length) 101 | { 102 | return readBytes((char *)buffer, length); 103 | } 104 | 105 | size_t readBytesUntil(char terminator, char *buffer, size_t length); 106 | 107 | size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) 108 | { 109 | return readBytesUntil(terminator, (char *)buffer, length); 110 | } 111 | 112 | //////////////////////////////////////////////////////////// 113 | String readString(size_t max = 512); 114 | String readStringUntil(char terminator, size_t max = 512); 115 | 116 | // KH, to not use String 117 | char* readCharsUntil(char terminator, size_t max = 512); 118 | //////////////////////////////////////////////////////////// 119 | 120 | int getReadError() 121 | { 122 | return read_error; 123 | } 124 | 125 | void clearReadError() 126 | { 127 | setReadError(0); 128 | } 129 | 130 | protected: 131 | void setReadError(int err = 1) 132 | { 133 | read_error = err; 134 | } 135 | 136 | unsigned long _timeout; 137 | 138 | // KH 139 | int timedRead(); 140 | int timedPeek(); 141 | int peekNextDigit(); 142 | ////// 143 | 144 | private: 145 | char read_error; 146 | }; 147 | 148 | #endif 149 | 150 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # AsyncMQTT_Generic Library (Async MQTT Client for ESP8266, ESP32, etc.) 2 | 3 | [![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncMQTT_Generic.svg?)](https://www.ardu-badge.com/AsyncMQTT_Generic) 4 | [![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncMQTT_Generic.svg)](https://github.com/khoih-prog/AsyncMQTT_Generic/releases) 5 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) 6 | [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncMQTT_Generic.svg)](http://github.com/khoih-prog/AsyncMQTT_Generic/issues) 7 | 8 | 9 | Donate to my libraries using BuyMeACoffee 10 | 11 | 12 | 13 | --- 14 | --- 15 | 16 | ## Table of Contents 17 | 18 | * [Changelog](#changelog) 19 | * [Releases v1.8.1](#releases-v181) 20 | * [Releases v1.8.0](#releases-v180) 21 | * [Releases v1.7.0](#releases-v170) 22 | * [Releases v1.6.1](#releases-v161) 23 | * [Releases v1.6.0](#releases-v160) 24 | * [Releases v1.5.0](#releases-v150) 25 | * [Releases v1.4.0](#releases-v140) 26 | * [Releases v1.3.0](#releases-v130) 27 | * [Releases v1.2.1](#releases-v121) 28 | * [Releases v1.2.0](#releases-v120) 29 | * [Releases v1.1.0](#releases-v110) 30 | * [Releases v1.0.1](#releases-v101) 31 | * [Initial Releases v1.0.0](#Initial-Releases-v100) 32 | 33 | --- 34 | --- 35 | 36 | ## Changelog 37 | 38 | ### Releases v1.8.1 39 | 40 | 1. Add `AsyncWebServer_MQTT` for ESP32 example to demo how to use `AsyncWebServer` and `AsyncMQTT_Generic` together 41 | 2. Add `AsyncWebServer_MQTT_RP2040W` example to demo how to use `AsyncWebServer_RP2040W` and `AsyncMQTT_Generic` together 42 | 3. Improve `README.md` so that links can be used in other sites, such as `PIO` 43 | 44 | ### Releases v1.8.0 45 | 46 | 1. Add support to ESP32 boards using `LwIP W5500 Ethernet` 47 | 2. Add support to ESP32 boards using `LwIP ENC28J60 Ethernet` 48 | 3. Use `allman astyle` and add `utils`. Restyle the library 49 | 50 | ### Releases v1.7.0 51 | 52 | 1. Fix ESP32 compile error. Check [Missing default case in switch causes #10](https://github.com/khoih-prog/AsyncMQTT_Generic/issues/10) 53 | 2. Change to new [KH_Forked ESPAsyncTCP library](https://github.com/khoih-prog/ESPAsyncTCP) for ESP8266 boards, using WiFi or LwIP Ethernet, with [ESP8266 core v3.0.2+](https://github.com/esp8266/Arduino/releases/tag/3.0.2) or WiFi with [ESP8266 core v2.7.4](https://github.com/esp8266/Arduino/releases/tag/2.7.4) to avoid compile errors 54 | 55 | ### Releases v1.6.1 56 | 57 | 1. Workaround for RP2040W `WiFi.status()` bug using `ping()` to local gateway for example [FullyFeatured_RP2040W](examples/RP2040W/FullyFeatured_RP2040W) 58 | 2. Use WiFi macAddress for RP2040W `_clientId` 59 | 60 | ### Releases v1.6.0 61 | 62 | 1. Add support to **RASPBERRY_PI_PICO_W with CYW43439 WiFi**, using [**arduino-pico core v2.4.0+**](https://github.com/earlephilhower/arduino-pico) 63 | 2. Add example [FullyFeatured_RP2040W](examples/RP2040W/FullyFeatured_RP2040W) 64 | 3. Update `Packages' Patches` 65 | 66 | ### Releases v1.5.0 67 | 68 | 1. Add support to ESP8266 W5x00 using [lwIP_w5100](https://github.com/esp8266/Arduino/tree/master/libraries/lwIP_w5100) or [lwIP_w5500](https://github.com/esp8266/Arduino/tree/master/libraries/lwIP_w5500) library 69 | 2. Add support to ESP8266 ENC28J60 using [lwIP_enc28j60](https://github.com/esp8266/Arduino/tree/master/libraries/lwIP_enc28j60) library 70 | 3. Add example [FullyFeatured_ESP8266_Ethernet](examples/ESP8266/FullyFeatured_ESP8266_Ethernet) 71 | 4. Update `Packages' Patches` 72 | 73 | ### Releases v1.4.0 74 | 75 | 1. Add support to **Teensy 4.1 using QNEthernet Library** 76 | 2. Add example for `QNEthernet` 77 | 78 | ### Releases v1.3.0 79 | 80 | 1. Add support to **Portenta_H7**, using either `Murata WiFi` or `Vision-shield Ethernet` 81 | 2. Add examples for `Portenta_H7_Ethernet` and `Portenta_H7_WiFi` 82 | 83 | ### Releases v1.2.1 84 | 85 | 1. Add support to many **STM32F4 and STM32F7 (without TLS/SSL)** using `LAN8720` Ethernet, such as F407xx, NUCLEO_F429ZI, DISCO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG, etc. 86 | 2. Add examples for `STM32_LAN8720` 87 | 88 | ### Releases v1.2.0 89 | 90 | 1. Add support to **STM32F/L/H/G/WB/MP1 (without TLS/SSL)** using `built-in LAN8742A` Ethernet, such as Nucleo-144, DISCOVERY, etc. 91 | 2. Add examples for `STM32` 92 | 93 | ### Releases v1.1.0 94 | 95 | 1. Add support to **WT32_ETH01 (SSL and non-SSL)** 96 | 2. Add examples for `WT32_ETH01` 97 | 98 | 99 | ### Releases v1.0.1 100 | 101 | 1. Fix Library Manager warnings 102 | 2. Suppress all compiler warnings 103 | 3. Optimize library code by using `reference-passing` instead of `value-passing` 104 | 105 | ### Initial Releases v1.0.0 106 | 107 | 1. Initial porting and coding to support **ESP32 (SSL and non-SSL) and ESP8266 (non-SSL)** 108 | -------------------------------------------------------------------------------- /docs/1.-Getting-started.md: -------------------------------------------------------------------------------- 1 | # Getting started 2 | 3 | To use AsyncMqttClient, you need: 4 | 5 | * An ESP8266 or ESP32 6 | * The Arduino IDE or equivalent IDE for ESP8266/32 7 | * Basic knowledge of the Arduino environment (use the IDE, upload a sketch, import libraries, ...) 8 | 9 | ## Installing AsyncMqttClient 10 | 11 | There are two ways to install AsyncMqttClient. 12 | 13 | ### 1a. For the Arduino IDE 14 | 15 | 1. Download the [corresponding release](https://github.com/marvinroger/async-mqtt-client/releases/latest) 16 | 2. Load the `.zip` with **Sketch → Include Library → Add .ZIP Library** 17 | 18 | AsyncMqttClient has 1 dependency: 19 | * For ESP8266: [ESPAsyncTCP](https://github.com/me-no-dev/ESPAsyncTCP). Download the [.zip](https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip) and install it with the same method as above. 20 | * Fors ESP32: [AsyncTCP](https://github.com/me-no-dev/AsyncTCP). Download the [.zip](https://github.com/me-no-dev/AsyncTCP/archive/master.zip) and install it with the same method as above. 21 | 22 | ## Fully-featured sketch 23 | 24 | See [examples/FullyFeatured-ESP8266.ino](../examples/FullyFeatured-ESP8266/FullyFeatured-ESP8266.ino) 25 | 26 | **Very important: As a rule of thumb, never use blocking functions in the callbacks (don't use `delay()` or `yield()`).** Otherwise, you may very probably experience unexpected behaviors. 27 | 28 | You can go to the [API reference](2.-API-reference.md). 29 | -------------------------------------------------------------------------------- /docs/2.-API-reference.md: -------------------------------------------------------------------------------- 1 | # API reference 2 | 3 | #### AsyncMqttClient() 4 | 5 | Instantiate a new AsyncMqttClient object. 6 | 7 | ### Configuration 8 | 9 | #### AsyncMqttClient& setKeepAlive(uint16_t `keepAlive`) 10 | 11 | Set the keep alive. Defaults to 15 seconds. 12 | 13 | * **`keepAlive`**: Keep alive in seconds 14 | 15 | #### AsyncMqttClient& setClientId(const char\* `clientId`) 16 | 17 | Set the client ID. Defaults to `esp8266`. 18 | 19 | * **`clientId`**: Client ID 20 | 21 | #### AsyncMqttClient& setCleanSession(bool `cleanSession`) 22 | 23 | Whether or not to set the CleanSession flag. Defaults to `true`. 24 | 25 | * **`cleanSession`**: clean session wanted or not 26 | 27 | #### AsyncMqttClient& setMaxTopicLength(uint16_t `maxTopicLength`) 28 | 29 | Set the maximum allowed topic length to receive. If an MQTT packet is received 30 | with a topic longer than this maximum, the packet will be ignored. Defaults to `128`. 31 | 32 | * **`maxTopicLength`**: Maximum allowed topic length to receive 33 | 34 | #### AsyncMqttClient& setCredentials(const char\* `username`, const char\* `password` = nullptr) 35 | 36 | Set the username/password. Defaults to non-auth. 37 | 38 | * **`username`**: Username 39 | * **`password`**: Password 40 | 41 | #### AsyncMqttClient& setWill(const char\* `topic`, uint8_t `qos`, bool `retain`, const char\* `payload` = nullptr, size_t `length` = 0) 42 | 43 | Set the Last Will Testament. Defaults to none. 44 | 45 | * **`topic`**: Topic of the LWT 46 | * **`qos`**: QoS of the LWT 47 | * **`retain`**: Retain flag of the LWT 48 | * **`payload`**: Payload of the LWT. If unset, the payload will be empty 49 | * **`length`**: Payload length. If unset or set to 0, the payload will be considered as a string and its size will be calculated using `strlen(payload)` 50 | 51 | #### AsyncMqttClient& setServer(IPAddress `ip`, uint16_t `port`) 52 | 53 | Set the server. 54 | 55 | * **`ip`**: IP of the server 56 | * **`port`**: Port of the server 57 | 58 | #### AsyncMqttClient& setServer(const char\* `host`, uint16_t `port`) 59 | 60 | Set the server. 61 | 62 | * **`host`**: Host of the server 63 | * **`port`**: Port of the server 64 | 65 | #### AsyncMqttClient& setSecure(bool `secure`) 66 | 67 | Whether or not to use SSL. Defaults to `false`. 68 | 69 | * **`secure`**: SSL wanted or not. 70 | 71 | #### AsyncMqttClient& addServerFingerprint(const uint8_t\* `fingerprint`) 72 | 73 | Adds an acceptable server fingerprint (SHA1). This may be called multiple times to permit any one of the specified fingerprints. By default, if no fingerprint is added, any fingerprint is accepted. 74 | 75 | * **`fingerprint`**: Fingerprint to add 76 | 77 | ### Events handlers 78 | 79 | #### AsyncMqttClient& onConnect(AsyncMqttClientInternals::OnConnectUserCallback `callback`) 80 | 81 | Add a connect event handler. 82 | 83 | * **`callback`**: Function to call 84 | 85 | #### AsyncMqttClient& onDisconnect(AsyncMqttClientInternals::OnDisconnectUserCallback `callback`) 86 | 87 | Add a disconnect event handler. 88 | 89 | * **`callback`**: Function to call 90 | 91 | #### AsyncMqttClient& onSubscribe(AsyncMqttClientInternals::OnSubscribeUserCallback `callback`) 92 | 93 | Add a subscribe acknowledged event handler. 94 | 95 | * **`callback`**: Function to call 96 | 97 | #### AsyncMqttClient& onUnsubscribe(AsyncMqttClientInternals::OnUnsubscribeUserCallback `callback`) 98 | 99 | Add an unsubscribe acknowledged event handler. 100 | 101 | * **`callback`**: Function to call 102 | 103 | #### AsyncMqttClient& onMessage(AsyncMqttClientInternals::OnMessageUserCallback `callback`) 104 | 105 | Add a publish received event handler. 106 | 107 | * **`callback`**: Function to call 108 | 109 | #### AsyncMqttClient& onPublish(AsyncMqttClientInternals::OnPublishUserCallback `callback`) 110 | 111 | Add a publish acknowledged event handler. 112 | 113 | * **`callback`**: Function to call 114 | 115 | ### Operation functions 116 | 117 | #### bool connected() 118 | 119 | Return if the client is currently connected to the broker or not. 120 | 121 | #### void connect() 122 | 123 | Connect to the server. 124 | 125 | #### void disconnect(bool `force` = false) 126 | 127 | Disconnect from the server. 128 | 129 | * **`force`**: Whether to force the disconnection. Defaults to `false` (clean disconnection). 130 | 131 | #### uint16_t subscribe(const char\* `topic`, uint8_t `qos`) 132 | 133 | Subscribe to the given topic at the given QoS. 134 | 135 | Return the packet ID or 0 if failed. 136 | 137 | * **`topic`**: Topic 138 | * **`qos`**: QoS 139 | 140 | #### uint16_t unsubscribe(const char\* `topic`) 141 | 142 | Unsubscribe from the given topic. 143 | 144 | Return the packet ID or 0 if failed. 145 | 146 | * **`topic`**: Topic 147 | 148 | #### uint16_t publish(const char\* `topic`, uint8_t `qos`, bool `retain`, const char\* `payload` = nullptr, size_t `length` = 0, bool dup = false, uint16_t message_id = 0) 149 | 150 | Publish a packet. 151 | 152 | Return the packet ID (or 1 if QoS 0) or 0 if failed. 153 | 154 | * **`topic`**: Topic 155 | * **`qos`**: QoS 156 | * **`retain`**: Retain flag 157 | * **`payload`**: Payload. If unset, the payload will be empty 158 | * **`length`**: Payload length. If unset or set to 0, the payload will be considered as a string and its size will be calculated using `strlen(payload)` 159 | * **`dup`**: ~~Duplicate flag. If set or set to 1, the payload will be flagged as a duplicate~~ Setting is not used anymore 160 | * **`message_id`**: ~~The message ID. If unset or set to 0, the message ID will be automtaically assigned. Use this with the DUP flag to identify which message is being duplicated~~ Setting is not used anymore 161 | 162 | #### bool clearQueue() 163 | 164 | When disconnected, clears all queued messages 165 | 166 | Returns true on success, false on failure (client is no disconnected) 167 | -------------------------------------------------------------------------------- /docs/3.-Memory-management.md: -------------------------------------------------------------------------------- 1 | # Memory management 2 | 3 | AsyncMqttClient buffers outgoing messages in a queue. On sending data is copied to a raw TCP buffer. Received data is passed directly to the API. 4 | 5 | ## Outgoing messages 6 | 7 | You can send data as long as memory permits. A minimum amount of free memory is set at 4096 bytes. You can lower (or raise) this value by setting `MQTT_MIN_FREE_MEMORY` to your desired value. 8 | If the free memory was sufficient to send your packet, the `publish` method will return a packet ID indicating the packet was queued. Otherwise, a `0` will be returned, and it's your responsibility to resend the packet with `publish`. 9 | 10 | ## Incoming messages 11 | 12 | No incoming data is buffered by this library. Messages received by the TCP library is passed directly to the API. The max receive size is about 1460 bytes per call to your onMessage callback but the amount of data you can receive is unlimited. If you receive, say, a 300kB payload (such as an OTA payload), then your `onMessage` callback will be called about 200 times, with the according len, index and total parameters. Keep in mind the library will call your `onMessage` callbacks with the same topic buffer, so if you change the buffer on one call, the buffer will remain changed on subsequent calls. 13 | -------------------------------------------------------------------------------- /docs/4.-Limitations-and-known-issues.md: -------------------------------------------------------------------------------- 1 | # Limitations and known issues 2 | 3 | * The library is spec compliant with one limitation. In case of power loss the following is not honored: 4 | 5 | > Must be kept in memory: 6 | * All messages in a QoS 1 or 2 flow, which are not confirmed by the broker 7 | * All received QoS 2 messages, which are not yet confirmed to the broker 8 | 9 | This means retransmission is not honored in case of a power failure. This behaviour is like explained in point 4.1.1 of the MQTT specification v3.1.1 10 | 11 | * You cannot send payload larger that what can fit on RAM. 12 | 13 | ## SSL limitations 14 | 15 | * SSL requires the build flag -DASYNC_TCP_SSL_ENABLED=1 16 | * SSL only supports fingerprints for server validation. 17 | * If you do not specify one or more acceptable server fingerprints, the SSL connection will be vulnerable to man-in-the-middle attacks. 18 | * Some server certificate signature algorithms do not work. SHA1, SHA224, SHA256, and MD5 are working. SHA384, and SHA512 will cause a crash. 19 | * TLS1.2 is not supported. 20 | -------------------------------------------------------------------------------- /docs/5.-Troubleshooting.md: -------------------------------------------------------------------------------- 1 | # Troubleshooting 2 | 3 | * The payload of incoming messages contains **raw data**. You cannot just print out the data without formatting. This is because Arduino's `print` functions expect a C-string as input and a MQTT payload is not. A simple solution is to print each character of the payload: 4 | 5 | ```cpp 6 | for (size_t i = 0; i < len; ++i) { 7 | Serial.print(payload[i]); 8 | } 9 | ``` 10 | 11 | Further reading: https://en.wikipedia.org/wiki/C_string_handling 12 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | AsyncMqttClient documentation 2 | ============================= 3 | 4 | See [index.md](index.md) to view it locally, or http://marvinroger.viewdocs.io/async-mqtt-client/ to view it online. 5 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | Welcome to the AsyncMqttClient for ESP8266 docs. 2 | 3 | **

This documentation is only valid for the AsyncMqttClient version in this repo/directory

** 4 | 5 | ----- 6 | 7 | #### 1. [Getting started](1.-Getting-started.md) 8 | #### 2. [API reference](2.-API-reference.md) 9 | #### 3. [Memory management](3.-Memory-management.md) 10 | #### 4. [Limitations and known issues](4.-Limitations-and-known-issues.md) 11 | #### 5. [Troubleshooting](5.-Troubleshooting.md) 12 | -------------------------------------------------------------------------------- /examples/ESP32/FullyFeaturedSSL_ESP32/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | #define _ASYNC_MQTT_LOGLEVEL_ 1 16 | 17 | #define WIFI_SSID "yourSSID" 18 | #define WIFI_PASSWORD "yourpass" 19 | 20 | #endif //defines_h 21 | -------------------------------------------------------------------------------- /examples/ESP32/FullyFeatured_ESP32/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | #define _ASYNC_MQTT_LOGLEVEL_ 1 16 | 17 | #define WIFI_SSID "yourSSID" 18 | #define WIFI_PASSWORD "yourpass" 19 | 20 | #endif //defines_h 21 | -------------------------------------------------------------------------------- /examples/ESP32_ENC/FullyFeaturedSSL_ESP32_ENC/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | #define _ASYNC_MQTT_LOGLEVEL_ 1 18 | 19 | ///////////////////////////////////////////// 20 | 21 | // Optional values to override default settings 22 | //#define SPI_HOST 1 23 | //#define SPI_CLOCK_MHZ 8 24 | 25 | // Must connect INT to GPIOxx or not working 26 | //#define INT_GPIO 4 27 | 28 | //#define MISO_GPIO 19 29 | //#define MOSI_GPIO 23 30 | //#define SCK_GPIO 18 31 | //#define CS_GPIO 5 32 | 33 | ///////////////////////////////////////////// 34 | 35 | #include // https://github.com/khoih-prog/WebServer_ESP32_ENC 36 | 37 | ///////////////////////////////////////////// 38 | 39 | // Enter a MAC address and IP address for your controller below. 40 | #define NUMBER_OF_MAC 20 41 | 42 | byte mac[][NUMBER_OF_MAC] = 43 | { 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, 56 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, 57 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, 58 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, 59 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, 60 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, 61 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, 62 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, 63 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, 64 | }; 65 | 66 | // Select the IP address according to your local network 67 | IPAddress myIP(192, 168, 2, 232); 68 | IPAddress myGW(192, 168, 2, 1); 69 | IPAddress mySN(255, 255, 255, 0); 70 | 71 | // Google DNS Server IP 72 | IPAddress myDNS(8, 8, 8, 8); 73 | 74 | #endif //defines_h 75 | -------------------------------------------------------------------------------- /examples/ESP32_ENC/FullyFeatured_ESP32_ENC/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | #define _ASYNC_MQTT_LOGLEVEL_ 1 18 | 19 | ///////////////////////////////////////////// 20 | 21 | // Optional values to override default settings 22 | //#define SPI_HOST 1 23 | //#define SPI_CLOCK_MHZ 8 24 | 25 | // Must connect INT to GPIOxx or not working 26 | //#define INT_GPIO 4 27 | 28 | //#define MISO_GPIO 19 29 | //#define MOSI_GPIO 23 30 | //#define SCK_GPIO 18 31 | //#define CS_GPIO 5 32 | 33 | ///////////////////////////////////////////// 34 | 35 | #include // https://github.com/khoih-prog/WebServer_ESP32_ENC 36 | 37 | ///////////////////////////////////////////// 38 | 39 | // Enter a MAC address and IP address for your controller below. 40 | #define NUMBER_OF_MAC 20 41 | 42 | byte mac[][NUMBER_OF_MAC] = 43 | { 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, 56 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, 57 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, 58 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, 59 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, 60 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, 61 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, 62 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, 63 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, 64 | }; 65 | 66 | // Select the IP address according to your local network 67 | IPAddress myIP(192, 168, 2, 232); 68 | IPAddress myGW(192, 168, 2, 1); 69 | IPAddress mySN(255, 255, 255, 0); 70 | 71 | // Google DNS Server IP 72 | IPAddress myDNS(8, 8, 8, 8); 73 | 74 | #endif //defines_h 75 | -------------------------------------------------------------------------------- /examples/ESP32_W5500/FullyFeaturedSSL_ESP32_W5500/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | #define _ASYNC_MQTT_LOGLEVEL_ 1 18 | 19 | ////////////////////////////////////////////////////////// 20 | 21 | // Optional values to override default settings 22 | // Don't change unless you know what you're doing 23 | //#define ETH_SPI_HOST SPI3_HOST 24 | //#define SPI_CLOCK_MHZ 25 25 | 26 | // Must connect INT to GPIOxx or not working 27 | //#define INT_GPIO 4 28 | 29 | //#define MISO_GPIO 19 30 | //#define MOSI_GPIO 23 31 | //#define SCK_GPIO 18 32 | //#define CS_GPIO 5 33 | 34 | ////////////////////////////////////////////////////////// 35 | 36 | #include 37 | 38 | ///////////////////////////////////////////// 39 | 40 | // Enter a MAC address and IP address for your controller below. 41 | #define NUMBER_OF_MAC 20 42 | 43 | byte mac[][NUMBER_OF_MAC] = 44 | { 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, 56 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, 57 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, 58 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, 59 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, 60 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, 61 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, 62 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, 63 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, 64 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, 65 | }; 66 | 67 | // Select the IP address according to your local network 68 | IPAddress myIP(192, 168, 2, 232); 69 | IPAddress myGW(192, 168, 2, 1); 70 | IPAddress mySN(255, 255, 255, 0); 71 | 72 | // Google DNS Server IP 73 | IPAddress myDNS(8, 8, 8, 8); 74 | 75 | #endif //defines_h 76 | -------------------------------------------------------------------------------- /examples/ESP32_W5500/FullyFeatured_ESP32_W5500/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | #define _ASYNC_MQTT_LOGLEVEL_ 1 18 | 19 | ////////////////////////////////////////////////////////// 20 | 21 | // Optional values to override default settings 22 | // Don't change unless you know what you're doing 23 | //#define ETH_SPI_HOST SPI3_HOST 24 | //#define SPI_CLOCK_MHZ 25 25 | 26 | // Must connect INT to GPIOxx or not working 27 | //#define INT_GPIO 4 28 | 29 | //#define MISO_GPIO 19 30 | //#define MOSI_GPIO 23 31 | //#define SCK_GPIO 18 32 | //#define CS_GPIO 5 33 | 34 | ////////////////////////////////////////////////////////// 35 | 36 | #include 37 | 38 | ///////////////////////////////////////////// 39 | 40 | // Enter a MAC address and IP address for your controller below. 41 | #define NUMBER_OF_MAC 20 42 | 43 | byte mac[][NUMBER_OF_MAC] = 44 | { 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, 56 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, 57 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, 58 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, 59 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, 60 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, 61 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, 62 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, 63 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, 64 | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, 65 | }; 66 | 67 | // Select the IP address according to your local network 68 | IPAddress myIP(192, 168, 2, 232); 69 | IPAddress myGW(192, 168, 2, 1); 70 | IPAddress mySN(255, 255, 255, 0); 71 | 72 | // Google DNS Server IP 73 | IPAddress myDNS(8, 8, 8, 8); 74 | 75 | #endif //defines_h 76 | -------------------------------------------------------------------------------- /examples/ESP8266/FullyFeatured_ESP8266/FullyFeatured_ESP8266.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | FullyFeature_ESP8266.ino 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | // Use ESP8266 core v2.7.4- for SSL as new cores don't use axtls anymore 14 | // Use core v3.0.2+ for LwIP Ethernet W5500lwIP, W5100lwIP and ENC28J60lwIP libraries 15 | // Must use KH forked ESPAsyncTCP library or compile error 16 | 17 | #include "defines.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | //#define MQTT_HOST IPAddress(192, 168, 2, 110) 24 | #define MQTT_HOST "broker.emqx.io" // Broker address 25 | #define MQTT_PORT 1883 26 | 27 | const char *PubTopic = "async-mqtt/ESP8266_Pub"; // Topic to publish 28 | 29 | AsyncMqttClient mqttClient; 30 | Ticker mqttReconnectTimer; 31 | 32 | WiFiEventHandler wifiConnectHandler; 33 | WiFiEventHandler wifiDisconnectHandler; 34 | 35 | Ticker wifiReconnectTimer; 36 | 37 | void connectToWifi() 38 | { 39 | Serial.println("Connecting to Wi-Fi..."); 40 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 41 | } 42 | 43 | void connectToMqtt() 44 | { 45 | Serial.println("Connecting to MQTT..."); 46 | mqttClient.connect(); 47 | } 48 | 49 | void onWifiConnect(const WiFiEventStationModeGotIP& event) 50 | { 51 | (void) event; 52 | 53 | Serial.print("Connected to Wi-Fi. IP address: "); 54 | Serial.println(WiFi.localIP()); 55 | connectToMqtt(); 56 | } 57 | 58 | void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) 59 | { 60 | (void) event; 61 | 62 | Serial.println("Disconnected from Wi-Fi."); 63 | mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi 64 | wifiReconnectTimer.once(2, connectToWifi); 65 | } 66 | 67 | void printSeparationLine() 68 | { 69 | Serial.println("************************************************"); 70 | } 71 | 72 | void onMqttConnect(bool sessionPresent) 73 | { 74 | Serial.print("Connected to MQTT broker: "); 75 | Serial.print(MQTT_HOST); 76 | Serial.print(", port: "); 77 | Serial.println(MQTT_PORT); 78 | Serial.print("PubTopic: "); 79 | Serial.println(PubTopic); 80 | 81 | printSeparationLine(); 82 | Serial.print("Session present: "); 83 | Serial.println(sessionPresent); 84 | 85 | uint16_t packetIdSub = mqttClient.subscribe(PubTopic, 2); 86 | Serial.print("Subscribing at QoS 2, packetId: "); 87 | Serial.println(packetIdSub); 88 | 89 | mqttClient.publish(PubTopic, 0, true, "ESP8266 Test1"); 90 | Serial.println("Publishing at QoS 0"); 91 | 92 | uint16_t packetIdPub1 = mqttClient.publish(PubTopic, 1, true, "ESP8266 Test2"); 93 | Serial.print("Publishing at QoS 1, packetId: "); 94 | Serial.println(packetIdPub1); 95 | 96 | uint16_t packetIdPub2 = mqttClient.publish(PubTopic, 2, true, "ESP8266 Test3"); 97 | Serial.print("Publishing at QoS 2, packetId: "); 98 | Serial.println(packetIdPub2); 99 | 100 | printSeparationLine(); 101 | } 102 | 103 | void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) 104 | { 105 | (void) reason; 106 | 107 | Serial.println("Disconnected from MQTT."); 108 | 109 | if (WiFi.isConnected()) 110 | { 111 | mqttReconnectTimer.once(2, connectToMqtt); 112 | } 113 | } 114 | 115 | void onMqttSubscribe(const uint16_t& packetId, const uint8_t& qos) 116 | { 117 | Serial.println("Subscribe acknowledged."); 118 | Serial.print(" packetId: "); 119 | Serial.println(packetId); 120 | Serial.print(" qos: "); 121 | Serial.println(qos); 122 | } 123 | 124 | void onMqttUnsubscribe(const uint16_t& packetId) 125 | { 126 | Serial.println("Unsubscribe acknowledged."); 127 | Serial.print(" packetId: "); 128 | Serial.println(packetId); 129 | } 130 | 131 | void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties, 132 | const size_t& len, const size_t& index, const size_t& total) 133 | { 134 | (void) payload; 135 | 136 | Serial.println("Publish received."); 137 | Serial.print(" topic: "); 138 | Serial.println(topic); 139 | Serial.print(" qos: "); 140 | Serial.println(properties.qos); 141 | Serial.print(" dup: "); 142 | Serial.println(properties.dup); 143 | Serial.print(" retain: "); 144 | Serial.println(properties.retain); 145 | Serial.print(" len: "); 146 | Serial.println(len); 147 | Serial.print(" index: "); 148 | Serial.println(index); 149 | Serial.print(" total: "); 150 | Serial.println(total); 151 | } 152 | 153 | void onMqttPublish(const uint16_t& packetId) 154 | { 155 | Serial.println("Publish acknowledged."); 156 | Serial.print(" packetId: "); 157 | Serial.println(packetId); 158 | } 159 | 160 | void setup() 161 | { 162 | Serial.begin(115200); 163 | 164 | while (!Serial && millis() < 5000); 165 | 166 | delay(300); 167 | 168 | Serial.print("\nStarting FullyFeature_ESP8266 on "); 169 | Serial.println(ARDUINO_BOARD); 170 | Serial.println(ASYNC_MQTT_GENERIC_VERSION); 171 | 172 | wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect); 173 | wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect); 174 | 175 | mqttClient.onConnect(onMqttConnect); 176 | mqttClient.onDisconnect(onMqttDisconnect); 177 | mqttClient.onSubscribe(onMqttSubscribe); 178 | mqttClient.onUnsubscribe(onMqttUnsubscribe); 179 | mqttClient.onMessage(onMqttMessage); 180 | mqttClient.onPublish(onMqttPublish); 181 | mqttClient.setServer(MQTT_HOST, MQTT_PORT); 182 | 183 | connectToWifi(); 184 | } 185 | 186 | void loop() 187 | { 188 | } 189 | -------------------------------------------------------------------------------- /examples/ESP8266/FullyFeatured_ESP8266/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | // Use ESP8266 core v2.7.4- for SSL as new cores don't use axtls anymore 13 | // Use core v3.0.2+ for LwIP Ethernet W5500lwIP, W5100lwIP and ENC28J60lwIP libraries 14 | // Must use KH forked ESPAsyncTCP library or compile error 15 | 16 | #ifndef defines_h 17 | #define defines_h 18 | 19 | #define _ASYNC_MQTT_LOGLEVEL_ 1 20 | 21 | #define WIFI_SSID "yourSSID" 22 | #define WIFI_PASSWORD "yourpass" 23 | 24 | #endif //defines_h 25 | -------------------------------------------------------------------------------- /examples/ESP8266/FullyFeatured_ESP8266_Ethernet/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | // Use ESP8266 core v2.7.4- for SSL as new cores don't use axtls anymore 13 | // Use core v3.0.2+ for LwIP Ethernet W5500lwIP, W5100lwIP and ENC28J60lwIP libraries 14 | // Must use KH forked ESPAsyncTCP library or compile error 15 | 16 | #ifndef defines_h 17 | #define defines_h 18 | 19 | #define _ASYNC_MQTT_LOGLEVEL_ 1 20 | 21 | ////////////////////////////////////////////////////////// 22 | 23 | #define USING_W5500 true 24 | #define USING_W5100 false 25 | #define USING_ENC28J60 false 26 | 27 | #include 28 | 29 | #define CSPIN 16 // 5 30 | 31 | #if USING_W5500 32 | #include "W5500lwIP.h" 33 | #define SHIELD_TYPE "ESP8266_W5500 Ethernet" 34 | 35 | Wiznet5500lwIP eth(CSPIN); 36 | 37 | #elif USING_W5100 38 | #include 39 | #define SHIELD_TYPE "ESP8266_W5100 Ethernet" 40 | 41 | Wiznet5100lwIP eth(CSPIN); 42 | 43 | #elif USING_ENC28J60 44 | #include 45 | #define SHIELD_TYPE "ESP8266_ENC28J60 Ethernet" 46 | 47 | ENC28J60lwIP eth(CSPIN); 48 | #else 49 | // default if none selected 50 | #include "W5500lwIP.h" 51 | 52 | Wiznet5500lwIP eth(CSPIN); 53 | #endif 54 | 55 | #include // WiFiClient (-> TCPClient) 56 | 57 | using TCPClient = WiFiClient; 58 | 59 | ////////////////////////////////////////////////////////// 60 | 61 | #define USING_DHCP true 62 | 63 | #if !USING_DHCP 64 | IPAddress localIP(192, 168, 2, 222); 65 | IPAddress gateway(192, 168, 2, 1); 66 | IPAddress netMask(255, 255, 255, 0); 67 | #endif 68 | 69 | #endif //defines_h 70 | -------------------------------------------------------------------------------- /examples/PortentaH7_Ethernet/FullyFeatured_PortentaH7_Ethernet/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 16 | #error For Portenta_H7 core M7 only 17 | #endif 18 | 19 | // Use from 0 to 4. Higher number, more debugging messages and memory usage. 20 | #define ASYNC_MQTT_DEBUG_PORT Serial 21 | #define _ASYNC_MQTT_LOGLEVEL_ 1 22 | 23 | #define USE_ETHERNET_PORTENTA_H7 true 24 | #define USE_WIFI_PORTENTA_H7 false 25 | 26 | #include 27 | 28 | #if (_ASYNC_MQTT_LOGLEVEL_ > 3) 29 | #warning Using Portenta_Ethernet lib for Portenta_H7 30 | #endif 31 | 32 | // Enter a MAC address and IP address for your controller below. 33 | #define NUMBER_OF_MAC 20 34 | 35 | byte mac[][NUMBER_OF_MAC] = 36 | { 37 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 38 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 39 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 40 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 41 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 42 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 43 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 56 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 57 | }; 58 | 59 | #endif //defines_h 60 | -------------------------------------------------------------------------------- /examples/PortentaH7_WiFi/FullyFeatured_PortentaH7_WiFi/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 16 | #error For Portenta_H7 only 17 | #endif 18 | 19 | // Use from 0 to 4. Higher number, more debugging messages and memory usage. 20 | #define ASYNC_MQTT_DEBUG_PORT Serial 21 | #define _ASYNC_MQTT_LOGLEVEL_ 1 22 | 23 | #define USE_ETHERNET_PORTENTA_H7 false 24 | #define USE_WIFI_PORTENTA_H7 true 25 | 26 | #include 27 | 28 | #if (_ASYNC_MQTT_LOGLEVEL_ > 3) 29 | #warning Using WiFi for Portenta_H7 30 | #endif 31 | 32 | #define WIFI_SSID "yourSSID" // your network SSID (name) 33 | #define WIFI_PASSWORD "yourpass" // your network password (use for WPA, or use as key for WEP), length must be 8+ 34 | 35 | int status = WL_IDLE_STATUS; 36 | 37 | #endif //defines_h 38 | -------------------------------------------------------------------------------- /examples/QNEthernet/FullyFeatured_QNEthernet/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | #if !( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) ) 16 | #error Only Teensy 4.1 supported 17 | #endif 18 | 19 | // Debug Level from 0 to 4 20 | #define _TEENSY41_ASYNC_TCP_LOGLEVEL_ 1 21 | #define _ASYNC_MQTT_LOGLEVEL_ 4 22 | 23 | #define SHIELD_TYPE "Teensy4.1 QNEthernet" 24 | 25 | #include "QNEthernet.h" // https://github.com/ssilverman/QNEthernet 26 | using namespace qindesign::network; 27 | 28 | #if (_ASYNC_MQTT_LOGLEVEL_ > 3) 29 | #warning Using QNEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error 30 | #endif 31 | #define USING_DHCP true 32 | //#define USING_DHCP false 33 | 34 | #if !USING_DHCP 35 | // Set the static IP address to use if the DHCP fails to assign 36 | IPAddress myIP(192, 168, 2, 222); 37 | IPAddress myNetmask(255, 255, 255, 0); 38 | IPAddress myGW(192, 168, 2, 1); 39 | //IPAddress mydnsServer(192, 168, 2, 1); 40 | IPAddress mydnsServer(8, 8, 8, 8); 41 | #endif 42 | 43 | #endif //defines_h 44 | -------------------------------------------------------------------------------- /examples/RP2040W/FullyFeatured_RP2040W/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, Teensy41_QNEthernet, STM32F7, etc. 5 | with current AsyncTCP support 6 | 7 | Based on and modified from : 8 | 9 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 10 | 11 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 12 | ***************************************************************************************************************************************/ 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) ) 18 | #error For RASPBERRY_PI_PICO_W only 19 | #endif 20 | 21 | // Debug Level from 0 to 4 22 | #define _ASYNCTCP_RP2040W_LOGLEVEL_ 1 23 | #define _ASYNC_MQTT_LOGLEVEL_ 1 24 | 25 | #if (_ASYNC_MQTT_LOGLEVEL_ > 3) 26 | #warning Using RASPBERRY_PI_PICO_W with CYC43439 WiFi 27 | #endif 28 | 29 | #define WIFI_SSID "yourSSID" // your network SSID (name) 30 | #define WIFI_PASSWORD "yourpass" // your network password (use for WPA, or use as key for WEP), length must be 8+ 31 | 32 | #endif //defines_h 33 | -------------------------------------------------------------------------------- /examples/STM32/FullyFeatured_STM32/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | #if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ 16 | defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ 17 | defined(STM32WB) || defined(STM32MP1) ) 18 | #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting. 19 | #endif 20 | 21 | #define _ASYNC_MQTT_LOGLEVEL_ 1 22 | 23 | #if defined(STM32F0) 24 | #warning STM32F0 board selected 25 | #define BOARD_TYPE "STM32F0" 26 | #elif defined(STM32F1) 27 | #warning STM32F1 board selected 28 | #define BOARD_TYPE "STM32F1" 29 | #elif defined(STM32F2) 30 | #warning STM32F2 board selected 31 | #define BOARD_TYPE "STM32F2" 32 | #elif defined(STM32F3) 33 | #warning STM32F3 board selected 34 | #define BOARD_TYPE "STM32F3" 35 | #elif defined(STM32F4) 36 | #warning STM32F4 board selected 37 | #define BOARD_TYPE "STM32F4" 38 | #elif defined(STM32F7) 39 | #warning STM32F7 board selected 40 | #define BOARD_TYPE "STM32F7" 41 | #elif defined(STM32L0) 42 | #warning STM32L0 board selected 43 | #define BOARD_TYPE "STM32L0" 44 | #elif defined(STM32L1) 45 | #warning STM32L1 board selected 46 | #define BOARD_TYPE "STM32L1" 47 | #elif defined(STM32L4) 48 | #warning STM32L4 board selected 49 | #define BOARD_TYPE "STM32L4" 50 | #elif defined(STM32H7) 51 | #warning STM32H7 board selected 52 | #define BOARD_TYPE "STM32H7" 53 | #elif defined(STM32G0) 54 | #warning STM32G0 board selected 55 | #define BOARD_TYPE "STM32G0" 56 | #elif defined(STM32G4) 57 | #warning STM32G4 board selected 58 | #define BOARD_TYPE "STM32G4" 59 | #elif defined(STM32WB) 60 | #warning STM32WB board selected 61 | #define BOARD_TYPE "STM32WB" 62 | #elif defined(STM32MP1) 63 | #warning STM32MP1 board selected 64 | #define BOARD_TYPE "STM32MP1" 65 | #else 66 | #warning STM32 unknown board selected 67 | #define BOARD_TYPE "STM32 Unknown" 68 | #endif 69 | 70 | #ifndef BOARD_NAME 71 | #define BOARD_NAME BOARD_TYPE 72 | #endif 73 | 74 | #define SHIELD_TYPE "LAN8742A built-in Ethernet" 75 | 76 | #include 77 | #include 78 | //#include 79 | 80 | // Enter a MAC address and IP address for your controller below. 81 | #define NUMBER_OF_MAC 20 82 | 83 | byte mac[][NUMBER_OF_MAC] = 84 | { 85 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 86 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 87 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 88 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 89 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 90 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 91 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 92 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 93 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 94 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 95 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 96 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 97 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 98 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 99 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 100 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 101 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 102 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 103 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 104 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 105 | }; 106 | 107 | // Select the IP address according to your local network 108 | IPAddress ip(192, 168, 2, 232); 109 | 110 | #endif //defines_h 111 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/FullyFeatured_STM32_LAN8720/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | defines.h 5 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 6 | 7 | Based on and modified from : 8 | 9 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 10 | 11 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 12 | *****************************************************************************************************************************/ 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_BLACK_F407VE) || defined(ARDUINO_BLACK_F407VG) || defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) || \ 18 | defined(ARDUINO_BLUE_F407VE_Mini) || defined(ARDUINO_DIYMORE_F407VGT) || defined(ARDUINO_FK407M1) || defined(ARDUINO_NUCLEO_F429ZI) || \ 19 | defined(ARDUINO_DISCO_F746NG) || defined(ARDUINO_NUCLEO_F746ZG) || defined(ARDUINO_NUCLEO_F756ZG) || defined(ARDUINO_NUCLEO_H743ZI) ) 20 | //#error This code is designed to run on some STM32F407XX NUCLEO-F429ZI, STM32F746 and STM32F756 platform! Please check your Tools->Board setting. 21 | #warning Must use with STM32 core v2.2.0- or error 22 | #endif 23 | 24 | // Use from 0 to 4. Higher number, more debugging messages and memory usage. 25 | #define _ASYNC_MQTT_LOGLEVEL_ 1 26 | 27 | #define USING_LAN8720 true 28 | 29 | #if defined(STM32F0) 30 | #warning STM32F0 board selected 31 | #define BOARD_TYPE "STM32F0" 32 | #elif defined(STM32F1) 33 | #warning STM32F1 board selected 34 | #define BOARD_TYPE "STM32F1" 35 | #elif defined(STM32F2) 36 | #warning STM32F2 board selected 37 | #define BOARD_TYPE "STM32F2" 38 | #elif defined(STM32F3) 39 | #warning STM32F3 board selected 40 | #define BOARD_TYPE "STM32F3" 41 | #elif defined(STM32F4) 42 | #warning STM32F4 board selected 43 | #define BOARD_TYPE "STM32F4" 44 | #elif defined(STM32F7) 45 | #warning STM32F7 board selected 46 | #define BOARD_TYPE "STM32F7" 47 | #elif defined(STM32L0) 48 | #warning STM32L0 board selected 49 | #define BOARD_TYPE "STM32L0" 50 | #elif defined(STM32L1) 51 | #warning STM32L1 board selected 52 | #define BOARD_TYPE "STM32L1" 53 | #elif defined(STM32L4) 54 | #warning STM32L4 board selected 55 | #define BOARD_TYPE "STM32L4" 56 | #elif defined(STM32H7) 57 | #warning STM32H7 board selected 58 | #define BOARD_TYPE "STM32H7" 59 | #elif defined(STM32G0) 60 | #warning STM32G0 board selected 61 | #define BOARD_TYPE "STM32G0" 62 | #elif defined(STM32G4) 63 | #warning STM32G4 board selected 64 | #define BOARD_TYPE "STM32G4" 65 | #elif defined(STM32WB) 66 | #warning STM32WB board selected 67 | #define BOARD_TYPE "STM32WB" 68 | #elif defined(STM32MP1) 69 | #warning STM32MP1 board selected 70 | #define BOARD_TYPE "STM32MP1" 71 | #else 72 | #warning STM32 unknown board selected 73 | #define BOARD_TYPE "STM32 Unknown" 74 | #endif 75 | 76 | #ifndef BOARD_NAME 77 | #define BOARD_NAME BOARD_TYPE 78 | #endif 79 | 80 | #define SHIELD_TYPE "LAN8720 Ethernet" 81 | 82 | #include 83 | #include 84 | //#include 85 | 86 | // Enter a MAC address and IP address for your controller below. 87 | #define NUMBER_OF_MAC 20 88 | 89 | byte mac[][NUMBER_OF_MAC] = 90 | { 91 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 92 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 93 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 94 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 95 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 96 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 97 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 98 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 99 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 100 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 101 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 102 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 103 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 104 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 105 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 106 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 107 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 108 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 109 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 110 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 111 | }; 112 | 113 | // Select the IP address according to your local network 114 | IPAddress ip(192, 168, 2, 232); 115 | 116 | #endif //defines_h 117 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/FullyFeatured_STM32_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STMicroelectronics/hardware/stm32/2.x.y/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // .arduino15/packages/STM32/hardware/stm32/1.x.y/system/STM32F4xx/stm32f4xx_hal_conf_default.h 4 | // as described in README.md 5 | 6 | #define HAL_ETH_MODULE_ENABLED 7 | 8 | #define LAN8742A_PHY_ADDRESS 0x01U 9 | -------------------------------------------------------------------------------- /examples/WT32_ETH01/FullyFeaturedSSL_WT32_ETH01/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | #define _ASYNC_MQTT_LOGLEVEL_ 4 18 | 19 | #include 20 | 21 | // Select the IP address according to your local network 22 | IPAddress myIP(192, 168, 2, 232); 23 | IPAddress myGW(192, 168, 2, 1); 24 | IPAddress mySN(255, 255, 255, 0); 25 | 26 | // Google DNS Server IP 27 | IPAddress myDNS(8, 8, 8, 8); 28 | 29 | #endif //defines_h 30 | -------------------------------------------------------------------------------- /examples/WT32_ETH01/FullyFeatured_WT32_ETH01/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 4 | 5 | Based on and modified from : 6 | 7 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 8 | 9 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 10 | ***************************************************************************************************************************************/ 11 | 12 | #ifndef defines_h 13 | #define defines_h 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | #define _ASYNC_MQTT_LOGLEVEL_ 1 18 | 19 | #include 20 | 21 | // Select the IP address according to your local network 22 | IPAddress myIP(192, 168, 2, 232); 23 | IPAddress myGW(192, 168, 2, 1); 24 | IPAddress mySN(255, 255, 255, 0); 25 | 26 | // Google DNS Server IP 27 | IPAddress myDNS(8, 8, 8, 8); 28 | 29 | #endif //defines_h 30 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Datatypes (KEYWORD1) 3 | ####################################### 4 | 5 | AsyncMqttClient KEYWORD1 6 | AsyncMqttClientDisconnectReason KEYWORD1 7 | AsyncMqttClientMessageProperties KEYWORD1 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | setKeepAlive KEYWORD2 14 | setClientId KEYWORD2 15 | setCleanSession KEYWORD2 16 | setMaxTopicLength KEYWORD2 17 | setCredentials KEYWORD2 18 | setWill KEYWORD2 19 | setServer KEYWORD2 20 | setSecure KEYWORD2 21 | addServerFingerprint KEYWORD2 22 | 23 | onConnect KEYWORD2 24 | onDisconnect KEYWORD2 25 | onSubscribe KEYWORD2 26 | onUnsubscribe KEYWORD2 27 | onMessage KEYWORD2 28 | onPublish KEYWORD2 29 | 30 | connected KEYWORD2 31 | connect KEYWORD2 32 | disconnect KEYWORD2 33 | subscribe KEYWORD2 34 | unsubscribe KEYWORD2 35 | publish KEYWORD2 36 | clearQueue KEYWORD2 37 | 38 | ####################################### 39 | # Constants (LITERAL1) 40 | ####################################### 41 | 42 | ASYNC_MQTT_GENERIC_SHORT_VERSION 43 | 44 | ASYNC_MQTT_GENERIC_VERSION LITERAL1 45 | ASYNC_MQTT_GENERIC_VERSION_MAJOR LITERAL1 46 | ASYNC_MQTT_GENERIC_VERSION_MINOR LITERAL1 47 | ASYNC_MQTT_GENERIC_VERSION_PATCH LITERAL1 48 | ASYNC_MQTT_GENERIC_VERSION_INT LITERAL1 49 | 50 | _ASYNC_MQTT_LOGLEVEL_ LITERAL1 51 | DBG_PORT_AMQTT LITERAL1 52 | 53 | ASYNC_TCP_SSL_ENABLED LITERAL1 54 | 55 | TCP_DISCONNECTED LITERAL1 56 | 57 | MQTT_UNACCEPTABLE_PROTOCOL_VERSION LITERAL1 58 | MQTT_IDENTIFIER_REJECTED LITERAL1 59 | MQTT_SERVER_UNAVAILABLE LITERAL1 60 | MQTT_MALFORMED_CREDENTIALS LITERAL1 61 | MQTT_NOT_AUTHORIZED LITERAL1 62 | 63 | USING_CORE_ESP32_CORE_V200_PLUS LITERAL1 64 | 65 | MQTT_MIN_FREE_MEMORY LITERAL1 66 | 67 | SHA1_SIZE LITERAL1 68 | 69 | ASYNC_MQTT_USING_STM32 LITERAL1 70 | ASYNC_MQTT_USING_PORTENTA_H7 LITERAL1 71 | ASYNC_MQTT_USING_TEENSY41_QNETHERNET LITERAL1 72 | 73 | USE_ETHERNET_PORTENTA_H7 LITERAL1 74 | USE_WIFI_PORTENTA_H7 LITERAL1 75 | 76 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "AsyncMQTT_Generic", 3 | "version": "1.8.1", 4 | "keywords": "communication, iot, automation, async, async-tcp, async-tcp-ssl, async-mqtt, mqtt, async-mqtt-client, esp8266, esp32, stm32, portenta-h7, wt32-eth01, tls, teensy-41, qn-ethernet, lwip, lan8742a, lan8720", 5 | "description": "Arduino Arduino Library for ESP8266, ESP32, Portenta_H7, STM32 and RP2040W asynchronous MQTT client implementation. This library, ported to support ESP32, WT32_ETH01 (ESP32 + LAN8720), (ESP32 + LwIP W5500), (ESP32 + LwIP ENC28J60), ESP8266, Portenta_H7 (Ethernet or WiFi) and STM32 (LAN8742A or LAN8720 Ethernet), Teensy 4.1 using QNEthernet, RASPBERRY_PI_PICO_W with CYW43439 WiFi. Currently supporting TLS/SSL for ESP32 only", 6 | "authors": 7 | [ 8 | { 9 | "name": "Marvin ROGER", 10 | "url": "https://www.marvinroger.fr" 11 | }, 12 | { 13 | "name": "Khoi Hoang", 14 | "url": "https://github.com/khoih-prog", 15 | "email": "khoih.prog@gmail.com", 16 | "maintainer": true 17 | } 18 | ], 19 | "repository": 20 | { 21 | "type": "git", 22 | "url": "https://github.com/khoih-prog/AsyncMQTT_Generic.git" 23 | }, 24 | "dependencies": 25 | [ 26 | { 27 | "owner": "me-no-dev", 28 | "name": "AsyncTCP", 29 | "version": ">=1.1.1", 30 | "platforms": ["espressif32"] 31 | }, 32 | { 33 | "owner": "khoih-prog", 34 | "name": "ESPAsyncTCP", 35 | "version": "https://github.com/khoih-prog/ESPAsyncTCP" 36 | }, 37 | { 38 | "owner": "khoih-prog", 39 | "name": "AsyncTCP_SSL", 40 | "version": ">=1.3.1", 41 | "platforms": "espressif32" 42 | }, 43 | { 44 | "owner": "khoih-prog", 45 | "name": "Portenta_H7_AsyncTCP", 46 | "version": ">=1.4.0", 47 | "platforms": "ststm32" 48 | }, 49 | { 50 | "owner": "khoih-prog", 51 | "name": "Teensy41_AsyncTCP", 52 | "version": ">=1.1.0", 53 | "platforms": ["teensy", "avr"] 54 | }, 55 | { 56 | "owner": "khoih-prog", 57 | "name": "AsyncTCP_RP2040W", 58 | "version": ">=1.1.0", 59 | "platforms": ["raspberrypi"] 60 | }, 61 | { 62 | "owner": "khoih-prog", 63 | "name": "AsyncWebServer_RP2040W", 64 | "version": ">=1.4.1", 65 | "platforms": ["raspberrypi"] 66 | }, 67 | { 68 | "owner": "khoih-prog", 69 | "name": "ESPAsync_WiFiManager", 70 | "version": ">=1.15.1", 71 | "platforms": ["espressif32", "espressif8266"] 72 | }, 73 | { 74 | "owner": "khoih-prog", 75 | "name": "WebServer_WT32_ETH01", 76 | "version": ">=1.5.1", 77 | "platforms": ["espressif32"] 78 | }, 79 | { 80 | "owner": "khoih-prog", 81 | "name": "WebServer_ESP32_W5500", 82 | "version": ">=1.5.3", 83 | "platforms": ["espressif32"] 84 | }, 85 | { 86 | "owner": "khoih-prog", 87 | "name": "WebServer_ESP32_ENC", 88 | "version": ">=1.5.3", 89 | "platforms": ["espressif32"] 90 | }, 91 | { 92 | "owner": "stm32duino", 93 | "name": "STM32duino LwIP", 94 | "version": "^2.1.2", 95 | "platforms": "ststm32" 96 | }, 97 | { 98 | "owner": "stm32duino", 99 | "name": "STM32Ethernet", 100 | "version": "^1.3.0", 101 | "platforms": "ststm32" 102 | }, 103 | { 104 | "name": "STM32AsyncTCP", 105 | "version": "https://github.com/khoih-prog/STM32AsyncTCP" 106 | } 107 | ], 108 | "license": "MIT", 109 | "frameworks": "*", 110 | "platforms": ["espressif8266", "espressif32", "ststm32", "raspberrypi", "teensy", "avr"], 111 | "examples": "examples/*/*/*.ino", 112 | "headers": ["AsyncMQTT_Generic.h"] 113 | } 114 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=AsyncMQTT_Generic 2 | version=1.8.1 3 | author=Marvin ROGER,Khoi Hoang 4 | maintainer=Khoi Hoang 5 | sentence=Arduino Library for ESP8266, ESP32, Portenta_H7, STM32 and RP2040W asynchronous MQTT client implementation 6 | paragraph=This library, ported to support ESP32, WT32_ETH01 (ESP32 + LAN8720), (ESP32 + LwIP W5500), (ESP32 + LwIP ENC28J60), ESP8266, Portenta_H7 (Ethernet or WiFi) and STM32 (LAN8742A or LAN8720 Ethernet), Teensy 4.1 using QNEthernet, RASPBERRY_PI_PICO_W with CYW43439 WiFi. Currently supporting TLS/SSL for ESP32 only 7 | category=Communication 8 | url=https://github.com/khoih-prog/AsyncMQTT_Generic 9 | architectures=* 10 | license=MIT 11 | depends=AsyncTCP_SSL, WebServer_WT32_ETH01, WebServer_ESP32_W5500, WebServer_ESP32_ENC, Portenta_H7_AsyncTCP, STM32duino LwIP, STM32duino STM32Ethernet, Teensy41_AsyncTCP, AsyncTCP_RP2040W 12 | includes=AsyncMQTT_Generic.h 13 | -------------------------------------------------------------------------------- /pics/STM32F407VET6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/AsyncMQTT_Generic/48a17e045fa3f8945524b3f5a87f96c075a505de/pics/STM32F407VET6.png -------------------------------------------------------------------------------- /scripts/CI/build_examples_pio.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #pip install -U platformio 4 | #platformio update 5 | platformio lib -g install AsyncTCP 6 | platformio lib -g install ESPAsyncTCP 7 | 8 | RED='\033[0;31m' 9 | GREEN='\033[0;32m' 10 | YELLOW='\033[0;33m' 11 | NC='\033[0m' 12 | 13 | lines=$(find ./examples/ -maxdepth 1 -mindepth 1 -type d) 14 | retval=0 15 | while read line; do 16 | if [[ "$line" != *ESP8266 && "$line" != *ESP32 ]] 17 | then 18 | echo -e "========================== BUILDING $line ==========================" 19 | echo -e "${YELLOW}SKIPPING${NC}" 20 | continue 21 | fi 22 | echo -e "========================== BUILDING $line ==========================" 23 | if [[ -e "$line/platformio.ini" ]] 24 | then 25 | # skipping 26 | #output=$(platformio ci --lib="." --project-conf="$line/platformio.ini" $line 2>&1) 27 | : 28 | else 29 | if [[ "$line" == *ESP8266 ]] 30 | then 31 | output=$(platformio ci --lib="." --project-conf="scripts/CI/platformio_esp8266.ini" $line 2>&1) 32 | else 33 | output=$(platformio ci --lib="." --project-conf="scripts/CI/platformio_esp32.ini" $line 2>&1) 34 | fi 35 | fi 36 | if [ $? -ne 0 ]; then 37 | echo "$output" 38 | echo -e "Building $line ${RED}FAILED${NC}" 39 | retval=1 40 | else 41 | echo -e "${GREEN}SUCCESS${NC}" 42 | fi 43 | done <<< "$lines" 44 | 45 | # cleanup 46 | platformio lib -g uninstall AsyncTCP 47 | platformio lib -g uninstall ESPAsyncTCP 48 | 49 | exit "$retval" 50 | -------------------------------------------------------------------------------- /scripts/CI/platformio_esp32.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32] 12 | platform = espressif32 13 | board = esp32dev 14 | framework = arduino 15 | build_flags = 16 | -Wall -------------------------------------------------------------------------------- /scripts/CI/platformio_esp8266.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp8266] 12 | platform = espressif8266 13 | board = esp01_1m 14 | framework = arduino 15 | build_flags = 16 | -Wall 17 | -------------------------------------------------------------------------------- /scripts/get-fingerprint/get-fingerprint.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import ssl 5 | import hashlib 6 | 7 | parser = argparse.ArgumentParser(description='Compute SSL/TLS fingerprints.') 8 | parser.add_argument('--host', required=True) 9 | parser.add_argument('--port', default=8883) 10 | 11 | args = parser.parse_args() 12 | print(args.host) 13 | 14 | cert_pem = ssl.get_server_certificate((args.host, args.port)) 15 | cert_der = ssl.PEM_cert_to_DER_cert(cert_pem) 16 | 17 | md5 = hashlib.md5(cert_der).hexdigest() 18 | sha1 = hashlib.sha1(cert_der).hexdigest() 19 | sha256 = hashlib.sha256(cert_der).hexdigest() 20 | print("MD5: " + md5) 21 | print("SHA1: " + sha1) 22 | print("SHA256: " + sha256) 23 | 24 | print("\nSHA1 as array initializer:") 25 | print("const uint8_t fingerprint[] = {0x" + ", 0x".join([sha1[i:i+2] for i in range(0, len(sha1), 2)]) + "};") 26 | 27 | print("\nSHA1 as function call:") 28 | print("mqttClient.addServerFingerprint((const uint8_t[]){0x" + ", 0x".join([sha1[i:i+2] for i in range(0, len(sha1), 2)]) + "});") 29 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Callbacks.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Callbacks.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef CALLBACKS_HPP 16 | #define CALLBACKS_HPP 17 | 18 | #include 19 | 20 | #include "DisconnectReasons.hpp" 21 | #include "MessageProperties.hpp" 22 | #include "Errors.hpp" 23 | 24 | namespace AsyncMqttClientInternals 25 | { 26 | // user callbacks 27 | typedef std::function OnConnectUserCallback; 28 | typedef std::function OnDisconnectUserCallback; 29 | typedef std::function OnSubscribeUserCallback; 30 | typedef std::function OnUnsubscribeUserCallback; 31 | typedef std::function OnMessageUserCallback; 32 | typedef std::function OnPublishUserCallback; 33 | typedef std::function OnErrorUserCallback; 34 | 35 | // internal callbacks 36 | typedef std::function OnConnAckInternalCallback; 37 | typedef std::function OnPingRespInternalCallback; 38 | typedef std::function OnSubAckInternalCallback; 39 | typedef std::function OnUnsubAckInternalCallback; 40 | typedef std::function OnMessageInternalCallback; 41 | typedef std::function OnPublishInternalCallback; 42 | typedef std::function OnPubRelInternalCallback; 43 | typedef std::function OnPubAckInternalCallback; 44 | typedef std::function OnPubRecInternalCallback; 45 | typedef std::function OnPubCompInternalCallback; 46 | } // namespace AsyncMqttClientInternals 47 | 48 | #endif // CALLBACKS_HPP 49 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/DisconnectReasons.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | DisconnectReasons.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef DISCONNECT_REASONS_HPP 16 | #define DISCONNECT_REASONS_HPP 17 | 18 | enum class AsyncMqttClientDisconnectReason : uint8_t 19 | { 20 | TCP_DISCONNECTED = 0, 21 | 22 | MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1, 23 | MQTT_IDENTIFIER_REJECTED = 2, 24 | MQTT_SERVER_UNAVAILABLE = 3, 25 | MQTT_MALFORMED_CREDENTIALS = 4, 26 | MQTT_NOT_AUTHORIZED = 5, 27 | 28 | ESP8266_NOT_ENOUGH_SPACE = 6, 29 | 30 | TLS_BAD_FINGERPRINT = 7 31 | }; 32 | 33 | #endif // DISCONNECT_REASONS_HPP 34 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Errors.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Errors.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef ERRORS_HPP 16 | #define ERRORS_HPP 17 | 18 | enum class AsyncMqttClientError : uint8_t 19 | { 20 | MAX_RETRIES = 0, 21 | OUT_OF_MEMORY = 1 22 | }; 23 | 24 | #endif // ERRORS_HPP 25 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Flags.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Flags.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef FLAGS_HPP 16 | #define FLAGS_HPP 17 | 18 | namespace AsyncMqttClientInternals 19 | { 20 | constexpr struct 21 | { 22 | const uint8_t RESERVED = 0; 23 | const uint8_t CONNECT = 1; 24 | const uint8_t CONNACK = 2; 25 | const uint8_t PUBLISH = 3; 26 | const uint8_t PUBACK = 4; 27 | const uint8_t PUBREC = 5; 28 | const uint8_t PUBREL = 6; 29 | const uint8_t PUBCOMP = 7; 30 | const uint8_t SUBSCRIBE = 8; 31 | const uint8_t SUBACK = 9; 32 | const uint8_t UNSUBSCRIBE = 10; 33 | const uint8_t UNSUBACK = 11; 34 | const uint8_t PINGREQ = 12; 35 | const uint8_t PINGRESP = 13; 36 | const uint8_t DISCONNECT = 14; 37 | const uint8_t RESERVED2 = 15; 38 | } PacketType; 39 | 40 | constexpr struct 41 | { 42 | const uint8_t CONNECT_RESERVED = 0x00; 43 | const uint8_t CONNACK_RESERVED = 0x00; 44 | const uint8_t PUBLISH_DUP = 0x08; 45 | const uint8_t PUBLISH_QOS0 = 0x00; 46 | const uint8_t PUBLISH_QOS1 = 0x02; 47 | const uint8_t PUBLISH_QOS2 = 0x04; 48 | const uint8_t PUBLISH_QOSRESERVED = 0x06; 49 | const uint8_t PUBLISH_RETAIN = 0x01; 50 | const uint8_t PUBACK_RESERVED = 0x00; 51 | const uint8_t PUBREC_RESERVED = 0x00; 52 | const uint8_t PUBREL_RESERVED = 0x02; 53 | const uint8_t PUBCOMP_RESERVED = 0x00; 54 | const uint8_t SUBSCRIBE_RESERVED = 0x02; 55 | const uint8_t SUBACK_RESERVED = 0x00; 56 | const uint8_t UNSUBSCRIBE_RESERVED = 0x02; 57 | const uint8_t UNSUBACK_RESERVED = 0x00; 58 | const uint8_t PINGREQ_RESERVED = 0x00; 59 | const uint8_t PINGRESP_RESERVED = 0x00; 60 | const uint8_t DISCONNECT_RESERVED = 0x00; 61 | const uint8_t RESERVED2_RESERVED = 0x00; 62 | } HeaderFlag; 63 | 64 | constexpr struct 65 | { 66 | const uint8_t USERNAME = 0x80; 67 | const uint8_t PASSWORD = 0x40; 68 | const uint8_t WILL_RETAIN = 0x20; 69 | const uint8_t WILL_QOS0 = 0x00; 70 | const uint8_t WILL_QOS1 = 0x08; 71 | const uint8_t WILL_QOS2 = 0x10; 72 | const uint8_t WILL = 0x04; 73 | const uint8_t CLEAN_SESSION = 0x02; 74 | const uint8_t RESERVED = 0x00; 75 | } ConnectFlag; 76 | } // namespace AsyncMqttClientInternals 77 | 78 | #endif // FLAGS_HPP 79 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Helpers.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Helpers.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef HELPERS_HPP 16 | #define HELPERS_HPP 17 | 18 | namespace AsyncMqttClientInternals 19 | { 20 | class Helpers 21 | { 22 | public: 23 | static uint32_t decodeRemainingLength(char* bytes) 24 | { 25 | uint32_t multiplier = 1; 26 | uint32_t value = 0; 27 | uint8_t currentByte = 0; 28 | uint8_t encodedByte; 29 | 30 | do 31 | { 32 | encodedByte = bytes[currentByte++]; 33 | value += (encodedByte & 127) * multiplier; 34 | multiplier *= 128; 35 | } while ((encodedByte & 128) != 0); 36 | 37 | return value; 38 | } 39 | 40 | static uint8_t encodeRemainingLength(uint32_t remainingLength, char* destination) 41 | { 42 | uint8_t currentByte = 0; 43 | uint8_t bytesNeeded = 0; 44 | 45 | do 46 | { 47 | uint8_t encodedByte = remainingLength % 128; 48 | remainingLength /= 128; 49 | 50 | if (remainingLength > 0) 51 | { 52 | encodedByte = encodedByte | 128; 53 | } 54 | 55 | destination[currentByte++] = encodedByte; 56 | bytesNeeded++; 57 | } while (remainingLength > 0); 58 | 59 | return bytesNeeded; 60 | } 61 | }; 62 | 63 | } // namespace AsyncMqttClientInternals 64 | 65 | #endif // HELPERS_HPP 66 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/MessageProperties.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MessageProperties.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef MESSAGE_PROPERTIES_HPP 16 | #define MESSAGE_PROPERTIES_HPP 17 | 18 | struct AsyncMqttClientMessageProperties 19 | { 20 | uint8_t qos; 21 | bool dup; 22 | bool retain; 23 | }; 24 | 25 | #endif // MESSAGE_PROPERTIES_HPP 26 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/ConnAckPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | ConnAckPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "ConnAckPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::ConnAckPacket; 16 | 17 | ConnAckPacket::ConnAckPacket(ParsingInformation* parsingInformation, OnConnAckInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _sessionPresent(false) 22 | , _connectReturnCode(0) 23 | { 24 | } 25 | 26 | ConnAckPacket::~ConnAckPacket() 27 | { 28 | } 29 | 30 | void ConnAckPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | 34 | char currentByte = data[(*currentBytePosition)++]; 35 | 36 | if (_bytePosition++ == 0) 37 | { 38 | _sessionPresent = (currentByte << 7) >> 7; 39 | } 40 | else 41 | { 42 | _connectReturnCode = currentByte; 43 | _parsingInformation->bufferState = BufferState::NONE; 44 | _callback(_sessionPresent, _connectReturnCode); 45 | } 46 | } 47 | 48 | void ConnAckPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 49 | { 50 | (void)data; 51 | (void)len; 52 | (void)currentBytePosition; 53 | } 54 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/ConnAckPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | ConnAckPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef CONN_ACK_PACKET_HPP 16 | #define CONN_ACK_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../ParsingInformation.hpp" 21 | #include "../Callbacks.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class ConnAckPacket : public Packet 26 | { 27 | public: 28 | explicit ConnAckPacket(ParsingInformation* parsingInformation, OnConnAckInternalCallback callback); 29 | ~ConnAckPacket(); 30 | 31 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 32 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 33 | 34 | private: 35 | ParsingInformation* _parsingInformation; 36 | OnConnAckInternalCallback _callback; 37 | 38 | uint8_t _bytePosition; 39 | bool _sessionPresent; 40 | uint8_t _connectReturnCode; 41 | }; 42 | } // namespace AsyncMqttClientInternals 43 | 44 | #endif // CONN_ACK_PACKET_HPP 45 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Connect.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Connect.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef CONNECT_HPP 16 | #define CONNECT_HPP 17 | 18 | #include 19 | #include // strlen 20 | 21 | #include "OutPacket.hpp" 22 | #include "../../Flags.hpp" 23 | #include "../../Helpers.hpp" 24 | 25 | namespace AsyncMqttClientInternals 26 | { 27 | class ConnectOutPacket : public OutPacket 28 | { 29 | public: 30 | ConnectOutPacket(bool cleanSession, 31 | const char* username, 32 | const char* password, 33 | const char* willTopic, 34 | bool willRetain, 35 | uint8_t willQos, 36 | const char* willPayload, 37 | uint16_t willPayloadLength, 38 | uint16_t keepAlive, 39 | const char* clientId); 40 | const uint8_t* data(size_t index = 0) const; 41 | size_t size() const; 42 | 43 | private: 44 | std::vector _data; 45 | }; 46 | } // namespace AsyncMqttClientInternals 47 | 48 | #endif // CONNECT_HPP 49 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Disconn.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Disconn.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "Disconn.hpp" 14 | 15 | using AsyncMqttClientInternals::DisconnOutPacket; 16 | 17 | DisconnOutPacket::DisconnOutPacket() 18 | { 19 | _data[0] = AsyncMqttClientInternals::PacketType.DISCONNECT; 20 | _data[0] = _data[0] << 4; 21 | _data[0] = _data[0] | AsyncMqttClientInternals::HeaderFlag.DISCONNECT_RESERVED; 22 | _data[1] = 0; 23 | } 24 | 25 | const uint8_t* DisconnOutPacket::data(size_t index) const 26 | { 27 | return &_data[index]; 28 | } 29 | 30 | size_t DisconnOutPacket::size() const 31 | { 32 | return 2; 33 | } 34 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Disconn.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Disconn.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef DISCONN_HPP 16 | #define DISCONN_HPP 17 | 18 | #include "OutPacket.hpp" 19 | #include "../../Flags.hpp" 20 | #include "../../Helpers.hpp" 21 | 22 | namespace AsyncMqttClientInternals 23 | { 24 | class DisconnOutPacket : public OutPacket 25 | { 26 | public: 27 | DisconnOutPacket(); 28 | const uint8_t* data(size_t index = 0) const; 29 | size_t size() const; 30 | 31 | private: 32 | uint8_t _data[2]; 33 | }; 34 | } // namespace AsyncMqttClientInternals 35 | 36 | #endif // DISCONN_HPP 37 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/OutPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | OutPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "OutPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::OutPacket; 16 | 17 | OutPacket::OutPacket() 18 | : next(nullptr) 19 | , timeout(0) 20 | , noTries(0) 21 | , _released(true) 22 | , _packetId(0) {} 23 | 24 | OutPacket::~OutPacket() {} 25 | 26 | bool OutPacket::released() const 27 | { 28 | return _released; 29 | } 30 | 31 | uint8_t OutPacket::packetType() const 32 | { 33 | return data(0)[0] >> 4; 34 | } 35 | 36 | uint16_t OutPacket::packetId() const 37 | { 38 | return _packetId; 39 | } 40 | 41 | uint8_t OutPacket::qos() const 42 | { 43 | if (packetType() == AsyncMqttClientInternals::PacketType.PUBLISH) 44 | { 45 | return (data()[1] & 0x06) >> 1; 46 | } 47 | 48 | return 0; 49 | } 50 | 51 | void OutPacket::release() 52 | { 53 | _released = true; 54 | } 55 | 56 | uint16_t OutPacket::_nextPacketId = 0; 57 | 58 | uint16_t OutPacket::_getNextPacketId() 59 | { 60 | if (++_nextPacketId == 0) 61 | { 62 | ++_nextPacketId; 63 | } 64 | 65 | return _nextPacketId; 66 | } 67 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/OutPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | OutPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef OUT_PACKET_HPP 16 | #define OUT_PACKET_HPP 17 | 18 | #include // uint*_t 19 | #include // size_t 20 | #include // std::min 21 | 22 | #include "../../Flags.hpp" 23 | 24 | namespace AsyncMqttClientInternals 25 | { 26 | class OutPacket 27 | { 28 | public: 29 | OutPacket(); 30 | virtual ~OutPacket(); 31 | virtual const uint8_t* data(size_t index = 0) const = 0; 32 | virtual size_t size() const = 0; 33 | bool released() const; 34 | uint8_t packetType() const; 35 | uint16_t packetId() const; 36 | uint8_t qos() const; 37 | void release(); 38 | 39 | public: 40 | OutPacket* next; 41 | uint32_t timeout; 42 | uint8_t noTries; 43 | 44 | protected: 45 | static uint16_t _getNextPacketId(); 46 | bool _released; 47 | uint16_t _packetId; 48 | 49 | private: 50 | static uint16_t _nextPacketId; 51 | }; 52 | } // namespace AsyncMqttClientInternals 53 | 54 | #endif // OUT_PACKET_HPP 55 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/PingReq.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PingReq.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PingReq.hpp" 14 | 15 | using AsyncMqttClientInternals::PingReqOutPacket; 16 | 17 | PingReqOutPacket::PingReqOutPacket() 18 | { 19 | _data[0] = AsyncMqttClientInternals::PacketType.PINGREQ; 20 | _data[0] = _data[0] << 4; 21 | _data[0] = _data[0] | AsyncMqttClientInternals::HeaderFlag.PINGREQ_RESERVED; 22 | _data[1] = 0; 23 | } 24 | 25 | const uint8_t* PingReqOutPacket::data(size_t index) const 26 | { 27 | return &_data[index];; 28 | } 29 | 30 | size_t PingReqOutPacket::size() const 31 | { 32 | return 2; 33 | } 34 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/PingReq.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PingReq.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PING_REQ_HPP 16 | #define PING_REQ_HPP 17 | 18 | #include "OutPacket.hpp" 19 | #include "../../Flags.hpp" 20 | #include "../../Helpers.hpp" 21 | 22 | namespace AsyncMqttClientInternals 23 | { 24 | class PingReqOutPacket : public OutPacket 25 | { 26 | public: 27 | PingReqOutPacket(); 28 | const uint8_t* data(size_t index = 0) const; 29 | size_t size() const; 30 | 31 | private: 32 | uint8_t _data[2]; 33 | }; 34 | } // namespace AsyncMqttClientInternals 35 | 36 | #endif // PING_REQ_HPP 37 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/PubAck.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubAck.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PubAck.hpp" 14 | 15 | using AsyncMqttClientInternals::PubAckOutPacket; 16 | 17 | PubAckOutPacket::PubAckOutPacket(PendingAck pendingAck) 18 | { 19 | _data[0] = pendingAck.packetType; 20 | _data[0] = _data[0] << 4; 21 | _data[0] = _data[0] | pendingAck.headerFlag; 22 | _data[1] = 2; 23 | _packetId = pendingAck.packetId; 24 | _data[2] = pendingAck.packetId >> 8; 25 | _data[3] = pendingAck.packetId & 0xFF; 26 | 27 | if (packetType() == AsyncMqttClientInternals::PacketType.PUBREL || 28 | packetType() == AsyncMqttClientInternals::PacketType.PUBREC) 29 | { 30 | _released = false; 31 | } 32 | } 33 | 34 | const uint8_t* PubAckOutPacket::data(size_t index) const 35 | { 36 | return &_data[index]; 37 | } 38 | 39 | size_t PubAckOutPacket::size() const 40 | { 41 | return 4; 42 | } 43 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/PubAck.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubAck.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PUB_ACK_HPP 16 | #define PUB_ACK_HPP 17 | 18 | #include "OutPacket.hpp" 19 | #include "../../Flags.hpp" 20 | #include "../../Helpers.hpp" 21 | #include "../../Storage.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class PubAckOutPacket : public OutPacket 26 | { 27 | public: 28 | explicit PubAckOutPacket(PendingAck pendingAck); 29 | const uint8_t* data(size_t index = 0) const; 30 | size_t size() const; 31 | 32 | private: 33 | uint8_t _data[4]; 34 | }; 35 | } // namespace AsyncMqttClientInternals 36 | 37 | #endif // PUB_ACK_HPP 38 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Publish.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Publish.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "Publish.hpp" 14 | 15 | using AsyncMqttClientInternals::PublishOutPacket; 16 | 17 | PublishOutPacket::PublishOutPacket(const char* topic, uint8_t qos, bool retain, const char* payload, size_t length) 18 | { 19 | char fixedHeader[5]; 20 | fixedHeader[0] = AsyncMqttClientInternals::PacketType.PUBLISH; 21 | fixedHeader[0] = fixedHeader[0] << 4; 22 | 23 | // if (dup) fixedHeader[0] |= AsyncMqttClientInternals::HeaderFlag.PUBLISH_DUP; 24 | if (retain) 25 | fixedHeader[0] |= AsyncMqttClientInternals::HeaderFlag.PUBLISH_RETAIN; 26 | 27 | switch (qos) 28 | { 29 | case 0: 30 | fixedHeader[0] |= AsyncMqttClientInternals::HeaderFlag.PUBLISH_QOS0; 31 | break; 32 | 33 | case 1: 34 | fixedHeader[0] |= AsyncMqttClientInternals::HeaderFlag.PUBLISH_QOS1; 35 | break; 36 | 37 | case 2: 38 | fixedHeader[0] |= AsyncMqttClientInternals::HeaderFlag.PUBLISH_QOS2; 39 | break; 40 | } 41 | 42 | uint16_t topicLength = strlen(topic); 43 | char topicLengthBytes[2]; 44 | topicLengthBytes[0] = topicLength >> 8; 45 | topicLengthBytes[1] = topicLength & 0xFF; 46 | 47 | uint32_t payloadLength = length; 48 | 49 | if (payload != nullptr && payloadLength == 0) 50 | payloadLength = strlen(payload); 51 | 52 | uint32_t remainingLength = 2 + topicLength + payloadLength; 53 | 54 | if (qos != 0) 55 | remainingLength += 2; 56 | 57 | uint8_t remainingLengthLength = AsyncMqttClientInternals::Helpers::encodeRemainingLength(remainingLength, 58 | fixedHeader + 1); 59 | 60 | size_t neededSpace = 0; 61 | neededSpace += 1 + remainingLengthLength; 62 | neededSpace += 2; 63 | neededSpace += topicLength; 64 | 65 | if (qos != 0) 66 | neededSpace += 2; 67 | 68 | if (payload != nullptr) 69 | neededSpace += payloadLength; 70 | 71 | _data.reserve(neededSpace); 72 | 73 | _packetId = (qos != 0) ? _getNextPacketId() : 1; 74 | char packetIdBytes[2]; 75 | packetIdBytes[0] = _packetId >> 8; 76 | packetIdBytes[1] = _packetId & 0xFF; 77 | 78 | _data.insert(_data.end(), fixedHeader, fixedHeader + 1 + remainingLengthLength); 79 | _data.insert(_data.end(), topicLengthBytes, topicLengthBytes + 2); 80 | _data.insert(_data.end(), topic, topic + topicLength); 81 | 82 | if (qos != 0) 83 | { 84 | _data.insert(_data.end(), packetIdBytes, packetIdBytes + 2); 85 | _released = false; 86 | } 87 | 88 | if (payload != nullptr) 89 | _data.insert(_data.end(), payload, payload + payloadLength); 90 | } 91 | 92 | const uint8_t* PublishOutPacket::data(size_t index) const 93 | { 94 | return &_data.data()[index]; 95 | } 96 | 97 | size_t PublishOutPacket::size() const 98 | { 99 | return _data.size(); 100 | } 101 | 102 | void PublishOutPacket::setDup() 103 | { 104 | _data[0] |= AsyncMqttClientInternals::HeaderFlag.PUBLISH_DUP; 105 | } 106 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Publish.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Publish.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PUBLISH_HPP 16 | #define PUBLISH_HPP 17 | 18 | #include // strlen 19 | #include 20 | 21 | #include "OutPacket.hpp" 22 | #include "../../Flags.hpp" 23 | #include "../../Helpers.hpp" 24 | #include "../../Storage.hpp" 25 | 26 | namespace AsyncMqttClientInternals 27 | { 28 | class PublishOutPacket : public OutPacket 29 | { 30 | public: 31 | PublishOutPacket(const char* topic, uint8_t qos, bool retain, const char* payload, size_t length); 32 | const uint8_t* data(size_t index = 0) const; 33 | size_t size() const; 34 | 35 | void setDup(); // you cannot unset dup 36 | 37 | private: 38 | std::vector _data; 39 | }; 40 | } // namespace AsyncMqttClientInternals 41 | 42 | #endif // PUBLISH_HPP 43 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Subscribe.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Subscribe.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "Subscribe.hpp" 14 | 15 | using AsyncMqttClientInternals::SubscribeOutPacket; 16 | 17 | SubscribeOutPacket::SubscribeOutPacket(const char* topic, uint8_t qos) 18 | { 19 | char fixedHeader[5]; 20 | fixedHeader[0] = AsyncMqttClientInternals::PacketType.SUBSCRIBE; 21 | fixedHeader[0] = fixedHeader[0] << 4; 22 | fixedHeader[0] = fixedHeader[0] | AsyncMqttClientInternals::HeaderFlag.SUBSCRIBE_RESERVED; 23 | 24 | uint16_t topicLength = strlen(topic); 25 | char topicLengthBytes[2]; 26 | topicLengthBytes[0] = topicLength >> 8; 27 | topicLengthBytes[1] = topicLength & 0xFF; 28 | 29 | char qosByte[1]; 30 | qosByte[0] = qos; 31 | 32 | uint8_t remainingLengthLength = AsyncMqttClientInternals::Helpers::encodeRemainingLength(2 + 2 + topicLength + 1, 33 | fixedHeader + 1); 34 | 35 | size_t neededSpace = 0; 36 | neededSpace += 1 + remainingLengthLength; 37 | neededSpace += 2; 38 | neededSpace += 2; 39 | neededSpace += topicLength; 40 | neededSpace += 1; 41 | 42 | _data.reserve(neededSpace); 43 | 44 | _packetId = _getNextPacketId(); 45 | char packetIdBytes[2]; 46 | packetIdBytes[0] = _packetId >> 8; 47 | packetIdBytes[1] = _packetId & 0xFF; 48 | 49 | _data.insert(_data.end(), fixedHeader, fixedHeader + 1 + remainingLengthLength); 50 | _data.insert(_data.end(), packetIdBytes, packetIdBytes + 2); 51 | _data.insert(_data.end(), topicLengthBytes, topicLengthBytes + 2); 52 | _data.insert(_data.end(), topic, topic + topicLength); 53 | _data.push_back(qosByte[0]); 54 | _released = false; 55 | } 56 | 57 | const uint8_t* SubscribeOutPacket::data(size_t index) const 58 | { 59 | return &_data.data()[index]; 60 | } 61 | 62 | size_t SubscribeOutPacket::size() const 63 | { 64 | return _data.size(); 65 | } 66 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Subscribe.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Subscribe.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef SUBSCRIBE_HPP 16 | #define SUBSCRIBE_HPP 17 | 18 | #include // strlen 19 | #include 20 | 21 | #include "OutPacket.hpp" 22 | #include "../../Flags.hpp" 23 | #include "../../Helpers.hpp" 24 | #include "../../Storage.hpp" 25 | 26 | namespace AsyncMqttClientInternals 27 | { 28 | class SubscribeOutPacket : public OutPacket 29 | { 30 | public: 31 | SubscribeOutPacket(const char* topic, uint8_t qos); 32 | const uint8_t* data(size_t index = 0) const; 33 | size_t size() const; 34 | 35 | private: 36 | std::vector _data; 37 | }; 38 | } // namespace AsyncMqttClientInternals 39 | 40 | #endif // SUBSCRIBE_HPP 41 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Unsubscribe.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Unsubscribe.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "Unsubscribe.hpp" 14 | 15 | using AsyncMqttClientInternals::UnsubscribeOutPacket; 16 | 17 | UnsubscribeOutPacket::UnsubscribeOutPacket(const char* topic) 18 | { 19 | char fixedHeader[5]; 20 | fixedHeader[0] = AsyncMqttClientInternals::PacketType.UNSUBSCRIBE; 21 | fixedHeader[0] = fixedHeader[0] << 4; 22 | fixedHeader[0] = fixedHeader[0] | AsyncMqttClientInternals::HeaderFlag.UNSUBSCRIBE_RESERVED; 23 | 24 | uint16_t topicLength = strlen(topic); 25 | char topicLengthBytes[2]; 26 | topicLengthBytes[0] = topicLength >> 8; 27 | topicLengthBytes[1] = topicLength & 0xFF; 28 | 29 | uint8_t remainingLengthLength = AsyncMqttClientInternals::Helpers::encodeRemainingLength(2 + 2 + topicLength, 30 | fixedHeader + 1); 31 | 32 | size_t neededSpace = 0; 33 | neededSpace += 1 + remainingLengthLength; 34 | neededSpace += 2; 35 | neededSpace += 2; 36 | neededSpace += topicLength; 37 | 38 | _packetId = _getNextPacketId(); 39 | char packetIdBytes[2]; 40 | packetIdBytes[0] = _packetId >> 8; 41 | packetIdBytes[1] = _packetId & 0xFF; 42 | 43 | _data.insert(_data.end(), fixedHeader, fixedHeader + 1 + remainingLengthLength); 44 | _data.insert(_data.end(), packetIdBytes, packetIdBytes + 2); 45 | _data.insert(_data.end(), topicLengthBytes, topicLengthBytes + 2); 46 | _data.insert(_data.end(), topic, topic + topicLength); 47 | _released = false; 48 | } 49 | 50 | const uint8_t* UnsubscribeOutPacket::data(size_t index) const 51 | { 52 | return &_data.data()[index]; 53 | } 54 | 55 | size_t UnsubscribeOutPacket::size() const 56 | { 57 | return _data.size(); 58 | } 59 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Out/Unsubscribe.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Unsubscribe.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef UNSUBSCRIBE_HPP 16 | #define UNSUBSCRIBE_HPP 17 | 18 | #include // strlen 19 | #include 20 | 21 | #include "OutPacket.hpp" 22 | #include "../../Flags.hpp" 23 | #include "../../Helpers.hpp" 24 | #include "../../Storage.hpp" 25 | 26 | namespace AsyncMqttClientInternals 27 | { 28 | class UnsubscribeOutPacket : public OutPacket 29 | { 30 | public: 31 | explicit UnsubscribeOutPacket(const char* topic); 32 | const uint8_t* data(size_t index = 0) const; 33 | size_t size() const; 34 | 35 | private: 36 | std::vector _data; 37 | }; 38 | } // namespace AsyncMqttClientInternals 39 | 40 | #endif // UNSUBSCRIBE_HPP 41 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/Packet.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Packet.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef PACKET_HPP 14 | #define PACKET_HPP 15 | 16 | namespace AsyncMqttClientInternals 17 | { 18 | class Packet 19 | { 20 | public: 21 | virtual ~Packet() {} 22 | 23 | virtual void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) = 0; 24 | virtual void parsePayload(char* data, size_t len, size_t* currentBytePosition) = 0; 25 | }; 26 | } // namespace AsyncMqttClientInternals 27 | 28 | #endif // PACKET_HPP 29 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PingRespPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PingRespPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PingRespPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::PingRespPacket; 16 | 17 | PingRespPacket::PingRespPacket(ParsingInformation* parsingInformation, OnPingRespInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | { 21 | } 22 | 23 | PingRespPacket::~PingRespPacket() 24 | { 25 | } 26 | 27 | void PingRespPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 28 | { 29 | (void)data; 30 | (void)len; 31 | (void)currentBytePosition; 32 | } 33 | 34 | void PingRespPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 35 | { 36 | (void)data; 37 | (void)len; 38 | (void)currentBytePosition; 39 | } 40 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PingRespPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PingRespPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 7 | 8 | Based on and modified from : 9 | 10 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 11 | 12 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 13 | *****************************************************************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef PING_RESP_PACKET_HPP 18 | #define PING_RESP_PACKET_HPP 19 | 20 | #include "Arduino.h" 21 | #include "Packet.hpp" 22 | #include "../ParsingInformation.hpp" 23 | #include "../Callbacks.hpp" 24 | 25 | namespace AsyncMqttClientInternals 26 | { 27 | class PingRespPacket : public Packet 28 | { 29 | public: 30 | explicit PingRespPacket(ParsingInformation* parsingInformation, OnPingRespInternalCallback callback); 31 | ~PingRespPacket(); 32 | 33 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 34 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 35 | 36 | private: 37 | ParsingInformation* _parsingInformation; 38 | OnPingRespInternalCallback _callback; 39 | }; 40 | } // namespace AsyncMqttClientInternals 41 | 42 | #endif // PING_RESP_PACKET_HPP 43 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubAckPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubAckPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PubAckPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::PubAckPacket; 16 | 17 | PubAckPacket::PubAckPacket(ParsingInformation* parsingInformation, OnPubAckInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _packetIdMsb(0) 22 | , _packetId(0) 23 | { 24 | } 25 | 26 | PubAckPacket::~PubAckPacket() 27 | { 28 | } 29 | 30 | void PubAckPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | 34 | char currentByte = data[(*currentBytePosition)++]; 35 | 36 | if (_bytePosition++ == 0) 37 | { 38 | _packetIdMsb = currentByte; 39 | } 40 | else 41 | { 42 | _packetId = currentByte | _packetIdMsb << 8; 43 | _parsingInformation->bufferState = BufferState::NONE; 44 | _callback(_packetId); 45 | } 46 | } 47 | 48 | void PubAckPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 49 | { 50 | (void)data; 51 | (void)len; 52 | (void)currentBytePosition; 53 | } 54 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubAckPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubAckPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PUB_ACK_PACKET_HPP 16 | #define PUB_ACK_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../ParsingInformation.hpp" 21 | #include "../Callbacks.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class PubAckPacket : public Packet 26 | { 27 | public: 28 | explicit PubAckPacket(ParsingInformation* parsingInformation, OnPubAckInternalCallback callback); 29 | ~PubAckPacket(); 30 | 31 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 32 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 33 | 34 | private: 35 | ParsingInformation* _parsingInformation; 36 | OnPubAckInternalCallback _callback; 37 | 38 | uint8_t _bytePosition; 39 | char _packetIdMsb; 40 | uint16_t _packetId; 41 | }; 42 | } // namespace AsyncMqttClientInternals 43 | 44 | #endif // PUB_ACK_PACKET_HPP 45 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubCompPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubCompPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PubCompPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::PubCompPacket; 16 | 17 | PubCompPacket::PubCompPacket(ParsingInformation* parsingInformation, OnPubCompInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _packetIdMsb(0) 22 | , _packetId(0) 23 | { 24 | } 25 | 26 | PubCompPacket::~PubCompPacket() 27 | { 28 | } 29 | 30 | void PubCompPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | 34 | char currentByte = data[(*currentBytePosition)++]; 35 | 36 | if (_bytePosition++ == 0) 37 | { 38 | _packetIdMsb = currentByte; 39 | } 40 | else 41 | { 42 | _packetId = currentByte | _packetIdMsb << 8; 43 | _parsingInformation->bufferState = BufferState::NONE; 44 | _callback(_packetId); 45 | } 46 | } 47 | 48 | void PubCompPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 49 | { 50 | (void)data; 51 | (void)len; 52 | (void)currentBytePosition; 53 | } 54 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubCompPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubCompPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 7 | 8 | Based on and modified from : 9 | 10 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 11 | 12 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 13 | *****************************************************************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef PUB_COMP_PACKET_HPP 18 | #define PUB_COMP_PACKET_HPP 19 | 20 | #include "Arduino.h" 21 | #include "Packet.hpp" 22 | #include "../ParsingInformation.hpp" 23 | #include "../Callbacks.hpp" 24 | 25 | namespace AsyncMqttClientInternals 26 | { 27 | class PubCompPacket : public Packet 28 | { 29 | public: 30 | explicit PubCompPacket(ParsingInformation* parsingInformation, OnPubCompInternalCallback callback); 31 | ~PubCompPacket(); 32 | 33 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 34 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 35 | 36 | private: 37 | ParsingInformation* _parsingInformation; 38 | OnPubCompInternalCallback _callback; 39 | 40 | uint8_t _bytePosition; 41 | char _packetIdMsb; 42 | uint16_t _packetId; 43 | }; 44 | } // namespace AsyncMqttClientInternals 45 | 46 | #endif // PUB_COMP_PACKET_HPP 47 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubRecPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubRecPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PubRecPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::PubRecPacket; 16 | 17 | PubRecPacket::PubRecPacket(ParsingInformation* parsingInformation, OnPubRecInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _packetIdMsb(0) 22 | , _packetId(0) 23 | { 24 | } 25 | 26 | PubRecPacket::~PubRecPacket() 27 | { 28 | } 29 | 30 | void PubRecPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | 34 | char currentByte = data[(*currentBytePosition)++]; 35 | 36 | if (_bytePosition++ == 0) 37 | { 38 | _packetIdMsb = currentByte; 39 | } 40 | else 41 | { 42 | _packetId = currentByte | _packetIdMsb << 8; 43 | _parsingInformation->bufferState = BufferState::NONE; 44 | _callback(_packetId); 45 | } 46 | } 47 | 48 | void PubRecPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 49 | { 50 | (void)data; 51 | (void)len; 52 | (void)currentBytePosition; 53 | } 54 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubRecPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubRecPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PUB_REC_PACKET_HPP 16 | #define PUB_REC_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../ParsingInformation.hpp" 21 | #include "../Callbacks.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class PubRecPacket : public Packet 26 | { 27 | public: 28 | explicit PubRecPacket(ParsingInformation* parsingInformation, OnPubRecInternalCallback callback); 29 | ~PubRecPacket(); 30 | 31 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 32 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 33 | 34 | private: 35 | ParsingInformation* _parsingInformation; 36 | OnPubRecInternalCallback _callback; 37 | 38 | uint8_t _bytePosition; 39 | char _packetIdMsb; 40 | uint16_t _packetId; 41 | }; 42 | } // namespace AsyncMqttClientInternals 43 | 44 | #endif // PUB_REC_PACKET_HPP 45 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubRelPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubRelPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PubRelPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::PubRelPacket; 16 | 17 | PubRelPacket::PubRelPacket(ParsingInformation* parsingInformation, OnPubRelInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _packetIdMsb(0) 22 | , _packetId(0) 23 | { 24 | } 25 | 26 | PubRelPacket::~PubRelPacket() 27 | { 28 | } 29 | 30 | void PubRelPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | 34 | char currentByte = data[(*currentBytePosition)++]; 35 | 36 | if (_bytePosition++ == 0) 37 | { 38 | _packetIdMsb = currentByte; 39 | } 40 | else 41 | { 42 | _packetId = currentByte | _packetIdMsb << 8; 43 | _parsingInformation->bufferState = BufferState::NONE; 44 | _callback(_packetId); 45 | } 46 | } 47 | 48 | void PubRelPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 49 | { 50 | (void)data; 51 | (void)len; 52 | (void)currentBytePosition; 53 | } 54 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PubRelPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PubRelPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PUB_REL_PACKET_HPP 16 | #define PUB_REL_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../ParsingInformation.hpp" 21 | #include "../Callbacks.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class PubRelPacket : public Packet 26 | { 27 | public: 28 | explicit PubRelPacket(ParsingInformation* parsingInformation, OnPubRelInternalCallback callback); 29 | ~PubRelPacket(); 30 | 31 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 32 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 33 | 34 | private: 35 | ParsingInformation* _parsingInformation; 36 | OnPubRelInternalCallback _callback; 37 | 38 | uint8_t _bytePosition; 39 | char _packetIdMsb; 40 | uint16_t _packetId; 41 | }; 42 | } // namespace AsyncMqttClientInternals 43 | 44 | #endif // PUB_REL_PACKET_HPP 45 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PublishPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PublishPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "PublishPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::PublishPacket; 16 | 17 | PublishPacket::PublishPacket(ParsingInformation* parsingInformation, OnMessageInternalCallback dataCallback, 18 | OnPublishInternalCallback completeCallback) 19 | : _parsingInformation(parsingInformation) 20 | , _dataCallback(dataCallback) 21 | , _completeCallback(completeCallback) 22 | , _dup(false) 23 | , _qos(0) 24 | , _retain(0) 25 | , _bytePosition(0) 26 | , _topicLengthMsb(0) 27 | , _topicLength(0) 28 | , _ignore(false) 29 | , _packetIdMsb(0) 30 | , _packetId(0) 31 | , _payloadLength(0) 32 | , _payloadBytesRead(0) 33 | { 34 | _dup = _parsingInformation->packetFlags & HeaderFlag.PUBLISH_DUP; 35 | _retain = _parsingInformation->packetFlags & HeaderFlag.PUBLISH_RETAIN; 36 | char qosMasked = _parsingInformation->packetFlags & 0x06; 37 | 38 | switch (qosMasked) 39 | { 40 | case HeaderFlag.PUBLISH_QOS0: 41 | _qos = 0; 42 | break; 43 | 44 | case HeaderFlag.PUBLISH_QOS1: 45 | _qos = 1; 46 | break; 47 | 48 | case HeaderFlag.PUBLISH_QOS2: 49 | _qos = 2; 50 | break; 51 | } 52 | } 53 | 54 | PublishPacket::~PublishPacket() 55 | { 56 | } 57 | 58 | void PublishPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 59 | { 60 | (void)len; 61 | 62 | char currentByte = data[(*currentBytePosition)++]; 63 | 64 | if (_bytePosition == 0) 65 | { 66 | _topicLengthMsb = currentByte; 67 | } 68 | else if (_bytePosition == 1) 69 | { 70 | _topicLength = currentByte | _topicLengthMsb << 8; 71 | 72 | if (_topicLength > _parsingInformation->maxTopicLength) 73 | { 74 | _ignore = true; 75 | } 76 | else 77 | { 78 | _parsingInformation->topicBuffer[_topicLength] = '\0'; 79 | } 80 | } 81 | else if (_bytePosition >= 2 && _bytePosition < 2 + _topicLength) 82 | { 83 | // Starting from here, _ignore might be true 84 | if (!_ignore) 85 | _parsingInformation->topicBuffer[_bytePosition - 2] = currentByte; 86 | 87 | if (_bytePosition == 2 + _topicLength - 1 && _qos == 0) 88 | { 89 | _preparePayloadHandling(_parsingInformation->remainingLength - (_bytePosition + 1)); 90 | return; 91 | } 92 | } 93 | else if (_bytePosition == 2 + _topicLength) 94 | { 95 | _packetIdMsb = currentByte; 96 | } 97 | else 98 | { 99 | _packetId = currentByte | _packetIdMsb << 8; 100 | _preparePayloadHandling(_parsingInformation->remainingLength - (_bytePosition + 1)); 101 | } 102 | 103 | _bytePosition++; 104 | } 105 | 106 | void PublishPacket::_preparePayloadHandling(uint32_t payloadLength) 107 | { 108 | _payloadLength = payloadLength; 109 | 110 | if (payloadLength == 0) 111 | { 112 | _parsingInformation->bufferState = BufferState::NONE; 113 | 114 | if (!_ignore) 115 | { 116 | _dataCallback(_parsingInformation->topicBuffer, nullptr, _qos, _dup, _retain, 0, 0, 0, _packetId); 117 | _completeCallback(_packetId, _qos); 118 | } 119 | } 120 | else 121 | { 122 | _parsingInformation->bufferState = BufferState::PAYLOAD; 123 | } 124 | } 125 | 126 | void PublishPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 127 | { 128 | size_t remainToRead = len - (*currentBytePosition); 129 | 130 | if (_payloadBytesRead + remainToRead > 131 | _payloadLength) 132 | remainToRead = _payloadLength - _payloadBytesRead; 133 | 134 | if (!_ignore) 135 | _dataCallback(_parsingInformation->topicBuffer, data + (*currentBytePosition), 136 | _qos, _dup, _retain, remainToRead, _payloadBytesRead, _payloadLength, _packetId); 137 | 138 | _payloadBytesRead += remainToRead; 139 | (*currentBytePosition) += remainToRead; 140 | 141 | if (_payloadBytesRead == _payloadLength) 142 | { 143 | _parsingInformation->bufferState = BufferState::NONE; 144 | 145 | if (!_ignore) 146 | _completeCallback(_packetId, _qos); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/PublishPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PublishPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PUBLISH_PACKET_HPP 16 | #define PUBLISH_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../Flags.hpp" 21 | #include "../ParsingInformation.hpp" 22 | #include "../Callbacks.hpp" 23 | 24 | namespace AsyncMqttClientInternals 25 | { 26 | class PublishPacket : public Packet 27 | { 28 | public: 29 | explicit PublishPacket(ParsingInformation* parsingInformation, OnMessageInternalCallback dataCallback, OnPublishInternalCallback completeCallback); 30 | ~PublishPacket(); 31 | 32 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 33 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 34 | 35 | private: 36 | ParsingInformation* _parsingInformation; 37 | OnMessageInternalCallback _dataCallback; 38 | OnPublishInternalCallback _completeCallback; 39 | 40 | void _preparePayloadHandling(uint32_t payloadLength); 41 | 42 | bool _dup; 43 | uint8_t _qos; 44 | bool _retain; 45 | 46 | uint8_t _bytePosition; 47 | char _topicLengthMsb; 48 | uint16_t _topicLength; 49 | bool _ignore; 50 | char _packetIdMsb; 51 | uint16_t _packetId; 52 | uint32_t _payloadLength; 53 | uint32_t _payloadBytesRead; 54 | }; 55 | } // namespace AsyncMqttClientInternals 56 | 57 | #endif // PUBLISH_PACKET_HPP 58 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/SubAckPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SubAckPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "SubAckPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::SubAckPacket; 16 | 17 | SubAckPacket::SubAckPacket(ParsingInformation* parsingInformation, OnSubAckInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _packetIdMsb(0) 22 | , _packetId(0) 23 | { 24 | } 25 | 26 | SubAckPacket::~SubAckPacket() 27 | { 28 | } 29 | 30 | void SubAckPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | 34 | char currentByte = data[(*currentBytePosition)++]; 35 | 36 | if (_bytePosition++ == 0) 37 | { 38 | _packetIdMsb = currentByte; 39 | } 40 | else 41 | { 42 | _packetId = currentByte | _packetIdMsb << 8; 43 | _parsingInformation->bufferState = BufferState::PAYLOAD; 44 | } 45 | } 46 | 47 | void SubAckPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 48 | { 49 | (void)len; 50 | char status = data[(*currentBytePosition)++]; 51 | 52 | /* switch (status) { 53 | case 0: 54 | Serial.println("Success QoS 0"); 55 | break; 56 | case 1: 57 | Serial.println("Success QoS 1"); 58 | break; 59 | case 2: 60 | Serial.println("Success QoS 2"); 61 | break; 62 | case 0x80: 63 | Serial.println("Failure"); 64 | break; 65 | } */ 66 | 67 | _parsingInformation->bufferState = BufferState::NONE; 68 | _callback(_packetId, status); 69 | } 70 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/SubAckPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SubAckPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef SUB_ACK_PACKET_HPP 16 | #define SUB_ACK_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../ParsingInformation.hpp" 21 | #include "../Callbacks.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class SubAckPacket : public Packet 26 | { 27 | public: 28 | explicit SubAckPacket(ParsingInformation* parsingInformation, OnSubAckInternalCallback callback); 29 | ~SubAckPacket(); 30 | 31 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 32 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 33 | 34 | private: 35 | ParsingInformation* _parsingInformation; 36 | OnSubAckInternalCallback _callback; 37 | 38 | uint8_t _bytePosition; 39 | char _packetIdMsb; 40 | uint16_t _packetId; 41 | }; 42 | } // namespace AsyncMqttClientInternals 43 | 44 | #endif // SUB_ACK_PACKET_HPP 45 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/UnsubAckPacket.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | UnsubAckPacket.cpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #include "UnsubAckPacket.hpp" 14 | 15 | using AsyncMqttClientInternals::UnsubAckPacket; 16 | 17 | UnsubAckPacket::UnsubAckPacket(ParsingInformation* parsingInformation, OnUnsubAckInternalCallback callback) 18 | : _parsingInformation(parsingInformation) 19 | , _callback(callback) 20 | , _bytePosition(0) 21 | , _packetIdMsb(0) 22 | , _packetId(0) 23 | { 24 | } 25 | 26 | UnsubAckPacket::~UnsubAckPacket() 27 | { 28 | } 29 | 30 | void UnsubAckPacket::parseVariableHeader(char* data, size_t len, size_t* currentBytePosition) 31 | { 32 | (void)len; 33 | char currentByte = data[(*currentBytePosition)++]; 34 | 35 | if (_bytePosition++ == 0) 36 | { 37 | _packetIdMsb = currentByte; 38 | } 39 | else 40 | { 41 | _packetId = currentByte | _packetIdMsb << 8; 42 | _parsingInformation->bufferState = BufferState::NONE; 43 | _callback(_packetId); 44 | } 45 | } 46 | 47 | void UnsubAckPacket::parsePayload(char* data, size_t len, size_t* currentBytePosition) 48 | { 49 | (void)data; 50 | (void)len; 51 | (void)currentBytePosition; 52 | } 53 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Packets/UnsubAckPacket.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | UnsubAckPacket.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef UNSUB_ACK_PACKET_HPP 16 | #define UNSUB_ACK_PACKET_HPP 17 | 18 | #include "Arduino.h" 19 | #include "Packet.hpp" 20 | #include "../ParsingInformation.hpp" 21 | #include "../Callbacks.hpp" 22 | 23 | namespace AsyncMqttClientInternals 24 | { 25 | class UnsubAckPacket : public Packet 26 | { 27 | public: 28 | explicit UnsubAckPacket(ParsingInformation* parsingInformation, OnUnsubAckInternalCallback callback); 29 | ~UnsubAckPacket(); 30 | 31 | void parseVariableHeader(char* data, size_t len, size_t* currentBytePosition); 32 | void parsePayload(char* data, size_t len, size_t* currentBytePosition); 33 | 34 | private: 35 | ParsingInformation* _parsingInformation; 36 | OnUnsubAckInternalCallback _callback; 37 | 38 | uint8_t _bytePosition; 39 | char _packetIdMsb; 40 | uint16_t _packetId; 41 | }; 42 | } // namespace AsyncMqttClientInternals 43 | 44 | #endif // UNSUB_ACK_PACKET_HPP 45 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/ParsingInformation.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | ParsingInformation.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef PARSING_INFORMATION_HPP 16 | #define PARSING_INFORMATION_HPP 17 | 18 | namespace AsyncMqttClientInternals 19 | { 20 | enum class BufferState : uint8_t 21 | { 22 | NONE = 0, 23 | REMAINING_LENGTH = 2, 24 | VARIABLE_HEADER = 3, 25 | PAYLOAD = 4 26 | }; 27 | 28 | struct ParsingInformation 29 | { 30 | BufferState bufferState; 31 | 32 | uint16_t maxTopicLength; 33 | char* topicBuffer; 34 | 35 | uint8_t packetType; 36 | uint16_t packetFlags; 37 | uint32_t remainingLength; 38 | }; 39 | } // namespace AsyncMqttClientInternals 40 | 41 | #endif // PARSING_INFORMATION_HPP 42 | -------------------------------------------------------------------------------- /src/AsyncMqttClient/Storage.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Storage.hpp 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | *****************************************************************************************************************************/ 12 | 13 | #pragma once 14 | 15 | #ifndef STORAGE_HPP 16 | #define STORAGE_HPP 17 | 18 | namespace AsyncMqttClientInternals 19 | { 20 | struct PendingPubRel 21 | { 22 | uint16_t packetId; 23 | }; 24 | 25 | struct PendingAck 26 | { 27 | uint8_t packetType; 28 | uint8_t headerFlag; 29 | uint16_t packetId; 30 | }; 31 | } // namespace AsyncMqttClientInternals 32 | 33 | #endif // STORAGE_HPP 34 | -------------------------------------------------------------------------------- /src/AsyncMqtt_Generic.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | AsyncMqtt_Generic.h 3 | 4 | AsyncMqttClient_Generic is a library for ESP32, ESP8266, Protenta_H7, STM32F7, etc. with current AsyncTCP support 5 | 6 | Based on and modified from : 7 | 8 | 1) async-mqtt-client (https://github.com/marvinroger/async-mqtt-client) 9 | 10 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncMqttClient_Generic 11 | 12 | Version: 1.8.1 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 10/03/2022 Initial coding to support only ESP32 (with SSL) and ESP8266 (without SSL) 17 | 1.0.1 K Hoang 10/03/2022 Fix Library Manager warnings 18 | 1.1.0 K Hoang 11/03/2022 Add support to WT32_ETH01 (with or without TLS/SSL) 19 | 1.2.0 K Hoang 15/03/2022 Add support to STM32 using LAN8742A (without TLS/SSL) 20 | 1.2.1 K Hoang 16/03/2022 Add support to STM32 using LAN8720 (without TLS/SSL) 21 | 1.3.0 K Hoang 16/03/2022 Add support to Portenta_H7 using built-in Ethernet or Murata WiFi (without TLS/SSL) 22 | 1.4.0 K Hoang 17/03/2022 Add support to Teensy 4.1 using QNEthernet Library 23 | 1.5.0 K Hoang 14/04/2022 Add support to ESP8266 W5x00/ENC28J60 using lwip_W5100/lwip_W5500 or lwip_enc28j60 library 24 | 1.6.0 K Hoang 14/08/2022 Add support to RP2040W with CYW43439 WiFi using arduino-pico core 25 | 1.6.1 K Hoang 17/08/2022 Better workaround for RP2040W WiFi.status() bug using ping() to local gateway 26 | 1.7.0 K Hoang 13/09/2022 Fix ESP32 and ESP8266 compile error 27 | 1.8.0 K Hoang 30/11/2022 Add support to ESP32 boards using LwIP W5500 or ENC28J60 Ethernet 28 | 1.8.1 K Hoang 28/01/2023 Add AsyncWebServer_MQTT and AsyncWebServer_MQTT_RP2040W examples 29 | *****************************************************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | #ifndef ASYNC_MQTT_GENERIC_H 34 | #define ASYNC_MQTT_GENERIC_H 35 | 36 | #include "AsyncMqttClient_Generic.hpp" 37 | #include "AsyncMqttClient_Generic_Impl.h" 38 | 39 | #endif // ASYNC_MQTT_GENERIC_H 40 | -------------------------------------------------------------------------------- /utils/astyle_library.conf: -------------------------------------------------------------------------------- 1 | # Code formatting rules for Arduino libraries, modified from for KH libraries: 2 | # 3 | # https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf 4 | # 5 | 6 | # astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino 7 | 8 | --mode=c 9 | --lineend=linux 10 | --style=allman 11 | 12 | # -r or -R 13 | #--recursive 14 | 15 | # -c => Converts tabs into spaces 16 | convert-tabs 17 | 18 | # -s2 => 2 spaces indentation 19 | --indent=spaces=2 20 | 21 | # -t2 => tab =2 spaces 22 | #--indent=tab=2 23 | 24 | # -C 25 | --indent-classes 26 | 27 | # -S 28 | --indent-switches 29 | 30 | # -xW 31 | --indent-preproc-block 32 | 33 | # -Y => indent classes, switches (and cases), comments starting at column 1 34 | --indent-col1-comments 35 | 36 | # -M120 => maximum of 120 spaces to indent a continuation line 37 | --max-continuation-indent=120 38 | 39 | # -xC120 => max‑code‑length will break a line if the code exceeds # characters 40 | --max-code-length=120 41 | 42 | # -f => 43 | --break-blocks 44 | 45 | # -p => put a space around operators 46 | --pad-oper 47 | 48 | # -xg => Insert space padding after commas 49 | --pad-comma 50 | 51 | # -H => put a space after if/for/while 52 | pad-header 53 | 54 | # -xb => Break one line headers (e.g. if/for/while) 55 | --break-one-line-headers 56 | 57 | # -c => Converts tabs into spaces 58 | #--convert-tabs 59 | 60 | # if you like one-liners, keep them 61 | #keep-one-line-statements 62 | 63 | # -xV 64 | --attach-closing-while 65 | 66 | #unpad-paren 67 | 68 | # -xp 69 | remove-comment-prefix 70 | 71 | -------------------------------------------------------------------------------- /utils/restyle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for dir in . ; do 4 | find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \; 5 | done 6 | 7 | --------------------------------------------------------------------------------