├── .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 └── 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 ├── README.md ├── changelog.md ├── examples ├── Ethernet │ ├── AsyncWebServer_SendChunked │ │ └── AsyncWebServer_SendChunked.ino │ ├── Async_AdvancedWebServer │ │ └── Async_AdvancedWebServer.ino │ ├── Async_AdvancedWebServer_MemoryIssues_SendArduinoString │ │ └── Async_AdvancedWebServer_MemoryIssues_SendArduinoString.ino │ ├── Async_AdvancedWebServer_MemoryIssues_Send_CString │ │ └── Async_AdvancedWebServer_MemoryIssues_Send_CString.ino │ ├── Async_AdvancedWebServer_SendChunked │ │ └── Async_AdvancedWebServer_SendChunked.ino │ ├── Async_HelloServer │ │ └── Async_HelloServer.ino │ ├── Async_HelloServer2 │ │ └── Async_HelloServer2.ino │ ├── Async_HttpBasicAuth │ │ └── Async_HttpBasicAuth.ino │ ├── Async_PostServer │ │ └── Async_PostServer.ino │ ├── MQTTClient_Auth │ │ ├── MQTTClient_Auth.ino │ │ └── defines.h │ ├── MQTTClient_Basic │ │ ├── MQTTClient_Basic.ino │ │ └── defines.h │ ├── MQTT_ThingStream │ │ ├── MQTT_ThingStream.ino │ │ └── defines.h │ ├── WebClient │ │ ├── WebClient.ino │ │ └── defines.h │ └── WebClientRepeating │ │ ├── WebClientRepeating.ino │ │ └── defines.h └── WiFi │ ├── AsyncWebServer_SendChunked │ └── AsyncWebServer_SendChunked.ino │ ├── Async_AdvancedWebServer │ └── Async_AdvancedWebServer.ino │ ├── Async_AdvancedWebServer_MemoryIssues_Send_CString │ └── Async_AdvancedWebServer_MemoryIssues_Send_CString.ino │ ├── Async_AdvancedWebServer_SendChunked │ └── Async_AdvancedWebServer_SendChunked.ino │ ├── Async_HelloServer │ └── Async_HelloServer.ino │ ├── Async_HelloServer2 │ └── Async_HelloServer2.ino │ ├── Async_HttpBasicAuth │ └── Async_HttpBasicAuth.ino │ ├── Async_PostServer │ └── Async_PostServer.ino │ ├── MQTTClient_Auth │ ├── MQTTClient_Auth.ino │ └── defines.h │ ├── MQTTClient_Basic │ ├── MQTTClient_Basic.ino │ └── defines.h │ ├── MQTT_ThingStream │ ├── MQTT_ThingStream.ino │ └── defines.h │ ├── WebClient │ ├── WebClient.ino │ └── defines.h │ └── WebClientRepeating │ ├── WebClientRepeating.ino │ └── defines.h ├── keywords.txt ├── library.json ├── library.properties ├── pics ├── AsyncWebServer_SendChunked_Ethernet.png ├── AsyncWebServer_SendChunked_WiFi.png ├── Async_AdvancedWebServer.png ├── Async_AdvancedWebServer_CString.png ├── Async_AdvancedWebServer_Firefox.png ├── Async_AdvancedWebServer_WiFi.png └── Portenta_Vision.jpg ├── platformio └── platformio.ini ├── src ├── Crypto │ ├── Hash.cpp │ ├── Hash.h │ ├── bearssl_hash.h │ ├── md5.h │ ├── sha1.c │ └── sha1.h ├── Portenta_H7_AsyncEventSource.cpp ├── Portenta_H7_AsyncEventSource.h ├── Portenta_H7_AsyncJson.h ├── Portenta_H7_AsyncWebAuthentication.cpp ├── Portenta_H7_AsyncWebAuthentication.h ├── Portenta_H7_AsyncWebHandlerImpl.h ├── Portenta_H7_AsyncWebHandlers.cpp ├── Portenta_H7_AsyncWebRequest.cpp ├── Portenta_H7_AsyncWebResponseImpl.h ├── Portenta_H7_AsyncWebResponses.cpp ├── Portenta_H7_AsyncWebServer.cpp ├── Portenta_H7_AsyncWebServer.h ├── Portenta_H7_AsyncWebServer_Debug.h ├── Portenta_H7_AsyncWebSocket.cpp ├── Portenta_H7_AsyncWebSocket.h ├── Portenta_H7_AsyncWebSynchronization.h ├── Portenta_H7_StringArray.h └── libb64 │ ├── cdecode.c │ ├── cdecode.h │ ├── cencode.c │ └── cencode.h ├── travis └── common.sh └── 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 | * `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v3.5.4) 42 | * `Portenta_H7` Board type (e.g. Portenta_H7 Rev2 ABX00042, etc.) 43 | * Contextual information (e.g. what you were trying to achieve) 44 | * Simplest possible steps to reproduce 45 | * Anything that might be relevant in your opinion, such as: 46 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 47 | * Network configuration 48 | 49 | 50 | 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. 51 | 52 | --- 53 | 54 | ### Example 55 | 56 | ``` 57 | Arduino IDE version: 1.8.19 58 | `ArduinoCore-mbed` mbed_portenta core v3.5.4 59 | Portenta_H7 Rev2 ABX00042 60 | OS: Ubuntu 20.04 LTS 61 | 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 62 | 63 | Context: 64 | I encountered a crash while using this library 65 | Steps to reproduce: 66 | 1. ... 67 | 2. ... 68 | 3. ... 69 | 4. ... 70 | ``` 71 | 72 | ### Additional context 73 | 74 | Add any other context about the problem here. 75 | 76 | --- 77 | 78 | ### Sending Feature Requests 79 | 80 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 81 | 82 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 83 | 84 | --- 85 | 86 | ### Sending Pull Requests 87 | 88 | Pull Requests with changes and fixes are also welcome! 89 | 90 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 91 | 92 | 1. Change directory to the library GitHub 93 | 94 | ``` 95 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/Portenta_H7_AsyncWebServer_GitHub/ 96 | xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncWebServer_GitHub$ 97 | ``` 98 | 99 | 2. Issue astyle command 100 | 101 | ``` 102 | xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncWebServer_GitHub$ bash utils/restyle.sh 103 | ``` 104 | -------------------------------------------------------------------------------- /.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 Portenta_H7_AsyncWebServer 2 | 3 | ### Reporting Bugs 4 | 5 | Please report bugs in [Portenta_H7_AsyncWebServer Issues](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/issues) 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/Portenta_H7_AsyncWebServer/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/Portenta_H7_AsyncWebServer/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 | * `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v3.5.4) 21 | * `Portenta_H7` Board type (e.g. Portenta_H7 Rev2 ABX00042, etc.) 22 | * Contextual information (e.g. what you were trying to achieve) 23 | * Simplest possible steps to reproduce 24 | * Anything that might be relevant in your opinion, such as: 25 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 26 | * Network configuration 27 | 28 | 29 | 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. 30 | 31 | --- 32 | 33 | ### Example 34 | 35 | ``` 36 | Arduino IDE version: 1.8.19 37 | `ArduinoCore-mbed` mbed_portenta core v3.5.4 38 | Portenta_H7 Rev2 ABX00042 39 | OS: Ubuntu 20.04 LTS 40 | 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 41 | 42 | Context: 43 | I encountered a crash while using this library 44 | Steps to reproduce: 45 | 1. ... 46 | 2. ... 47 | 3. ... 48 | 4. ... 49 | ``` 50 | 51 | ### Additional context 52 | 53 | Add any other context about the problem here. 54 | 55 | --- 56 | 57 | ### Sending Feature Requests 58 | 59 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 60 | 61 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 62 | 63 | --- 64 | 65 | ### Sending Pull Requests 66 | 67 | Pull Requests with changes and fixes are also welcome! 68 | 69 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 70 | 71 | 1. Change directory to the library GitHub 72 | 73 | ``` 74 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/Portenta_H7_AsyncWebServer_GitHub/ 75 | xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncWebServer_GitHub$ 76 | ``` 77 | 78 | 2. Issue astyle command 79 | 80 | ``` 81 | xy@xy-Inspiron-3593:~/Arduino/xy/Portenta_H7_AsyncWebServer_GitHub$ bash utils/restyle.sh 82 | ``` 83 | 84 | 85 | -------------------------------------------------------------------------------- /Packages_Patches/arduino/hardware/mbed_portenta/2.4.1/libraries/SocketWrapper/src/MbedUdp.cpp: -------------------------------------------------------------------------------- 1 | #include "MbedUdp.h" 2 | 3 | arduino::MbedUDP::MbedUDP() { 4 | _packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE]; 5 | _current_packet = NULL; 6 | _current_packet_size = 0; 7 | // if this allocation fails then ::begin will fail 8 | } 9 | 10 | arduino::MbedUDP::~MbedUDP() { 11 | delete[] _packet_buffer; 12 | } 13 | 14 | uint8_t arduino::MbedUDP::begin(uint16_t port) { 15 | // success = 1, fail = 0 16 | 17 | nsapi_error_t rt = _socket.open(getNetwork()); 18 | if (rt != NSAPI_ERROR_OK) { 19 | return 0; 20 | } 21 | 22 | if (_socket.bind(port) < 0) { 23 | return 0; //Failed to bind UDP Socket to port 24 | } 25 | 26 | if (!_packet_buffer) { 27 | return 0; 28 | } 29 | 30 | _socket.set_blocking(false); 31 | _socket.set_timeout(0); 32 | 33 | return 1; 34 | } 35 | 36 | uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) { 37 | // success = 1, fail = 0 38 | if (begin(port) != 1) { 39 | return 0; 40 | } 41 | 42 | SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port); 43 | 44 | if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) { 45 | printf("Error joining the multicast group\n"); 46 | return 0; 47 | } 48 | 49 | return 1; 50 | } 51 | 52 | void arduino::MbedUDP::stop() { 53 | _socket.close(); 54 | } 55 | 56 | int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) { 57 | _host = SocketHelpers::socketAddressFromIpAddress(ip, port); 58 | //If IP is null and port is 0 the initialization failed 59 | txBuffer.clear(); 60 | return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1; 61 | } 62 | 63 | int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) { 64 | _host = SocketAddress(host, port); 65 | txBuffer.clear(); 66 | getNetwork()->gethostbyname(host, &_host); 67 | //If IP is null and port is 0 the initialization failed 68 | return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1; 69 | } 70 | 71 | int arduino::MbedUDP::endPacket() { 72 | _socket.set_blocking(true); 73 | _socket.set_timeout(1000); 74 | 75 | size_t size = txBuffer.available(); 76 | uint8_t buffer[size]; 77 | for (int i = 0; i < size; i++) { 78 | buffer[i] = txBuffer.read_char(); 79 | } 80 | 81 | nsapi_size_or_error_t ret = _socket.sendto(_host, buffer, size); 82 | _socket.set_blocking(false); 83 | _socket.set_timeout(0); 84 | if (ret < 0) { 85 | return 0; 86 | } 87 | return size; 88 | } 89 | 90 | // Write a single byte into the packet 91 | size_t arduino::MbedUDP::write(uint8_t byte) { 92 | return write(&byte, 1); 93 | } 94 | 95 | // Write size bytes from buffer into the packet 96 | size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size) { 97 | for (int i = 0; i _packet_buffer + _current_packet_size) { 146 | // try reading the next packet... 147 | if (parsePacket() > 0) { 148 | // if so, read first byte of next packet; 149 | return read(); 150 | } else { 151 | // no new data... not sure what to return here now 152 | return -1; 153 | } 154 | } 155 | 156 | return _current_packet[0]; 157 | } 158 | 159 | // Read up to len bytes from the current packet and place them into buffer 160 | // Returns the number of bytes read, or 0 if none are available 161 | int arduino::MbedUDP::read(unsigned char *buffer, size_t len) { 162 | // Q: does Arduino read() function handle fragmentation? I won't for now... 163 | if (_current_packet == NULL) { 164 | if (parsePacket() == 0) return 0; 165 | } 166 | 167 | // how much data do we have in the current packet? 168 | int offset = _current_packet - _packet_buffer; 169 | if (offset < 0) { 170 | return 0; 171 | } 172 | 173 | int max_bytes = _current_packet_size - offset; 174 | if (max_bytes < 0) { 175 | return 0; 176 | } 177 | 178 | // at the end of the packet? 179 | if (max_bytes == 0) { 180 | // try read next packet... 181 | if (parsePacket() > 0) { 182 | return read(buffer, len); 183 | } else { 184 | return 0; 185 | } 186 | } 187 | 188 | if (len > (size_t)max_bytes) len = max_bytes; 189 | 190 | // copy to target buffer 191 | memcpy(buffer, _current_packet, len); 192 | 193 | _current_packet += len; 194 | 195 | return len; 196 | } 197 | 198 | IPAddress arduino::MbedUDP::remoteIP() { 199 | nsapi_addr_t address = _remoteHost.get_addr(); 200 | return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]); 201 | } 202 | 203 | uint16_t arduino::MbedUDP::remotePort() { 204 | return _remoteHost.get_port(); 205 | } 206 | 207 | void arduino::MbedUDP::flush() { 208 | // TODO: a real check to ensure transmission has been completed 209 | } 210 | 211 | int arduino::MbedUDP::peek() { 212 | if (_current_packet_size < 1) { 213 | return -1; 214 | } 215 | 216 | return _current_packet[0]; 217 | } 218 | -------------------------------------------------------------------------------- /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 | class MbedUDP : public UDP { 34 | private: 35 | UDPSocket _socket; // Mbed OS socket 36 | SocketAddress _host; // Host to be used to send data 37 | SocketAddress _remoteHost; // Remote host that sent incoming packets 38 | 39 | uint8_t* _packet_buffer; // Raw packet buffer (contains data we got from the UDPSocket) 40 | 41 | // The Arduino APIs allow you to iterate through this buffer, so we need to be able to iterate over the current packet 42 | // these two variables are used to cache the state of the current packet 43 | uint8_t* _current_packet; 44 | size_t _current_packet_size; 45 | 46 | RingBufferN txBuffer; 47 | 48 | protected: 49 | virtual NetworkInterface* getNetwork() = 0; 50 | 51 | public: 52 | MbedUDP(); // Constructor 53 | ~MbedUDP(); 54 | virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 55 | virtual uint8_t beginMulticast(IPAddress, 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 56 | virtual void stop(); // Finish with the UDP socket 57 | 58 | // Sending UDP packets 59 | 60 | // Start building up a packet to send to the remote host specific in ip and port 61 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 62 | virtual int beginPacket(IPAddress ip, uint16_t port); 63 | // Start building up a packet to send to the remote host specific in host and port 64 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 65 | virtual int beginPacket(const char* host, uint16_t port); 66 | // Finish off this packet and send it 67 | // Returns 1 if the packet was sent successfully, 0 if there was an error 68 | virtual int endPacket(); 69 | // Write a single byte into the packet 70 | virtual size_t write(uint8_t); 71 | // Write size bytes from buffer into the packet 72 | virtual size_t write(const uint8_t* buffer, size_t size); 73 | 74 | using Print::write; 75 | 76 | // Start processing the next available incoming packet 77 | // Returns the size of the packet in bytes, or 0 if no packets are available 78 | virtual int parsePacket(); 79 | // Number of bytes remaining in the current packet 80 | virtual int available(); 81 | // Read a single byte from the current packet 82 | virtual int read(); 83 | // Read up to len bytes from the current packet and place them into buffer 84 | // Returns the number of bytes read, or 0 if none are available 85 | virtual int read(unsigned char* buffer, size_t len); 86 | // Read up to len characters from the current packet and place them into buffer 87 | // Returns the number of characters read, or 0 if none are available 88 | virtual int read(char* buffer, size_t len) { 89 | return read((unsigned char*)buffer, len); 90 | }; 91 | // Return the next byte from the current packet without moving on to the next byte 92 | virtual int peek(); 93 | virtual void flush(); // Finish reading the current packet 94 | 95 | // Return the IP address of the host who sent the current incoming packet 96 | virtual IPAddress remoteIP(); 97 | // // Return the port of the host who sent the current incoming packet 98 | virtual uint16_t remotePort(); 99 | 100 | friend class MbedSocketClass; 101 | }; 102 | 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /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.cpp: -------------------------------------------------------------------------------- 1 | #include "MbedUdp.h" 2 | 3 | arduino::MbedUDP::MbedUDP() { 4 | _packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE]; 5 | _current_packet = NULL; 6 | _current_packet_size = 0; 7 | // if this allocation fails then ::begin will fail 8 | } 9 | 10 | arduino::MbedUDP::~MbedUDP() { 11 | delete[] _packet_buffer; 12 | } 13 | 14 | uint8_t arduino::MbedUDP::begin(uint16_t port) { 15 | // success = 1, fail = 0 16 | 17 | nsapi_error_t rt = _socket.open(getNetwork()); 18 | if (rt != NSAPI_ERROR_OK) { 19 | return 0; 20 | } 21 | 22 | if (_socket.bind(port) < 0) { 23 | return 0; //Failed to bind UDP Socket to port 24 | } 25 | 26 | if (!_packet_buffer) { 27 | return 0; 28 | } 29 | 30 | _socket.set_blocking(false); 31 | _socket.set_timeout(0); 32 | 33 | return 1; 34 | } 35 | 36 | uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) { 37 | // success = 1, fail = 0 38 | if (begin(port) != 1) { 39 | return 0; 40 | } 41 | 42 | SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port); 43 | 44 | if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) { 45 | printf("Error joining the multicast group\n"); 46 | return 0; 47 | } 48 | 49 | return 1; 50 | } 51 | 52 | void arduino::MbedUDP::stop() { 53 | _socket.close(); 54 | } 55 | 56 | int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) { 57 | _host = SocketHelpers::socketAddressFromIpAddress(ip, port); 58 | //If IP is null and port is 0 the initialization failed 59 | txBuffer.clear(); 60 | return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1; 61 | } 62 | 63 | int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) { 64 | _host = SocketAddress(host, port); 65 | txBuffer.clear(); 66 | getNetwork()->gethostbyname(host, &_host); 67 | //If IP is null and port is 0 the initialization failed 68 | return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1; 69 | } 70 | 71 | int arduino::MbedUDP::endPacket() { 72 | _socket.set_blocking(true); 73 | _socket.set_timeout(1000); 74 | 75 | size_t size = txBuffer.available(); 76 | uint8_t buffer[size]; 77 | for (int i = 0; i < size; i++) { 78 | buffer[i] = txBuffer.read_char(); 79 | } 80 | 81 | nsapi_size_or_error_t ret = _socket.sendto(_host, buffer, size); 82 | _socket.set_blocking(false); 83 | _socket.set_timeout(0); 84 | if (ret < 0) { 85 | return 0; 86 | } 87 | return size; 88 | } 89 | 90 | // Write a single byte into the packet 91 | size_t arduino::MbedUDP::write(uint8_t byte) { 92 | return write(&byte, 1); 93 | } 94 | 95 | // Write size bytes from buffer into the packet 96 | size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size) { 97 | for (int i = 0; i _packet_buffer + _current_packet_size) { 146 | // try reading the next packet... 147 | if (parsePacket() > 0) { 148 | // if so, read first byte of next packet; 149 | return read(); 150 | } else { 151 | // no new data... not sure what to return here now 152 | return -1; 153 | } 154 | } 155 | 156 | return _current_packet[0]; 157 | } 158 | 159 | // Read up to len bytes from the current packet and place them into buffer 160 | // Returns the number of bytes read, or 0 if none are available 161 | int arduino::MbedUDP::read(unsigned char *buffer, size_t len) { 162 | // Q: does Arduino read() function handle fragmentation? I won't for now... 163 | if (_current_packet == NULL) { 164 | if (parsePacket() == 0) return 0; 165 | } 166 | 167 | // how much data do we have in the current packet? 168 | int offset = _current_packet - _packet_buffer; 169 | if (offset < 0) { 170 | return 0; 171 | } 172 | 173 | int max_bytes = _current_packet_size - offset; 174 | if (max_bytes < 0) { 175 | return 0; 176 | } 177 | 178 | // at the end of the packet? 179 | if (max_bytes == 0) { 180 | // try read next packet... 181 | if (parsePacket() > 0) { 182 | return read(buffer, len); 183 | } else { 184 | return 0; 185 | } 186 | } 187 | 188 | if (len > (size_t)max_bytes) len = max_bytes; 189 | 190 | // copy to target buffer 191 | memcpy(buffer, _current_packet, len); 192 | 193 | _current_packet += len; 194 | 195 | return len; 196 | } 197 | 198 | IPAddress arduino::MbedUDP::remoteIP() { 199 | nsapi_addr_t address = _remoteHost.get_addr(); 200 | return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]); 201 | } 202 | 203 | uint16_t arduino::MbedUDP::remotePort() { 204 | return _remoteHost.get_port(); 205 | } 206 | 207 | void arduino::MbedUDP::flush() { 208 | // TODO: a real check to ensure transmission has been completed 209 | } 210 | 211 | int arduino::MbedUDP::peek() { 212 | if (_current_packet_size < 1) { 213 | return -1; 214 | } 215 | 216 | return _current_packet[0]; 217 | } 218 | -------------------------------------------------------------------------------- /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 | class MbedUDP : public UDP { 34 | private: 35 | UDPSocket _socket; // Mbed OS socket 36 | SocketAddress _host; // Host to be used to send data 37 | SocketAddress _remoteHost; // Remote host that sent incoming packets 38 | 39 | uint8_t* _packet_buffer; // Raw packet buffer (contains data we got from the UDPSocket) 40 | 41 | // The Arduino APIs allow you to iterate through this buffer, so we need to be able to iterate over the current packet 42 | // these two variables are used to cache the state of the current packet 43 | uint8_t* _current_packet; 44 | size_t _current_packet_size; 45 | 46 | RingBufferN txBuffer; 47 | 48 | protected: 49 | virtual NetworkInterface* getNetwork() = 0; 50 | 51 | public: 52 | MbedUDP(); // Constructor 53 | ~MbedUDP(); 54 | virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 55 | virtual uint8_t beginMulticast(IPAddress, 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 56 | virtual void stop(); // Finish with the UDP socket 57 | 58 | // Sending UDP packets 59 | 60 | // Start building up a packet to send to the remote host specific in ip and port 61 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 62 | virtual int beginPacket(IPAddress ip, uint16_t port); 63 | // Start building up a packet to send to the remote host specific in host and port 64 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 65 | virtual int beginPacket(const char* host, uint16_t port); 66 | // Finish off this packet and send it 67 | // Returns 1 if the packet was sent successfully, 0 if there was an error 68 | virtual int endPacket(); 69 | // Write a single byte into the packet 70 | virtual size_t write(uint8_t); 71 | // Write size bytes from buffer into the packet 72 | virtual size_t write(const uint8_t* buffer, size_t size); 73 | 74 | using Print::write; 75 | 76 | // Start processing the next available incoming packet 77 | // Returns the size of the packet in bytes, or 0 if no packets are available 78 | virtual int parsePacket(); 79 | // Number of bytes remaining in the current packet 80 | virtual int available(); 81 | // Read a single byte from the current packet 82 | virtual int read(); 83 | // Read up to len bytes from the current packet and place them into buffer 84 | // Returns the number of bytes read, or 0 if none are available 85 | virtual int read(unsigned char* buffer, size_t len); 86 | // Read up to len characters from the current packet and place them into buffer 87 | // Returns the number of characters read, or 0 if none are available 88 | virtual int read(char* buffer, size_t len) { 89 | return read((unsigned char*)buffer, len); 90 | }; 91 | // Return the next byte from the current packet without moving on to the next byte 92 | virtual int peek(); 93 | virtual void flush(); // Finish reading the current packet 94 | 95 | // Return the IP address of the host who sent the current incoming packet 96 | virtual IPAddress remoteIP(); 97 | // // Return the port of the host who sent the current incoming packet 98 | virtual uint16_t remotePort(); 99 | 100 | friend class MbedSocketClass; 101 | }; 102 | 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /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.cpp: -------------------------------------------------------------------------------- 1 | #include "MbedUdp.h" 2 | 3 | arduino::MbedUDP::MbedUDP() { 4 | _packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE]; 5 | _current_packet = NULL; 6 | _current_packet_size = 0; 7 | // if this allocation fails then ::begin will fail 8 | } 9 | 10 | arduino::MbedUDP::~MbedUDP() { 11 | delete[] _packet_buffer; 12 | } 13 | 14 | uint8_t arduino::MbedUDP::begin(uint16_t port) { 15 | // success = 1, fail = 0 16 | 17 | nsapi_error_t rt = _socket.open(getNetwork()); 18 | if (rt != NSAPI_ERROR_OK) { 19 | return 0; 20 | } 21 | 22 | if (_socket.bind(port) < 0) { 23 | return 0; //Failed to bind UDP Socket to port 24 | } 25 | 26 | if (!_packet_buffer) { 27 | return 0; 28 | } 29 | 30 | _socket.set_blocking(false); 31 | _socket.set_timeout(0); 32 | 33 | return 1; 34 | } 35 | 36 | uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) { 37 | // success = 1, fail = 0 38 | if (begin(port) != 1) { 39 | return 0; 40 | } 41 | 42 | SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port); 43 | 44 | if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) { 45 | printf("Error joining the multicast group\n"); 46 | return 0; 47 | } 48 | 49 | return 1; 50 | } 51 | 52 | void arduino::MbedUDP::stop() { 53 | _socket.close(); 54 | } 55 | 56 | int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) { 57 | _host = SocketHelpers::socketAddressFromIpAddress(ip, port); 58 | //If IP is null and port is 0 the initialization failed 59 | txBuffer.clear(); 60 | return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1; 61 | } 62 | 63 | int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) { 64 | _host = SocketAddress(host, port); 65 | txBuffer.clear(); 66 | getNetwork()->gethostbyname(host, &_host); 67 | //If IP is null and port is 0 the initialization failed 68 | return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1; 69 | } 70 | 71 | int arduino::MbedUDP::endPacket() { 72 | _socket.set_blocking(true); 73 | _socket.set_timeout(1000); 74 | 75 | size_t size = txBuffer.available(); 76 | uint8_t buffer[size]; 77 | for (int i = 0; i < size; i++) { 78 | buffer[i] = txBuffer.read_char(); 79 | } 80 | 81 | nsapi_size_or_error_t ret = _socket.sendto(_host, buffer, size); 82 | _socket.set_blocking(false); 83 | _socket.set_timeout(0); 84 | if (ret < 0) { 85 | return 0; 86 | } 87 | return size; 88 | } 89 | 90 | // Write a single byte into the packet 91 | size_t arduino::MbedUDP::write(uint8_t byte) { 92 | return write(&byte, 1); 93 | } 94 | 95 | // Write size bytes from buffer into the packet 96 | size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size) { 97 | for (int i = 0; i _packet_buffer + _current_packet_size) { 146 | // try reading the next packet... 147 | if (parsePacket() > 0) { 148 | // if so, read first byte of next packet; 149 | return read(); 150 | } else { 151 | // no new data... not sure what to return here now 152 | return -1; 153 | } 154 | } 155 | 156 | return _current_packet[0]; 157 | } 158 | 159 | // Read up to len bytes from the current packet and place them into buffer 160 | // Returns the number of bytes read, or 0 if none are available 161 | int arduino::MbedUDP::read(unsigned char *buffer, size_t len) { 162 | // Q: does Arduino read() function handle fragmentation? I won't for now... 163 | if (_current_packet == NULL) { 164 | if (parsePacket() == 0) return 0; 165 | } 166 | 167 | // how much data do we have in the current packet? 168 | int offset = _current_packet - _packet_buffer; 169 | if (offset < 0) { 170 | return 0; 171 | } 172 | 173 | int max_bytes = _current_packet_size - offset; 174 | if (max_bytes < 0) { 175 | return 0; 176 | } 177 | 178 | // at the end of the packet? 179 | if (max_bytes == 0) { 180 | // try read next packet... 181 | if (parsePacket() > 0) { 182 | return read(buffer, len); 183 | } else { 184 | return 0; 185 | } 186 | } 187 | 188 | if (len > (size_t)max_bytes) len = max_bytes; 189 | 190 | // copy to target buffer 191 | memcpy(buffer, _current_packet, len); 192 | 193 | _current_packet += len; 194 | 195 | return len; 196 | } 197 | 198 | IPAddress arduino::MbedUDP::remoteIP() { 199 | nsapi_addr_t address = _remoteHost.get_addr(); 200 | return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]); 201 | } 202 | 203 | uint16_t arduino::MbedUDP::remotePort() { 204 | return _remoteHost.get_port(); 205 | } 206 | 207 | void arduino::MbedUDP::flush() { 208 | // TODO: a real check to ensure transmission has been completed 209 | } 210 | 211 | int arduino::MbedUDP::peek() { 212 | if (_current_packet_size < 1) { 213 | return -1; 214 | } 215 | 216 | return _current_packet[0]; 217 | } 218 | -------------------------------------------------------------------------------- /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 | class MbedUDP : public UDP { 34 | private: 35 | UDPSocket _socket; // Mbed OS socket 36 | SocketAddress _host; // Host to be used to send data 37 | SocketAddress _remoteHost; // Remote host that sent incoming packets 38 | 39 | uint8_t* _packet_buffer; // Raw packet buffer (contains data we got from the UDPSocket) 40 | 41 | // The Arduino APIs allow you to iterate through this buffer, so we need to be able to iterate over the current packet 42 | // these two variables are used to cache the state of the current packet 43 | uint8_t* _current_packet; 44 | size_t _current_packet_size; 45 | 46 | RingBufferN txBuffer; 47 | 48 | protected: 49 | virtual NetworkInterface* getNetwork() = 0; 50 | 51 | public: 52 | MbedUDP(); // Constructor 53 | ~MbedUDP(); 54 | virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 55 | virtual uint8_t beginMulticast(IPAddress, 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 56 | virtual void stop(); // Finish with the UDP socket 57 | 58 | // Sending UDP packets 59 | 60 | // Start building up a packet to send to the remote host specific in ip and port 61 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 62 | virtual int beginPacket(IPAddress ip, uint16_t port); 63 | // Start building up a packet to send to the remote host specific in host and port 64 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 65 | virtual int beginPacket(const char* host, uint16_t port); 66 | // Finish off this packet and send it 67 | // Returns 1 if the packet was sent successfully, 0 if there was an error 68 | virtual int endPacket(); 69 | // Write a single byte into the packet 70 | virtual size_t write(uint8_t); 71 | // Write size bytes from buffer into the packet 72 | virtual size_t write(const uint8_t* buffer, size_t size); 73 | 74 | using Print::write; 75 | 76 | // Start processing the next available incoming packet 77 | // Returns the size of the packet in bytes, or 0 if no packets are available 78 | virtual int parsePacket(); 79 | // Number of bytes remaining in the current packet 80 | virtual int available(); 81 | // Read a single byte from the current packet 82 | virtual int read(); 83 | // Read up to len bytes from the current packet and place them into buffer 84 | // Returns the number of bytes read, or 0 if none are available 85 | virtual int read(unsigned char* buffer, size_t len); 86 | // Read up to len characters from the current packet and place them into buffer 87 | // Returns the number of characters read, or 0 if none are available 88 | virtual int read(char* buffer, size_t len) { 89 | return read((unsigned char*)buffer, len); 90 | }; 91 | // Return the next byte from the current packet without moving on to the next byte 92 | virtual int peek(); 93 | virtual void flush(); // Finish reading the current packet 94 | 95 | // Return the IP address of the host who sent the current incoming packet 96 | virtual IPAddress remoteIP(); 97 | // // Return the port of the host who sent the current incoming packet 98 | virtual uint16_t remotePort(); 99 | 100 | friend class MbedSocketClass; 101 | }; 102 | 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Portenta_H7_AsyncWebServer 2 | 3 | [![arduino-library-badge](https://www.ardu-badge.com/badge/Portenta_H7_AsyncWebServer.svg?)](https://www.ardu-badge.com/Portenta_H7_AsyncWebServer) 4 | [![GitHub release](https://img.shields.io/github/release/khoih-prog/Portenta_H7_AsyncWebServer.svg)](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/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/Portenta_H7_AsyncWebServer.svg)](http://github.com/khoih-prog/Portenta_H7_AsyncWebServer/issues) 7 | 8 | Donate to my libraries using BuyMeACoffee 9 | 10 | 11 | --- 12 | --- 13 | 14 | ## Table of Contents 15 | 16 | * [Changelog](#changelog) 17 | * [Release v1.5.0](#Release-v150) 18 | * [Release v1.4.2](#Release-v142) 19 | * [Releases v1.4.1](#Releases-v141) 20 | * [Releases v1.4.0](#Releases-v140) 21 | * [Releases v1.3.0](#Releases-v130) 22 | * [Releases v1.2.1](#Releases-v121) 23 | * [Releases v1.2.0](#Releases-v120) 24 | * [Releases v1.1.1](#Releases-v111) 25 | * [Releases v1.1.0](#Releases-v110) 26 | * [Initial Releases v1.0.0](#Initial-Releases-v100) 27 | 28 | --- 29 | --- 30 | 31 | ## Changelog 32 | 33 | #### Release v1.5.0 34 | 35 | 1. Fix `_catchAllHandler` not working bug. Check [catchAll handler not working #12](https://github.com/khoih-prog/AsyncWebServer_RP2040W/issues/12) 36 | 2. Improve `README.md` so that links can be used in other sites, such as `PIO` 37 | 38 | ### Releases v1.4.2 39 | 40 | 1. Add examples 41 | 42 | - [Async_AdvancedWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/Ethernet/Async_AdvancedWebServer_SendChunked) 43 | - [AsyncWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/Ethernet/AsyncWebServer_SendChunked) 44 | - [Async_AdvancedWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/WiFi/Async_AdvancedWebServer_SendChunked) 45 | - [AsyncWebServer_SendChunked](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/tree/main/examples/WiFi/AsyncWebServer_SendChunked) 46 | 47 | to demo how to use `beginChunkedResponse()` to send large `html` in chunks 48 | 49 | 2. Use `allman astyle` and add `utils` 50 | 3. Update `Packages_Patches` 51 | 52 | ### Releases v1.4.1 53 | 54 | 1. Don't need `memmove()`, CString no longer destroyed. Check [All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11) 55 | 56 | ### Releases v1.4.0 57 | 58 | 1. Support using `CString` in optional `SDRAM` to save heap to send `very large data`. Check [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8) 59 | 2. Add multiple examples to demo the new feature 60 | 61 | ### Releases v1.3.0 62 | 63 | 1. Fix issue with slow browsers or network. Check [Target stops responding after variable time when using Firefox on Windows 10 #3](https://github.com/khoih-prog/AsyncWebServer_RP2040W/issues/3) 64 | 65 | ### Releases v1.2.1 66 | 67 | 1. Fix authenticate issue caused by libb64 68 | 69 | ### Releases v1.2.0 70 | 71 | 1. Fix crashing issue in mbed_portenta v2.6.1+. To be used with [**Portenta_H7_AsyncTCP releases v1.3.0+**](https://github.com/khoih-prog/Portenta_H7_AsyncTCP/releases/tag/v1.3.0) 72 | 73 | ### Releases v1.1.1 74 | 75 | 1. Update `platform.ini` and `library.json` to use original `khoih-prog` instead of `khoih.prog` after PIO fix 76 | 77 | 78 | ### Releases v1.1.0 79 | 80 | 1. Add support to **Portenta_H7 boards** such as Portenta_H7 Rev2 ABX00042, etc., using [**ArduinoCore-mbed mbed_portenta** core](https://github.com/arduino/ArduinoCore-mbed) and `Murata WiFi` 81 | 82 | ### Initial Releases v1.0.0 83 | 84 | 1. Initial coding to support **Portenta_H7 boards** such as Portenta_H7 Rev2 ABX00042, etc., using [**ArduinoCore-mbed mbed_portenta** core](https://github.com/arduino/ArduinoCore-mbed) and `Vision-shield Ethernet` 85 | -------------------------------------------------------------------------------- /examples/Ethernet/Async_HelloServer/Async_HelloServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_HelloServer.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 4 18 | 19 | #define USE_ETHERNET_PORTENTA_H7 true 20 | 21 | #include 22 | #include 23 | #warning Using Portenta_Ethernet lib for Portenta_H7. 24 | 25 | #include 26 | 27 | // Enter a MAC address and IP address for your controller below. 28 | #define NUMBER_OF_MAC 20 29 | 30 | byte mac[][NUMBER_OF_MAC] = 31 | { 32 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 33 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 34 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 35 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 36 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 37 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 38 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 39 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 40 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 41 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 42 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 43 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 52 | }; 53 | // Select the IP address according to your local network 54 | IPAddress ip(192, 168, 2, 232); 55 | 56 | AsyncWebServer server(80); 57 | 58 | #define LED_OFF HIGH 59 | #define LED_ON LOW 60 | 61 | #define BUFFER_SIZE 64 62 | char temp[BUFFER_SIZE]; 63 | 64 | void handleRoot(AsyncWebServerRequest *request) 65 | { 66 | digitalWrite(LED_BUILTIN, LED_ON); 67 | 68 | snprintf(temp, BUFFER_SIZE - 1, "Hello from Async_HelloServer on %s\n", BOARD_NAME); 69 | request->send(200, "text/plain", temp); 70 | 71 | digitalWrite(LED_BUILTIN, LED_OFF); 72 | } 73 | 74 | void handleNotFound(AsyncWebServerRequest *request) 75 | { 76 | digitalWrite(LED_BUILTIN, LED_ON); 77 | 78 | String message = "File Not Found\n\n"; 79 | 80 | message += "URI: "; 81 | //message += server.uri(); 82 | message += request->url(); 83 | message += "\nMethod: "; 84 | message += (request->method() == HTTP_GET) ? "GET" : "POST"; 85 | message += "\nArguments: "; 86 | message += request->args(); 87 | message += "\n"; 88 | 89 | for (uint8_t i = 0; i < request->args(); i++) 90 | { 91 | message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; 92 | } 93 | 94 | request->send(404, "text/plain", message); 95 | digitalWrite(LED_BUILTIN, LED_OFF); 96 | } 97 | 98 | void setup() 99 | { 100 | pinMode(LED_BUILTIN, OUTPUT); 101 | digitalWrite(LED_BUILTIN, LED_OFF); 102 | 103 | Serial.begin(115200); 104 | 105 | while (!Serial && millis() < 5000); 106 | 107 | delay(200); 108 | 109 | Serial.print("\nStart Async_HelloServer on "); 110 | Serial.print(BOARD_NAME); 111 | Serial.print(" with "); 112 | Serial.println(SHIELD_TYPE); 113 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 114 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 115 | 116 | /////////////////////////////////// 117 | 118 | // start the ethernet connection and the server 119 | // Use random mac 120 | uint16_t index = millis() % NUMBER_OF_MAC; 121 | 122 | // Use Static IP 123 | //Ethernet.begin(mac[index], ip); 124 | //Ethernet.begin(ip); 125 | // Use DHCP dynamic IP and random mac 126 | //Ethernet.begin(mac[index]); 127 | Ethernet.begin(); 128 | 129 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 130 | { 131 | Serial.println("No Ethernet found. Stay here forever"); 132 | 133 | while (true) 134 | { 135 | delay(1); // do nothing, no point running without Ethernet hardware 136 | } 137 | } 138 | 139 | if (Ethernet.linkStatus() == LinkOFF) 140 | { 141 | Serial.println("Not connected Ethernet cable"); 142 | } 143 | 144 | Serial.print(F("Using mac index = ")); 145 | Serial.println(index); 146 | 147 | Serial.print(F("Connected! IP address: ")); 148 | Serial.println(Ethernet.localIP()); 149 | 150 | /////////////////////////////////// 151 | 152 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 153 | { 154 | handleRoot(request); 155 | }); 156 | 157 | server.on("/inline", [](AsyncWebServerRequest * request) 158 | { 159 | request->send(200, "text/plain", "This works as well"); 160 | }); 161 | 162 | server.onNotFound(handleNotFound); 163 | 164 | server.begin(); 165 | 166 | Serial.print(F("HTTP EthernetWebServer is @ IP : ")); 167 | Serial.println(Ethernet.localIP()); 168 | } 169 | 170 | void heartBeatPrint() 171 | { 172 | static int num = 1; 173 | 174 | Serial.print(F(".")); 175 | 176 | if (num == 80) 177 | { 178 | Serial.println(); 179 | num = 1; 180 | } 181 | else if (num++ % 10 == 0) 182 | { 183 | Serial.print(F(" ")); 184 | } 185 | } 186 | 187 | void check_status() 188 | { 189 | static unsigned long checkstatus_timeout = 0; 190 | 191 | #define STATUS_CHECK_INTERVAL 10000L 192 | 193 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 194 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 195 | { 196 | heartBeatPrint(); 197 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 198 | } 199 | } 200 | 201 | void loop() 202 | { 203 | //check_status(); 204 | } 205 | -------------------------------------------------------------------------------- /examples/Ethernet/Async_HelloServer2/Async_HelloServer2.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_HelloServer.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 18 | 19 | #define USE_ETHERNET_PORTENTA_H7 true 20 | 21 | #include 22 | #include 23 | #warning Using Portenta_Ethernet lib for Portenta_H7. 24 | 25 | #include 26 | 27 | // Enter a MAC address and IP address for your controller below. 28 | #define NUMBER_OF_MAC 20 29 | 30 | byte mac[][NUMBER_OF_MAC] = 31 | { 32 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 33 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 34 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 35 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 36 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 37 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 38 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 39 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 40 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 41 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 42 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 43 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 52 | }; 53 | // Select the IP address according to your local network 54 | IPAddress ip(192, 168, 2, 232); 55 | 56 | AsyncWebServer server(80); 57 | 58 | #define LED_OFF HIGH 59 | #define LED_ON LOW 60 | 61 | #define BUFFER_SIZE 64 62 | char temp[BUFFER_SIZE]; 63 | 64 | void handleRoot(AsyncWebServerRequest *request) 65 | { 66 | digitalWrite(LED_BUILTIN, LED_ON); 67 | 68 | snprintf(temp, BUFFER_SIZE - 1, "Hello from Async_HelloServer2 on %s\n", BOARD_NAME); 69 | request->send(200, "text/plain", temp); 70 | 71 | digitalWrite(LED_BUILTIN, LED_OFF); 72 | } 73 | 74 | void handleNotFound(AsyncWebServerRequest *request) 75 | { 76 | digitalWrite(LED_BUILTIN, LED_ON); 77 | String message = "File Not Found\n\n"; 78 | 79 | message += "URI: "; 80 | //message += server.uri(); 81 | message += request->url(); 82 | message += "\nMethod: "; 83 | message += (request->method() == HTTP_GET) ? "GET" : "POST"; 84 | message += "\nArguments: "; 85 | message += request->args(); 86 | message += "\n"; 87 | 88 | for (uint8_t i = 0; i < request->args(); i++) 89 | { 90 | message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; 91 | } 92 | 93 | request->send(404, "text/plain", message); 94 | digitalWrite(LED_BUILTIN, LED_OFF); 95 | } 96 | 97 | void setup() 98 | { 99 | pinMode(LED_BUILTIN, OUTPUT); 100 | digitalWrite(LED_BUILTIN, LED_OFF); 101 | 102 | Serial.begin(115200); 103 | 104 | while (!Serial && millis() < 5000); 105 | 106 | delay(200); 107 | 108 | Serial.print("\nStart Async_HelloServer2 on "); 109 | Serial.print(BOARD_NAME); 110 | Serial.print(" with "); 111 | Serial.println(SHIELD_TYPE); 112 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 113 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 114 | 115 | /////////////////////////////////// 116 | 117 | // start the ethernet connection and the server 118 | // Use random mac 119 | uint16_t index = millis() % NUMBER_OF_MAC; 120 | 121 | // Use Static IP 122 | //Ethernet.begin(mac[index], ip); 123 | // Use DHCP dynamic IP and random mac 124 | Ethernet.begin(mac[index]); 125 | 126 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 127 | { 128 | Serial.println("No Ethernet found. Stay here forever"); 129 | 130 | while (true) 131 | { 132 | delay(1); // do nothing, no point running without Ethernet hardware 133 | } 134 | } 135 | 136 | if (Ethernet.linkStatus() == LinkOFF) 137 | { 138 | Serial.println("Not connected Ethernet cable"); 139 | } 140 | 141 | Serial.print(F("Using mac index = ")); 142 | Serial.println(index); 143 | 144 | Serial.print(F("Connected! IP address: ")); 145 | Serial.println(Ethernet.localIP()); 146 | 147 | /////////////////////////////////// 148 | 149 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 150 | { 151 | handleRoot(request); 152 | }); 153 | 154 | server.on("/inline", [](AsyncWebServerRequest * request) 155 | { 156 | request->send(200, "text/plain", "This works as well"); 157 | }); 158 | 159 | server.on("/gif", [](AsyncWebServerRequest * request) 160 | { 161 | static const uint8_t gif[] = 162 | { 163 | 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01, 164 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00, 165 | 0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d, 166 | 0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c, 167 | 0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b 168 | }; 169 | 170 | char gif_colored[sizeof(gif)]; 171 | 172 | memcpy(gif_colored, gif, sizeof(gif)); 173 | 174 | // Set the background to a random set of colors 175 | gif_colored[16] = millis() % 256; 176 | gif_colored[17] = millis() % 256; 177 | gif_colored[18] = millis() % 256; 178 | 179 | request->send(200, (char *) "image/gif", gif_colored); 180 | }); 181 | 182 | server.onNotFound(handleNotFound); 183 | 184 | server.begin(); 185 | 186 | Serial.print("HTTP EthernetWebServer started @ IP : "); 187 | Serial.println(Ethernet.localIP()); 188 | } 189 | 190 | void heartBeatPrint() 191 | { 192 | static int num = 1; 193 | 194 | Serial.print(F(".")); 195 | 196 | if (num == 80) 197 | { 198 | Serial.println(); 199 | num = 1; 200 | } 201 | else if (num++ % 10 == 0) 202 | { 203 | Serial.print(F(" ")); 204 | } 205 | } 206 | 207 | void check_status() 208 | { 209 | static unsigned long checkstatus_timeout = 0; 210 | 211 | #define STATUS_CHECK_INTERVAL 10000L 212 | 213 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 214 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 215 | { 216 | heartBeatPrint(); 217 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 218 | } 219 | } 220 | 221 | void loop() 222 | { 223 | check_status(); 224 | } 225 | -------------------------------------------------------------------------------- /examples/Ethernet/Async_HttpBasicAuth/Async_HttpBasicAuth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_HttpBasicAuth.ino - Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 18 | 19 | #define USE_ETHERNET_PORTENTA_H7 true 20 | 21 | #include 22 | #include 23 | #warning Using Portenta_Ethernet lib for Portenta_H7. 24 | 25 | #include 26 | 27 | // Enter a MAC address and IP address for your controller below. 28 | #define NUMBER_OF_MAC 20 29 | 30 | byte mac[][NUMBER_OF_MAC] = 31 | { 32 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 33 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 34 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 35 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 36 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 37 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 38 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 39 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 40 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 41 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 42 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 43 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 52 | }; 53 | // Select the IP address according to your local network 54 | IPAddress ip(192, 168, 2, 232); 55 | 56 | AsyncWebServer server(80); 57 | 58 | const char* www_username = "admin"; 59 | const char* www_password = "portenta"; 60 | 61 | void setup() 62 | { 63 | Serial.begin(115200); 64 | 65 | while (!Serial && millis() < 5000); 66 | 67 | delay(200); 68 | 69 | Serial.print("\nStart Async_HTTPBasicAuth on "); 70 | Serial.print(BOARD_NAME); 71 | Serial.print(" with "); 72 | Serial.println(SHIELD_TYPE); 73 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 74 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 75 | 76 | /////////////////////////////////// 77 | 78 | // start the ethernet connection and the server 79 | // Use random mac 80 | uint16_t index = millis() % NUMBER_OF_MAC; 81 | 82 | // Use Static IP 83 | //Ethernet.begin(mac[index], ip); 84 | // Use DHCP dynamic IP and random mac 85 | Ethernet.begin(mac[index]); 86 | 87 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 88 | { 89 | Serial.println("No Ethernet found. Stay here forever"); 90 | 91 | while (true) 92 | { 93 | delay(1); // do nothing, no point running without Ethernet hardware 94 | } 95 | } 96 | 97 | if (Ethernet.linkStatus() == LinkOFF) 98 | { 99 | Serial.println("Not connected Ethernet cable"); 100 | } 101 | 102 | Serial.print(F("Using mac index = ")); 103 | Serial.println(index); 104 | 105 | Serial.print(F("Connected! IP address: ")); 106 | Serial.println(Ethernet.localIP()); 107 | 108 | /////////////////////////////////// 109 | 110 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 111 | { 112 | if (!request->authenticate(www_username, www_password)) 113 | { 114 | return request->requestAuthentication(); 115 | } 116 | 117 | request->send(200, "text/plain", "Login OK"); 118 | }); 119 | 120 | 121 | server.begin(); 122 | 123 | Serial.print(F("Async_HttpBasicAuth started @ IP : ")); 124 | Serial.println(Ethernet.localIP()); 125 | 126 | Serial.print(F("Open http://")); 127 | Serial.print(Ethernet.localIP()); 128 | Serial.println(F("/ in your browser to see it working")); 129 | 130 | Serial.print(F("Login using username = ")); 131 | Serial.print(www_username); 132 | Serial.print(F(" and password = ")); 133 | Serial.println(www_password); 134 | } 135 | 136 | void heartBeatPrint() 137 | { 138 | static int num = 1; 139 | 140 | Serial.print(F(".")); 141 | 142 | if (num == 80) 143 | { 144 | Serial.println(); 145 | num = 1; 146 | } 147 | else if (num++ % 10 == 0) 148 | { 149 | Serial.print(F(" ")); 150 | } 151 | } 152 | 153 | void check_status() 154 | { 155 | static unsigned long checkstatus_timeout = 0; 156 | 157 | #define STATUS_CHECK_INTERVAL 10000L 158 | 159 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 160 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 161 | { 162 | heartBeatPrint(); 163 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 164 | } 165 | } 166 | 167 | void loop() 168 | { 169 | check_status(); 170 | } 171 | -------------------------------------------------------------------------------- /examples/Ethernet/MQTTClient_Auth/MQTTClient_Auth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_Auth.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | /* 14 | Basic MQTT example (without SSL!) with Authentication 15 | This sketch demonstrates the basic capabilities of the library. 16 | It connects to an MQTT server then: 17 | - providing username and password 18 | - publishes "hello world" to the topic "outTopic" 19 | - subscribes to the topic "inTopic", printing out any messages 20 | it receives. NB - it assumes the received payloads are strings not binary 21 | It will reconnect to the server if the connection is lost using a blocking 22 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 23 | achieve the same result without blocking the main loop. 24 | */ 25 | 26 | // To remove boolean warnings caused by PubSubClient library 27 | #define boolean bool 28 | 29 | #include "defines.h" 30 | 31 | #include 32 | 33 | // Update these with values suitable for your network. 34 | const char* mqttServer = "broker.emqx.io"; // Broker address 35 | 36 | const char *ID = "MQTTClient_Auth"; // Name of our device, must be unique 37 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 38 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 39 | 40 | //IPAddress mqttServer(172, 16, 0, 2); 41 | 42 | void callback(char* topic, byte* payload, unsigned int length) 43 | { 44 | Serial.print("Message arrived ["); 45 | Serial.print(topic); 46 | Serial.print("] "); 47 | 48 | for (unsigned int i = 0; i < length; i++) 49 | { 50 | Serial.print((char)payload[i]); 51 | } 52 | 53 | Serial.println(); 54 | } 55 | 56 | EthernetClient ethClient; 57 | PubSubClient client(mqttServer, 1883, callback, ethClient); 58 | 59 | String data = "Hello from MQTTClient_Auth on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 60 | const char *pubData = data.c_str(); 61 | 62 | void reconnect() 63 | { 64 | // Loop until we're reconnected 65 | while (!client.connected()) 66 | { 67 | Serial.print("Attempting MQTT connection to "); 68 | Serial.print(mqttServer); 69 | 70 | // Attempt to connect 71 | if (client.connect("arduino", "try", "try")) 72 | { 73 | Serial.println("...connected"); 74 | 75 | // Once connected, publish an announcement... 76 | client.publish(TOPIC, data.c_str()); 77 | 78 | //Serial.println("Published connection message successfully!"); 79 | //Serial.print("Subcribed to: "); 80 | //Serial.println(subTopic); 81 | 82 | client.subscribe(subTopic); 83 | // for loopback testing 84 | client.subscribe(TOPIC); 85 | } 86 | else 87 | { 88 | Serial.print("...failed, rc="); 89 | Serial.print(client.state()); 90 | Serial.println(" try again in 5 seconds"); 91 | 92 | // Wait 5 seconds before retrying 93 | delay(5000); 94 | } 95 | } 96 | } 97 | 98 | void setup() 99 | { 100 | // Open serial communications and wait for port to open: 101 | Serial.begin(115200); 102 | 103 | while (!Serial && millis() < 5000); 104 | 105 | Serial.print("\nStart MQTTClient_Auth on "); 106 | Serial.print(BOARD_NAME); 107 | Serial.print(" with "); 108 | Serial.println(SHIELD_TYPE); 109 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 110 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 111 | 112 | /////////////////////////////////// 113 | 114 | // start the ethernet connection and the server 115 | // Use random mac 116 | uint16_t index = millis() % NUMBER_OF_MAC; 117 | 118 | // Use Static IP 119 | //Ethernet.begin(mac[index], ip); 120 | // Use DHCP dynamic IP and random mac 121 | Ethernet.begin(mac[index]); 122 | 123 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 124 | { 125 | Serial.println("No Ethernet found. Stay here forever"); 126 | 127 | while (true) 128 | { 129 | delay(1); // do nothing, no point running without Ethernet hardware 130 | } 131 | } 132 | 133 | if (Ethernet.linkStatus() == LinkOFF) 134 | { 135 | Serial.println("Not connected Ethernet cable"); 136 | } 137 | 138 | Serial.print(F("Using mac index = ")); 139 | Serial.println(index); 140 | 141 | Serial.print(F("Connected! IP address: ")); 142 | Serial.println(Ethernet.localIP()); 143 | 144 | /////////////////////////////////// 145 | 146 | // Note - the default maximum packet size is 128 bytes. If the 147 | // combined length of clientId, username and password exceed this use the 148 | // following to increase the buffer size: 149 | // client.setBufferSize(255); 150 | } 151 | 152 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 153 | 154 | unsigned long lastMsg = 0; 155 | 156 | void loop() 157 | { 158 | static unsigned long now; 159 | 160 | if (!client.connected()) 161 | { 162 | reconnect(); 163 | } 164 | 165 | // Sending Data 166 | now = millis(); 167 | 168 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 169 | { 170 | lastMsg = now; 171 | 172 | if (!client.publish(TOPIC, pubData)) 173 | { 174 | Serial.println("Message failed to send."); 175 | } 176 | 177 | Serial.print("Message Send : " + String(TOPIC) + " => "); 178 | Serial.println(data); 179 | } 180 | 181 | client.loop(); 182 | } 183 | -------------------------------------------------------------------------------- /examples/Ethernet/MQTTClient_Auth/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | 18 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 19 | #error For Portenta_H7 only 20 | #endif 21 | 22 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 23 | 24 | #define USE_ETHERNET_PORTENTA_H7 true 25 | 26 | #include 27 | #include 28 | #warning Using Portenta_Ethernet lib for Portenta_H7. 29 | 30 | #include 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 | // Select the IP address according to your local network 59 | IPAddress ip(192, 168, 2, 232); 60 | 61 | #endif //defines_h 62 | -------------------------------------------------------------------------------- /examples/Ethernet/MQTTClient_Basic/MQTTClient_Basic.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_Basic.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | /* 14 | Basic MQTT example (without SSL!) with Authentication 15 | This sketch demonstrates the basic capabilities of the library. 16 | It connects to an MQTT server then: 17 | - providing username and password 18 | - publishes "hello world" to the topic "outTopic" 19 | - subscribes to the topic "inTopic", printing out any messages 20 | it receives. NB - it assumes the received payloads are strings not binary 21 | 22 | It will reconnect to the server if the connection is lost using a blocking 23 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 24 | achieve the same result without blocking the main loop. 25 | */ 26 | 27 | // To remove boolean warnings caused by PubSubClient library 28 | #define boolean bool 29 | 30 | #include "defines.h" 31 | 32 | #include 33 | 34 | // Update these with values suitable for your network. 35 | const char* mqttServer = "broker.emqx.io"; // Broker address 36 | 37 | const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 38 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 39 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 40 | 41 | void callback(char* topic, byte* payload, unsigned int length) 42 | { 43 | Serial.print("Message arrived ["); 44 | Serial.print(topic); 45 | Serial.print("] "); 46 | 47 | for (unsigned int i = 0; i < length; i++) 48 | { 49 | Serial.print((char)payload[i]); 50 | } 51 | 52 | Serial.println(); 53 | } 54 | 55 | EthernetClient ethClient; 56 | PubSubClient client(mqttServer, 1883, callback, ethClient); 57 | 58 | String data = "Hello from MQTTClient_Basic on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 59 | const char *pubData = data.c_str(); 60 | 61 | void reconnect() 62 | { 63 | // Loop until we're reconnected 64 | while (!client.connected()) 65 | { 66 | Serial.print("Attempting MQTT connection to "); 67 | Serial.print(mqttServer); 68 | 69 | // Attempt to connect 70 | if (client.connect(ID, "try", "try")) 71 | { 72 | Serial.println("...connected"); 73 | 74 | // Once connected, publish an announcement... 75 | client.publish(TOPIC, data.c_str()); 76 | 77 | //Serial.println("Published connection message successfully!"); 78 | //Serial.print("Subcribed to: "); 79 | //Serial.println(subTopic); 80 | 81 | client.subscribe(subTopic); 82 | // for loopback testing 83 | client.subscribe(TOPIC); 84 | } 85 | else 86 | { 87 | Serial.print("...failed, rc="); 88 | Serial.print(client.state()); 89 | Serial.println(" try again in 5 seconds"); 90 | 91 | // Wait 5 seconds before retrying 92 | delay(5000); 93 | } 94 | } 95 | } 96 | 97 | void setup() 98 | { 99 | // Open serial communications and wait for port to open: 100 | Serial.begin(115200); 101 | 102 | while (!Serial && millis() < 5000); 103 | 104 | Serial.print("\nStart MQTTClient_Basic on "); 105 | Serial.print(BOARD_NAME); 106 | Serial.print(" with "); 107 | Serial.println(SHIELD_TYPE); 108 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 109 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 110 | 111 | /////////////////////////////////// 112 | 113 | // start the ethernet connection and the server 114 | // Use random mac 115 | uint16_t index = millis() % NUMBER_OF_MAC; 116 | 117 | // Use Static IP 118 | //Ethernet.begin(mac[index], ip); 119 | // Use DHCP dynamic IP and random mac 120 | Ethernet.begin(mac[index]); 121 | 122 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 123 | { 124 | Serial.println("No Ethernet found. Stay here forever"); 125 | 126 | while (true) 127 | { 128 | delay(1); // do nothing, no point running without Ethernet hardware 129 | } 130 | } 131 | 132 | if (Ethernet.linkStatus() == LinkOFF) 133 | { 134 | Serial.println("Not connected Ethernet cable"); 135 | } 136 | 137 | Serial.print(F("Using mac index = ")); 138 | Serial.println(index); 139 | 140 | Serial.print(F("Connected! IP address: ")); 141 | Serial.println(Ethernet.localIP()); 142 | 143 | /////////////////////////////////// 144 | 145 | client.setServer(mqttServer, 1883); 146 | client.setCallback(callback); 147 | 148 | // Allow the hardware to sort itself out 149 | delay(1500); 150 | } 151 | 152 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 153 | 154 | unsigned long lastMsg = 0; 155 | 156 | void loop() 157 | { 158 | static unsigned long now; 159 | 160 | if (!client.connected()) 161 | { 162 | reconnect(); 163 | } 164 | 165 | // Sending Data 166 | now = millis(); 167 | 168 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 169 | { 170 | lastMsg = now; 171 | 172 | if (!client.publish(TOPIC, pubData)) 173 | { 174 | Serial.println("Message failed to send."); 175 | } 176 | 177 | Serial.print("Message Send : " + String(TOPIC) + " => "); 178 | Serial.println(data); 179 | } 180 | 181 | client.loop(); 182 | } 183 | -------------------------------------------------------------------------------- /examples/Ethernet/MQTTClient_Basic/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | 18 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 19 | #error For Portenta_H7 only 20 | #endif 21 | 22 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 23 | 24 | #define USE_ETHERNET_PORTENTA_H7 true 25 | 26 | #include 27 | #include 28 | #warning Using Portenta_Ethernet lib for Portenta_H7. 29 | 30 | #include 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 | // Select the IP address according to your local network 59 | IPAddress ip(192, 168, 2, 232); 60 | 61 | #endif //defines_h 62 | -------------------------------------------------------------------------------- /examples/Ethernet/MQTT_ThingStream/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet 5 | 6 | For STM32 with LAN8720 (STM32F4/F7) or built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc) 7 | 8 | AsyncWebServer_STM32 is a library for the STM32 with LAN8720 or built-in LAN8742A Ethernet WebServer 9 | 10 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 11 | Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_STM32 12 | Licensed under GPLv3 license 13 | *****************************************************************************************************************************/ 14 | 15 | 16 | #ifndef defines_h 17 | #define defines_h 18 | 19 | 20 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 21 | #error For Portenta_H7 only 22 | #endif 23 | 24 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 25 | 26 | #define USE_ETHERNET_PORTENTA_H7 true 27 | 28 | #include 29 | #include 30 | #warning Using Portenta_Ethernet lib for Portenta_H7. 31 | 32 | #include 33 | 34 | // Enter a MAC address and IP address for your controller below. 35 | #define NUMBER_OF_MAC 20 36 | 37 | byte mac[][NUMBER_OF_MAC] = 38 | { 39 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 40 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 41 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 42 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 43 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 56 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 57 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 58 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 59 | }; 60 | // Select the IP address according to your local network 61 | IPAddress ip(192, 168, 2, 232); 62 | 63 | #endif //defines_h 64 | -------------------------------------------------------------------------------- /examples/Ethernet/WebClient/WebClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClient.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #include "defines.h" 15 | 16 | char server[] = "arduino.cc"; 17 | 18 | // Initialize the Web client object 19 | EthernetClient client; 20 | 21 | void setup() 22 | { 23 | // Open serial communications and wait for port to open: 24 | Serial.begin(115200); 25 | 26 | while (!Serial && millis() < 5000); 27 | 28 | Serial.print("\nStart WebClient on "); 29 | Serial.print(BOARD_NAME); 30 | Serial.print(" with "); 31 | Serial.println(SHIELD_TYPE); 32 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 33 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 34 | 35 | /////////////////////////////////// 36 | 37 | // start the ethernet connection and the server 38 | // Use random mac 39 | uint16_t index = millis() % NUMBER_OF_MAC; 40 | 41 | // Use Static IP 42 | //Ethernet.begin(mac[index], ip); 43 | // Use DHCP dynamic IP and random mac 44 | Ethernet.begin(mac[index]); 45 | 46 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 47 | { 48 | Serial.println("No Ethernet found. Stay here forever"); 49 | 50 | while (true) 51 | { 52 | delay(1); // do nothing, no point running without Ethernet hardware 53 | } 54 | } 55 | 56 | if (Ethernet.linkStatus() == LinkOFF) 57 | { 58 | Serial.println("Not connected Ethernet cable"); 59 | } 60 | 61 | Serial.print(F("Using mac index = ")); 62 | Serial.println(index); 63 | 64 | Serial.print(F("Connected! IP address: ")); 65 | Serial.println(Ethernet.localIP()); 66 | 67 | /////////////////////////////////// 68 | 69 | Serial.println(); 70 | Serial.println(F("Starting connection to server...")); 71 | 72 | // if you get a connection, report back via serial 73 | if (client.connect(server, 80)) 74 | { 75 | Serial.println(F("Connected to server")); 76 | // Make a HTTP request 77 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 78 | client.println(F("Host: arduino.cc")); 79 | client.println(F("Connection: close")); 80 | client.println(); 81 | } 82 | } 83 | 84 | void printoutData(void) 85 | { 86 | // if there are incoming bytes available 87 | // from the server, read them and print them 88 | while (client.available()) 89 | { 90 | char c = client.read(); 91 | Serial.write(c); 92 | } 93 | } 94 | 95 | void loop() 96 | { 97 | printoutData(); 98 | 99 | // if the server's disconnected, stop the client 100 | if (!client.connected()) 101 | { 102 | Serial.println(); 103 | Serial.println(F("Disconnecting from server...")); 104 | client.stop(); 105 | 106 | // do nothing forevermore 107 | while (true); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /examples/Ethernet/WebClient/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 18 | #error For Portenta_H7 only 19 | #endif 20 | 21 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 22 | 23 | #define USE_WIFI_PORTENTA_H7 true 24 | 25 | #include 26 | #include 27 | #warning Using Portenta_Ethernet lib for Portenta_H7. 28 | 29 | #include 30 | 31 | // Enter a MAC address and IP address for your controller below. 32 | #define NUMBER_OF_MAC 20 33 | 34 | byte mac[][NUMBER_OF_MAC] = 35 | { 36 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 }, 37 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 }, 38 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 }, 39 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 }, 40 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 }, 41 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 }, 42 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 }, 43 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 }, 44 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 }, 45 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A }, 46 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B }, 47 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C }, 48 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D }, 49 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E }, 50 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F }, 51 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 }, 52 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 }, 53 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 }, 54 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 }, 55 | { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 }, 56 | }; 57 | // Select the IP address according to your local network 58 | IPAddress ip(192, 168, 2, 232); 59 | 60 | #endif //defines_h 61 | -------------------------------------------------------------------------------- /examples/Ethernet/WebClientRepeating/WebClientRepeating.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClientRepeating.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #include "defines.h" 14 | 15 | char server[] = "arduino.cc"; 16 | 17 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 18 | const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds 19 | 20 | // Initialize the Web client object 21 | EthernetClient client; 22 | 23 | // this method makes a HTTP connection to the server 24 | void httpRequest() 25 | { 26 | Serial.println(); 27 | 28 | // close any connection before send a new request 29 | // this will free the socket on the WiFi shield 30 | client.stop(); 31 | 32 | // if there's a successful connection 33 | if (client.connect(server, 80)) 34 | { 35 | Serial.println(F("Connecting...")); 36 | 37 | // send the HTTP PUT request 38 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 39 | client.println(F("Host: arduino.cc")); 40 | client.println(F("Connection: close")); 41 | client.println(); 42 | 43 | // note the time that the connection was made 44 | lastConnectionTime = millis(); 45 | } 46 | else 47 | { 48 | // if you couldn't make a connection 49 | Serial.println(F("Connection failed")); 50 | } 51 | } 52 | 53 | void setup() 54 | { 55 | // Open serial communications and wait for port to open: 56 | Serial.begin(115200); 57 | 58 | while (!Serial && millis() < 5000); 59 | 60 | Serial.print("\nStart WebClientRepeating on "); 61 | Serial.print(BOARD_NAME); 62 | Serial.print(" with "); 63 | Serial.println(SHIELD_TYPE); 64 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 65 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 66 | 67 | /////////////////////////////////// 68 | 69 | // start the ethernet connection and the server 70 | // Use random mac 71 | uint16_t index = millis() % NUMBER_OF_MAC; 72 | 73 | // Use Static IP 74 | //Ethernet.begin(mac[index], ip); 75 | // Use DHCP dynamic IP and random mac 76 | Ethernet.begin(mac[index]); 77 | 78 | if (Ethernet.hardwareStatus() == EthernetNoHardware) 79 | { 80 | Serial.println("No Ethernet found. Stay here forever"); 81 | 82 | while (true) 83 | { 84 | delay(1); // do nothing, no point running without Ethernet hardware 85 | } 86 | } 87 | 88 | if (Ethernet.linkStatus() == LinkOFF) 89 | { 90 | Serial.println("Not connected Ethernet cable"); 91 | } 92 | 93 | Serial.print(F("Using mac index = ")); 94 | Serial.println(index); 95 | 96 | Serial.print(F("Connected! IP address: ")); 97 | Serial.println(Ethernet.localIP()); 98 | 99 | /////////////////////////////////// 100 | } 101 | 102 | void loop() 103 | { 104 | // if there's incoming data from the net connection send it out the serial port 105 | // this is for debugging purposes only 106 | while (client.available()) 107 | { 108 | char c = client.read(); 109 | Serial.write(c); 110 | } 111 | 112 | // if 10 seconds have passed since your last connection, 113 | // then connect again and send data 114 | if (millis() - lastConnectionTime > postingInterval) 115 | { 116 | httpRequest(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /examples/Ethernet/WebClientRepeating/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | 18 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 19 | #error For Portenta_H7 only 20 | #endif 21 | 22 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 23 | 24 | #define USE_WIFI_PORTENTA_H7 true 25 | 26 | #include 27 | #include 28 | #warning Using Portenta_Ethernet lib for Portenta_H7. 29 | 30 | #include 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 | // Select the IP address according to your local network 59 | IPAddress ip(192, 168, 2, 232); 60 | 61 | #endif //defines_h 62 | -------------------------------------------------------------------------------- /examples/WiFi/Async_HelloServer/Async_HelloServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_HelloServer.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define USE_WIFI_PORTENTA_H7 true 18 | 19 | #include 20 | #warning Using WiFi for Portenta_H7. 21 | 22 | #include 23 | 24 | char ssid[] = "your_ssid"; // your network SSID (name) 25 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 26 | 27 | int status = WL_IDLE_STATUS; 28 | 29 | AsyncWebServer server(80); 30 | 31 | #define LED_OFF HIGH 32 | #define LED_ON LOW 33 | 34 | #define BUFFER_SIZE 64 35 | char temp[BUFFER_SIZE]; 36 | 37 | void handleRoot(AsyncWebServerRequest *request) 38 | { 39 | digitalWrite(LED_BUILTIN, LED_ON); 40 | 41 | snprintf(temp, BUFFER_SIZE - 1, "Hello from Async_HelloServer on %s\n", BOARD_NAME); 42 | 43 | request->send(200, "text/plain", temp); 44 | 45 | digitalWrite(LED_BUILTIN, LED_OFF); 46 | } 47 | 48 | void handleNotFound(AsyncWebServerRequest *request) 49 | { 50 | digitalWrite(LED_BUILTIN, LED_ON); 51 | 52 | String message = "File Not Found\n\n"; 53 | 54 | message += "URI: "; 55 | //message += server.uri(); 56 | message += request->url(); 57 | message += "\nMethod: "; 58 | message += (request->method() == HTTP_GET) ? "GET" : "POST"; 59 | message += "\nArguments: "; 60 | message += request->args(); 61 | message += "\n"; 62 | 63 | for (uint8_t i = 0; i < request->args(); i++) 64 | { 65 | message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; 66 | } 67 | 68 | request->send(404, "text/plain", message); 69 | digitalWrite(LED_BUILTIN, LED_OFF); 70 | } 71 | 72 | void printWifiStatus() 73 | { 74 | // print the SSID of the network you're attached to: 75 | Serial.print("SSID: "); 76 | Serial.println(WiFi.SSID()); 77 | 78 | // print your board's IP address: 79 | IPAddress ip = WiFi.localIP(); 80 | Serial.print("Local IP Address: "); 81 | Serial.println(ip); 82 | 83 | // print the received signal strength: 84 | long rssi = WiFi.RSSI(); 85 | Serial.print("signal strength (RSSI):"); 86 | Serial.print(rssi); 87 | Serial.println(" dBm"); 88 | } 89 | 90 | void setup() 91 | { 92 | pinMode(LED_BUILTIN, OUTPUT); 93 | digitalWrite(LED_BUILTIN, LED_OFF); 94 | 95 | Serial.begin(115200); 96 | 97 | while (!Serial && millis() < 5000); 98 | 99 | delay(200); 100 | 101 | Serial.print("\nStart Async_HelloServer on "); 102 | Serial.print(BOARD_NAME); 103 | Serial.print(" with "); 104 | Serial.println(SHIELD_TYPE); 105 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 106 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 107 | 108 | /////////////////////////////////// 109 | 110 | // check for the WiFi module: 111 | if (WiFi.status() == WL_NO_MODULE) 112 | { 113 | Serial.println("Communication with WiFi module failed!"); 114 | 115 | // don't continue 116 | while (true); 117 | } 118 | 119 | Serial.print(F("Connecting to SSID: ")); 120 | Serial.println(ssid); 121 | 122 | status = WiFi.begin(ssid, pass); 123 | 124 | delay(1000); 125 | 126 | // attempt to connect to WiFi network 127 | while ( status != WL_CONNECTED) 128 | { 129 | delay(500); 130 | 131 | // Connect to WPA/WPA2 network 132 | status = WiFi.status(); 133 | } 134 | 135 | printWifiStatus(); 136 | 137 | /////////////////////////////////// 138 | 139 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 140 | { 141 | handleRoot(request); 142 | }); 143 | 144 | server.on("/inline", [](AsyncWebServerRequest * request) 145 | { 146 | request->send(200, "text/plain", "This works as well"); 147 | }); 148 | 149 | server.onNotFound(handleNotFound); 150 | 151 | server.begin(); 152 | 153 | Serial.print(F("HTTP EthernetWebServer is @ IP : ")); 154 | Serial.println(WiFi.localIP()); 155 | } 156 | 157 | void heartBeatPrint() 158 | { 159 | static int num = 1; 160 | 161 | Serial.print(F(".")); 162 | 163 | if (num == 80) 164 | { 165 | Serial.println(); 166 | num = 1; 167 | } 168 | else if (num++ % 10 == 0) 169 | { 170 | Serial.print(F(" ")); 171 | } 172 | } 173 | 174 | void check_status() 175 | { 176 | static unsigned long checkstatus_timeout = 0; 177 | 178 | #define STATUS_CHECK_INTERVAL 10000L 179 | 180 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 181 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 182 | { 183 | heartBeatPrint(); 184 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 185 | } 186 | } 187 | 188 | void loop() 189 | { 190 | check_status(); 191 | } 192 | -------------------------------------------------------------------------------- /examples/WiFi/Async_HelloServer2/Async_HelloServer2.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_HelloServer.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define USE_WIFI_PORTENTA_H7 true 18 | 19 | #include 20 | #warning Using WiFi for Portenta_H7. 21 | 22 | #include 23 | 24 | char ssid[] = "your_ssid"; // your network SSID (name) 25 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 26 | 27 | int status = WL_IDLE_STATUS; 28 | 29 | AsyncWebServer server(80); 30 | 31 | #define LED_OFF HIGH 32 | #define LED_ON LOW 33 | 34 | #define BUFFER_SIZE 64 35 | char temp[BUFFER_SIZE]; 36 | 37 | void handleRoot(AsyncWebServerRequest *request) 38 | { 39 | digitalWrite(LED_BUILTIN, LED_ON); 40 | 41 | snprintf(temp, BUFFER_SIZE - 1, "Hello from Async_HelloServer2 on %s\n", BOARD_NAME); 42 | request->send(200, "text/plain", temp); 43 | 44 | digitalWrite(LED_BUILTIN, LED_OFF); 45 | } 46 | 47 | void handleNotFound(AsyncWebServerRequest *request) 48 | { 49 | digitalWrite(LED_BUILTIN, LED_ON); 50 | String message = "File Not Found\n\n"; 51 | 52 | message += "URI: "; 53 | //message += server.uri(); 54 | message += request->url(); 55 | message += "\nMethod: "; 56 | message += (request->method() == HTTP_GET) ? "GET" : "POST"; 57 | message += "\nArguments: "; 58 | message += request->args(); 59 | message += "\n"; 60 | 61 | for (uint8_t i = 0; i < request->args(); i++) 62 | { 63 | message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; 64 | } 65 | 66 | request->send(404, "text/plain", message); 67 | digitalWrite(LED_BUILTIN, LED_OFF); 68 | } 69 | 70 | void printWifiStatus() 71 | { 72 | // print the SSID of the network you're attached to: 73 | Serial.print("SSID: "); 74 | Serial.println(WiFi.SSID()); 75 | 76 | // print your board's IP address: 77 | IPAddress ip = WiFi.localIP(); 78 | Serial.print("Local IP Address: "); 79 | Serial.println(ip); 80 | 81 | // print the received signal strength: 82 | long rssi = WiFi.RSSI(); 83 | Serial.print("signal strength (RSSI):"); 84 | Serial.print(rssi); 85 | Serial.println(" dBm"); 86 | } 87 | 88 | void setup() 89 | { 90 | pinMode(LED_BUILTIN, OUTPUT); 91 | digitalWrite(LED_BUILTIN, LED_OFF); 92 | 93 | Serial.begin(115200); 94 | 95 | while (!Serial && millis() < 5000); 96 | 97 | delay(200); 98 | 99 | Serial.print("\nStart Async_HelloServer2 on "); 100 | Serial.print(BOARD_NAME); 101 | Serial.print(" with "); 102 | Serial.println(SHIELD_TYPE); 103 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 104 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 105 | 106 | /////////////////////////////////// 107 | 108 | // check for the WiFi module: 109 | if (WiFi.status() == WL_NO_MODULE) 110 | { 111 | Serial.println("Communication with WiFi module failed!"); 112 | 113 | // don't continue 114 | while (true); 115 | } 116 | 117 | Serial.print(F("Connecting to SSID: ")); 118 | Serial.println(ssid); 119 | 120 | status = WiFi.begin(ssid, pass); 121 | 122 | delay(1000); 123 | 124 | // attempt to connect to WiFi network 125 | while ( status != WL_CONNECTED) 126 | { 127 | delay(500); 128 | 129 | // Connect to WPA/WPA2 network 130 | status = WiFi.status(); 131 | } 132 | 133 | printWifiStatus(); 134 | 135 | /////////////////////////////////// 136 | 137 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 138 | { 139 | handleRoot(request); 140 | }); 141 | 142 | server.on("/inline", [](AsyncWebServerRequest * request) 143 | { 144 | request->send(200, "text/plain", "This works as well"); 145 | }); 146 | 147 | server.on("/gif", [](AsyncWebServerRequest * request) 148 | { 149 | static const uint8_t gif[] = 150 | { 151 | 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01, 152 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00, 153 | 0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d, 154 | 0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c, 155 | 0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b 156 | }; 157 | 158 | char gif_colored[sizeof(gif)]; 159 | 160 | memcpy(gif_colored, gif, sizeof(gif)); 161 | 162 | // Set the background to a random set of colors 163 | gif_colored[16] = millis() % 256; 164 | gif_colored[17] = millis() % 256; 165 | gif_colored[18] = millis() % 256; 166 | 167 | request->send(200, (char *) "image/gif", gif_colored); 168 | }); 169 | 170 | server.onNotFound(handleNotFound); 171 | 172 | server.begin(); 173 | 174 | Serial.print("HTTP Async_HelloServer2 started @ IP : "); 175 | Serial.println(WiFi.localIP()); 176 | } 177 | 178 | void heartBeatPrint() 179 | { 180 | static int num = 1; 181 | 182 | Serial.print(F(".")); 183 | 184 | if (num == 80) 185 | { 186 | Serial.println(); 187 | num = 1; 188 | } 189 | else if (num++ % 10 == 0) 190 | { 191 | Serial.print(F(" ")); 192 | } 193 | } 194 | 195 | void check_status() 196 | { 197 | static unsigned long checkstatus_timeout = 0; 198 | 199 | #define STATUS_CHECK_INTERVAL 10000L 200 | 201 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 202 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 203 | { 204 | heartBeatPrint(); 205 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 206 | } 207 | } 208 | 209 | void loop() 210 | { 211 | check_status(); 212 | } 213 | -------------------------------------------------------------------------------- /examples/WiFi/Async_HttpBasicAuth/Async_HttpBasicAuth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_HttpBasicAuth.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define USE_WIFI_PORTENTA_H7 true 18 | 19 | #include 20 | #warning Using WiFi for Portenta_H7. 21 | 22 | #include 23 | 24 | char ssid[] = "your_ssid"; // your network SSID (name) 25 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 26 | 27 | int status = WL_IDLE_STATUS; 28 | 29 | AsyncWebServer server(80); 30 | 31 | const char* www_username = "admin"; 32 | const char* www_password = "portenta"; 33 | 34 | void printWifiStatus() 35 | { 36 | // print the SSID of the network you're attached to: 37 | Serial.print("SSID: "); 38 | Serial.println(WiFi.SSID()); 39 | 40 | // print your board's IP address: 41 | IPAddress ip = WiFi.localIP(); 42 | Serial.print("Local IP Address: "); 43 | Serial.println(ip); 44 | 45 | // print the received signal strength: 46 | long rssi = WiFi.RSSI(); 47 | Serial.print("signal strength (RSSI):"); 48 | Serial.print(rssi); 49 | Serial.println(" dBm"); 50 | } 51 | 52 | void setup() 53 | { 54 | Serial.begin(115200); 55 | 56 | while (!Serial && millis() < 5000); 57 | 58 | delay(200); 59 | 60 | Serial.print("\nStart Async_HTTPBasicAuth on "); 61 | Serial.print(BOARD_NAME); 62 | Serial.print(" with "); 63 | Serial.println(SHIELD_TYPE); 64 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 65 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 66 | 67 | /////////////////////////////////// 68 | 69 | // check for the WiFi module: 70 | if (WiFi.status() == WL_NO_MODULE) 71 | { 72 | Serial.println("Communication with WiFi module failed!"); 73 | 74 | // don't continue 75 | while (true); 76 | } 77 | 78 | Serial.print(F("Connecting to SSID: ")); 79 | Serial.println(ssid); 80 | 81 | status = WiFi.begin(ssid, pass); 82 | 83 | delay(1000); 84 | 85 | // attempt to connect to WiFi network 86 | while ( status != WL_CONNECTED) 87 | { 88 | delay(500); 89 | 90 | // Connect to WPA/WPA2 network 91 | status = WiFi.status(); 92 | } 93 | 94 | printWifiStatus(); 95 | 96 | /////////////////////////////////// 97 | 98 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 99 | { 100 | if (!request->authenticate(www_username, www_password)) 101 | { 102 | return request->requestAuthentication(); 103 | } 104 | 105 | request->send(200, "text/plain", "Login OK"); 106 | }); 107 | 108 | server.begin(); 109 | 110 | Serial.print(F("Async_HttpBasicAuth started @ IP : ")); 111 | Serial.println(WiFi.localIP()); 112 | 113 | Serial.print(F("Open http://")); 114 | Serial.print(WiFi.localIP()); 115 | Serial.println(F("/ in your browser to see it working")); 116 | 117 | Serial.print(F("Login using username = ")); 118 | Serial.print(www_username); 119 | Serial.print(F(" and password = ")); 120 | Serial.println(www_password); 121 | } 122 | 123 | void heartBeatPrint() 124 | { 125 | static int num = 1; 126 | 127 | Serial.print(F(".")); 128 | 129 | if (num == 80) 130 | { 131 | Serial.println(); 132 | num = 1; 133 | } 134 | else if (num++ % 10 == 0) 135 | { 136 | Serial.print(F(" ")); 137 | } 138 | } 139 | 140 | void check_status() 141 | { 142 | static unsigned long checkstatus_timeout = 0; 143 | 144 | #define STATUS_CHECK_INTERVAL 10000L 145 | 146 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 147 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 148 | { 149 | heartBeatPrint(); 150 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 151 | } 152 | } 153 | 154 | void loop() 155 | { 156 | check_status(); 157 | } 158 | -------------------------------------------------------------------------------- /examples/WiFi/Async_PostServer/Async_PostServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Async_PostServer.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 14 | #error For Portenta_H7 only 15 | #endif 16 | 17 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 18 | 19 | #define USE_WIFI_PORTENTA_H7 true 20 | 21 | #include 22 | #warning Using WiFi for Portenta_H7. 23 | 24 | #include 25 | 26 | char ssid[] = "your_ssid"; // your network SSID (name) 27 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 28 | 29 | int status = WL_IDLE_STATUS; 30 | 31 | AsyncWebServer server(80); 32 | 33 | const String postForms = 34 | "\ 35 | \ 36 | AsyncWebServer POST handling\ 37 | \ 40 | \ 41 | \ 42 |

POST plain text to /postplain/


\ 43 |
\ 44 |
\ 45 | \ 46 |
\ 47 |

POST form data to /postform/


\ 48 |
\ 49 |
\ 50 | \ 51 |
\ 52 | \ 53 | "; 54 | 55 | void handleRoot(AsyncWebServerRequest *request) 56 | { 57 | request->send(200, "text/html", postForms); 58 | } 59 | 60 | void handlePlain(AsyncWebServerRequest *request) 61 | { 62 | if (request->method() != HTTP_POST) 63 | { 64 | request->send(405, "text/plain", "Method Not Allowed"); 65 | } 66 | else 67 | { 68 | request->send(200, "text/plain", "POST body was:\n" + request->arg("plain")); 69 | } 70 | } 71 | 72 | void handleForm(AsyncWebServerRequest *request) 73 | { 74 | if (request->method() != HTTP_POST) 75 | { 76 | request->send(405, "text/plain", "Method Not Allowed"); 77 | } 78 | else 79 | { 80 | String message = "POST form was:\n"; 81 | 82 | for (uint8_t i = 0; i < request->args(); i++) 83 | { 84 | message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; 85 | } 86 | 87 | request->send(200, "text/plain", message); 88 | } 89 | } 90 | 91 | void handleNotFound(AsyncWebServerRequest *request) 92 | { 93 | String message = "File Not Found\n\n"; 94 | message += "URI: "; 95 | message += request->url(); 96 | message += "\nMethod: "; 97 | message += (request->method() == HTTP_GET) ? "GET" : "POST"; 98 | message += "\nArguments: "; 99 | message += request->args(); 100 | message += "\n"; 101 | 102 | for (uint8_t i = 0; i < request->args(); i++) 103 | { 104 | message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; 105 | } 106 | 107 | request->send(404, "text/plain", message); 108 | } 109 | 110 | void printWifiStatus() 111 | { 112 | // print the SSID of the network you're attached to: 113 | Serial.print("SSID: "); 114 | Serial.println(WiFi.SSID()); 115 | 116 | // print your board's IP address: 117 | IPAddress ip = WiFi.localIP(); 118 | Serial.print("Local IP Address: "); 119 | Serial.println(ip); 120 | 121 | // print the received signal strength: 122 | long rssi = WiFi.RSSI(); 123 | Serial.print("signal strength (RSSI):"); 124 | Serial.print(rssi); 125 | Serial.println(" dBm"); 126 | } 127 | 128 | void setup() 129 | { 130 | Serial.begin(115200); 131 | 132 | while (!Serial && millis() < 5000); 133 | 134 | delay(200); 135 | 136 | Serial.print("\nStart Async_PostServer on "); 137 | Serial.print(BOARD_NAME); 138 | Serial.print(" with "); 139 | Serial.println(SHIELD_TYPE); 140 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 141 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 142 | 143 | /////////////////////////////////// 144 | 145 | // check for the WiFi module: 146 | if (WiFi.status() == WL_NO_MODULE) 147 | { 148 | Serial.println("Communication with WiFi module failed!"); 149 | 150 | // don't continue 151 | while (true); 152 | } 153 | 154 | Serial.print(F("Connecting to SSID: ")); 155 | Serial.println(ssid); 156 | 157 | status = WiFi.begin(ssid, pass); 158 | 159 | delay(1000); 160 | 161 | // attempt to connect to WiFi network 162 | while ( status != WL_CONNECTED) 163 | { 164 | delay(500); 165 | 166 | // Connect to WPA/WPA2 network 167 | status = WiFi.status(); 168 | } 169 | 170 | printWifiStatus(); 171 | 172 | /////////////////////////////////// 173 | 174 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 175 | { 176 | handleRoot(request); 177 | }); 178 | 179 | //server.on("/postplain/", handlePlain); 180 | server.on("/postplain/", HTTP_POST, [](AsyncWebServerRequest * request) 181 | { 182 | handlePlain(request); 183 | }); 184 | 185 | //server.on("/postform/", handleForm); 186 | server.on("/postform/", HTTP_POST, [](AsyncWebServerRequest * request) 187 | { 188 | handleForm(request); 189 | }); 190 | 191 | server.onNotFound(handleNotFound); 192 | 193 | server.begin(); 194 | 195 | Serial.print(F("HTTP Async_PostServer started @ IP : ")); 196 | Serial.println(WiFi.localIP()); 197 | } 198 | 199 | void heartBeatPrint() 200 | { 201 | static int num = 1; 202 | 203 | Serial.print(F(".")); 204 | 205 | if (num == 80) 206 | { 207 | Serial.println(); 208 | num = 1; 209 | } 210 | else if (num++ % 10 == 0) 211 | { 212 | Serial.print(F(" ")); 213 | } 214 | } 215 | 216 | void check_status() 217 | { 218 | static unsigned long checkstatus_timeout = 0; 219 | 220 | #define STATUS_CHECK_INTERVAL 10000L 221 | 222 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 223 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 224 | { 225 | heartBeatPrint(); 226 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 227 | } 228 | } 229 | 230 | void loop() 231 | { 232 | check_status(); 233 | } 234 | -------------------------------------------------------------------------------- /examples/WiFi/MQTTClient_Auth/MQTTClient_Auth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_Auth.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | /* 14 | Basic MQTT example (without SSL!) with Authentication 15 | This sketch demonstrates the basic capabilities of the library. 16 | It connects to an MQTT server then: 17 | - providing username and password 18 | - publishes "hello world" to the topic "outTopic" 19 | - subscribes to the topic "inTopic", printing out any messages 20 | it receives. NB - it assumes the received payloads are strings not binary 21 | It will reconnect to the server if the connection is lost using a blocking 22 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 23 | achieve the same result without blocking the main loop. 24 | */ 25 | 26 | // To remove boolean warnings caused by PubSubClient library 27 | #define boolean bool 28 | 29 | #include "defines.h" 30 | 31 | #include 32 | 33 | // Update these with values suitable for your network. 34 | const char* mqttServer = "broker.emqx.io"; // Broker address 35 | 36 | const char *ID = "MQTTClient_Auth"; // Name of our device, must be unique 37 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 38 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 39 | 40 | //IPAddress mqttServer(172, 16, 0, 2); 41 | 42 | void callback(char* topic, byte* payload, unsigned int length) 43 | { 44 | Serial.print("Message arrived ["); 45 | Serial.print(topic); 46 | Serial.print("] "); 47 | 48 | for (unsigned int i = 0; i < length; i++) 49 | { 50 | Serial.print((char)payload[i]); 51 | } 52 | 53 | Serial.println(); 54 | } 55 | 56 | WiFiClient wifiClient; 57 | PubSubClient client(mqttServer, 1883, callback, wifiClient); 58 | 59 | String data = "Hello from MQTTClient_Auth on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 60 | const char *pubData = data.c_str(); 61 | 62 | void reconnect() 63 | { 64 | // Loop until we're reconnected 65 | while (!client.connected()) 66 | { 67 | Serial.print("Attempting MQTT connection to "); 68 | Serial.print(mqttServer); 69 | 70 | // Attempt to connect 71 | if (client.connect("arduino", "try", "try")) 72 | { 73 | Serial.println("...connected"); 74 | 75 | // Once connected, publish an announcement... 76 | client.publish(TOPIC, data.c_str()); 77 | 78 | //Serial.println("Published connection message successfully!"); 79 | //Serial.print("Subcribed to: "); 80 | //Serial.println(subTopic); 81 | 82 | client.subscribe(subTopic); 83 | // for loopback testing 84 | client.subscribe(TOPIC); 85 | } 86 | else 87 | { 88 | Serial.print("...failed, rc="); 89 | Serial.print(client.state()); 90 | Serial.println(" try again in 5 seconds"); 91 | 92 | // Wait 5 seconds before retrying 93 | delay(5000); 94 | } 95 | } 96 | } 97 | 98 | void printWifiStatus() 99 | { 100 | // print the SSID of the network you're attached to: 101 | Serial.print("SSID: "); 102 | Serial.println(WiFi.SSID()); 103 | 104 | // print your board's IP address: 105 | IPAddress ip = WiFi.localIP(); 106 | Serial.print("Local IP Address: "); 107 | Serial.println(ip); 108 | 109 | // print the received signal strength: 110 | long rssi = WiFi.RSSI(); 111 | Serial.print("signal strength (RSSI):"); 112 | Serial.print(rssi); 113 | Serial.println(" dBm"); 114 | } 115 | 116 | void setup() 117 | { 118 | // Open serial communications and wait for port to open: 119 | Serial.begin(115200); 120 | 121 | while (!Serial && millis() < 5000); 122 | 123 | Serial.print("\nStart MQTTClient_Auth on "); 124 | Serial.print(BOARD_NAME); 125 | Serial.print(" with "); 126 | Serial.println(SHIELD_TYPE); 127 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 128 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 129 | 130 | /////////////////////////////////// 131 | 132 | // check for the WiFi module: 133 | if (WiFi.status() == WL_NO_MODULE) 134 | { 135 | Serial.println("Communication with WiFi module failed!"); 136 | 137 | // don't continue 138 | while (true); 139 | } 140 | 141 | Serial.print(F("Connecting to SSID: ")); 142 | Serial.println(ssid); 143 | 144 | status = WiFi.begin(ssid, pass); 145 | 146 | delay(1000); 147 | 148 | // attempt to connect to WiFi network 149 | while ( status != WL_CONNECTED) 150 | { 151 | delay(500); 152 | 153 | // Connect to WPA/WPA2 network 154 | status = WiFi.status(); 155 | } 156 | 157 | printWifiStatus(); 158 | 159 | /////////////////////////////////// 160 | 161 | // Note - the default maximum packet size is 128 bytes. If the 162 | // combined length of clientId, username and password exceed this use the 163 | // following to increase the buffer size: 164 | // client.setBufferSize(255); 165 | } 166 | 167 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 168 | 169 | unsigned long lastMsg = 0; 170 | 171 | void loop() 172 | { 173 | static unsigned long now; 174 | 175 | if (!client.connected()) 176 | { 177 | reconnect(); 178 | } 179 | 180 | // Sending Data 181 | now = millis(); 182 | 183 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 184 | { 185 | lastMsg = now; 186 | 187 | if (!client.publish(TOPIC, pubData)) 188 | { 189 | Serial.println("Message failed to send."); 190 | } 191 | 192 | Serial.print("Message Send : " + String(TOPIC) + " => "); 193 | Serial.println(data); 194 | } 195 | 196 | client.loop(); 197 | } 198 | -------------------------------------------------------------------------------- /examples/WiFi/MQTTClient_Auth/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 18 | #error For Portenta_H7 only 19 | #endif 20 | 21 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 22 | 23 | #define USE_WIFI_PORTENTA_H7 true 24 | 25 | #include 26 | #warning Using WiFi for Portenta_H7. 27 | 28 | #include 29 | 30 | char ssid[] = "your_ssid"; // your network SSID (name) 31 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 32 | 33 | int status = WL_IDLE_STATUS; 34 | 35 | #include 36 | 37 | 38 | #endif //defines_h 39 | -------------------------------------------------------------------------------- /examples/WiFi/MQTTClient_Basic/MQTTClient_Basic.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_Basic.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | /* 14 | Basic MQTT example (without SSL!) with Authentication 15 | This sketch demonstrates the basic capabilities of the library. 16 | It connects to an MQTT server then: 17 | - providing username and password 18 | - publishes "hello world" to the topic "outTopic" 19 | - subscribes to the topic "inTopic", printing out any messages 20 | it receives. NB - it assumes the received payloads are strings not binary 21 | 22 | It will reconnect to the server if the connection is lost using a blocking 23 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 24 | achieve the same result without blocking the main loop. 25 | */ 26 | 27 | // To remove boolean warnings caused by PubSubClient library 28 | #define boolean bool 29 | 30 | #include "defines.h" 31 | 32 | #include 33 | 34 | // Update these with values suitable for your network. 35 | const char* mqttServer = "broker.emqx.io"; // Broker address 36 | 37 | const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 38 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 39 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 40 | 41 | void callback(char* topic, byte* payload, unsigned int length) 42 | { 43 | Serial.print("Message arrived ["); 44 | Serial.print(topic); 45 | Serial.print("] "); 46 | 47 | for (unsigned int i = 0; i < length; i++) 48 | { 49 | Serial.print((char)payload[i]); 50 | } 51 | 52 | Serial.println(); 53 | } 54 | 55 | WiFiClient wifiClient; 56 | PubSubClient client(mqttServer, 1883, callback, wifiClient); 57 | 58 | String data = "Hello from MQTTClient_Basic on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 59 | const char *pubData = data.c_str(); 60 | 61 | void reconnect() 62 | { 63 | // Loop until we're reconnected 64 | while (!client.connected()) 65 | { 66 | Serial.print("Attempting MQTT connection to "); 67 | Serial.print(mqttServer); 68 | 69 | // Attempt to connect 70 | if (client.connect(ID, "try", "try")) 71 | { 72 | Serial.println("...connected"); 73 | 74 | // Once connected, publish an announcement... 75 | client.publish(TOPIC, data.c_str()); 76 | 77 | //Serial.println("Published connection message successfully!"); 78 | //Serial.print("Subcribed to: "); 79 | //Serial.println(subTopic); 80 | 81 | client.subscribe(subTopic); 82 | // for loopback testing 83 | client.subscribe(TOPIC); 84 | } 85 | else 86 | { 87 | Serial.print("...failed, rc="); 88 | Serial.print(client.state()); 89 | Serial.println(" try again in 5 seconds"); 90 | 91 | // Wait 5 seconds before retrying 92 | delay(5000); 93 | } 94 | } 95 | } 96 | 97 | void printWifiStatus() 98 | { 99 | // print the SSID of the network you're attached to: 100 | Serial.print("SSID: "); 101 | Serial.println(WiFi.SSID()); 102 | 103 | // print your board's IP address: 104 | IPAddress ip = WiFi.localIP(); 105 | Serial.print("Local IP Address: "); 106 | Serial.println(ip); 107 | 108 | // print the received signal strength: 109 | long rssi = WiFi.RSSI(); 110 | Serial.print("signal strength (RSSI):"); 111 | Serial.print(rssi); 112 | Serial.println(" dBm"); 113 | } 114 | 115 | void setup() 116 | { 117 | // Open serial communications and wait for port to open: 118 | Serial.begin(115200); 119 | 120 | while (!Serial && millis() < 5000); 121 | 122 | Serial.print("\nStart MQTTClient_Basic on "); 123 | Serial.print(BOARD_NAME); 124 | Serial.print(" with "); 125 | Serial.println(SHIELD_TYPE); 126 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 127 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 128 | 129 | /////////////////////////////////// 130 | 131 | // check for the WiFi module: 132 | if (WiFi.status() == WL_NO_MODULE) 133 | { 134 | Serial.println("Communication with WiFi module failed!"); 135 | 136 | // don't continue 137 | while (true); 138 | } 139 | 140 | Serial.print(F("Connecting to SSID: ")); 141 | Serial.println(ssid); 142 | 143 | status = WiFi.begin(ssid, pass); 144 | 145 | delay(1000); 146 | 147 | // attempt to connect to WiFi network 148 | while ( status != WL_CONNECTED) 149 | { 150 | delay(500); 151 | 152 | // Connect to WPA/WPA2 network 153 | status = WiFi.status(); 154 | } 155 | 156 | printWifiStatus(); 157 | 158 | /////////////////////////////////// 159 | 160 | client.setServer(mqttServer, 1883); 161 | client.setCallback(callback); 162 | 163 | // Allow the hardware to sort itself out 164 | delay(1500); 165 | } 166 | 167 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 168 | 169 | unsigned long lastMsg = 0; 170 | 171 | void loop() 172 | { 173 | static unsigned long now; 174 | 175 | if (!client.connected()) 176 | { 177 | reconnect(); 178 | } 179 | 180 | // Sending Data 181 | now = millis(); 182 | 183 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 184 | { 185 | lastMsg = now; 186 | 187 | if (!client.publish(TOPIC, pubData)) 188 | { 189 | Serial.println("Message failed to send."); 190 | } 191 | 192 | Serial.print("Message Send : " + String(TOPIC) + " => "); 193 | Serial.println(data); 194 | } 195 | 196 | client.loop(); 197 | } 198 | -------------------------------------------------------------------------------- /examples/WiFi/MQTTClient_Basic/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 18 | #error For Portenta_H7 only 19 | #endif 20 | 21 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 22 | 23 | #define USE_WIFI_PORTENTA_H7 true 24 | 25 | #include 26 | #warning Using WiFi for Portenta_H7. 27 | 28 | #include 29 | 30 | char ssid[] = "your_ssid"; // your network SSID (name) 31 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 32 | 33 | int status = WL_IDLE_STATUS; 34 | 35 | #include 36 | 37 | 38 | #endif //defines_h 39 | -------------------------------------------------------------------------------- /examples/WiFi/MQTT_ThingStream/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 18 | #error For Portenta_H7 only 19 | #endif 20 | 21 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 22 | 23 | #define USE_WIFI_PORTENTA_H7 true 24 | 25 | #include 26 | #warning Using WiFi for Portenta_H7. 27 | 28 | #include 29 | 30 | char ssid[] = "your_ssid"; // your network SSID (name) 31 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 32 | 33 | int status = WL_IDLE_STATUS; 34 | 35 | #include 36 | 37 | 38 | #endif //defines_h 39 | -------------------------------------------------------------------------------- /examples/WiFi/WebClient/WebClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClient.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #include "defines.h" 15 | 16 | char server[] = "arduino.cc"; 17 | 18 | // Initialize the Web client object 19 | WiFiClient client; 20 | 21 | void printWifiStatus() 22 | { 23 | // print the SSID of the network you're attached to: 24 | Serial.print("SSID: "); 25 | Serial.println(WiFi.SSID()); 26 | 27 | // print your board's IP address: 28 | IPAddress ip = WiFi.localIP(); 29 | Serial.print("Local IP Address: "); 30 | Serial.println(ip); 31 | 32 | // print the received signal strength: 33 | long rssi = WiFi.RSSI(); 34 | Serial.print("signal strength (RSSI):"); 35 | Serial.print(rssi); 36 | Serial.println(" dBm"); 37 | } 38 | 39 | void setup() 40 | { 41 | // Open serial communications and wait for port to open: 42 | Serial.begin(115200); 43 | 44 | while (!Serial && millis() < 5000); 45 | 46 | Serial.print("\nStart WebClient on "); 47 | Serial.print(BOARD_NAME); 48 | Serial.print(" with "); 49 | Serial.println(SHIELD_TYPE); 50 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 51 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 52 | 53 | /////////////////////////////////// 54 | 55 | // check for the WiFi module: 56 | if (WiFi.status() == WL_NO_MODULE) 57 | { 58 | Serial.println("Communication with WiFi module failed!"); 59 | 60 | // don't continue 61 | while (true); 62 | } 63 | 64 | Serial.print(F("Connecting to SSID: ")); 65 | Serial.println(ssid); 66 | 67 | status = WiFi.begin(ssid, pass); 68 | 69 | delay(1000); 70 | 71 | // attempt to connect to WiFi network 72 | while ( status != WL_CONNECTED) 73 | { 74 | delay(500); 75 | 76 | // Connect to WPA/WPA2 network 77 | status = WiFi.status(); 78 | } 79 | 80 | printWifiStatus(); 81 | 82 | /////////////////////////////////// 83 | 84 | Serial.println(); 85 | Serial.println(F("Starting connection to server...")); 86 | 87 | // if you get a connection, report back via serial 88 | if (client.connect(server, 80)) 89 | { 90 | Serial.println(F("Connected to server")); 91 | // Make a HTTP request 92 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 93 | client.println(F("Host: arduino.cc")); 94 | client.println(F("Connection: close")); 95 | client.println(); 96 | } 97 | } 98 | 99 | void printoutData(void) 100 | { 101 | // if there are incoming bytes available 102 | // from the server, read them and print them 103 | while (client.available()) 104 | { 105 | char c = client.read(); 106 | Serial.write(c); 107 | } 108 | } 109 | 110 | void loop() 111 | { 112 | printoutData(); 113 | 114 | // if the server's disconnected, stop the client 115 | if (!client.connected()) 116 | { 117 | Serial.println(); 118 | Serial.println(F("Disconnecting from server...")); 119 | client.stop(); 120 | 121 | // do nothing forevermore 122 | while (true); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /examples/WiFi/WebClient/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | 18 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 19 | #error For Portenta_H7 only 20 | #endif 21 | 22 | #define USE_WIFI_PORTENTA_H7 true 23 | 24 | #include 25 | #warning Using WiFi for Portenta_H7. 26 | 27 | #include 28 | 29 | char ssid[] = "your_ssid"; // your network SSID (name) 30 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 31 | 32 | int status = WL_IDLE_STATUS; 33 | 34 | #include 35 | 36 | 37 | #endif //defines_h 38 | -------------------------------------------------------------------------------- /examples/WiFi/WebClientRepeating/WebClientRepeating.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClientRepeating.ino 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | #include "defines.h" 14 | 15 | char server[] = "arduino.cc"; 16 | 17 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 18 | const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds 19 | 20 | // Initialize the Web client object 21 | WiFiClient client; 22 | 23 | // this method makes a HTTP connection to the server 24 | void httpRequest() 25 | { 26 | Serial.println(); 27 | 28 | // close any connection before send a new request 29 | // this will free the socket on the WiFi shield 30 | client.stop(); 31 | 32 | // if there's a successful connection 33 | if (client.connect(server, 80)) 34 | { 35 | Serial.println(F("Connecting...")); 36 | 37 | // send the HTTP PUT request 38 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 39 | client.println(F("Host: arduino.cc")); 40 | client.println(F("Connection: close")); 41 | client.println(); 42 | 43 | // note the time that the connection was made 44 | lastConnectionTime = millis(); 45 | } 46 | else 47 | { 48 | // if you couldn't make a connection 49 | Serial.println(F("Connection failed")); 50 | } 51 | } 52 | 53 | void printWifiStatus() 54 | { 55 | // print the SSID of the network you're attached to: 56 | Serial.print("SSID: "); 57 | Serial.println(WiFi.SSID()); 58 | 59 | // print your board's IP address: 60 | IPAddress ip = WiFi.localIP(); 61 | Serial.print("Local IP Address: "); 62 | Serial.println(ip); 63 | 64 | // print the received signal strength: 65 | long rssi = WiFi.RSSI(); 66 | Serial.print("signal strength (RSSI):"); 67 | Serial.print(rssi); 68 | Serial.println(" dBm"); 69 | } 70 | 71 | void setup() 72 | { 73 | // Open serial communications and wait for port to open: 74 | Serial.begin(115200); 75 | 76 | while (!Serial && millis() < 5000); 77 | 78 | Serial.print("\nStart WebClientRepeating on "); 79 | Serial.print(BOARD_NAME); 80 | Serial.print(" with "); 81 | Serial.println(SHIELD_TYPE); 82 | Serial.println(PORTENTA_H7_ASYNC_TCP_VERSION); 83 | Serial.println(PORTENTA_H7_ASYNC_WEBSERVER_VERSION); 84 | 85 | /////////////////////////////////// 86 | 87 | // check for the WiFi module: 88 | if (WiFi.status() == WL_NO_MODULE) 89 | { 90 | Serial.println("Communication with WiFi module failed!"); 91 | 92 | // don't continue 93 | while (true); 94 | } 95 | 96 | Serial.print(F("Connecting to SSID: ")); 97 | Serial.println(ssid); 98 | 99 | status = WiFi.begin(ssid, pass); 100 | 101 | delay(1000); 102 | 103 | // attempt to connect to WiFi network 104 | while ( status != WL_CONNECTED) 105 | { 106 | delay(500); 107 | 108 | // Connect to WPA/WPA2 network 109 | status = WiFi.status(); 110 | } 111 | 112 | printWifiStatus(); 113 | 114 | /////////////////////////////////// 115 | } 116 | 117 | void loop() 118 | { 119 | // if there's incoming data from the net connection send it out the serial port 120 | // this is for debugging purposes only 121 | while (client.available()) 122 | { 123 | char c = client.read(); 124 | Serial.write(c); 125 | } 126 | 127 | // if 10 seconds have passed since your last connection, 128 | // then connect again and send data 129 | if (millis() - lastConnectionTime > postingInterval) 130 | { 131 | httpRequest(); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /examples/WiFi/WebClientRepeating/defines.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | defines.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #ifndef defines_h 15 | #define defines_h 16 | 17 | #if !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 18 | #error For Portenta_H7 only 19 | #endif 20 | 21 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 22 | 23 | #define USE_WIFI_PORTENTA_H7 true 24 | 25 | #include 26 | #warning Using WiFi for Portenta_H7. 27 | 28 | #include 29 | 30 | char ssid[] = "your_ssid"; // your network SSID (name) 31 | char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+ 32 | 33 | int status = WL_IDLE_STATUS; 34 | 35 | #include 36 | 37 | #endif //defines_h 38 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Portenta_H7_AsyncWebServer", 3 | "version": "1.5.0", 4 | "keywords": "http, async, websocket, webserver, async-webserver, async-tcp, async-udp, async-websocket, async-http, ssl, tls, mbed, mbed-portenta, portenta-h7, portentah7, portenta-h7-m7, portenta-h7-m4, portentah7-m7, portentah7-m4, stm32h7", 5 | "description": "Asynchronous WebServer Library for STM32H7-based Portenta_H7 using mbed_portenta core. This library, which is relied on Portenta_H7_AsyncTCP, is part of a series of advanced Async libraries, such as AsyncTCP, AsyncUDP, AsyncWebSockets, AsyncHTTPRequest, AsyncHTTPSRequest, etc. Now supporting using CString in optional SDRAM to save heap to send very large data and examples to demo how to use beginChunkedResponse() to send large html in chunks", 6 | "authors": 7 | [ 8 | { 9 | "name": "Hristo Gochkov", 10 | "url": "https://github.com/me-no-dev" 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/Portenta_H7_AsyncWebServer" 23 | }, 24 | "homepage": "https://github.com/khoih-prog/Portenta_H7_AsyncWebServer", 25 | "export": { 26 | "exclude": [ 27 | "linux", 28 | "extras", 29 | "tests" 30 | ] 31 | }, 32 | "dependencies": 33 | [ 34 | { 35 | "owner": "khoih-prog", 36 | "name": "Portenta_H7_AsyncTCP", 37 | "version": "^1.4.0" 38 | } 39 | ], 40 | "license": "LGPL-3.0", 41 | "frameworks": "*", 42 | "platforms": "mbed_portenta", 43 | "examples": "examples/*/*/*.ino", 44 | "headers": "Portenta_H7_AsyncWebServer.h" 45 | } 46 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Portenta_H7_AsyncWebServer 2 | version=1.5.0 3 | author=Hristo Gochkov,Khoi Hoang 4 | maintainer=Khoi Hoang 5 | sentence=Asynchronous WebServer Library for STM32H7-based Portenta_H7 using mbed_portenta core. 6 | paragraph=This library, which is relied on Portenta_H7_AsyncTCP, is part of a series of advanced Async libraries, such as AsyncTCP, AsyncUDP, AsyncWebSockets, AsyncHTTPRequest, AsyncHTTPSRequest, etc. Now supporting using CString in optional SDRAM to save heap to send very large data and examples to demo how to use beginChunkedResponse() to send large html in chunks 7 | category=Communication 8 | url=https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 9 | architectures=mbed,mbed_portenta,ArduinoCore-mbed 10 | repository=https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 11 | license=GPLv3 12 | depends=Portenta_H7_AsyncTCP 13 | includes=Portenta_H7_AsyncWebServer.h 14 | -------------------------------------------------------------------------------- /pics/AsyncWebServer_SendChunked_Ethernet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/AsyncWebServer_SendChunked_Ethernet.png -------------------------------------------------------------------------------- /pics/AsyncWebServer_SendChunked_WiFi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/AsyncWebServer_SendChunked_WiFi.png -------------------------------------------------------------------------------- /pics/Async_AdvancedWebServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/Async_AdvancedWebServer.png -------------------------------------------------------------------------------- /pics/Async_AdvancedWebServer_CString.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/Async_AdvancedWebServer_CString.png -------------------------------------------------------------------------------- /pics/Async_AdvancedWebServer_Firefox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/Async_AdvancedWebServer_Firefox.png -------------------------------------------------------------------------------- /pics/Async_AdvancedWebServer_WiFi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/Async_AdvancedWebServer_WiFi.png -------------------------------------------------------------------------------- /pics/Portenta_Vision.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/Portenta_H7_AsyncWebServer/aa173e7bb1f135c78bd1ec13255899189b554bb5/pics/Portenta_Vision.jpg -------------------------------------------------------------------------------- /src/Crypto/Hash.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | @file Hash.cpp 3 | @date 20.05.2015 4 | @author Markus Sattler 5 | 6 | Copyright (c) 2015 Markus Sattler. All rights reserved. 7 | This file is part of the esp8266 core for Arduino environment. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | */ 24 | 25 | #include 26 | #include "bearssl_hash.h" 27 | 28 | #include "Hash.h" 29 | 30 | /** 31 | create a sha1 hash from data 32 | @param data uint8_t 33 | @param size uint32_t 34 | @param hash uint8_t[HASH_BUFFER_SIZE] 35 | */ 36 | void sha1(const uint8_t* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]) 37 | { 38 | br_sha1_context ctx; 39 | 40 | AWS_LOGDEBUG0("DATA:"); 41 | 42 | for (uint16_t i = 0; i < size; i++) 43 | { 44 | AWS_LOGDEBUG0(data[i]); 45 | } 46 | 47 | AWS_LOGDEBUG0("\nDATA:"); 48 | 49 | for (uint16_t i = 0; i < size; i++) 50 | { 51 | AWS_LOGDEBUG0((char) data[i]); 52 | 53 | } 54 | 55 | AWS_LOGDEBUG0("\n"); 56 | 57 | br_sha1_init(&ctx); 58 | br_sha1_update(&ctx, data, size); 59 | br_sha1_out(&ctx, hash); 60 | 61 | AWS_LOGDEBUG0("SHA1:"); 62 | 63 | for (uint16_t i = 0; i < HASH_BUFFER_SIZE; i++) 64 | { 65 | AWS_LOGDEBUG0(hash[i]); 66 | } 67 | 68 | AWS_LOGDEBUG0("\n"); 69 | } 70 | 71 | void sha1(const char* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]) 72 | { 73 | sha1((const uint8_t *) data, size, hash); 74 | } 75 | 76 | void sha1(const String& data, uint8_t hash[HASH_BUFFER_SIZE]) 77 | { 78 | sha1(data.c_str(), data.length(), hash); 79 | } 80 | 81 | String sha1(const uint8_t* data, uint32_t size) 82 | { 83 | uint8_t hash[HASH_BUFFER_SIZE]; 84 | 85 | String hashStr((const char*)nullptr); 86 | hashStr.reserve(HASH_BUFFER_SIZE * 2 + 1); 87 | 88 | sha1(&data[0], size, &hash[0]); 89 | 90 | for (uint16_t i = 0; i < HASH_BUFFER_SIZE; i++) 91 | { 92 | char hex[3]; 93 | snprintf(hex, sizeof(hex), "%02x", hash[i]); 94 | hashStr += hex; 95 | } 96 | 97 | return hashStr; 98 | } 99 | 100 | String sha1(const char* data, uint32_t size) 101 | { 102 | return sha1((const uint8_t*) data, size); 103 | } 104 | 105 | String sha1(const String& data) 106 | { 107 | return sha1(data.c_str(), data.length()); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /src/Crypto/Hash.h: -------------------------------------------------------------------------------- 1 | /** 2 | @file Hash.h 3 | @date 20.05.2015 4 | @author Markus Sattler 5 | 6 | Copyright (c) 2015 Markus Sattler. All rights reserved. 7 | This file is part of the esp8266 core for Arduino environment. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | */ 24 | 25 | #pragma once 26 | 27 | #ifndef HASH_H_ 28 | #define HASH_H_ 29 | 30 | #include "Portenta_H7_AsyncWebServer_Debug.h" 31 | 32 | #ifdef HASH_BUFFER_SIZE 33 | #undef HASH_BUFFER_SIZE 34 | #endif 35 | 36 | #define HASH_BUFFER_SIZE 20 37 | 38 | void sha1(const uint8_t* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]); 39 | void sha1(const char* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]); 40 | void sha1(const String& data, uint8_t hash[HASH_BUFFER_SIZE]); 41 | 42 | String sha1(const uint8_t* data, uint32_t size); 43 | String sha1(const char* data, uint32_t size); 44 | String sha1(const String& data); 45 | 46 | #endif /* HASH_H_ */ 47 | -------------------------------------------------------------------------------- /src/Crypto/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file md5.h 3 | 4 | Based on XySSL: Copyright (C) 2006-2008 Christophe Devine 5 | 6 | Copyright (C) 2009 Paul Bakker 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions 12 | are met: 13 | 14 | * * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors 20 | may be used to endorse or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #ifndef LWIP_INCLUDED_POLARSSL_MD5_H 39 | #define LWIP_INCLUDED_POLARSSL_MD5_H 40 | 41 | #include "Portenta_H7_AsyncWebServer_Debug.h" 42 | 43 | /** 44 | \brief MD5 context structure 45 | */ 46 | typedef struct 47 | { 48 | unsigned long total[2]; /*!< number of bytes processed */ 49 | unsigned long state[4]; /*!< intermediate digest state */ 50 | unsigned char buffer[64]; /*!< data block being processed */ 51 | } 52 | md5_context; 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /** 59 | \brief MD5 context setup 60 | 61 | \param ctx context to be initialized 62 | */ 63 | void md5_starts( md5_context *ctx ); 64 | 65 | /** 66 | \brief MD5 process buffer 67 | 68 | \param ctx MD5 context 69 | \param input buffer holding the data 70 | \param ilen length of the input data 71 | */ 72 | void md5_update( md5_context *ctx, const unsigned char *input, int ilen ); 73 | 74 | /** 75 | \brief MD5 final digest 76 | 77 | \param ctx MD5 context 78 | \param output MD5 checksum result 79 | */ 80 | void md5_finish( md5_context *ctx, unsigned char output[16] ); 81 | 82 | /** 83 | \brief Output = MD5( input buffer ) 84 | 85 | \param input buffer holding the data 86 | \param ilen length of the input data 87 | \param output MD5 checksum result 88 | */ 89 | void md5( unsigned char *input, int ilen, unsigned char output[16] ); 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /* LWIP_INCLUDED_POLARSSL_MD5_H */ 96 | -------------------------------------------------------------------------------- /src/Crypto/sha1.h: -------------------------------------------------------------------------------- 1 | /** 2 | \file sha1.h 3 | 4 | Based on XySSL: Copyright (C) 2006-2008 Christophe Devine 5 | 6 | Copyright (C) 2009 Paul Bakker 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions 12 | are met: 13 | 14 | * * Redistributions of source code must retain the above copyright 15 | notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors 20 | may be used to endorse or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #ifndef LWIP_INCLUDED_POLARSSL_SHA1_H 39 | #define LWIP_INCLUDED_POLARSSL_SHA1_H 40 | 41 | #include "Portenta_H7_AsyncWebServer_Debug.h" 42 | 43 | #ifdef SHA1_BUFFER_SIZE 44 | #undef SHA1_BUFFER_SIZE 45 | #endif 46 | 47 | #define SHA1_BUFFER_SIZE 20 48 | 49 | /** 50 | \brief SHA-1 context structure 51 | */ 52 | typedef struct 53 | { 54 | unsigned long total[2]; /*!< number of bytes processed */ 55 | unsigned long state[5]; /*!< intermediate digest state */ 56 | unsigned char buffer[64]; /*!< data block being processed */ 57 | } 58 | sha1_context; 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | /** 65 | \brief SHA-1 context setup 66 | 67 | \param ctx context to be initialized 68 | */ 69 | void sha1_starts( sha1_context *ctx ); 70 | 71 | /** 72 | \brief SHA-1 process buffer 73 | 74 | \param ctx SHA-1 context 75 | \param input buffer holding the data 76 | \param ilen length of the input data 77 | */ 78 | void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ); 79 | 80 | /** 81 | \brief SHA-1 final digest 82 | 83 | \param ctx SHA-1 context 84 | \param output SHA-1 checksum result 85 | */ 86 | void sha1_finish( sha1_context *ctx, unsigned char output[SHA1_BUFFER_SIZE] ); 87 | 88 | /** 89 | \brief Output = SHA-1( input buffer ) 90 | 91 | \param input buffer holding the data 92 | \param ilen length of the input data 93 | \param output SHA-1 checksum result 94 | */ 95 | void sha1( unsigned char *input, int ilen, unsigned char output[SHA1_BUFFER_SIZE] ); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* LWIP_INCLUDED_POLARSSL_SHA1_H */ 102 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncEventSource.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************************************* 2 | Portenta_H7_AsyncEventSource.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #pragma once 29 | 30 | #ifndef PORTENTA_H7_ASYNCEVENTSOURCE_H_ 31 | #define PORTENTA_H7_ASYNCEVENTSOURCE_H_ 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include "Portenta_H7_AsyncWebSynchronization.h" 38 | 39 | // STM32 40 | #include 41 | 42 | #define SSE_MAX_QUEUED_MESSAGES 32 43 | //#define SSE_MAX_QUEUED_MESSAGES 8 44 | 45 | #define DEFAULT_MAX_SSE_CLIENTS 8 46 | //#define DEFAULT_MAX_SSE_CLIENTS 4 47 | 48 | ///////////////////////////////////////////////// 49 | 50 | class AsyncEventSource; 51 | class AsyncEventSourceResponse; 52 | class AsyncEventSourceClient; 53 | typedef std::function ArEventHandlerFunction; 54 | 55 | ///////////////////////////////////////////////// 56 | 57 | class AsyncEventSourceMessage 58 | { 59 | private: 60 | uint8_t * _data; 61 | size_t _len; 62 | size_t _sent; 63 | //size_t _ack; 64 | size_t _acked; 65 | 66 | public: 67 | AsyncEventSourceMessage(const char * data, size_t len); 68 | ~AsyncEventSourceMessage(); 69 | size_t ack(size_t len, uint32_t time __attribute__((unused))); 70 | size_t send(AsyncClient *client); 71 | 72 | bool finished() 73 | { 74 | return _acked == _len; 75 | } 76 | 77 | bool sent() 78 | { 79 | return _sent == _len; 80 | } 81 | }; 82 | 83 | ///////////////////////////////////////////////// 84 | 85 | class AsyncEventSourceClient 86 | { 87 | private: 88 | AsyncClient *_client; 89 | AsyncEventSource *_server; 90 | uint32_t _lastId; 91 | LinkedList _messageQueue; 92 | void _queueMessage(AsyncEventSourceMessage *dataMessage); 93 | void _runQueue(); 94 | 95 | public: 96 | 97 | AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server); 98 | ~AsyncEventSourceClient(); 99 | 100 | AsyncClient* client() 101 | { 102 | return _client; 103 | } 104 | 105 | void close(); 106 | void write(const char * message, size_t len); 107 | void send(const char *message, const char *event = NULL, uint32_t id = 0, uint32_t reconnect = 0); 108 | 109 | bool connected() const 110 | { 111 | return (_client != NULL) && _client->connected(); 112 | } 113 | 114 | uint32_t lastId() const 115 | { 116 | return _lastId; 117 | } 118 | 119 | size_t packetsWaiting() const 120 | { 121 | return _messageQueue.length(); 122 | } 123 | 124 | //system callbacks (do not call) 125 | void _onAck(size_t len, uint32_t time); 126 | void _onPoll(); 127 | void _onTimeout(uint32_t time); 128 | void _onDisconnect(); 129 | }; 130 | 131 | ///////////////////////////////////////////////// 132 | 133 | class AsyncEventSource: public AsyncWebHandler 134 | { 135 | private: 136 | String _url; 137 | LinkedList _clients; 138 | ArEventHandlerFunction _connectcb; 139 | 140 | public: 141 | AsyncEventSource(const String& url); 142 | ~AsyncEventSource(); 143 | 144 | const char * url() const 145 | { 146 | return _url.c_str(); 147 | } 148 | 149 | void close(); 150 | void onConnect(ArEventHandlerFunction cb); 151 | void send(const char *message, const char *event = NULL, uint32_t id = 0, uint32_t reconnect = 0); 152 | size_t count() const; //number clinets connected 153 | size_t avgPacketsWaiting() const; 154 | 155 | //system callbacks (do not call) 156 | void _addClient(AsyncEventSourceClient * client); 157 | void _handleDisconnect(AsyncEventSourceClient * client); 158 | virtual bool canHandle(AsyncWebServerRequest *request) override final; 159 | virtual void handleRequest(AsyncWebServerRequest *request) override final; 160 | }; 161 | 162 | ///////////////////////////////////////////////// 163 | 164 | class AsyncEventSourceResponse: public AsyncWebServerResponse 165 | { 166 | private: 167 | String _content; 168 | AsyncEventSource *_server; 169 | 170 | public: 171 | AsyncEventSourceResponse(AsyncEventSource *server); 172 | void _respond(AsyncWebServerRequest *request); 173 | size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); 174 | 175 | bool _sourceValid() const 176 | { 177 | return true; 178 | } 179 | }; 180 | 181 | ///////////////////////////////////////////////// 182 | 183 | #endif /* PORTENTA_H7_ASYNCEVENTSOURCE_H_ */ 184 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncWebAuthentication.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Portenta_H7_AsyncWebAuthentication.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #pragma once 29 | 30 | #ifndef PORTENTA_H7_ASYNCWEB_AUTHENTICATION_H_ 31 | #define PORTENTA_H7_ASYNCWEB_AUTHENTICATION_H_ 32 | 33 | #include "Arduino.h" 34 | #include "Portenta_H7_AsyncWebServer_Debug.h" 35 | 36 | ///////////////////////////////////////////////// 37 | 38 | bool checkBasicAuthentication(const char * header, const char * username, const char * password); 39 | String requestDigestAuthentication(const char * realm); 40 | bool checkDigestAuthentication(const char * header, const char * method, const char * username, const char * password, 41 | const char * realm, 42 | bool passwordIsHash, const char * nonce, const char * opaque, const char * uri); 43 | 44 | //for storing hashed versions on the device that can be authenticated against 45 | String generateDigestHash(const char * username, const char * password, const char * realm); 46 | 47 | #endif // APORTENTA_H7_SYNCWEB_AUTHENTICATIO_H_ 48 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncWebHandlerImpl.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Portenta_H7_AsyncWebHandlerImpl.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #pragma once 29 | 30 | #ifndef PORTENTA_H7_ASYNCWEBSERVERHANDLERIMPL_H_ 31 | #define PORTENTA_H7_ASYNCWEBSERVERHANDLERIMPL_H_ 32 | 33 | #include 34 | 35 | #ifdef ASYNCWEBSERVER_REGEX 36 | #include 37 | #endif 38 | 39 | #include "stddef.h" 40 | #include 41 | 42 | ///////////////////////////////////////////////// 43 | 44 | class AsyncStaticWebHandler: public AsyncWebHandler 45 | { 46 | private: 47 | uint8_t _countBits(const uint8_t value) const; 48 | 49 | protected: 50 | String _uri; 51 | String _path; 52 | String _cache_control; 53 | String _last_modified; 54 | AwsTemplateProcessor _callback; 55 | bool _isDir; 56 | bool _gzipFirst; 57 | uint8_t _gzipStats; 58 | 59 | public: 60 | AsyncStaticWebHandler(const char* uri, const char* path, const char* cache_control); 61 | virtual bool canHandle(AsyncWebServerRequest *request) override final; 62 | virtual void handleRequest(AsyncWebServerRequest *request) override final; 63 | AsyncStaticWebHandler& setIsDir(bool isDir); 64 | AsyncStaticWebHandler& setCacheControl(const char* cache_control); 65 | AsyncStaticWebHandler& setLastModified(const char* last_modified); 66 | AsyncStaticWebHandler& setLastModified(struct tm* last_modified); 67 | 68 | AsyncStaticWebHandler& setLastModified(time_t last_modified); 69 | AsyncStaticWebHandler& setLastModified(); //sets to current time. Make sure sntp is runing and time is updated 70 | 71 | ///////////////////////////////////////////////// 72 | 73 | AsyncStaticWebHandler& setTemplateProcessor(AwsTemplateProcessor newCallback) 74 | { 75 | _callback = newCallback; 76 | 77 | return *this; 78 | } 79 | }; 80 | 81 | ///////////////////////////////////////////////// 82 | 83 | class AsyncCallbackWebHandler: public AsyncWebHandler 84 | { 85 | private: 86 | protected: 87 | String _uri; 88 | WebRequestMethodComposite _method; 89 | ArRequestHandlerFunction _onRequest; 90 | ArUploadHandlerFunction _onUpload; 91 | ArBodyHandlerFunction _onBody; 92 | bool _isRegex; 93 | 94 | public: 95 | AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), 96 | _isRegex(false) {} 97 | 98 | ///////////////////////////////////////////////// 99 | 100 | void setUri(const String& uri) 101 | { 102 | _uri = uri; 103 | _isRegex = uri.startsWith("^") && uri.endsWith("$"); 104 | } 105 | 106 | ///////////////////////////////////////////////// 107 | 108 | void setMethod(WebRequestMethodComposite method) 109 | { 110 | _method = method; 111 | } 112 | 113 | ///////////////////////////////////////////////// 114 | 115 | void onRequest(ArRequestHandlerFunction fn) 116 | { 117 | _onRequest = fn; 118 | } 119 | 120 | ///////////////////////////////////////////////// 121 | 122 | void onUpload(ArUploadHandlerFunction fn) 123 | { 124 | _onUpload = fn; 125 | } 126 | 127 | ///////////////////////////////////////////////// 128 | 129 | void onBody(ArBodyHandlerFunction fn) 130 | { 131 | _onBody = fn; 132 | } 133 | 134 | ///////////////////////////////////////////////// 135 | 136 | virtual bool canHandle(AsyncWebServerRequest *request) override final 137 | { 138 | if (!_onRequest) 139 | return false; 140 | 141 | if (!(_method & request->method())) 142 | return false; 143 | 144 | #ifdef ASYNCWEBSERVER_REGEX 145 | 146 | if (_isRegex) 147 | { 148 | std::regex pattern(_uri.c_str()); 149 | std::smatch matches; 150 | std::string s(request->url().c_str()); 151 | 152 | if (std::regex_search(s, matches, pattern)) 153 | { 154 | for (size_t i = 1; i < matches.size(); ++i) 155 | { 156 | // start from 1 157 | request->_addPathParam(matches[i].str().c_str()); 158 | } 159 | } 160 | else 161 | { 162 | return false; 163 | } 164 | } 165 | else 166 | #endif 167 | if (_uri.length() && _uri.endsWith("*")) 168 | { 169 | String uriTemplate = String(_uri); 170 | uriTemplate = uriTemplate.substring(0, uriTemplate.length() - 1); 171 | 172 | if (!request->url().startsWith(uriTemplate)) 173 | return false; 174 | } 175 | else if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/"))) 176 | return false; 177 | 178 | request->addInterestingHeader("ANY"); 179 | 180 | return true; 181 | } 182 | 183 | ///////////////////////////////////////////////// 184 | 185 | virtual void handleRequest(AsyncWebServerRequest *request) override final 186 | { 187 | if (_onRequest) 188 | _onRequest(request); 189 | else 190 | request->send(500); 191 | } 192 | 193 | ///////////////////////////////////////////////// 194 | 195 | virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, 196 | size_t total) override final 197 | { 198 | if (_onBody) 199 | _onBody(request, data, len, index, total); 200 | } 201 | 202 | ///////////////////////////////////////////////// 203 | 204 | virtual bool isRequestHandlerTrivial() override final 205 | { 206 | return _onRequest ? false : true; 207 | } 208 | }; 209 | 210 | ///////////////////////////////////////////////// 211 | 212 | #endif /* PORTENTA_H7_ASYNCWEBSERVERHANDLERIMPL_H_ */ 213 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncWebHandlers.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Portenta_H7_AsyncWebHandlers.cpp 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #if !defined(_PORTENTA_H7_AWS_LOGLEVEL_) 29 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 1 30 | #endif 31 | 32 | #include "Portenta_H7_AsyncWebServer_Debug.h" 33 | 34 | #include "Portenta_H7_AsyncWebServer.h" 35 | #include "Portenta_H7_AsyncWebHandlerImpl.h" 36 | 37 | ///////////////////////////////////////////////// 38 | 39 | AsyncStaticWebHandler::AsyncStaticWebHandler(const char* uri, /*FS& fs,*/ const char* path, const char* cache_control) 40 | : _uri(uri), _path(path), _cache_control(cache_control), _last_modified(""), _callback(nullptr) 41 | { 42 | // Ensure leading '/' 43 | if (_uri.length() == 0 || _uri[0] != '/') 44 | _uri = "/" + _uri; 45 | 46 | if (_path.length() == 0 || _path[0] != '/') 47 | _path = "/" + _path; 48 | 49 | // If path ends with '/' we assume a hint that this is a directory to improve performance. 50 | // However - if it does not end with '/' we, can't assume a file, path can still be a directory. 51 | _isDir = _path[_path.length() - 1] == '/'; 52 | 53 | // Remove the trailing '/' so we can handle default file 54 | // Notice that root will be "" not "/" 55 | if (_uri[_uri.length() - 1] == '/') 56 | _uri = _uri.substring(0, _uri.length() - 1); 57 | 58 | if (_path[_path.length() - 1] == '/') 59 | _path = _path.substring(0, _path.length() - 1); 60 | 61 | // Reset stats 62 | _gzipFirst = false; 63 | _gzipStats = 0xF8; 64 | } 65 | 66 | ///////////////////////////////////////////////// 67 | 68 | AsyncStaticWebHandler& AsyncStaticWebHandler::setIsDir(bool isDir) 69 | { 70 | _isDir = isDir; 71 | 72 | return *this; 73 | } 74 | 75 | ///////////////////////////////////////////////// 76 | 77 | AsyncStaticWebHandler& AsyncStaticWebHandler::setCacheControl(const char* cache_control) 78 | { 79 | _cache_control = String(cache_control); 80 | 81 | return *this; 82 | } 83 | 84 | ///////////////////////////////////////////////// 85 | 86 | AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(const char* last_modified) 87 | { 88 | _last_modified = String(last_modified); 89 | 90 | return *this; 91 | } 92 | 93 | ///////////////////////////////////////////////// 94 | 95 | AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(struct tm* last_modified) 96 | { 97 | char result[30]; 98 | 99 | strftime (result, 30, "%a, %d %b %Y %H:%M:%S %Z", last_modified); 100 | 101 | return setLastModified((const char *)result); 102 | } 103 | 104 | ///////////////////////////////////////////////// 105 | 106 | AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(time_t last_modified) 107 | { 108 | return setLastModified((struct tm *)gmtime(&last_modified)); 109 | } 110 | 111 | ///////////////////////////////////////////////// 112 | 113 | AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified() 114 | { 115 | time_t last_modified; 116 | 117 | if (time(&last_modified) == 0) //time is not yet set 118 | return *this; 119 | 120 | return setLastModified(last_modified); 121 | } 122 | 123 | ///////////////////////////////////////////////// 124 | 125 | bool AsyncStaticWebHandler::canHandle(AsyncWebServerRequest *request) 126 | { 127 | if (request->method() != HTTP_GET 128 | || !request->url().startsWith(_uri) 129 | || !request->isExpectedRequestedConnType(RCT_DEFAULT, RCT_HTTP) 130 | ) 131 | { 132 | return false; 133 | } 134 | 135 | return false; 136 | } 137 | 138 | ///////////////////////////////////////////////// 139 | 140 | #define FILE_IS_REAL(f) (f == true) 141 | 142 | ///////////////////////////////////////////////// 143 | 144 | uint8_t AsyncStaticWebHandler::_countBits(const uint8_t value) const 145 | { 146 | uint8_t w = value; 147 | uint8_t n; 148 | 149 | for (n = 0; w != 0; n++) 150 | w &= w - 1; 151 | 152 | return n; 153 | } 154 | 155 | ///////////////////////////////////////////////// 156 | 157 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncWebResponseImpl.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Portenta_H7_AsyncWebResponseImpl.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #pragma once 29 | 30 | #ifndef PORTENTA_H7_ASYNCWEBSERVERRESPONSEIMPL_H_ 31 | #define PORTENTA_H7_ASYNCWEBSERVERRESPONSEIMPL_H_ 32 | 33 | ///////////////////////////////////////////////// 34 | 35 | #ifdef Arduino_h 36 | // arduino is not compatible with std::vector 37 | #undef min 38 | #undef max 39 | #endif 40 | 41 | #include 42 | // It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max. 43 | 44 | ///////////////////////////////////////////////// 45 | 46 | class AsyncBasicResponse: public AsyncWebServerResponse 47 | { 48 | private: 49 | String _content; 50 | char *_contentCstr; // RSMOD 51 | String _partialHeader; 52 | 53 | public: 54 | AsyncBasicResponse(int code, const String& contentType = String(), const String& content = String()); 55 | AsyncBasicResponse(int code, const String& contentType, const char *content = nullptr); // RSMOD 56 | void _respond(AsyncWebServerRequest *request); 57 | 58 | size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); 59 | 60 | bool _sourceValid() const 61 | { 62 | return true; 63 | } 64 | }; 65 | 66 | ///////////////////////////////////////////////// 67 | 68 | class AsyncAbstractResponse: public AsyncWebServerResponse 69 | { 70 | private: 71 | String _head; 72 | // Data is inserted into cache at begin(). 73 | // This is inefficient with vector, but if we use some other container, 74 | // we won't be able to access it as contiguous array of bytes when reading from it, 75 | // so by gaining performance in one place, we'll lose it in another. 76 | std::vector _cache; 77 | size_t _readDataFromCacheOrContent(uint8_t* data, const size_t len); 78 | size_t _fillBufferAndProcessTemplates(uint8_t* buf, size_t maxLen); 79 | 80 | protected: 81 | AwsTemplateProcessor _callback; 82 | 83 | public: 84 | AsyncAbstractResponse(AwsTemplateProcessor callback = nullptr); 85 | void _respond(AsyncWebServerRequest *request); 86 | size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); 87 | 88 | bool _sourceValid() const 89 | { 90 | return false; 91 | } 92 | 93 | virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused))) 94 | { 95 | return 0; 96 | } 97 | }; 98 | 99 | ///////////////////////////////////////////////// 100 | 101 | #ifndef TEMPLATE_PLACEHOLDER 102 | #define TEMPLATE_PLACEHOLDER '%' 103 | #endif 104 | 105 | #define TEMPLATE_PARAM_NAME_LENGTH 32 106 | 107 | ///////////////////////////////////////////////// 108 | 109 | class AsyncStreamResponse: public AsyncAbstractResponse 110 | { 111 | private: 112 | Stream *_content; 113 | 114 | public: 115 | AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr); 116 | 117 | bool _sourceValid() const 118 | { 119 | return !!(_content); 120 | } 121 | 122 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; 123 | }; 124 | 125 | ///////////////////////////////////////////////// 126 | 127 | class AsyncCallbackResponse: public AsyncAbstractResponse 128 | { 129 | private: 130 | AwsResponseFiller _content; 131 | size_t _filledLength; 132 | 133 | public: 134 | AsyncCallbackResponse(const String& contentType, size_t len, AwsResponseFiller callback, 135 | AwsTemplateProcessor templateCallback = nullptr); 136 | 137 | bool _sourceValid() const 138 | { 139 | return !!(_content); 140 | } 141 | 142 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; 143 | }; 144 | 145 | ///////////////////////////////////////////////// 146 | 147 | class AsyncChunkedResponse: public AsyncAbstractResponse 148 | { 149 | private: 150 | AwsResponseFiller _content; 151 | size_t _filledLength; 152 | 153 | public: 154 | AsyncChunkedResponse(const String& contentType, AwsResponseFiller callback, 155 | AwsTemplateProcessor templateCallback = nullptr); 156 | 157 | bool _sourceValid() const 158 | { 159 | return !!(_content); 160 | } 161 | 162 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; 163 | }; 164 | 165 | ///////////////////////////////////////////////// 166 | 167 | class cbuf; 168 | 169 | ///////////////////////////////////////////////// 170 | 171 | class AsyncResponseStream: public AsyncAbstractResponse, public Print 172 | { 173 | private: 174 | cbuf *_content; 175 | 176 | public: 177 | AsyncResponseStream(const String& contentType, size_t bufferSize); 178 | ~AsyncResponseStream(); 179 | 180 | bool _sourceValid() const 181 | { 182 | return (_state < RESPONSE_END); 183 | } 184 | 185 | virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; 186 | size_t write(const uint8_t *data, size_t len); 187 | size_t write(uint8_t data); 188 | using Print::write; 189 | }; 190 | 191 | ///////////////////////////////////////////////// 192 | 193 | #endif /* PORTENTA_H7_ASYNCWEBSERVERRESPONSEIMPL_H_ */ 194 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncWebServer_Debug.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Portenta_H7_AsyncWebServer_Debug.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #pragma once 29 | 30 | #ifndef PORTENTA_H7_ASYNC_WEBSERVER_DEBUG_H 31 | #define PORTENTA_H7_ASYNC_WEBSERVER_DEBUG_H 32 | 33 | ///////////////////////////////////////////////// 34 | 35 | #ifdef PORTENTA_H7_ASYNCWEBSERVER_DEBUG_PORT 36 | #define DBG_PORT_AWS PORTENTA_H7_ASYNCWEBSERVER_DEBUG_PORT 37 | #else 38 | #define DBG_PORT_AWS Serial 39 | #endif 40 | 41 | ///////////////////////////////////////////////// 42 | 43 | // Change _PORTENTA_H7_AWS_LOGLEVEL_ to set tracing and logging verbosity 44 | // 0: DISABLED: no logging 45 | // 1: ERROR: errors 46 | // 2: WARN: errors and warnings 47 | // 3: INFO: errors, warnings and informational (default) 48 | // 4: DEBUG: errors, warnings, informational and debug 49 | 50 | #ifndef _PORTENTA_H7_AWS_LOGLEVEL_ 51 | #define _PORTENTA_H7_AWS_LOGLEVEL_ 0 52 | #endif 53 | 54 | ///////////////////////////////////////////////////////// 55 | 56 | #define AWS_PRINT_MARK AWS_PRINT("[AWS] ") 57 | #define AWS_PRINT_SP DBG_PORT_AWS.print(" ") 58 | 59 | #define AWS_PRINT DBG_PORT_AWS.print 60 | #define AWS_PRINTLN DBG_PORT_AWS.println 61 | 62 | ///////////////////////////////////////////////////////// 63 | 64 | #define AWS_LOGERROR(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINTLN(x); } 65 | #define AWS_LOGERROR0(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>0) { AWS_PRINT(x); } 66 | #define AWS_LOGERROR1(x,y) if(_PORTENTA_H7_AWS_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } 67 | #define AWS_LOGERROR2(x,y,z) if(_PORTENTA_H7_AWS_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } 68 | #define AWS_LOGERROR3(x,y,z,w) if(_PORTENTA_H7_AWS_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } 69 | 70 | ///////////////////////////////////////////////// 71 | 72 | #define AWS_LOGWARN(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINTLN(x); } 73 | #define AWS_LOGWARN0(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>1) { AWS_PRINT(x); } 74 | #define AWS_LOGWARN1(x,y) if(_PORTENTA_H7_AWS_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } 75 | #define AWS_LOGWARN2(x,y,z) if(_PORTENTA_H7_AWS_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } 76 | #define AWS_LOGWARN3(x,y,z,w) if(_PORTENTA_H7_AWS_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } 77 | 78 | ///////////////////////////////////////////////// 79 | 80 | #define AWS_LOGINFO(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINTLN(x); } 81 | #define AWS_LOGINFO0(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>2) { AWS_PRINT(x); } 82 | #define AWS_LOGINFO1(x,y) if(_PORTENTA_H7_AWS_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } 83 | #define AWS_LOGINFO2(x,y,z) if(_PORTENTA_H7_AWS_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } 84 | #define AWS_LOGINFO3(x,y,z,w) if(_PORTENTA_H7_AWS_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } 85 | 86 | ///////////////////////////////////////////////// 87 | 88 | #define AWS_LOGDEBUG(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINTLN(x); } 89 | #define AWS_LOGDEBUG0(x) if(_PORTENTA_H7_AWS_LOGLEVEL_>3) { AWS_PRINT(x); } 90 | #define AWS_LOGDEBUG1(x,y) if(_PORTENTA_H7_AWS_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } 91 | #define AWS_LOGDEBUG2(x,y,z) if(_PORTENTA_H7_AWS_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } 92 | #define AWS_LOGDEBUG3(x,y,z,w) if(_PORTENTA_H7_AWS_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } 93 | #define AWS_LOGDEBUG5(x,y,z,w,xx,yy) if(_PORTENTA_H7_AWS_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINT(w); AWS_PRINT_SP; AWS_PRINT(xx); AWS_PRINT_SP; AWS_PRINTLN(yy);} 94 | 95 | ///////////////////////////////////////////////// 96 | 97 | #endif //PORTENTA_H7_ASYNC_WEBSERVER_DEBUG_H 98 | -------------------------------------------------------------------------------- /src/Portenta_H7_AsyncWebSynchronization.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Portenta_H7_AsyncWebSynchronization.h 3 | 4 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet or Murata WiFi 5 | 6 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with Vision-Shield Ethernet or Murata WiFi 7 | 8 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 9 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 10 | Licensed under GPLv3 license 11 | 12 | Version: 1.5.0 13 | 14 | Version Modified By Date Comments 15 | ------- ----------- ---------- ----------- 16 | 1.0.0 K Hoang 06/10/2021 Initial coding for Portenta_H7 (STM32H7) with Vision-Shield Ethernet 17 | 1.1.0 K Hoang 08/10/2021 Add support to Portenta_H7 (STM32H7) using Murata WiFi 18 | 1.1.1 K Hoang 12/10/2021 Update `platform.ini` and `library.json` 19 | 1.2.0 K Hoang 07/12/2021 Fix crashing issue 20 | 1.2.1 K Hoang 12/01/2022 Fix authenticate issue caused by libb64 21 | 1.3.0 K Hoang 26/09/2022 Fix issue with slow browsers or network 22 | 1.4.0 K Hoang 02/10/2022 Option to use cString instead og String to save Heap 23 | 1.4.1 K Hoang 04/10/2022 Don't need memmove(), String no longer destroyed 24 | 1.4.2 K Hoang 10/11/2022 Add examples to demo how to use beginChunkedResponse() to send in chunks 25 | 1.5.0 K Hoang 30/01/2023 Fix _catchAllHandler not working bug 26 | *****************************************************************************************************************************/ 27 | 28 | #pragma once 29 | 30 | #ifndef PORTENTA_H7_ASYNCWEBSYNCHRONIZATION_H_ 31 | #define PORTENTA_H7_ASYNCWEBSYNCHRONIZATION_H_ 32 | 33 | #include 34 | 35 | ///////////////////////////////////////////////// 36 | 37 | // This is the STM32 version of the Sync Lock which is currently unimplemented 38 | class AsyncWebLock 39 | { 40 | 41 | public: 42 | AsyncWebLock() {} 43 | 44 | ~AsyncWebLock() {} 45 | 46 | bool lock() const 47 | { 48 | return false; 49 | } 50 | 51 | void unlock() const {} 52 | }; 53 | 54 | ///////////////////////////////////////////////// 55 | 56 | class AsyncWebLockGuard 57 | { 58 | private: 59 | const AsyncWebLock *_lock; 60 | 61 | public: 62 | AsyncWebLockGuard(const AsyncWebLock &l) 63 | { 64 | if (l.lock()) 65 | { 66 | _lock = &l; 67 | } 68 | else 69 | { 70 | _lock = NULL; 71 | } 72 | } 73 | 74 | ~AsyncWebLockGuard() 75 | { 76 | if (_lock) 77 | { 78 | _lock->unlock(); 79 | } 80 | } 81 | }; 82 | 83 | ///////////////////////////////////////////////// 84 | 85 | #endif // PORTENTA_H7_ASYNCWEBSYNCHRONIZATION_H_ 86 | -------------------------------------------------------------------------------- /src/libb64/cdecode.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | cdecode.c - c source to a base64 decoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | 7 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 8 | 9 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 10 | 11 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 12 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 13 | Licensed under GPLv3 license 14 | *****************************************************************************************************************************/ 15 | 16 | #include "cdecode.h" 17 | 18 | int base64_decode_value(int value_in) 19 | { 20 | static const char decoding[] = 21 | { 22 | 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 23 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, 24 | -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 25 | 47, 48, 49, 50, 51 26 | }; 27 | 28 | static const char decoding_size = sizeof(decoding); 29 | value_in -= 43; 30 | 31 | if (value_in < 0 || value_in > decoding_size) 32 | return -1; 33 | 34 | return decoding[(int)value_in]; 35 | } 36 | 37 | void base64_init_decodestate(base64_decodestate* state_in) 38 | { 39 | state_in->step = step_a; 40 | state_in->plainchar = 0; 41 | } 42 | 43 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) 44 | { 45 | const char* codechar = code_in; 46 | char* plainchar = plaintext_out; 47 | int fragment; 48 | 49 | *plainchar = state_in->plainchar; 50 | 51 | switch (state_in->step) 52 | { 53 | while (1) 54 | { 55 | case step_a: 56 | do 57 | { 58 | if (codechar == code_in + length_in) 59 | { 60 | state_in->step = step_a; 61 | state_in->plainchar = *plainchar; 62 | return plainchar - plaintext_out; 63 | } 64 | 65 | fragment = base64_decode_value(*codechar++); 66 | } while (fragment < 0); 67 | 68 | *plainchar = (fragment & 0x03f) << 2; 69 | 70 | // fall through 71 | 72 | case step_b: 73 | do 74 | { 75 | if (codechar == code_in + length_in) 76 | { 77 | state_in->step = step_b; 78 | state_in->plainchar = *plainchar; 79 | return plainchar - plaintext_out; 80 | } 81 | 82 | fragment = base64_decode_value(*codechar++); 83 | } while (fragment < 0); 84 | 85 | *plainchar++ |= (fragment & 0x030) >> 4; 86 | *plainchar = (fragment & 0x00f) << 4; 87 | 88 | // fall through 89 | 90 | case step_c: 91 | do 92 | { 93 | if (codechar == code_in + length_in) 94 | { 95 | state_in->step = step_c; 96 | state_in->plainchar = *plainchar; 97 | return plainchar - plaintext_out; 98 | } 99 | 100 | fragment = base64_decode_value(*codechar++); 101 | } while (fragment < 0); 102 | 103 | *plainchar++ |= (fragment & 0x03c) >> 2; 104 | *plainchar = (fragment & 0x003) << 6; 105 | 106 | // fall through 107 | 108 | case step_d: 109 | do 110 | { 111 | if (codechar == code_in + length_in) 112 | { 113 | state_in->step = step_d; 114 | state_in->plainchar = *plainchar; 115 | return plainchar - plaintext_out; 116 | } 117 | 118 | fragment = base64_decode_value(*codechar++); 119 | } while (fragment < 0); 120 | 121 | *plainchar++ |= (fragment & 0x03f); 122 | 123 | // fall through 124 | } 125 | } 126 | 127 | /* control should not reach here */ 128 | return plainchar - plaintext_out; 129 | } 130 | 131 | int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out) 132 | { 133 | 134 | base64_decodestate _state; 135 | base64_init_decodestate(&_state); 136 | int len = base64_decode_block(code_in, length_in, plaintext_out, &_state); 137 | 138 | if (len > 0) 139 | plaintext_out[len] = 0; 140 | 141 | return len; 142 | } 143 | -------------------------------------------------------------------------------- /src/libb64/cdecode.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | cdecode.h - c header for a base64 decoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | 7 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 8 | 9 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 10 | 11 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 12 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 13 | Licensed under GPLv3 license 14 | *****************************************************************************************************************************/ 15 | 16 | #pragma once 17 | 18 | // Reintroduce to prevent duplication compile error if other lib/core already has LIB64 19 | // pragma once can't prevent that 20 | #ifndef BASE64_CDECODE_H 21 | #define BASE64_CDECODE_H 22 | 23 | #define base64_decode_expected_len(n) ((n * 3) / 4) 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef enum 30 | { 31 | step_a, step_b, step_c, step_d 32 | } base64_decodestep; 33 | 34 | typedef struct 35 | { 36 | base64_decodestep step; 37 | char plainchar; 38 | } base64_decodestate; 39 | 40 | void base64_init_decodestate(base64_decodestate* state_in); 41 | 42 | int base64_decode_value(int value_in); 43 | 44 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); 45 | 46 | int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out); 47 | 48 | #ifdef __cplusplus 49 | } // extern "C" 50 | #endif 51 | 52 | #endif /* BASE64_CDECODE_H */ 53 | -------------------------------------------------------------------------------- /src/libb64/cencode.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | cencode.c - c source to a base64 encoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | 7 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 8 | 9 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 10 | 11 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 12 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 13 | Licensed under GPLv3 license 14 | *****************************************************************************************************************************/ 15 | 16 | #include "cencode.h" 17 | 18 | const int CHARS_PER_LINE = 72; 19 | 20 | void base64_init_encodestate(base64_encodestate* state_in) 21 | { 22 | state_in->step = step_A; 23 | state_in->result = 0; 24 | state_in->stepcount = 0; 25 | } 26 | 27 | char base64_encode_value(char value_in) 28 | { 29 | static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 30 | 31 | if (value_in > 63) 32 | return '='; 33 | 34 | return encoding[(unsigned int)value_in]; 35 | } 36 | 37 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) 38 | { 39 | const char* plainchar = plaintext_in; 40 | const char* const plaintextend = plaintext_in + length_in; 41 | char* codechar = code_out; 42 | char result; 43 | char fragment; 44 | 45 | result = state_in->result; 46 | 47 | switch (state_in->step) 48 | { 49 | while (1) 50 | { 51 | case step_A: 52 | if (plainchar == plaintextend) 53 | { 54 | state_in->result = result; 55 | state_in->step = step_A; 56 | return codechar - code_out; 57 | } 58 | 59 | fragment = *plainchar++; 60 | result = (fragment & 0x0fc) >> 2; 61 | *codechar++ = base64_encode_value(result); 62 | result = (fragment & 0x003) << 4; 63 | 64 | // fall through 65 | 66 | case step_B: 67 | if (plainchar == plaintextend) 68 | { 69 | state_in->result = result; 70 | state_in->step = step_B; 71 | return codechar - code_out; 72 | } 73 | 74 | fragment = *plainchar++; 75 | result |= (fragment & 0x0f0) >> 4; 76 | *codechar++ = base64_encode_value(result); 77 | result = (fragment & 0x00f) << 2; 78 | 79 | // fall through 80 | 81 | case step_C: 82 | if (plainchar == plaintextend) 83 | { 84 | state_in->result = result; 85 | state_in->step = step_C; 86 | return codechar - code_out; 87 | } 88 | 89 | fragment = *plainchar++; 90 | result |= (fragment & 0x0c0) >> 6; 91 | *codechar++ = base64_encode_value(result); 92 | result = (fragment & 0x03f) >> 0; 93 | *codechar++ = base64_encode_value(result); 94 | 95 | ++(state_in->stepcount); 96 | 97 | if (state_in->stepcount == CHARS_PER_LINE / 4) 98 | { 99 | *codechar++ = '\n'; 100 | state_in->stepcount = 0; 101 | } 102 | 103 | // fall through 104 | } 105 | } 106 | 107 | /* control should not reach here */ 108 | return codechar - code_out; 109 | } 110 | 111 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in) 112 | { 113 | char* codechar = code_out; 114 | 115 | switch (state_in->step) 116 | { 117 | case step_B: 118 | *codechar++ = base64_encode_value(state_in->result); 119 | *codechar++ = '='; 120 | *codechar++ = '='; 121 | break; 122 | 123 | case step_C: 124 | *codechar++ = base64_encode_value(state_in->result); 125 | *codechar++ = '='; 126 | break; 127 | 128 | case step_A: 129 | break; 130 | } 131 | 132 | *codechar = 0x00; 133 | 134 | return codechar - code_out; 135 | } 136 | 137 | int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out) 138 | { 139 | base64_encodestate _state; 140 | base64_init_encodestate(&_state); 141 | int len = base64_encode_block(plaintext_in, length_in, code_out, &_state); 142 | 143 | return len + base64_encode_blockend((code_out + len), &_state); 144 | } 145 | -------------------------------------------------------------------------------- /src/libb64/cencode.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | cencode.h - c header for a base64 encoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | 7 | For Portenta_H7 (STM32H7) with Vision-Shield Ethernet 8 | 9 | Portenta_H7_AsyncWebServer is a library for the Portenta_H7 with with Vision-Shield Ethernet 10 | 11 | Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) 12 | Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_AsyncWebServer 13 | Licensed under GPLv3 license 14 | *****************************************************************************************************************************/ 15 | 16 | #pragma once 17 | 18 | // Reintroduce to prevent duplication compile error if other lib/core already has LIB64 19 | // pragma once can't prevent that 20 | #ifndef BASE64_CENCODE_H 21 | #define BASE64_CENCODE_H 22 | 23 | #define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3) 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef enum 30 | { 31 | step_A, step_B, step_C 32 | } base64_encodestep; 33 | 34 | typedef struct 35 | { 36 | base64_encodestep step; 37 | char result; 38 | int stepcount; 39 | } base64_encodestate; 40 | 41 | void base64_init_encodestate(base64_encodestate* state_in); 42 | 43 | char base64_encode_value(char value_in); 44 | 45 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); 46 | 47 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in); 48 | 49 | int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out); 50 | 51 | #ifdef __cplusplus 52 | } // extern "C" 53 | #endif 54 | 55 | #endif /* BASE64_CENCODE_H */ 56 | -------------------------------------------------------------------------------- /travis/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function build_examples() 4 | { 5 | # track the exit code for this platform 6 | local exit_code=0 7 | # loop through results and add them to the array 8 | examples=($(find $PWD/examples/ -name "*.pde" -o -name "*.ino")) 9 | 10 | # get the last example in the array 11 | local last="${examples[@]:(-1)}" 12 | 13 | # loop through example sketches 14 | for example in "${examples[@]}"; do 15 | 16 | # store the full path to the example's sketch directory 17 | local example_dir=$(dirname $example) 18 | 19 | # store the filename for the example without the path 20 | local example_file=$(basename $example) 21 | 22 | echo "$example_file: " 23 | local sketch="$example_dir/$example_file" 24 | echo "$sketch" 25 | #arduino -v --verbose-build --verify $sketch 26 | 27 | # verify the example, and save stdout & stderr to a variable 28 | # we have to avoid reading the exit code of local: 29 | # "when declaring a local variable in a function, the local acts as a command in its own right" 30 | local build_stdout 31 | build_stdout=$(arduino --verify $sketch 2>&1) 32 | 33 | # echo output if the build failed 34 | if [ $? -ne 0 ]; then 35 | # heavy X 36 | echo -e "\xe2\x9c\x96" 37 | echo -e "----------------------------- DEBUG OUTPUT -----------------------------\n" 38 | echo "$build_stdout" 39 | echo -e "\n------------------------------------------------------------------------\n" 40 | 41 | # mark as fail 42 | exit_code=1 43 | 44 | else 45 | # heavy checkmark 46 | echo -e "\xe2\x9c\x93" 47 | fi 48 | done 49 | 50 | return $exit_code 51 | } 52 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------