├── .codespellrc ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml ├── stale.yml └── workflows │ ├── auto-github-actions.yml │ ├── check-arduino.yml │ ├── report-size-deltas.yml │ └── spell-check.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── LibraryPatches ├── Ethernet │ └── src │ │ ├── Ethernet.cpp │ │ ├── Ethernet.h │ │ ├── EthernetServer.cpp │ │ └── utility │ │ ├── w5100.cpp │ │ └── w5100.h ├── Ethernet2 │ └── src │ │ ├── Ethernet2.cpp │ │ ├── Ethernet2.h │ │ ├── EthernetUdp2.cpp │ │ └── EthernetUdp2.h ├── Ethernet3 │ └── src │ │ ├── Ethernet3.cpp │ │ └── Ethernet3.h ├── EthernetLarge │ └── src │ │ ├── EthernetLarge.cpp │ │ ├── EthernetLarge.h │ │ ├── EthernetServer.cpp │ │ └── utility │ │ ├── w5100.cpp │ │ └── w5100.h ├── UIPEthernet-2.0.9 │ ├── UIPEthernet.cpp │ ├── UIPEthernet.h │ └── utility │ │ ├── Enc28J60Network.cpp │ │ └── Enc28J60Network.h ├── UIPEthernet │ ├── UIPEthernet.cpp │ ├── UIPEthernet.h │ └── utility │ │ ├── Enc28J60Network.cpp │ │ └── Enc28J60Network.h └── esp32 │ └── cores │ └── esp32 │ └── Server.h ├── Packages_Patches └── STM32 │ └── hardware │ └── stm32 │ ├── 1.9.0 │ ├── system │ │ ├── STM32F4xx │ │ │ └── stm32f4xx_hal_conf_default.h │ │ └── STM32F7xx │ │ │ └── stm32f7xx_hal_conf_default.h │ └── variants │ │ ├── NUCLEO_F767ZI │ │ └── variant.h │ │ └── NUCLEO_L053R8 │ │ └── variant.h │ ├── 2.0.0 │ ├── system │ │ ├── STM32F4xx │ │ │ └── stm32f4xx_hal_conf_default.h │ │ └── STM32F7xx │ │ │ └── stm32f7xx_hal_conf_default.h │ └── variants │ │ ├── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ └── variant_NUCLEO_F767ZI.h │ │ ├── L052R(6-8)H_L053R(6-8)H │ │ └── variant_generic.h │ │ ├── STM32F7xx │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ └── variant_NUCLEO_F767ZI.h │ │ └── STM32L0xx │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ └── variant_generic.h │ ├── 2.1.0 │ ├── system │ │ ├── STM32F4xx │ │ │ └── stm32f4xx_hal_conf_default.h │ │ └── STM32F7xx │ │ │ └── stm32f7xx_hal_conf_default.h │ └── variants │ │ ├── STM32F7xx │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ └── variant_NUCLEO_F767ZI.h │ │ └── STM32L0xx │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ └── variant_generic.h │ ├── 2.2.0 │ ├── system │ │ ├── STM32F4xx │ │ │ └── stm32f4xx_hal_conf_default.h │ │ └── STM32F7xx │ │ │ └── stm32f7xx_hal_conf_default.h │ └── variants │ │ ├── STM32F7xx │ │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ │ └── variant_NUCLEO_F767ZI.h │ │ └── STM32L0xx │ │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ │ └── variant_generic.h │ └── 2.3.0 │ ├── system │ ├── STM32F4xx │ │ └── stm32f4xx_hal_conf_default.h │ └── STM32F7xx │ │ └── stm32f7xx_hal_conf_default.h │ └── variants │ ├── STM32F7xx │ └── F765Z(G-I)T_F767Z(G-I)T_F777ZIT │ │ └── variant_NUCLEO_F767ZI.h │ └── STM32L0xx │ └── L052R(6-8)T_L053R(6-8)T_L063R8T │ └── variant_generic.h ├── README.md ├── changelog.md ├── examples ├── AdvancedWebServer │ ├── AdvancedWebServer.ino │ └── defines.h ├── HTTPClient │ ├── BasicAuthGet │ │ ├── BasicAuthGet.ino │ │ └── defines.h │ ├── CustomHeader │ │ ├── CustomHeader.ino │ │ └── defines.h │ ├── DweetGet │ │ ├── DweetGet.ino │ │ └── defines.h │ ├── DweetPost │ │ ├── DweetPost.ino │ │ └── defines.h │ ├── HueBlink │ │ ├── HueBlink.ino │ │ └── defines.h │ ├── PostWithHeaders │ │ ├── PostWithHeaders.ino │ │ └── defines.h │ ├── SimpleDelete │ │ ├── SimpleDelete.ino │ │ └── defines.h │ ├── SimpleGet │ │ ├── SimpleGet.ino │ │ └── defines.h │ ├── SimpleHTTPExample │ │ ├── SimpleHTTPExample.ino │ │ └── defines.h │ ├── SimplePost │ │ ├── SimplePost.ino │ │ └── defines.h │ ├── SimplePut │ │ ├── SimplePut.ino │ │ └── defines.h │ ├── SimpleWebSocket │ │ ├── SimpleWebSocket.ino │ │ └── defines.h │ └── node_test_server │ │ ├── getPostPutDelete.js │ │ └── package.json ├── HelloServer │ ├── HelloServer.ino │ └── defines.h ├── HelloServer2 │ ├── HelloServer2.ino │ └── defines.h ├── HttpBasicAuth │ ├── HttpBasicAuth.ino │ └── defines.h ├── MQTTClient_Auth │ ├── MQTTClient_Auth.ino │ └── defines.h ├── MQTTClient_Basic │ ├── MQTTClient_Basic.ino │ └── defines.h ├── MQTT_ThingStream │ ├── MQTT_ThingStream.ino │ └── defines.h ├── PostServer │ ├── PostServer.ino │ └── defines.h ├── STM32_LAN8720 │ ├── AdvancedWebServer_LAN8720 │ │ ├── AdvancedWebServer_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── HTTPClient_LAN8720 │ │ ├── BasicAuthGet_LAN8720 │ │ │ ├── BasicAuthGet_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── CustomHeader_LAN8720 │ │ │ ├── CustomHeader_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── DweetGet_LAN8720 │ │ │ ├── DweetGet_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── DweetPost_LAN8720 │ │ │ ├── DweetPost_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── HueBlink_LAN8720 │ │ │ ├── HueBlink_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── PostWithHeaders_LAN8720 │ │ │ ├── PostWithHeaders_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── SimpleDelete_LAN8720 │ │ │ ├── SimpleDelete_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── SimpleGet_LAN8720 │ │ │ ├── SimpleGet_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── SimpleHTTPExample_LAN8720 │ │ │ ├── SimpleHTTPExample_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── SimplePost_LAN8720 │ │ │ ├── SimplePost_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── SimplePut_LAN8720 │ │ │ ├── SimplePut_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ ├── SimpleWebSocket_LAN8720 │ │ │ ├── SimpleWebSocket_LAN8720.ino │ │ │ ├── defines.h │ │ │ └── hal_conf_extra.h │ │ └── node_test_server │ │ │ ├── getPostPutDelete.js │ │ │ └── package.json │ ├── HelloServer2_LAN8720 │ │ ├── HelloServer2_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── HelloServer_LAN8720 │ │ ├── HelloServer_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── HttpBasicAuth_LAN8720 │ │ ├── HttpBasicAuth_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── MQTTClient_Auth_LAN8720 │ │ ├── MQTTClient_Auth_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── MQTTClient_Basic_LAN8720 │ │ ├── MQTTClient_Basic_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── MQTT_ThingStream_LAN8720 │ │ ├── MQTT_ThingStream_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── PostServer_LAN8720 │ │ ├── PostServer_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── SimpleAuthentication_LAN8720 │ │ ├── SimpleAuthentication_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── UdpNTPClient_LAN8720 │ │ ├── UdpNTPClient_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── UdpSendReceive_LAN8720 │ │ ├── UdpSendReceive_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── WebClientRepeating_LAN8720 │ │ ├── WebClientRepeating_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ ├── WebClient_LAN8720 │ │ ├── WebClient_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h │ └── WebServer_LAN8720 │ │ ├── WebServer_LAN8720.ino │ │ ├── defines.h │ │ └── hal_conf_extra.h ├── SimpleAuthentication │ ├── SimpleAuthentication.ino │ └── defines.h ├── UdpNTPClient │ ├── UdpNTPClient.ino │ └── defines.h ├── UdpSendReceive │ ├── UdpSendReceive.ino │ └── defines.h ├── WebClient │ ├── WebClient.ino │ └── defines.h ├── WebClientRepeating │ ├── WebClientRepeating.ino │ └── defines.h ├── WebServer │ ├── WebServer.ino │ └── defines.h └── multiFileProject │ ├── multiFileProject.cpp │ ├── multiFileProject.h │ └── multiFileProject.ino ├── keywords.txt ├── library.json ├── library.properties ├── pics ├── AdvancedWebServer.png ├── AdvancedWebServer_LAN8720.png ├── AdvancedWebServer_NUCLEO_L552ZE_Q.png ├── LAN8720_STM32F4_Wiring.png └── STM32F407VET6.png ├── platformio └── platformio.ini ├── src ├── EthernetHttpClient_STM32.h ├── EthernetWebServer_STM32-impl.h ├── EthernetWebServer_STM32.h ├── EthernetWebServer_STM32.hpp ├── Ethernet_HTTPClient │ ├── Ethernet_HttpClient.cpp │ ├── Ethernet_HttpClient.h │ ├── Ethernet_URLEncoder.cpp │ ├── Ethernet_URLEncoder.h │ ├── Ethernet_WebSocketClient.cpp │ └── Ethernet_WebSocketClient.h ├── Parsing_STM32-impl.h ├── detail │ ├── Debug_STM32.h │ ├── RequestHandler_STM32.h │ ├── RequestHandlersImpl_STM32.h │ └── mimetable.h └── libb64 │ ├── base64.cpp │ ├── base64.h │ ├── cdecode.c │ ├── cdecode.h │ ├── cencode.c │ └── cencode.h └── utils ├── astyle_library.conf └── restyle.sh /.codespellrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/codespell-project/codespell#using-a-config-file 2 | [codespell] 3 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 4 | ignore-words-list = , 5 | check-filenames = 6 | check-hidden = 7 | skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the bug 11 | 12 | A clear and concise description of what the bug is. 13 | 14 | ### Steps to Reproduce 15 | 16 | Steps to reproduce the behavior. Including the [MRE](https://stackoverflow.com/help/minimal-reproducible-example) sketches 17 | 18 | ### Expected behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ### Actual behavior 23 | 24 | A clear and concise description of what you expected to happen. 25 | 26 | ### Debug and AT-command log (if applicable) 27 | 28 | A clear and concise description of what you expected to happen. 29 | 30 | ### Screenshots 31 | 32 | If applicable, add screenshots to help explain your problem. 33 | 34 | ### Information 35 | 36 | Please ensure to specify the following: 37 | 38 | * Arduino IDE version (e.g. 1.8.19) or Platform.io version 39 | * Board Core Version (e.g. STM32F7 Nucleo-144 NUCLEO_F767ZI, STM32 core v2.3.0, etc.) 40 | * Contextual information (e.g. what you were trying to achieve) 41 | * Simplest possible steps to reproduce 42 | * Anything that might be relevant in your opinion, such as: 43 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 44 | * Network configuration 45 | 46 | 47 | ### Example 48 | 49 | ``` 50 | Arduino IDE version: 1.8.19 51 | STM32F7 Nucleo-144 NUCLEO_F767ZI, STM32 core v2.3.0 52 | OS: Ubuntu 20.04 LTS 53 | Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 54 | 55 | Context: 56 | I encountered a crash while using this library 57 | 58 | Steps to reproduce: 59 | 1. ... 60 | 2. ... 61 | 3. ... 62 | 4. ... 63 | ``` 64 | 65 | --- 66 | 67 | ### Sending Feature Requests 68 | 69 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 70 | 71 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/EthernetWebServer_STM32/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 72 | 73 | --- 74 | 75 | ### Sending Pull Requests 76 | 77 | Pull Requests with changes and fixes are also welcome! 78 | 79 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 80 | 81 | 1. Change directory to the library GitHub 82 | 83 | ``` 84 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/EthernetWebServer_STM32_GitHub/ 85 | xy@xy-Inspiron-3593:~/Arduino/xy/EthernetWebServer_STM32_GitHub$ 86 | ``` 87 | 88 | 2. Issue astyle command 89 | 90 | ``` 91 | xy@xy-Inspiron-3593:~/Arduino/xy/EthernetWebServer_STM32_GitHub$ bash utils/restyle.sh 92 | ``` 93 | 94 | 95 | -------------------------------------------------------------------------------- /.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 | 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | 22 | ### Additional context 23 | 24 | Add any other context or screenshots about the feature request here. 25 | -------------------------------------------------------------------------------- /.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/check-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Check Arduino 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v3 20 | 21 | - name: Arduino Lint 22 | uses: arduino/arduino-lint-action@v1 23 | with: 24 | compliance: specification 25 | library-manager: update 26 | # Always use this setting for official repositories. Remove for 3rd party projects. 27 | official: true 28 | project-type: library 29 | -------------------------------------------------------------------------------- /.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 EthernetWebServer_STM32 2 | 3 | ### Reporting Bugs 4 | 5 | Please report bugs in EthernetWebServer_STM32 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/EthernetWebServer_STM32/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/EthernetWebServer_STM32/issues/new). 12 | 13 | ### How to submit a bug report 14 | 15 | Please ensure to specify the following: 16 | 17 | * Arduino IDE version (e.g. 1.8.19) or Platform.io version 18 | * Board Core Version (e.g. STM32F7 Nucleo-144 NUCLEO_F767ZI, STM32 core v2.3.0, etc.) 19 | * Contextual information (e.g. what you were trying to achieve) 20 | * Simplest possible steps to reproduce 21 | * Anything that might be relevant in your opinion, such as: 22 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 23 | * Network configuration 24 | 25 | 26 | ### Example 27 | 28 | ``` 29 | Arduino IDE version: 1.8.19 30 | STM32F7 Nucleo-144 NUCLEO_F767ZI, STM32 core v2.3.0 31 | OS: Ubuntu 20.04 LTS 32 | Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 33 | 34 | Context: 35 | I encountered a crash while using this library 36 | 37 | Steps to reproduce: 38 | 1. ... 39 | 2. ... 40 | 3. ... 41 | 4. ... 42 | ``` 43 | 44 | --- 45 | 46 | ### Sending Feature Requests 47 | 48 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 49 | 50 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/EthernetWebServer_STM32/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 51 | 52 | --- 53 | 54 | ### Sending Pull Requests 55 | 56 | Pull Requests with changes and fixes are also welcome! 57 | 58 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 59 | 60 | 1. Change directory to the library GitHub 61 | 62 | ``` 63 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/EthernetWebServer_STM32_GitHub/ 64 | xy@xy-Inspiron-3593:~/Arduino/xy/EthernetWebServer_STM32_GitHub$ 65 | ``` 66 | 67 | 2. Issue astyle command 68 | 69 | ``` 70 | xy@xy-Inspiron-3593:~/Arduino/xy/EthernetWebServer_STM32_GitHub$ bash utils/restyle.sh 71 | ``` 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Khoi Hoang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LibraryPatches/Ethernet2/src/Ethernet2.h: -------------------------------------------------------------------------------- 1 | /* 2 | modified 12 Aug 2013 3 | by Soohwan Kim (suhwan@wiznet.co.kr) 4 | 5 | - 10 Apr. 2015 6 | Added support for Arduino Ethernet Shield 2 7 | by Arduino.org team 8 | 9 | */ 10 | #ifndef ethernet_h 11 | #define ethernet_h 12 | 13 | #include 14 | #include "utility/w5500.h" 15 | #include "IPAddress.h" 16 | #include "EthernetClient.h" 17 | #include "EthernetServer.h" 18 | #include "Dhcp.h" 19 | 20 | 21 | 22 | class EthernetClass 23 | { 24 | private: 25 | IPAddress _dnsServerAddress; 26 | char* _dnsDomainName; 27 | char* _hostName; 28 | DhcpClass* _dhcp; 29 | 30 | // KH add to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+ 31 | uint8_t _mac_address[6] = {0,}; 32 | ////// 33 | 34 | public: 35 | uint8_t w5500_cspin; 36 | 37 | static uint8_t _state[MAX_SOCK_NUM]; 38 | static uint16_t _server_port[MAX_SOCK_NUM]; 39 | 40 | EthernetClass() 41 | { 42 | _dhcp = NULL; 43 | w5500_cspin = 10; 44 | } 45 | void init(uint8_t _cspin = 10) 46 | { 47 | w5500_cspin = _cspin; 48 | } 49 | 50 | #if defined(WIZ550io_WITH_MACADDRESS) 51 | // Initialize function when use the ioShield serise (included WIZ550io) 52 | // WIZ550io has a MAC address which is written after reset. 53 | // Default IP, Gateway and subnet address are also writen. 54 | // so, It needs some initial time. please refer WIZ550io Datasheet in details. 55 | int begin(void); 56 | void begin(IPAddress local_ip); 57 | void begin(IPAddress local_ip, IPAddress dns_server); 58 | void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway); 59 | void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); 60 | #else 61 | // Initialize the Ethernet shield to use the provided MAC address and gain the rest of the 62 | // configuration through DHCP. 63 | // Returns 0 if the DHCP configuration failed, and 1 if it succeeded 64 | int begin(uint8_t *mac_address); 65 | void begin(uint8_t *mac_address, IPAddress local_ip); 66 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server); 67 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway); 68 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); 69 | 70 | #endif 71 | 72 | int maintain(); 73 | 74 | // KH add to report link status 75 | uint8_t link(); // returns the linkstate, 1 = linked, 0 = no link 76 | const char* linkReport(); // returns the linkstate as a string 77 | ////// 78 | 79 | // KH add to have similar function to Ethernet lib 80 | // Certainly we can use void macAddress(uint8_t mac[]) to read from W5x00. 81 | void MACAddress(uint8_t *mac_address) 82 | { 83 | memcpy(mac_address, _mac_address, sizeof(_mac_address)); 84 | } 85 | ////// 86 | 87 | IPAddress localIP(); 88 | IPAddress subnetMask(); 89 | IPAddress gatewayIP(); 90 | IPAddress dnsServerIP(); 91 | char* dnsDomainName(); 92 | char* hostName(); 93 | 94 | friend class EthernetClient; 95 | friend class EthernetServer; 96 | }; 97 | 98 | extern EthernetClass Ethernet; 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /LibraryPatches/Ethernet3/src/Ethernet3.h: -------------------------------------------------------------------------------- 1 | /* 2 | modified 12 Aug 2013 3 | by Soohwan Kim (suhwan@wiznet.co.kr) 4 | 5 | - 10 Apr. 2015 6 | Added support for Arduino Ethernet Shield 2 7 | by Arduino.org team 8 | 9 | */ 10 | #ifndef ethernet3_h 11 | #define ethernet3_h 12 | 13 | #include 14 | #include "utility/w5500.h" 15 | #include "IPAddress.h" 16 | #include "EthernetClient.h" 17 | #include "EthernetServer.h" 18 | #include "Dhcp.h" 19 | 20 | enum phyMode_t 21 | { 22 | HALF_DUPLEX_10, 23 | FULL_DUPLEX_10, 24 | HALF_DUPLEX_100, 25 | FULL_DUPLEX_100, 26 | FULL_DUPLEX_100_AUTONEG, 27 | POWER_DOWN, 28 | ALL_AUTONEG 29 | }; 30 | 31 | class EthernetClass 32 | { 33 | private: 34 | IPAddress _dnsServerAddress; 35 | DhcpClass* _dhcp; 36 | char _customHostname[32]; 37 | 38 | // KH add to work with new func void MACAddress(uint8_t *mac_address); and SinricPro v2.5.1+ 39 | uint8_t _mac_address[6] = {0,}; 40 | ////// 41 | 42 | public: 43 | uint8_t _maxSockNum; 44 | uint8_t _pinCS; 45 | uint8_t _pinRST; 46 | 47 | static uint8_t _state[MAX_SOCK_NUM]; 48 | static uint16_t _server_port[MAX_SOCK_NUM]; 49 | 50 | EthernetClass() 51 | { 52 | _dhcp = NULL; 53 | _pinCS = 10; 54 | _maxSockNum = 8; 55 | } 56 | 57 | void setRstPin(uint8_t pinRST = 9); // for WIZ550io or USR-ES1, must set befor Ethernet.begin 58 | void setCsPin(uint8_t pinCS = 10); // must set befor Ethernet.begin 59 | 60 | // Initialize with less sockets but more RX/TX Buffer 61 | // maxSockNum = 1 Socket 0 -> RX/TX Buffer 16k 62 | // maxSockNum = 2 Socket 0, 1 -> RX/TX Buffer 8k 63 | // maxSockNum = 4 Socket 0...3 -> RX/TX Buffer 4k 64 | // maxSockNum = 8 (Standard) all sockets -> RX/TX Buffer 2k 65 | // be carefull of the MAX_SOCK_NUM, because in the moment it can't dynamicly changed 66 | void init(uint8_t maxSockNum = 8); 67 | 68 | uint8_t softreset(); // can set only after Ethernet.begin 69 | void hardreset(); // You need to set the Rst pin 70 | 71 | #if defined(WIZ550io_WITH_MACADDRESS) 72 | 73 | // Initialize function when use the ioShield serise (included WIZ550io) 74 | // WIZ550io has a MAC address which is written after reset. 75 | // Default IP, Gateway and subnet address are also writen. 76 | // so, It needs some initial time. please refer WIZ550io Datasheet in details. 77 | int begin(void); 78 | void begin(IPAddress local_ip); 79 | void begin(IPAddress local_ip, IPAddress subnet); 80 | void begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway); 81 | void begin(IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server); 82 | #else 83 | // Initialize the Ethernet shield to use the provided MAC address and gain the rest of the 84 | // configuration through DHCP. 85 | // Returns 0 if the DHCP configuration failed, and 1 if it succeeded 86 | int begin(uint8_t *mac_address); 87 | void begin(uint8_t *mac_address, IPAddress local_ip); 88 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress subnet); 89 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress subnet, IPAddress gateway); 90 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress subnet, IPAddress gateway, IPAddress dns_server); 91 | #endif 92 | 93 | int maintain(); 94 | void WoL(bool wol); // set Wake on LAN 95 | bool WoL(); // get the WoL state 96 | void phyMode(phyMode_t mode); // set PHYCFGR 97 | uint8_t phyState(); // returns the PHYCFGR 98 | uint8_t link(); // returns the linkstate, 1 = linked, 0 = no link 99 | const char* linkReport(); // returns the linkstate as a string 100 | uint8_t speed(); // returns speed in MB/s 101 | const char* speedReport(); // returns speed as a string 102 | uint8_t duplex(); // returns duplex mode 0 = no link, 1 = Half Duplex, 2 = Full Duplex 103 | const char* duplexReport(); // returns duplex mode as a string 104 | 105 | void setRtTimeOut(uint16_t timeout = 2000); // set the retransmission timout *100us 106 | uint16_t getRtTimeOut(); // get the retransmission timout 107 | void setRtCount(uint8_t count = 8); // set the retransmission count 108 | uint8_t getRtCount(); // get the retransmission count 109 | 110 | void macAddress(uint8_t mac[]); // get the MAC Address 111 | const char* macAddressReport(); // returns the the MAC Address as a string 112 | 113 | void setHostname(const char* hostname); 114 | 115 | // KH add to have similar function to Ethernet lib 116 | // Certainly we can use void macAddress(uint8_t mac[]) to read from W5x00. 117 | void MACAddress(uint8_t *mac_address) 118 | { 119 | memcpy(mac_address, _mac_address, sizeof(_mac_address)); 120 | } 121 | ////// 122 | 123 | IPAddress localIP(); 124 | IPAddress subnetMask(); 125 | IPAddress gatewayIP(); 126 | IPAddress dnsServerIP(); 127 | 128 | friend class EthernetClient; 129 | friend class EthernetServer; 130 | }; 131 | 132 | extern EthernetClass Ethernet; 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /LibraryPatches/esp32/cores/esp32/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server: public Print 26 | { 27 | public: 28 | // KH, change to fix compiler error for EthernetWebServer 29 | // error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer' 30 | // virtual void begin(uint16_t port=0) =0; 31 | //virtual void begin() = 0; 32 | void begin() {}; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Packages_Patches/STM32/hardware/stm32/1.9.0/variants/NUCLEO_L053R8/variant.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _VARIANT_ARDUINO_STM32_ 20 | #define _VARIANT_ARDUINO_STM32_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif // __cplusplus 25 | 26 | /*---------------------------------------------------------------------------- 27 | Pins 28 | ----------------------------------------------------------------------------*/ 29 | 30 | #define PA3 0 31 | #define PA2 1 32 | #define PA10 2 33 | #define PB3 3 34 | #define PB5 4 35 | #define PB4 5 36 | #define PB10 6 37 | #define PA8 7 38 | #define PA9 8 39 | #define PC7 9 40 | #define PB6 10 41 | #define PA7 A6 42 | #define PA6 A7 43 | #define PA5 13 44 | #define PB9 14 45 | #define PB8 15 46 | // ST Morpho 47 | // CN7 Left Side 48 | #define PC10 16 49 | #define PC12 17 50 | // 18 is NC - BOOT0 51 | #define PA13 19 // SWD 52 | #define PA14 20 // SWD 53 | #define PA15 21 54 | #define PB7 22 55 | #define PC13 23 56 | #define PC14 24 57 | #define PC15 25 58 | #define PH0 26 59 | #define PH1 27 60 | #define PC2 A8 61 | #define PC3 A9 62 | // CN7 Right Side 63 | #define PC11 30 64 | #define PD2 31 65 | // CN10 Left Side 66 | #define PC9 32 67 | // CN10 Right side 68 | #define PC8 33 69 | #define PC6 34 70 | #define PC5 A10 71 | #define PA12 36 72 | #define PA11 37 73 | #define PB12 38 74 | #define PB11 39 75 | #define PB2 40 76 | #define PB1 41 77 | #define PB15 42 78 | #define PB14 43 79 | #define PB13 44 80 | #define PC4 A11 81 | #define PA0 A0 82 | #define PA1 A1 83 | #define PA4 A2 84 | #define PB0 A3 85 | #define PC1 A4 86 | #define PC0 A5 87 | 88 | // This must be a literal 89 | #define NUM_DIGITAL_PINS 52 90 | // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS 91 | #define NUM_ANALOG_INPUTS 12 92 | 93 | // On-board LED pin number 94 | #define LED_BUILTIN 13 95 | #define LED_GREEN LED_BUILTIN 96 | 97 | // On-board user button 98 | #define USER_BTN PC13 99 | 100 | // Timer Definitions 101 | // Use TIM6 when possible as servo and tone don't need GPIO output pin 102 | #define TIMER_TONE TIM6 103 | #define TIMER_SERVO TIM2 104 | 105 | // UART Definitions 106 | #define SERIAL_UART_INSTANCE 2 //Connected to ST-Link 107 | // Default pin used for 'Serial' instance (ex: ST-Link) 108 | // Mandatory for Firmata 109 | #define PIN_SERIAL_RX 0 110 | #define PIN_SERIAL_TX 1 111 | 112 | /* Extra HAL modules */ 113 | #define HAL_DAC_MODULE_ENABLED 114 | 115 | #ifdef __cplusplus 116 | } // extern "C" 117 | #endif 118 | /*---------------------------------------------------------------------------- 119 | Arduino objects - C++ only 120 | ----------------------------------------------------------------------------*/ 121 | 122 | #ifdef __cplusplus 123 | // These serial port names are intended to allow libraries and architecture-neutral 124 | // sketches to automatically default to the correct port name for a particular type 125 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, 126 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. 127 | // 128 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor 129 | // 130 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial 131 | // 132 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library 133 | // 134 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. 135 | // 136 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX 137 | // pins are NOT connected to anything by default. 138 | #define SERIAL_PORT_MONITOR Serial 139 | 140 | // KH mod to add Serial1, for ESP-AT 141 | //#define SERIAL_PORT_HARDWARE Serial 142 | #define SERIAL_PORT_HARDWARE Serial1 143 | #endif 144 | 145 | #endif /* _VARIANT_ARDUINO_STM32_ */ 146 | -------------------------------------------------------------------------------- /examples/HTTPClient/BasicAuthGet/BasicAuthGet.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BasicAuthGet.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | GET client with HTTP basic authentication for ArduinoHttpClient library 13 | Connects to server once every five seconds, sends a GET request 14 | 15 | created 14 Feb 2016 16 | by Tom Igoe 17 | modified 3 Jan 2017 to add HTTP basic authentication 18 | by Sandeep Mistry 19 | modified 22 Jan 2019 20 | by Tom Igoe 21 | *****************************************************************************************************************************/ 22 | 23 | #include "defines.h" 24 | 25 | char serverAddress[] = "192.168.2.112"; // server address 26 | int port = 8080; 27 | 28 | EthernetClient client; 29 | EthernetHttpClient httpClient(client, serverAddress, port); 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | 35 | while (!Serial && millis() < 5000); 36 | 37 | Serial.print("\nStarting BasicAuthGet on " + String(BOARD_NAME)); 38 | Serial.println(" with " + String(SHIELD_TYPE)); 39 | 40 | #if USE_ETHERNET_GENERIC 41 | Serial.println(ETHERNET_GENERIC_VERSION); 42 | #endif 43 | 44 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 45 | 46 | #if !(USE_BUILTIN_ETHERNET) 47 | #if (USING_SPI2) 48 | #if defined(CUR_PIN_MISO) 49 | ET_LOGWARN(F("Default SPI pinout:")); 50 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 51 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 52 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 53 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 54 | ET_LOGWARN(F("=========================")); 55 | #endif 56 | #else 57 | ET_LOGWARN(F("Default SPI pinout:")); 58 | ET_LOGWARN1(F("MOSI:"), MOSI); 59 | ET_LOGWARN1(F("MISO:"), MISO); 60 | ET_LOGWARN1(F("SCK:"), SCK); 61 | ET_LOGWARN1(F("SS:"), SS); 62 | ET_LOGWARN(F("=========================")); 63 | #endif 64 | #endif 65 | 66 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 67 | // For other boards, to change if necessary 68 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 69 | Ethernet.init (USE_THIS_SS_PIN); 70 | 71 | #elif USE_CUSTOM_ETHERNET 72 | // You have to add initialization for your Custom Ethernet here 73 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 74 | //Ethernet.init(USE_THIS_SS_PIN); 75 | 76 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 77 | #endif 78 | 79 | // start the ethernet connection and the server: 80 | // Use DHCP dynamic IP and random mac 81 | uint16_t index = millis() % NUMBER_OF_MAC; 82 | // Use Static IP 83 | //Ethernet.begin(mac[index], ip); 84 | Ethernet.begin(mac[index]); 85 | 86 | Serial.print(F("Connected! IP address: ")); 87 | Serial.println(Ethernet.localIP()); 88 | } 89 | 90 | void loop() 91 | { 92 | Serial.println("making GET request with HTTP basic authentication"); 93 | httpClient.beginRequest(); 94 | httpClient.get("/secure"); 95 | httpClient.sendBasicAuth("username", "password"); // send the username and password for authentication 96 | httpClient.endRequest(); 97 | 98 | // read the status code and body of the response 99 | int statusCode = httpClient.responseStatusCode(); 100 | String response = httpClient.responseBody(); 101 | 102 | Serial.print("Status code: "); 103 | Serial.println(statusCode); 104 | Serial.print("Response: "); 105 | Serial.println(response); 106 | 107 | Serial.println("Wait five seconds"); 108 | delay(5000); 109 | } 110 | -------------------------------------------------------------------------------- /examples/HTTPClient/CustomHeader/CustomHeader.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | CustomHeader.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Custom request header example for the ArduinoHttpClient 13 | library. This example sends a GET and a POST request with a custom header every 5 seconds. 14 | 15 | based on SimpleGet example by Tom Igoe 16 | header modifications by Todd Treece 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | 20 | *****************************************************************************************************************************/ 21 | 22 | #include "defines.h" 23 | 24 | char serverAddress[] = "192.168.2.112"; // server address 25 | int port = 8080; 26 | 27 | EthernetClient client; 28 | EthernetHttpClient httpClient(client, serverAddress, port); 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | 34 | while (!Serial && millis() < 5000); 35 | 36 | Serial.print("\nStarting BasicAuthGet on " + String(BOARD_NAME)); 37 | Serial.println(" with " + String(SHIELD_TYPE)); 38 | 39 | #if USE_ETHERNET_GENERIC 40 | Serial.println(ETHERNET_GENERIC_VERSION); 41 | #endif 42 | 43 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 44 | 45 | #if !(USE_BUILTIN_ETHERNET) 46 | #if (USING_SPI2) 47 | #if defined(CUR_PIN_MISO) 48 | ET_LOGWARN(F("Default SPI pinout:")); 49 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 50 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 51 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 52 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 53 | ET_LOGWARN(F("=========================")); 54 | #endif 55 | #else 56 | ET_LOGWARN(F("Default SPI pinout:")); 57 | ET_LOGWARN1(F("MOSI:"), MOSI); 58 | ET_LOGWARN1(F("MISO:"), MISO); 59 | ET_LOGWARN1(F("SCK:"), SCK); 60 | ET_LOGWARN1(F("SS:"), SS); 61 | ET_LOGWARN(F("=========================")); 62 | #endif 63 | #endif 64 | 65 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 66 | // For other boards, to change if necessary 67 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 68 | Ethernet.init (USE_THIS_SS_PIN); 69 | 70 | #elif USE_CUSTOM_ETHERNET 71 | // You have to add initialization for your Custom Ethernet here 72 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 73 | //Ethernet.init(USE_THIS_SS_PIN); 74 | 75 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 76 | #endif 77 | 78 | // start the ethernet connection and the server: 79 | // Use DHCP dynamic IP and random mac 80 | uint16_t index = millis() % NUMBER_OF_MAC; 81 | // Use Static IP 82 | //Ethernet.begin(mac[index], ip); 83 | Ethernet.begin(mac[index]); 84 | 85 | Serial.print(F("Connected! IP address: ")); 86 | Serial.println(Ethernet.localIP()); 87 | } 88 | 89 | void loop() 90 | { 91 | Serial.println("Making GET request"); 92 | httpClient.beginRequest(); 93 | 94 | httpClient.get("/"); 95 | httpClient.sendHeader("X-CUSTOM-HEADER", "custom_value"); 96 | httpClient.endRequest(); 97 | 98 | // read the status code and body of the response 99 | int statusCode = httpClient.responseStatusCode(); 100 | String response = httpClient.responseBody(); 101 | 102 | Serial.print("GET Status code: "); 103 | Serial.println(statusCode); 104 | Serial.print("GET Response: "); 105 | Serial.println(response); 106 | 107 | Serial.println("Wait five seconds"); 108 | delay(5000); 109 | 110 | Serial.println("Making POST request"); 111 | String postData = "name=Alice&age=12"; 112 | httpClient.beginRequest(); 113 | httpClient.post("/"); 114 | httpClient.sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded"); 115 | httpClient.sendHeader(HTTP_HEADER_CONTENT_LENGTH, postData.length()); 116 | httpClient.sendHeader("X-CUSTOM-HEADER", "custom_value"); 117 | httpClient.endRequest(); 118 | httpClient.write((const byte*)postData.c_str(), postData.length()); 119 | // note: the above line can also be achieved with the simpler line below: 120 | //httpClient.print(postData); 121 | 122 | // read the status code and body of the response 123 | statusCode = httpClient.responseStatusCode(); 124 | response = httpClient.responseBody(); 125 | 126 | Serial.print("POST Status code: "); 127 | Serial.println(statusCode); 128 | Serial.print("POST Response: "); 129 | Serial.println(response); 130 | 131 | Serial.println("Wait five seconds"); 132 | delay(5000); 133 | } 134 | -------------------------------------------------------------------------------- /examples/HTTPClient/DweetGet/DweetGet.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | DweetGet.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Connects to dweet.io once every ten seconds, sends a GET request and a request body. Uses SSL 13 | 14 | Shows how to use Strings to assemble path and parse content from response. dweet.io expects: 15 | https://dweet.io/get/latest/dweet/for/thingName 16 | 17 | For more on dweet.io, see https://dweet.io/play/ 18 | 19 | created 15 Feb 2016 20 | updated 22 Jan 2019 21 | by Tom Igoe 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | 26 | const char serverAddress[] = "dweet.io"; // server address 27 | int port = 80; 28 | String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here 29 | 30 | EthernetClient client; 31 | EthernetHttpClient httpClient(client, serverAddress, port); 32 | 33 | void setup() 34 | { 35 | Serial.begin(115200); 36 | 37 | while (!Serial && millis() < 5000); 38 | 39 | Serial.print("\nStarting DweetGet on " + String(BOARD_NAME)); 40 | Serial.println(" with " + String(SHIELD_TYPE)); 41 | 42 | #if USE_ETHERNET_GENERIC 43 | Serial.println(ETHERNET_GENERIC_VERSION); 44 | #endif 45 | 46 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 47 | 48 | #if !(USE_BUILTIN_ETHERNET) 49 | #if (USING_SPI2) 50 | #if defined(CUR_PIN_MISO) 51 | ET_LOGWARN(F("Default SPI pinout:")); 52 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 53 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 54 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 55 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 56 | ET_LOGWARN(F("=========================")); 57 | #endif 58 | #else 59 | ET_LOGWARN(F("Default SPI pinout:")); 60 | ET_LOGWARN1(F("MOSI:"), MOSI); 61 | ET_LOGWARN1(F("MISO:"), MISO); 62 | ET_LOGWARN1(F("SCK:"), SCK); 63 | ET_LOGWARN1(F("SS:"), SS); 64 | ET_LOGWARN(F("=========================")); 65 | #endif 66 | #endif 67 | 68 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 69 | // For other boards, to change if necessary 70 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 71 | Ethernet.init (USE_THIS_SS_PIN); 72 | 73 | #elif USE_CUSTOM_ETHERNET 74 | // You have to add initialization for your Custom Ethernet here 75 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 76 | //Ethernet.init(USE_THIS_SS_PIN); 77 | 78 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 79 | #endif 80 | 81 | // start the ethernet connection and the server: 82 | // Use DHCP dynamic IP and random mac 83 | uint16_t index = millis() % NUMBER_OF_MAC; 84 | // Use Static IP 85 | //Ethernet.begin(mac[index], ip); 86 | Ethernet.begin(mac[index]); 87 | 88 | Serial.print(F("Connected! IP address: ")); 89 | Serial.println(Ethernet.localIP()); 90 | } 91 | 92 | void loop() 93 | { 94 | // assemble the path for the GET message: 95 | String path = "/get/latest/dweet/for/" + dweetName; 96 | 97 | // send the GET request 98 | Serial.println("Making GET request"); 99 | httpClient.get(path); 100 | 101 | // read the status code and body of the response 102 | int statusCode = httpClient.responseStatusCode(); 103 | String response = httpClient.responseBody(); 104 | Serial.print("Status code: "); 105 | Serial.println(statusCode); 106 | Serial.print("Response: "); 107 | Serial.println(response); 108 | 109 | /* 110 | Typical response is: 111 | {"this":"succeeded", 112 | "by":"getting", 113 | "the":"dweets", 114 | "with":[{"thing":"my-thing-name", 115 | "created":"2016-02-16T05:10:36.589Z", 116 | "content":{"sensorValue":456}}]} 117 | 118 | You want "content": numberValue 119 | */ 120 | // now parse the response looking for "content": 121 | int labelStart = response.indexOf("content\":"); 122 | // find the first { after "content": 123 | int contentStart = response.indexOf("{", labelStart); 124 | // find the following } and get what's between the braces: 125 | int contentEnd = response.indexOf("}", labelStart); 126 | String content = response.substring(contentStart + 1, contentEnd); 127 | Serial.println(content); 128 | 129 | // now get the value after the colon, and convert to an int: 130 | int valueStart = content.indexOf(":"); 131 | String valueString = content.substring(valueStart + 1); 132 | int number = valueString.toInt(); 133 | Serial.print("Value string: "); 134 | Serial.println(valueString); 135 | Serial.print("Actual value: "); 136 | Serial.println(number); 137 | 138 | Serial.println("Wait ten seconds\n"); 139 | delay(10000); 140 | } 141 | -------------------------------------------------------------------------------- /examples/HTTPClient/DweetPost/DweetPost.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | DweetPost.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Connects to dweet.io once every ten seconds, sends a POST request and a request body. 13 | 14 | Shows how to use Strings to assemble path and parse content from response. dweet.io expects: 15 | https://dweet.io/get/latest/dweet/for/thingName 16 | 17 | For more on dweet.io, see https://dweet.io/play/ 18 | 19 | created 15 Feb 2016 20 | modified 22 Jan 2019 21 | by Tom Igoe 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | 26 | const char serverAddress[] = "dweet.io"; // server address 27 | int port = 80; 28 | 29 | EthernetClient client; 30 | EthernetHttpClient httpClient(client, serverAddress, port); 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | 36 | while (!Serial && millis() < 5000); 37 | 38 | Serial.print("\nStarting DweetPost on " + String(BOARD_NAME)); 39 | Serial.println(" with " + String(SHIELD_TYPE)); 40 | 41 | #if USE_ETHERNET_GENERIC 42 | Serial.println(ETHERNET_GENERIC_VERSION); 43 | #endif 44 | 45 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 46 | 47 | #if !(USE_BUILTIN_ETHERNET) 48 | #if (USING_SPI2) 49 | #if defined(CUR_PIN_MISO) 50 | ET_LOGWARN(F("Default SPI pinout:")); 51 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 52 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 53 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 54 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 55 | ET_LOGWARN(F("=========================")); 56 | #endif 57 | #else 58 | ET_LOGWARN(F("Default SPI pinout:")); 59 | ET_LOGWARN1(F("MOSI:"), MOSI); 60 | ET_LOGWARN1(F("MISO:"), MISO); 61 | ET_LOGWARN1(F("SCK:"), SCK); 62 | ET_LOGWARN1(F("SS:"), SS); 63 | ET_LOGWARN(F("=========================")); 64 | #endif 65 | #endif 66 | 67 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 68 | // For other boards, to change if necessary 69 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 70 | Ethernet.init (USE_THIS_SS_PIN); 71 | 72 | #elif USE_CUSTOM_ETHERNET 73 | // You have to add initialization for your Custom Ethernet here 74 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 75 | //Ethernet.init(USE_THIS_SS_PIN); 76 | 77 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 78 | #endif 79 | 80 | // start the ethernet connection and the server: 81 | // Use DHCP dynamic IP and random mac 82 | uint16_t index = millis() % NUMBER_OF_MAC; 83 | // Use Static IP 84 | //Ethernet.begin(mac[index], ip); 85 | Ethernet.begin(mac[index]); 86 | 87 | Serial.print(F("Connected! IP address: ")); 88 | Serial.println(Ethernet.localIP()); 89 | } 90 | 91 | void loop() 92 | { 93 | // assemble the path for the POST message: 94 | String dweetName = "scandalous-cheese-hoarder"; 95 | String path = "/dweet/for/" + dweetName; 96 | String contentType = "application/json"; 97 | 98 | // assemble the body of the POST message: 99 | int sensorValue = analogRead(A0); 100 | String postData = "{\"sensorValue\":\""; 101 | postData += sensorValue; 102 | postData += "\"}"; 103 | 104 | Serial.println("making POST request"); 105 | 106 | // send the POST request 107 | httpClient.post(path, contentType, postData); 108 | 109 | // read the status code and body of the response 110 | int statusCode = httpClient.responseStatusCode(); 111 | String response = httpClient.responseBody(); 112 | 113 | Serial.print("Status code: "); 114 | Serial.println(statusCode); 115 | Serial.print("Response: "); 116 | Serial.println(response); 117 | 118 | Serial.println("Wait ten seconds\n"); 119 | delay(10000); 120 | } 121 | -------------------------------------------------------------------------------- /examples/HTTPClient/HueBlink/HueBlink.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HueBlink.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Uses HttpClient to control Philips Hue 13 | For more on Hue developer API see http://developer.meethue.com 14 | 15 | To control a light, the Hue expects a HTTP PUT request to: 16 | 17 | http://hue.hub.address/api/hueUserName/lights/lightNumber/state 18 | 19 | The body of the PUT request looks like this: 20 | {"on": true} or {"on":false} 21 | 22 | This example shows how to concatenate Strings to assemble the 23 | PUT request and the body of the request. 24 | 25 | modified 15 Feb 2016 26 | by Tom Igoe (tigoe) to match new API 27 | *****************************************************************************************************************************/ 28 | 29 | #include "defines.h" 30 | 31 | char hueHubIP[] = "192.168.2.223"; // IP address of the HUE bridge 32 | String hueUserName = "huebridgeusername"; // hue bridge username 33 | 34 | EthernetClient client; 35 | EthernetHttpClient httpClient(client, hueHubIP); 36 | 37 | void setup() 38 | { 39 | Serial.begin(115200); 40 | 41 | while (!Serial && millis() < 5000); 42 | 43 | Serial.print("\nStarting HueBlink on " + String(BOARD_NAME)); 44 | Serial.println(" with " + String(SHIELD_TYPE)); 45 | 46 | #if USE_ETHERNET_GENERIC 47 | Serial.println(ETHERNET_GENERIC_VERSION); 48 | #endif 49 | 50 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 51 | 52 | #if !(USE_BUILTIN_ETHERNET) 53 | #if (USING_SPI2) 54 | #if defined(CUR_PIN_MISO) 55 | ET_LOGWARN(F("Default SPI pinout:")); 56 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 57 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 58 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 59 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 60 | ET_LOGWARN(F("=========================")); 61 | #endif 62 | #else 63 | ET_LOGWARN(F("Default SPI pinout:")); 64 | ET_LOGWARN1(F("MOSI:"), MOSI); 65 | ET_LOGWARN1(F("MISO:"), MISO); 66 | ET_LOGWARN1(F("SCK:"), SCK); 67 | ET_LOGWARN1(F("SS:"), SS); 68 | ET_LOGWARN(F("=========================")); 69 | #endif 70 | #endif 71 | 72 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 73 | // For other boards, to change if necessary 74 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 75 | Ethernet.init (USE_THIS_SS_PIN); 76 | 77 | #elif USE_CUSTOM_ETHERNET 78 | // You have to add initialization for your Custom Ethernet here 79 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 80 | //Ethernet.init(USE_THIS_SS_PIN); 81 | 82 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 83 | #endif 84 | 85 | // start the ethernet connection and the server: 86 | // Use DHCP dynamic IP and random mac 87 | uint16_t index = millis() % NUMBER_OF_MAC; 88 | // Use Static IP 89 | //Ethernet.begin(mac[index], ip); 90 | Ethernet.begin(mac[index]); 91 | 92 | Serial.print(F("Connected! IP address: ")); 93 | Serial.println(Ethernet.localIP()); 94 | } 95 | 96 | void sendRequest(int light, String cmd, String value) 97 | { 98 | // make a String for the HTTP request path: 99 | String request = "/api/" + hueUserName; 100 | request += "/lights/"; 101 | request += light; 102 | request += "/state/"; 103 | 104 | String contentType = "application/json"; 105 | 106 | // make a string for the JSON command: 107 | String hueCmd = "{\"" + cmd; 108 | hueCmd += "\":"; 109 | hueCmd += value; 110 | hueCmd += "}"; 111 | 112 | // see what you assembled to send: 113 | Serial.print("PUT request to server: "); 114 | Serial.println(request); 115 | Serial.print("JSON command to server: "); 116 | 117 | // make the PUT request to the hub: 118 | httpClient.put(request, contentType, hueCmd); 119 | 120 | // read the status code and body of the response 121 | int statusCode = httpClient.responseStatusCode(); 122 | String response = httpClient.responseBody(); 123 | 124 | Serial.println(hueCmd); 125 | Serial.print("Status code from server: "); 126 | Serial.println(statusCode); 127 | Serial.print("Server response: "); 128 | Serial.println(response); 129 | Serial.println(); 130 | } 131 | 132 | void loop() 133 | { 134 | sendRequest(3, "on", "true"); // turn light on 135 | delay(2000); // wait 2 seconds 136 | sendRequest(3, "on", "false"); // turn light off 137 | delay(2000); // wait 2 seconds 138 | } 139 | -------------------------------------------------------------------------------- /examples/HTTPClient/PostWithHeaders/PostWithHeaders.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PostWithHeaders.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | POST with headers client for HttpClient 13 | Connects to server once every five seconds, sends a POST request 14 | with custome headers and a request body 15 | 16 | created 14 Feb 2016 17 | by Tom Igoe 18 | modified 18 Mar 2017 19 | by Sandeep Mistry 20 | modified 22 Jan 2019 21 | by Tom Igoe 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | 26 | char serverAddress[] = "192.168.2.112"; // server address 27 | int port = 8080; 28 | 29 | EthernetClient client; 30 | EthernetHttpClient httpClient(client, serverAddress, port); 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | 36 | while (!Serial && millis() < 5000); 37 | 38 | Serial.print("\nStarting PostWithHeaders on " + String(BOARD_NAME)); 39 | Serial.println(" with " + String(SHIELD_TYPE)); 40 | 41 | #if USE_ETHERNET_GENERIC 42 | Serial.println(ETHERNET_GENERIC_VERSION); 43 | #endif 44 | 45 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 46 | 47 | #if !(USE_BUILTIN_ETHERNET) 48 | #if (USING_SPI2) 49 | #if defined(CUR_PIN_MISO) 50 | ET_LOGWARN(F("Default SPI pinout:")); 51 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 52 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 53 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 54 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 55 | ET_LOGWARN(F("=========================")); 56 | #endif 57 | #else 58 | ET_LOGWARN(F("Default SPI pinout:")); 59 | ET_LOGWARN1(F("MOSI:"), MOSI); 60 | ET_LOGWARN1(F("MISO:"), MISO); 61 | ET_LOGWARN1(F("SCK:"), SCK); 62 | ET_LOGWARN1(F("SS:"), SS); 63 | ET_LOGWARN(F("=========================")); 64 | #endif 65 | #endif 66 | 67 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 68 | // For other boards, to change if necessary 69 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 70 | Ethernet.init (USE_THIS_SS_PIN); 71 | 72 | #elif USE_CUSTOM_ETHERNET 73 | // You have to add initialization for your Custom Ethernet here 74 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 75 | //Ethernet.init(USE_THIS_SS_PIN); 76 | 77 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 78 | #endif 79 | 80 | // start the ethernet connection and the server: 81 | // Use DHCP dynamic IP and random mac 82 | uint16_t index = millis() % NUMBER_OF_MAC; 83 | // Use Static IP 84 | //Ethernet.begin(mac[index], ip); 85 | Ethernet.begin(mac[index]); 86 | 87 | Serial.print(F("Connected! IP address: ")); 88 | Serial.println(Ethernet.localIP()); 89 | } 90 | 91 | void loop() 92 | { 93 | Serial.println("making POST request"); 94 | String postData = "name=Alice&age=12"; 95 | 96 | httpClient.beginRequest(); 97 | httpClient.post("/"); 98 | httpClient.sendHeader("Content-Type", "application/x-www-form-urlencoded"); 99 | httpClient.sendHeader("Content-Length", postData.length()); 100 | httpClient.sendHeader("X-Custom-Header", "custom-header-value"); 101 | httpClient.beginBody(); 102 | httpClient.print(postData); 103 | httpClient.endRequest(); 104 | 105 | // read the status code and body of the response 106 | int statusCode = httpClient.responseStatusCode(); 107 | String response = httpClient.responseBody(); 108 | 109 | Serial.print("Status code: "); 110 | Serial.println(statusCode); 111 | Serial.print("Response: "); 112 | Serial.println(response); 113 | 114 | Serial.println("Wait five seconds"); 115 | delay(5000); 116 | } 117 | -------------------------------------------------------------------------------- /examples/HTTPClient/SimpleDelete/SimpleDelete.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleDelete.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple DELETE client for HttpClient 13 | Connects to server once every five seconds, sends a DELETE request 14 | and a request body 15 | 16 | created 14 Feb 2016 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "192.168.2.112"; // server address 24 | int port = 8080; 25 | 26 | EthernetClient client; 27 | EthernetHttpClient httpClient(client, serverAddress, port); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial && millis() < 5000); 34 | 35 | Serial.print("\nStarting SimpleDelete on " + String(BOARD_NAME)); 36 | Serial.println(" with " + String(SHIELD_TYPE)); 37 | 38 | #if USE_ETHERNET_GENERIC 39 | Serial.println(ETHERNET_GENERIC_VERSION); 40 | #endif 41 | 42 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 43 | 44 | #if !(USE_BUILTIN_ETHERNET) 45 | #if (USING_SPI2) 46 | #if defined(CUR_PIN_MISO) 47 | ET_LOGWARN(F("Default SPI pinout:")); 48 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 49 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 50 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 51 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 52 | ET_LOGWARN(F("=========================")); 53 | #endif 54 | #else 55 | ET_LOGWARN(F("Default SPI pinout:")); 56 | ET_LOGWARN1(F("MOSI:"), MOSI); 57 | ET_LOGWARN1(F("MISO:"), MISO); 58 | ET_LOGWARN1(F("SCK:"), SCK); 59 | ET_LOGWARN1(F("SS:"), SS); 60 | ET_LOGWARN(F("=========================")); 61 | #endif 62 | #endif 63 | 64 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 65 | // For other boards, to change if necessary 66 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 67 | Ethernet.init (USE_THIS_SS_PIN); 68 | 69 | #elif USE_CUSTOM_ETHERNET 70 | // You have to add initialization for your Custom Ethernet here 71 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 72 | //Ethernet.init(USE_THIS_SS_PIN); 73 | 74 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 75 | #endif 76 | 77 | // start the ethernet connection and the server: 78 | // Use DHCP dynamic IP and random mac 79 | uint16_t index = millis() % NUMBER_OF_MAC; 80 | // Use Static IP 81 | //Ethernet.begin(mac[index], ip); 82 | Ethernet.begin(mac[index]); 83 | 84 | Serial.print(F("Connected! IP address: ")); 85 | Serial.println(Ethernet.localIP()); 86 | } 87 | 88 | void loop() 89 | { 90 | Serial.println("making DELETE request"); 91 | String contentType = "application/x-www-form-urlencoded"; 92 | String delData = "name=light&age=46"; 93 | 94 | httpClient.del("/", contentType, delData); 95 | 96 | // read the status code and body of the response 97 | int statusCode = httpClient.responseStatusCode(); 98 | String response = httpClient.responseBody(); 99 | 100 | Serial.print("Status code: "); 101 | Serial.println(statusCode); 102 | Serial.print("Response: "); 103 | Serial.println(response); 104 | 105 | Serial.println("Wait five seconds"); 106 | delay(5000); 107 | } 108 | -------------------------------------------------------------------------------- /examples/HTTPClient/SimpleGet/SimpleGet.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleGet.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple GET client for HttpClient 13 | Connects to server once every five seconds, sends a GET request 14 | 15 | created 14 Feb 2016 16 | modified 22 Jan 2019 17 | by Tom Igoe 18 | *****************************************************************************************************************************/ 19 | 20 | #include "defines.h" 21 | 22 | char serverAddress[] = "192.168.2.112"; // server address 23 | int port = 8080; 24 | 25 | EthernetClient client; 26 | EthernetHttpClient httpClient(client, serverAddress, port); 27 | 28 | void setup() 29 | { 30 | Serial.begin(115200); 31 | 32 | while (!Serial && millis() < 5000); 33 | 34 | Serial.print("\nStarting SimpleGet on " + String(BOARD_NAME)); 35 | Serial.println(" with " + String(SHIELD_TYPE)); 36 | 37 | #if USE_ETHERNET_GENERIC 38 | Serial.println(ETHERNET_GENERIC_VERSION); 39 | #endif 40 | 41 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 42 | 43 | #if !(USE_BUILTIN_ETHERNET) 44 | #if (USING_SPI2) 45 | #if defined(CUR_PIN_MISO) 46 | ET_LOGWARN(F("Default SPI pinout:")); 47 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 48 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 49 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 50 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 51 | ET_LOGWARN(F("=========================")); 52 | #endif 53 | #else 54 | ET_LOGWARN(F("Default SPI pinout:")); 55 | ET_LOGWARN1(F("MOSI:"), MOSI); 56 | ET_LOGWARN1(F("MISO:"), MISO); 57 | ET_LOGWARN1(F("SCK:"), SCK); 58 | ET_LOGWARN1(F("SS:"), SS); 59 | ET_LOGWARN(F("=========================")); 60 | #endif 61 | #endif 62 | 63 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 64 | // For other boards, to change if necessary 65 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 66 | Ethernet.init (USE_THIS_SS_PIN); 67 | 68 | #elif USE_CUSTOM_ETHERNET 69 | // You have to add initialization for your Custom Ethernet here 70 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 71 | //Ethernet.init(USE_THIS_SS_PIN); 72 | 73 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 74 | #endif 75 | 76 | // start the ethernet connection and the server: 77 | // Use DHCP dynamic IP and random mac 78 | uint16_t index = millis() % NUMBER_OF_MAC; 79 | // Use Static IP 80 | //Ethernet.begin(mac[index], ip); 81 | Ethernet.begin(mac[index]); 82 | 83 | Serial.print(F("Connected! IP address: ")); 84 | Serial.println(Ethernet.localIP()); 85 | } 86 | 87 | void loop() 88 | { 89 | Serial.println("making GET request"); 90 | httpClient.get("/"); 91 | 92 | // read the status code and body of the response 93 | int statusCode = httpClient.responseStatusCode(); 94 | String response = httpClient.responseBody(); 95 | 96 | Serial.print("Status code: "); 97 | Serial.println(statusCode); 98 | Serial.print("Response: "); 99 | Serial.println(response); 100 | Serial.println("Wait five seconds"); 101 | delay(5000); 102 | } 103 | -------------------------------------------------------------------------------- /examples/HTTPClient/SimplePost/SimplePost.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimplePost.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple POST client for HttpClient 13 | Connects to server once every five seconds, sends a POST request 14 | and a request body 15 | 16 | created 14 Feb 2016 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "192.168.2.112"; // server address 24 | int port = 8080; 25 | 26 | EthernetClient client; 27 | EthernetHttpClient httpClient(client, serverAddress, port); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial && millis() < 5000); 34 | 35 | Serial.print("\nStarting SimplePost on " + String(BOARD_NAME)); 36 | Serial.println(" with " + String(SHIELD_TYPE)); 37 | 38 | #if USE_ETHERNET_GENERIC 39 | Serial.println(ETHERNET_GENERIC_VERSION); 40 | #endif 41 | 42 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 43 | 44 | #if !(USE_BUILTIN_ETHERNET) 45 | #if (USING_SPI2) 46 | #if defined(CUR_PIN_MISO) 47 | ET_LOGWARN(F("Default SPI pinout:")); 48 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 49 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 50 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 51 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 52 | ET_LOGWARN(F("=========================")); 53 | #endif 54 | #else 55 | ET_LOGWARN(F("Default SPI pinout:")); 56 | ET_LOGWARN1(F("MOSI:"), MOSI); 57 | ET_LOGWARN1(F("MISO:"), MISO); 58 | ET_LOGWARN1(F("SCK:"), SCK); 59 | ET_LOGWARN1(F("SS:"), SS); 60 | ET_LOGWARN(F("=========================")); 61 | #endif 62 | #endif 63 | 64 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 65 | // For other boards, to change if necessary 66 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 67 | Ethernet.init (USE_THIS_SS_PIN); 68 | 69 | #elif USE_CUSTOM_ETHERNET 70 | // You have to add initialization for your Custom Ethernet here 71 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 72 | //Ethernet.init(USE_THIS_SS_PIN); 73 | 74 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 75 | #endif 76 | 77 | // start the ethernet connection and the server: 78 | // Use DHCP dynamic IP and random mac 79 | uint16_t index = millis() % NUMBER_OF_MAC; 80 | // Use Static IP 81 | //Ethernet.begin(mac[index], ip); 82 | Ethernet.begin(mac[index]); 83 | 84 | Serial.print(F("Connected! IP address: ")); 85 | Serial.println(Ethernet.localIP()); 86 | } 87 | 88 | void loop() 89 | { 90 | Serial.println("making POST request"); 91 | String contentType = "application/x-www-form-urlencoded"; 92 | String postData = "name=Alice&age=12"; 93 | 94 | httpClient.post("/", contentType, postData); 95 | 96 | // read the status code and body of the response 97 | int statusCode = httpClient.responseStatusCode(); 98 | String response = httpClient.responseBody(); 99 | 100 | Serial.print("Status code: "); 101 | Serial.println(statusCode); 102 | Serial.print("Response: "); 103 | Serial.println(response); 104 | 105 | Serial.println("Wait five seconds"); 106 | delay(5000); 107 | } 108 | -------------------------------------------------------------------------------- /examples/HTTPClient/SimplePut/SimplePut.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimplePut.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple PUT client for HttpClient 13 | Connects to server once every five seconds, sends a PUT request 14 | and a request body 15 | 16 | created 14 Feb 2016 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "192.168.2.112"; // server address 24 | int port = 8080; 25 | 26 | EthernetClient client; 27 | EthernetHttpClient httpClient(client, serverAddress, port); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial && millis() < 5000); 34 | 35 | Serial.print("\nStarting SimplePut on " + String(BOARD_NAME)); 36 | Serial.println(" with " + String(SHIELD_TYPE)); 37 | 38 | #if USE_ETHERNET_GENERIC 39 | Serial.println(ETHERNET_GENERIC_VERSION); 40 | #endif 41 | 42 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 43 | 44 | #if !(USE_BUILTIN_ETHERNET) 45 | #if (USING_SPI2) 46 | #if defined(CUR_PIN_MISO) 47 | ET_LOGWARN(F("Default SPI pinout:")); 48 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 49 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 50 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 51 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 52 | ET_LOGWARN(F("=========================")); 53 | #endif 54 | #else 55 | ET_LOGWARN(F("Default SPI pinout:")); 56 | ET_LOGWARN1(F("MOSI:"), MOSI); 57 | ET_LOGWARN1(F("MISO:"), MISO); 58 | ET_LOGWARN1(F("SCK:"), SCK); 59 | ET_LOGWARN1(F("SS:"), SS); 60 | ET_LOGWARN(F("=========================")); 61 | #endif 62 | #endif 63 | 64 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 65 | // For other boards, to change if necessary 66 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 67 | Ethernet.init (USE_THIS_SS_PIN); 68 | 69 | #elif USE_CUSTOM_ETHERNET 70 | // You have to add initialization for your Custom Ethernet here 71 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 72 | //Ethernet.init(USE_THIS_SS_PIN); 73 | 74 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 75 | #endif 76 | 77 | // start the ethernet connection and the server: 78 | // Use DHCP dynamic IP and random mac 79 | uint16_t index = millis() % NUMBER_OF_MAC; 80 | // Use Static IP 81 | //Ethernet.begin(mac[index], ip); 82 | Ethernet.begin(mac[index]); 83 | 84 | Serial.print(F("Connected! IP address: ")); 85 | Serial.println(Ethernet.localIP()); 86 | } 87 | 88 | void loop() 89 | { 90 | Serial.println("making PUT request"); 91 | String contentType = "application/x-www-form-urlencoded"; 92 | String putData = "name=light&age=46"; 93 | 94 | httpClient.put("/", contentType, putData); 95 | 96 | // read the status code and body of the response 97 | int statusCode = httpClient.responseStatusCode(); 98 | String response = httpClient.responseBody(); 99 | 100 | Serial.print("Status code: "); 101 | Serial.println(statusCode); 102 | Serial.print("Response: "); 103 | Serial.println(response); 104 | 105 | Serial.println("Wait five seconds"); 106 | delay(5000); 107 | } 108 | -------------------------------------------------------------------------------- /examples/HTTPClient/SimpleWebSocket/SimpleWebSocket.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleWebSocket.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | Simple WebSocket client for HttpClient 12 | Connects to the WebSocket server, and sends a hello 13 | message every 5 seconds 14 | 15 | created 28 Jun 2016 16 | by Sandeep Mistry 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "echo.websocket.org"; // server address 24 | int port = 80; 25 | 26 | EthernetClient client; 27 | EthernetWebSocketClient wsClient(client, serverAddress, port); 28 | 29 | int count = 0; 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | 35 | while (!Serial && millis() < 5000); 36 | 37 | Serial.print("\nStarting SimpleWebSocket on " + String(BOARD_NAME)); 38 | Serial.println(" with " + String(SHIELD_TYPE)); 39 | 40 | #if USE_ETHERNET_GENERIC 41 | Serial.println(ETHERNET_GENERIC_VERSION); 42 | #endif 43 | 44 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 45 | 46 | #if !(USE_BUILTIN_ETHERNET) 47 | #if (USING_SPI2) 48 | #if defined(CUR_PIN_MISO) 49 | ET_LOGWARN(F("Default SPI pinout:")); 50 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 51 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 52 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 53 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 54 | ET_LOGWARN(F("=========================")); 55 | #endif 56 | #else 57 | ET_LOGWARN(F("Default SPI pinout:")); 58 | ET_LOGWARN1(F("MOSI:"), MOSI); 59 | ET_LOGWARN1(F("MISO:"), MISO); 60 | ET_LOGWARN1(F("SCK:"), SCK); 61 | ET_LOGWARN1(F("SS:"), SS); 62 | ET_LOGWARN(F("=========================")); 63 | #endif 64 | #endif 65 | 66 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 67 | // For other boards, to change if necessary 68 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 69 | Ethernet.init (USE_THIS_SS_PIN); 70 | 71 | #elif USE_CUSTOM_ETHERNET 72 | // You have to add initialization for your Custom Ethernet here 73 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 74 | //Ethernet.init(USE_THIS_SS_PIN); 75 | 76 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 77 | #endif 78 | 79 | // start the ethernet connection and the server: 80 | // Use DHCP dynamic IP and random mac 81 | uint16_t index = millis() % NUMBER_OF_MAC; 82 | // Use Static IP 83 | //Ethernet.begin(mac[index], ip); 84 | Ethernet.begin(mac[index]); 85 | 86 | Serial.print(F("Connected! IP address: ")); 87 | Serial.println(Ethernet.localIP()); 88 | } 89 | 90 | void loop() 91 | { 92 | Serial.println("starting WebSocket client"); 93 | 94 | wsClient.begin(); 95 | 96 | while (wsClient.connected()) 97 | { 98 | Serial.print("Sending Hello "); 99 | Serial.println(count); 100 | 101 | // send a hello # 102 | wsClient.beginMessage(TYPE_TEXT); 103 | wsClient.print(count); 104 | String data = " => Hello from SimpleWebSocket on " + String(BOARD_NAME) + ", millis = " + String(millis()); 105 | wsClient.print(data); 106 | wsClient.endMessage(); 107 | 108 | // increment count for next message 109 | count++; 110 | 111 | // check if a message is available to be received 112 | int messageSize = wsClient.parseMessage(); 113 | 114 | if (messageSize > 0) 115 | { 116 | Serial.println("Received a message:"); 117 | Serial.println(wsClient.readString()); 118 | } 119 | 120 | // wait 5 seconds 121 | delay(5000); 122 | } 123 | 124 | Serial.println("disconnected"); 125 | } 126 | -------------------------------------------------------------------------------- /examples/HTTPClient/node_test_server/getPostPutDelete.js: -------------------------------------------------------------------------------- 1 | /* 2 | Express.js GET/POST example 3 | Shows how handle GET, POST, PUT, DELETE 4 | in Express.js 4.0 5 | 6 | created 14 Feb 2016 7 | by Tom Igoe 8 | */ 9 | 10 | var express = require('express'); // include express.js 11 | var app = express(); // a local instance of it 12 | var bodyParser = require('body-parser'); // include body-parser 13 | var WebSocketServer = require('ws').Server // include Web Socket server 14 | 15 | // you need a body parser: 16 | app.use(bodyParser.urlencoded({extended: false})); // for application/x-www-form-urlencoded 17 | 18 | // this runs after the server successfully starts: 19 | function serverStart() { 20 | var port = server.address().port; 21 | console.log('Server listening on port '+ port); 22 | } 23 | 24 | app.get('/chunked', function(request, response) { 25 | response.write('\n'); 26 | response.write(' `:;;;,` .:;;:. \n'); 27 | response.write(' .;;;;;;;;;;;` :;;;;;;;;;;: TM \n'); 28 | response.write(' `;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;; \n'); 29 | response.write(' :;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;; \n'); 30 | response.write(' ;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;; \n'); 31 | response.write(' ;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;; \n'); 32 | response.write(' .;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;; \n'); 33 | response.write(' ;;;;;; ;;;;;;; ;;;;;;, ;;;;;;. \n'); 34 | response.write(' ,;;;;; ;;;;;;.;;;;;;` ;;;;;; \n'); 35 | response.write(' ;;;;;. ;;;;;;;;;;;` ``` ;;;;;`\n'); 36 | response.write(' ;;;;; ;;;;;;;;;, ;;; .;;;;;\n'); 37 | response.write('`;;;;: `;;;;;;;; ;;; ;;;;;\n'); 38 | response.write(',;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;\n'); 39 | response.write(':;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;\n'); 40 | response.write(':;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;\n'); 41 | response.write('.;;;;. ;;;;;;;. ;;; ;;;;;\n'); 42 | response.write(' ;;;;; ;;;;;;;;; ;;; ;;;;;\n'); 43 | response.write(' ;;;;; .;;;;;;;;;; ;;; ;;;;;,\n'); 44 | response.write(' ;;;;;; `;;;;;;;;;;;; ;;;;; \n'); 45 | response.write(' `;;;;;, .;;;;;; ;;;;;;; ;;;;;; \n'); 46 | response.write(' ;;;;;;: :;;;;;;. ;;;;;;; ;;;;;; \n'); 47 | response.write(' ;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;: \n'); 48 | response.write(' ;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;; \n'); 49 | response.write(' `;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;; \n'); 50 | response.write(' ;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;: \n'); 51 | response.write(' ,;;;;;;;;;;;;;, ;;;;;;;;;;;;;; \n'); 52 | response.write(' .;;;;;;;;;` ,;;;;;;;;: \n'); 53 | response.write(' \n'); 54 | response.write(' \n'); 55 | response.write(' \n'); 56 | response.write(' \n'); 57 | response.write(' ;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;; \n'); 58 | response.write(' ;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;; \n'); 59 | response.write(' ,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;; \n'); 60 | response.write(' ;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;. \n'); 61 | response.write(' ;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;` \n'); 62 | response.write(' ,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;; \n'); 63 | response.write(' ;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;; \n'); 64 | response.write(' ;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;; \n'); 65 | response.write('\n'); 66 | response.end(); 67 | }); 68 | 69 | // this is the POST handler: 70 | app.all('/*', function (request, response) { 71 | console.log('Got a ' + request.method + ' request'); 72 | // the parameters of a GET request are passed in 73 | // request.body. Pass that to formatResponse() 74 | // for formatting: 75 | console.log(request.headers); 76 | if (request.method == 'GET') { 77 | console.log(request.query); 78 | } else { 79 | console.log(request.body); 80 | } 81 | 82 | // send the response: 83 | response.send('OK'); 84 | response.end(); 85 | }); 86 | 87 | // start the server: 88 | var server = app.listen(8080, serverStart); 89 | 90 | // create a WebSocket server and attach it to the server 91 | var wss = new WebSocketServer({server: server}); 92 | 93 | wss.on('connection', function connection(ws) { 94 | // new connection, add message listener 95 | ws.on('message', function incoming(message) { 96 | // received a message 97 | console.log('received: %s', message); 98 | 99 | // echo it back 100 | ws.send(message); 101 | }); 102 | }); 103 | -------------------------------------------------------------------------------- /examples/HTTPClient/node_test_server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node_test_server", 3 | "version": "0.0.1", 4 | "author": { 5 | "name": "Tom Igoe" 6 | }, 7 | "dependencies": { 8 | "body-parser": ">=1.11.0", 9 | "express": ">=4.0.0", 10 | "multer": "*", 11 | "ws": ">=5.2.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/HelloServer/HelloServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HelloServer.ino - Dead simple web-server for Ethernet shields 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 19 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 20 | */ 21 | 22 | #include "defines.h" 23 | 24 | EthernetWebServer server(80); 25 | 26 | const int led = 13; 27 | 28 | void handleRoot() 29 | { 30 | server.send(200, "text/plain", String("Hello from EthernetWebServer on ") + BOARD_NAME ); 31 | } 32 | 33 | void handleNotFound() 34 | { 35 | String message = "File Not Found\n\n"; 36 | message += "URI: "; 37 | message += server.uri(); 38 | message += "\nMethod: "; 39 | message += (server.method() == HTTP_GET) ? "GET" : "POST"; 40 | message += "\nArguments: "; 41 | message += server.args(); 42 | message += "\n"; 43 | 44 | for (uint8_t i = 0; i < server.args(); i++) 45 | { 46 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 47 | } 48 | 49 | server.send(404, "text/plain", message); 50 | digitalWrite(led, 0); 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.println("\nStart HelloServer on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 61 | 62 | #if USE_ETHERNET_GENERIC 63 | Serial.println(ETHERNET_GENERIC_VERSION); 64 | #endif 65 | 66 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 67 | 68 | #if !(USE_BUILTIN_ETHERNET) 69 | #if (USING_SPI2) 70 | #if defined(CUR_PIN_MISO) 71 | ET_LOGWARN(F("Default SPI pinout:")); 72 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 73 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 74 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 75 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 76 | ET_LOGWARN(F("=========================")); 77 | #endif 78 | #else 79 | ET_LOGWARN(F("Default SPI pinout:")); 80 | ET_LOGWARN1(F("MOSI:"), MOSI); 81 | ET_LOGWARN1(F("MISO:"), MISO); 82 | ET_LOGWARN1(F("SCK:"), SCK); 83 | ET_LOGWARN1(F("SS:"), SS); 84 | ET_LOGWARN(F("=========================")); 85 | #endif 86 | #endif 87 | 88 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 89 | // For other boards, to change if necessary 90 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 91 | Ethernet.init (USE_THIS_SS_PIN); 92 | 93 | #elif USE_CUSTOM_ETHERNET 94 | // You have to add initialization for your Custom Ethernet here 95 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 96 | //Ethernet.init(USE_THIS_SS_PIN); 97 | 98 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 99 | #endif 100 | 101 | // start the ethernet connection and the server: 102 | // Use DHCP dynamic IP and random mac 103 | uint16_t index = millis() % NUMBER_OF_MAC; 104 | // Use Static IP 105 | //Ethernet.begin(mac[index], ip); 106 | Ethernet.begin(mac[index]); 107 | 108 | Serial.print(F("Connected! IP address: ")); 109 | Serial.println(Ethernet.localIP()); 110 | 111 | server.on("/", handleRoot); 112 | 113 | server.on("/inline", []() 114 | { 115 | server.send(200, "text/plain", "This works as well"); 116 | }); 117 | 118 | server.onNotFound(handleNotFound); 119 | 120 | server.begin(); 121 | 122 | Serial.print(F("HTTP EthernetWebServer is @ IP : ")); 123 | Serial.println(Ethernet.localIP()); 124 | } 125 | 126 | void loop() 127 | { 128 | server.handleClient(); 129 | } 130 | -------------------------------------------------------------------------------- /examples/HttpBasicAuth/HttpBasicAuth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HTTPBasicAuth.h - Dead simple web-server for Ethernet shields 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 19 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 20 | */ 21 | 22 | #include "defines.h" 23 | 24 | EthernetWebServer server(80); 25 | 26 | const char* www_username = "admin"; 27 | const char* www_password = "ethernet"; 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial && millis() < 5000); 34 | 35 | Serial.println("\nStart HTTPBasicAuth on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 36 | 37 | #if USE_ETHERNET_GENERIC 38 | Serial.println(ETHERNET_GENERIC_VERSION); 39 | #endif 40 | 41 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 42 | 43 | #if !(USE_BUILTIN_ETHERNET) 44 | #if (USING_SPI2) 45 | #if defined(CUR_PIN_MISO) 46 | ET_LOGWARN(F("Default SPI pinout:")); 47 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 48 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 49 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 50 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 51 | ET_LOGWARN(F("=========================")); 52 | #endif 53 | #else 54 | ET_LOGWARN(F("Default SPI pinout:")); 55 | ET_LOGWARN1(F("MOSI:"), MOSI); 56 | ET_LOGWARN1(F("MISO:"), MISO); 57 | ET_LOGWARN1(F("SCK:"), SCK); 58 | ET_LOGWARN1(F("SS:"), SS); 59 | ET_LOGWARN(F("=========================")); 60 | #endif 61 | #endif 62 | 63 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 64 | // For other boards, to change if necessary 65 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 66 | Ethernet.init (USE_THIS_SS_PIN); 67 | 68 | #elif USE_CUSTOM_ETHERNET 69 | // You have to add initialization for your Custom Ethernet here 70 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 71 | //Ethernet.init(USE_THIS_SS_PIN); 72 | 73 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 74 | #endif 75 | 76 | // start the ethernet connection and the server: 77 | // Use DHCP dynamic IP and random mac 78 | uint16_t index = millis() % NUMBER_OF_MAC; 79 | // Use Static IP 80 | //Ethernet.begin(mac[index], ip); 81 | Ethernet.begin(mac[index]); 82 | 83 | Serial.print(F("Connected! IP address: ")); 84 | Serial.println(Ethernet.localIP()); 85 | 86 | server.on("/", []() 87 | { 88 | if (!server.authenticate(www_username, www_password)) 89 | { 90 | return server.requestAuthentication(); 91 | } 92 | 93 | server.send(200, "text/plain", "Login OK"); 94 | }); 95 | 96 | server.begin(); 97 | 98 | Serial.print(F("HTTP EthernetWebServer started @ IP : ")); 99 | Serial.println(Ethernet.localIP()); 100 | 101 | Serial.print(F("Open http://")); 102 | Serial.print(Ethernet.localIP()); 103 | Serial.println(F("/ in your browser to see it working")); 104 | 105 | Serial.print(F("Login using username = ")); 106 | Serial.print(www_username); 107 | Serial.print(F(" and password = ")); 108 | Serial.println(www_password); 109 | } 110 | 111 | void loop() 112 | { 113 | server.handleClient(); 114 | } 115 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/AdvancedWebServer_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/BasicAuthGet_LAN8720/BasicAuthGet_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BasicAuthGet_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | GET client with HTTP basic authentication for ArduinoHttpClient library 13 | Connects to server once every five seconds, sends a GET request 14 | 15 | created 14 Feb 2016 16 | by Tom Igoe 17 | modified 3 Jan 2017 to add HTTP basic authentication 18 | by Sandeep Mistry 19 | modified 22 Jan 2019 20 | by Tom Igoe 21 | *****************************************************************************************************************************/ 22 | 23 | #include "defines.h" 24 | 25 | char serverAddress[] = "192.168.2.112"; // server address 26 | int port = 8080; 27 | 28 | EthernetClient client; 29 | EthernetHttpClient httpClient(client, serverAddress, port); 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | delay(2000); 35 | 36 | Serial.print("\nStarting BasicAuthGet_LAN8720 on " + String(BOARD_NAME)); 37 | Serial.println(" with " + String(SHIELD_TYPE)); 38 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 39 | 40 | // start the ethernet connection and the server: 41 | // Use DHCP dynamic IP and random mac 42 | uint16_t index = millis() % NUMBER_OF_MAC; 43 | // Use Static IP 44 | //Ethernet.begin(mac[index], ip); 45 | Ethernet.begin(mac[index]); 46 | 47 | Serial.print(F("Using mac index = ")); 48 | Serial.println(index); 49 | 50 | Serial.print(F("Connected! IP address: ")); 51 | Serial.println(Ethernet.localIP()); 52 | } 53 | 54 | void loop() 55 | { 56 | Serial.println("making GET request with HTTP basic authentication"); 57 | httpClient.beginRequest(); 58 | httpClient.get("/secure"); 59 | httpClient.sendBasicAuth("username", "password"); // send the username and password for authentication 60 | httpClient.endRequest(); 61 | 62 | // read the status code and body of the response 63 | int statusCode = httpClient.responseStatusCode(); 64 | String response = httpClient.responseBody(); 65 | 66 | Serial.print("Status code: "); 67 | Serial.println(statusCode); 68 | Serial.print("Response: "); 69 | Serial.println(response); 70 | 71 | Serial.println("Wait five seconds"); 72 | delay(5000); 73 | } 74 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/BasicAuthGet_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/CustomHeader_LAN8720/CustomHeader_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | CustomHeader_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Custom request header example for the ArduinoHttpClient 13 | library. This example sends a GET and a POST request with a custom header every 5 seconds. 14 | 15 | based on SimpleGet example by Tom Igoe 16 | header modifications by Todd Treece 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | 20 | *****************************************************************************************************************************/ 21 | 22 | #include "defines.h" 23 | 24 | char serverAddress[] = "192.168.2.112"; // server address 25 | int port = 8080; 26 | 27 | EthernetClient client; 28 | EthernetHttpClient httpClient(client, serverAddress, port); 29 | 30 | void setup() 31 | { 32 | Serial.begin(115200); 33 | delay(2000); 34 | 35 | Serial.print("\nStarting BasicAuthGet_LAN8720 on " + String(BOARD_NAME)); 36 | Serial.println(" with " + String(SHIELD_TYPE)); 37 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 38 | 39 | // start the ethernet connection and the server: 40 | // Use DHCP dynamic IP and random mac 41 | uint16_t index = millis() % NUMBER_OF_MAC; 42 | // Use Static IP 43 | //Ethernet.begin(mac[index], ip); 44 | Ethernet.begin(mac[index]); 45 | 46 | Serial.print(F("Using mac index = ")); 47 | Serial.println(index); 48 | 49 | Serial.print(F("Connected! IP address: ")); 50 | Serial.println(Ethernet.localIP()); 51 | } 52 | 53 | void loop() 54 | { 55 | Serial.println("Making GET request"); 56 | httpClient.beginRequest(); 57 | 58 | httpClient.get("/"); 59 | httpClient.sendHeader("X-CUSTOM-HEADER", "custom_value"); 60 | httpClient.endRequest(); 61 | 62 | // read the status code and body of the response 63 | int statusCode = httpClient.responseStatusCode(); 64 | String response = httpClient.responseBody(); 65 | 66 | Serial.print("GET Status code: "); 67 | Serial.println(statusCode); 68 | Serial.print("GET Response: "); 69 | Serial.println(response); 70 | 71 | Serial.println("Wait five seconds"); 72 | delay(5000); 73 | 74 | Serial.println("Making POST request"); 75 | String postData = "name=Alice&age=12"; 76 | httpClient.beginRequest(); 77 | httpClient.post("/"); 78 | httpClient.sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded"); 79 | httpClient.sendHeader(HTTP_HEADER_CONTENT_LENGTH, postData.length()); 80 | httpClient.sendHeader("X-CUSTOM-HEADER", "custom_value"); 81 | httpClient.endRequest(); 82 | httpClient.write((const byte*)postData.c_str(), postData.length()); 83 | // note: the above line can also be achieved with the simpler line below: 84 | //httpClient.print(postData); 85 | 86 | // read the status code and body of the response 87 | statusCode = httpClient.responseStatusCode(); 88 | response = httpClient.responseBody(); 89 | 90 | Serial.print("POST Status code: "); 91 | Serial.println(statusCode); 92 | Serial.print("POST Response: "); 93 | Serial.println(response); 94 | 95 | Serial.println("Wait five seconds"); 96 | delay(5000); 97 | } 98 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/CustomHeader_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/DweetGet_LAN8720/DweetGet_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | DweetGet_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Connects to dweet.io once every ten seconds, sends a GET request and a request body. Uses SSL 13 | 14 | Shows how to use Strings to assemble path and parse content from response. dweet.io expects: 15 | https://dweet.io/get/latest/dweet/for/thingName 16 | 17 | For more on dweet.io, see https://dweet.io/play/ 18 | 19 | created 15 Feb 2016 20 | updated 22 Jan 2019 21 | by Tom Igoe 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | 26 | const char serverAddress[] = "dweet.io"; // server address 27 | int port = 80; 28 | String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here 29 | 30 | EthernetClient client; 31 | EthernetHttpClient httpClient(client, serverAddress, port); 32 | 33 | void setup() 34 | { 35 | Serial.begin(115200); 36 | delay(2000); 37 | 38 | Serial.print("\nStarting DweetGet_LAN8720 on " + String(BOARD_NAME)); 39 | Serial.println(" with " + String(SHIELD_TYPE)); 40 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 41 | 42 | // start the ethernet connection and the server: 43 | // Use DHCP dynamic IP and random mac 44 | uint16_t index = millis() % NUMBER_OF_MAC; 45 | // Use Static IP 46 | //Ethernet.begin(mac[index], ip); 47 | Ethernet.begin(mac[index]); 48 | 49 | Serial.print(F("Using mac index = ")); 50 | Serial.println(index); 51 | 52 | Serial.print(F("Connected! IP address: ")); 53 | Serial.println(Ethernet.localIP()); 54 | } 55 | 56 | void loop() 57 | { 58 | // assemble the path for the GET message: 59 | String path = "/get/latest/dweet/for/" + dweetName; 60 | 61 | // send the GET request 62 | Serial.println("Making GET request"); 63 | httpClient.get(path); 64 | 65 | // read the status code and body of the response 66 | int statusCode = httpClient.responseStatusCode(); 67 | String response = httpClient.responseBody(); 68 | Serial.print("Status code: "); 69 | Serial.println(statusCode); 70 | Serial.print("Response: "); 71 | Serial.println(response); 72 | 73 | /* 74 | Typical response is: 75 | {"this":"succeeded", 76 | "by":"getting", 77 | "the":"dweets", 78 | "with":[{"thing":"my-thing-name", 79 | "created":"2016-02-16T05:10:36.589Z", 80 | "content":{"sensorValue":456}}]} 81 | 82 | You want "content": numberValue 83 | */ 84 | // now parse the response looking for "content": 85 | int labelStart = response.indexOf("content\":"); 86 | // find the first { after "content": 87 | int contentStart = response.indexOf("{", labelStart); 88 | // find the following } and get what's between the braces: 89 | int contentEnd = response.indexOf("}", labelStart); 90 | String content = response.substring(contentStart + 1, contentEnd); 91 | Serial.println(content); 92 | 93 | // now get the value after the colon, and convert to an int: 94 | int valueStart = content.indexOf(":"); 95 | String valueString = content.substring(valueStart + 1); 96 | int number = valueString.toInt(); 97 | Serial.print("Value string: "); 98 | Serial.println(valueString); 99 | Serial.print("Actual value: "); 100 | Serial.println(number); 101 | 102 | Serial.println("Wait ten seconds\n"); 103 | delay(10000); 104 | } 105 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/DweetGet_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/DweetPost_LAN8720/DweetPost_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | DweetPost_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Connects to dweet.io once every ten seconds, sends a POST request and a request body. 13 | 14 | Shows how to use Strings to assemble path and parse content from response. dweet.io expects: 15 | https://dweet.io/get/latest/dweet/for/thingName 16 | 17 | For more on dweet.io, see https://dweet.io/play/ 18 | 19 | created 15 Feb 2016 20 | modified 22 Jan 2019 21 | by Tom Igoe 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | 26 | const char serverAddress[] = "dweet.io"; // server address 27 | int port = 80; 28 | 29 | EthernetClient client; 30 | EthernetHttpClient httpClient(client, serverAddress, port); 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | delay(2000); 36 | 37 | Serial.print("\nStarting DweetPost_LAN8720 on " + String(BOARD_NAME)); 38 | Serial.println(" with " + String(SHIELD_TYPE)); 39 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 40 | 41 | // start the ethernet connection and the server: 42 | // Use DHCP dynamic IP and random mac 43 | uint16_t index = millis() % NUMBER_OF_MAC; 44 | // Use Static IP 45 | //Ethernet.begin(mac[index], ip); 46 | Ethernet.begin(mac[index]); 47 | 48 | Serial.print(F("Using mac index = ")); 49 | Serial.println(index); 50 | 51 | Serial.print(F("Connected! IP address: ")); 52 | Serial.println(Ethernet.localIP()); 53 | } 54 | 55 | void loop() 56 | { 57 | // assemble the path for the POST message: 58 | String dweetName = "scandalous-cheese-hoarder"; 59 | String path = "/dweet/for/" + dweetName; 60 | String contentType = "application/json"; 61 | 62 | // assemble the body of the POST message: 63 | int sensorValue = analogRead(A0); 64 | String postData = "{\"sensorValue\":\""; 65 | postData += sensorValue; 66 | postData += "\"}"; 67 | 68 | Serial.println("making POST request"); 69 | 70 | // send the POST request 71 | httpClient.post(path, contentType, postData); 72 | 73 | // read the status code and body of the response 74 | int statusCode = httpClient.responseStatusCode(); 75 | String response = httpClient.responseBody(); 76 | 77 | Serial.print("Status code: "); 78 | Serial.println(statusCode); 79 | Serial.print("Response: "); 80 | Serial.println(response); 81 | 82 | Serial.println("Wait ten seconds\n"); 83 | delay(10000); 84 | } 85 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/DweetPost_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/HueBlink_LAN8720/HueBlink_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HueBlink_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Uses HttpClient to control Philips Hue 13 | For more on Hue developer API see http://developer.meethue.com 14 | 15 | To control a light, the Hue expects a HTTP PUT request to: 16 | 17 | http://hue.hub.address/api/hueUserName/lights/lightNumber/state 18 | 19 | The body of the PUT request looks like this: 20 | {"on": true} or {"on":false} 21 | 22 | This example shows how to concatenate Strings to assemble the 23 | PUT request and the body of the request. 24 | 25 | modified 15 Feb 2016 26 | by Tom Igoe (tigoe) to match new API 27 | *****************************************************************************************************************************/ 28 | 29 | #include "defines.h" 30 | 31 | char hueHubIP[] = "192.168.2.223"; // IP address of the HUE bridge 32 | String hueUserName = "huebridgeusername"; // hue bridge username 33 | 34 | EthernetClient client; 35 | EthernetHttpClient httpClient(client, hueHubIP); 36 | 37 | void setup() 38 | { 39 | Serial.begin(115200); 40 | delay(2000); 41 | 42 | Serial.print("\nStarting HueBlink_LAN8720 on " + String(BOARD_NAME)); 43 | Serial.println(" with " + String(SHIELD_TYPE)); 44 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 45 | 46 | // start the ethernet connection and the server: 47 | // Use DHCP dynamic IP and random mac 48 | uint16_t index = millis() % NUMBER_OF_MAC; 49 | // Use Static IP 50 | //Ethernet.begin(mac[index], ip); 51 | Ethernet.begin(mac[index]); 52 | 53 | Serial.print(F("Using mac index = ")); 54 | Serial.println(index); 55 | 56 | Serial.print(F("Connected! IP address: ")); 57 | Serial.println(Ethernet.localIP()); 58 | } 59 | 60 | void sendRequest(int light, String cmd, String value) 61 | { 62 | // make a String for the HTTP request path: 63 | String request = "/api/" + hueUserName; 64 | request += "/lights/"; 65 | request += light; 66 | request += "/state/"; 67 | 68 | String contentType = "application/json"; 69 | 70 | // make a string for the JSON command: 71 | String hueCmd = "{\"" + cmd; 72 | hueCmd += "\":"; 73 | hueCmd += value; 74 | hueCmd += "}"; 75 | 76 | // see what you assembled to send: 77 | Serial.print("PUT request to server: "); 78 | Serial.println(request); 79 | Serial.print("JSON command to server: "); 80 | 81 | // make the PUT request to the hub: 82 | httpClient.put(request, contentType, hueCmd); 83 | 84 | // read the status code and body of the response 85 | int statusCode = httpClient.responseStatusCode(); 86 | String response = httpClient.responseBody(); 87 | 88 | Serial.println(hueCmd); 89 | Serial.print("Status code from server: "); 90 | Serial.println(statusCode); 91 | Serial.print("Server response: "); 92 | Serial.println(response); 93 | Serial.println(); 94 | } 95 | 96 | void loop() 97 | { 98 | sendRequest(3, "on", "true"); // turn light on 99 | delay(2000); // wait 2 seconds 100 | sendRequest(3, "on", "false"); // turn light off 101 | delay(2000); // wait 2 seconds 102 | } 103 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/HueBlink_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/PostWithHeaders_LAN8720/PostWithHeaders_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PostWithHeaders_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | POST with headers client for HttpClient 13 | Connects to server once every five seconds, sends a POST request 14 | with custome headers and a request body 15 | 16 | created 14 Feb 2016 17 | by Tom Igoe 18 | modified 18 Mar 2017 19 | by Sandeep Mistry 20 | modified 22 Jan 2019 21 | by Tom Igoe 22 | *****************************************************************************************************************************/ 23 | 24 | #include "defines.h" 25 | 26 | char serverAddress[] = "192.168.2.112"; // server address 27 | int port = 8080; 28 | 29 | EthernetClient client; 30 | EthernetHttpClient httpClient(client, serverAddress, port); 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | delay(2000); 36 | 37 | Serial.print("\nStarting PostWithHeaders_LAN8720 on " + String(BOARD_NAME)); 38 | Serial.println(" with " + String(SHIELD_TYPE)); 39 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 40 | 41 | // start the ethernet connection and the server: 42 | // Use DHCP dynamic IP and random mac 43 | uint16_t index = millis() % NUMBER_OF_MAC; 44 | // Use Static IP 45 | //Ethernet.begin(mac[index], ip); 46 | Ethernet.begin(mac[index]); 47 | 48 | Serial.print(F("Using mac index = ")); 49 | Serial.println(index); 50 | 51 | Serial.print(F("Connected! IP address: ")); 52 | Serial.println(Ethernet.localIP()); 53 | } 54 | 55 | void loop() 56 | { 57 | Serial.println("making POST request"); 58 | String postData = "name=Alice&age=12"; 59 | 60 | httpClient.beginRequest(); 61 | httpClient.post("/"); 62 | httpClient.sendHeader("Content-Type", "application/x-www-form-urlencoded"); 63 | httpClient.sendHeader("Content-Length", postData.length()); 64 | httpClient.sendHeader("X-Custom-Header", "custom-header-value"); 65 | httpClient.beginBody(); 66 | httpClient.print(postData); 67 | httpClient.endRequest(); 68 | 69 | // read the status code and body of the response 70 | int statusCode = httpClient.responseStatusCode(); 71 | String response = httpClient.responseBody(); 72 | 73 | Serial.print("Status code: "); 74 | Serial.println(statusCode); 75 | Serial.print("Response: "); 76 | Serial.println(response); 77 | 78 | Serial.println("Wait five seconds"); 79 | delay(5000); 80 | } 81 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/PostWithHeaders_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleDelete_LAN8720/SimpleDelete_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleDelete_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple DELETE client for HttpClient 13 | Connects to server once every five seconds, sends a DELETE request 14 | and a request body 15 | 16 | created 14 Feb 2016 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "192.168.2.112"; // server address 24 | int port = 8080; 25 | 26 | EthernetClient client; 27 | EthernetHttpClient httpClient(client, serverAddress, port); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | delay(2000); 33 | 34 | Serial.print("\nStarting SimpleDelete_LAN8720 on " + String(BOARD_NAME)); 35 | Serial.println(" with " + String(SHIELD_TYPE)); 36 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 37 | 38 | // start the ethernet connection and the server: 39 | // Use DHCP dynamic IP and random mac 40 | uint16_t index = millis() % NUMBER_OF_MAC; 41 | // Use Static IP 42 | //Ethernet.begin(mac[index], ip); 43 | Ethernet.begin(mac[index]); 44 | 45 | Serial.print(F("Using mac index = ")); 46 | Serial.println(index); 47 | 48 | Serial.print(F("Connected! IP address: ")); 49 | Serial.println(Ethernet.localIP()); 50 | } 51 | 52 | void loop() 53 | { 54 | Serial.println("making DELETE request"); 55 | String contentType = "application/x-www-form-urlencoded"; 56 | String delData = "name=light&age=46"; 57 | 58 | httpClient.del("/", contentType, delData); 59 | 60 | // read the status code and body of the response 61 | int statusCode = httpClient.responseStatusCode(); 62 | String response = httpClient.responseBody(); 63 | 64 | Serial.print("Status code: "); 65 | Serial.println(statusCode); 66 | Serial.print("Response: "); 67 | Serial.println(response); 68 | 69 | Serial.println("Wait five seconds"); 70 | delay(5000); 71 | } 72 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleDelete_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleGet_LAN8720/SimpleGet_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleGet_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple GET client for HttpClient 13 | Connects to server once every five seconds, sends a GET request 14 | 15 | created 14 Feb 2016 16 | modified 22 Jan 2019 17 | by Tom Igoe 18 | *****************************************************************************************************************************/ 19 | 20 | #include "defines.h" 21 | 22 | char serverAddress[] = "192.168.2.112"; // server address 23 | int port = 8080; 24 | 25 | EthernetClient client; 26 | EthernetHttpClient httpClient(client, serverAddress, port); 27 | 28 | void setup() 29 | { 30 | Serial.begin(115200); 31 | delay(2000); 32 | 33 | Serial.print("\nStarting SimpleGet_LAN8720 on " + String(BOARD_NAME)); 34 | Serial.println(" with " + String(SHIELD_TYPE)); 35 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 36 | 37 | // start the ethernet connection and the server: 38 | // Use DHCP dynamic IP and random mac 39 | uint16_t index = millis() % NUMBER_OF_MAC; 40 | // Use Static IP 41 | //Ethernet.begin(mac[index], ip); 42 | Ethernet.begin(mac[index]); 43 | 44 | Serial.print(F("Using mac index = ")); 45 | Serial.println(index); 46 | 47 | Serial.print(F("Connected! IP address: ")); 48 | Serial.println(Ethernet.localIP()); 49 | } 50 | 51 | void loop() 52 | { 53 | Serial.println("making GET request"); 54 | httpClient.get("/"); 55 | 56 | // read the status code and body of the response 57 | int statusCode = httpClient.responseStatusCode(); 58 | String response = httpClient.responseBody(); 59 | 60 | Serial.print("Status code: "); 61 | Serial.println(statusCode); 62 | Serial.print("Response: "); 63 | Serial.println(response); 64 | Serial.println("Wait five seconds"); 65 | delay(5000); 66 | } 67 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleGet_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleHTTPExample_LAN8720/SimpleHTTPExample_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleHTTPExample_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple example to show how to use the HttpClient library 13 | Get's the web page given at http:// and outputs the content to the serial port 14 | *****************************************************************************************************************************/ 15 | 16 | #include "defines.h" 17 | 18 | // This example downloads the URL "http://arduino.cc/" 19 | // Name of the server we want to connect to 20 | const char kHostname[] = "arduino.tips"; 21 | 22 | // Path to download (this is the bit after the hostname in the URL 23 | // that you want to download 24 | const char kPath[] = "/asciilogo.txt"; 25 | 26 | // Number of milliseconds to wait without receiving any data before we give up 27 | #define NETWORK_TIMEOUT_MS 30000L 28 | 29 | // Number of milliseconds to wait if no data is available before trying again 30 | #define NETWORK_RETRY_MS 1000L 31 | 32 | EthernetClient client; 33 | EthernetHttpClient httpClient(client, kHostname); 34 | 35 | void setup() 36 | { 37 | Serial.begin(115200); 38 | delay(2000); 39 | 40 | Serial.print("\nStarting SimpleHTTPExample_LAN8720 on " + String(BOARD_NAME)); 41 | Serial.println(" with " + String(SHIELD_TYPE)); 42 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 43 | 44 | // start the ethernet connection and the server: 45 | // Use DHCP dynamic IP and random mac 46 | uint16_t index = millis() % NUMBER_OF_MAC; 47 | // Use Static IP 48 | //Ethernet.begin(mac[index], ip); 49 | Ethernet.begin(mac[index]); 50 | 51 | Serial.print(F("Using mac index = ")); 52 | Serial.println(index); 53 | 54 | Serial.print(F("Connected! IP address: ")); 55 | Serial.println(Ethernet.localIP()); 56 | } 57 | 58 | void loop() 59 | { 60 | int err = 0; 61 | 62 | err = httpClient.get(kPath); 63 | 64 | if (err == 0) 65 | { 66 | Serial.println("startedRequest ok"); 67 | 68 | err = httpClient.responseStatusCode(); 69 | 70 | if (err >= 0) 71 | { 72 | Serial.print("Got status code: "); 73 | Serial.println(err); 74 | 75 | // Usually you'd check that the response code is 200 or a 76 | // similar "success" code (200-299) before carrying on, 77 | // but we'll print out whatever response we get 78 | 79 | err = httpClient.skipResponseHeaders(); 80 | 81 | if (err >= 0) 82 | { 83 | int bodyLen = httpClient.contentLength(); 84 | Serial.print("Content length is: "); 85 | Serial.println(bodyLen); 86 | Serial.println(); 87 | Serial.println("Body returned follows:"); 88 | 89 | // Now we've got to the body, so we can print it out 90 | unsigned long timeoutStart = millis(); 91 | 92 | // Whilst we haven't timed out & haven't reached the end of the body 93 | while ( (httpClient.connected() || httpClient.available()) && 94 | ((millis() - timeoutStart) < NETWORK_TIMEOUT_MS) ) 95 | { 96 | if (httpClient.available()) 97 | { 98 | Serial.print((char) httpClient.read()); 99 | 100 | bodyLen--; 101 | 102 | // We read something, reset the timeout counter 103 | timeoutStart = millis(); 104 | } 105 | else 106 | { 107 | // We haven't got any data, so let's pause to allow some to 108 | // arrive 109 | delay(NETWORK_RETRY_MS); 110 | } 111 | } 112 | } 113 | else 114 | { 115 | Serial.print("Failed to skip response headers: "); 116 | Serial.println(err); 117 | } 118 | } 119 | else 120 | { 121 | Serial.print("Getting response failed: "); 122 | Serial.println(err); 123 | } 124 | } 125 | else 126 | { 127 | Serial.print("Connect failed: "); 128 | Serial.println(err); 129 | } 130 | 131 | httpClient.stop(); 132 | 133 | // And just stop, now that we've tried a download 134 | while (1); 135 | } 136 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleHTTPExample_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimplePost_LAN8720/SimplePost_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimplePost_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple POST client for HttpClient 13 | Connects to server once every five seconds, sends a POST request 14 | and a request body 15 | 16 | created 14 Feb 2016 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "192.168.2.112"; // server address 24 | int port = 8080; 25 | 26 | EthernetClient client; 27 | EthernetHttpClient httpClient(client, serverAddress, port); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | delay(2000); 33 | 34 | Serial.print("\nStarting SimplePost_LAN8720 on " + String(BOARD_NAME)); 35 | Serial.println(" with " + String(SHIELD_TYPE)); 36 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 37 | 38 | // start the ethernet connection and the server: 39 | // Use DHCP dynamic IP and random mac 40 | uint16_t index = millis() % NUMBER_OF_MAC; 41 | // Use Static IP 42 | //Ethernet.begin(mac[index], ip); 43 | Ethernet.begin(mac[index]); 44 | 45 | Serial.print(F("Using mac index = ")); 46 | Serial.println(index); 47 | 48 | Serial.print(F("Connected! IP address: ")); 49 | Serial.println(Ethernet.localIP()); 50 | } 51 | 52 | void loop() 53 | { 54 | Serial.println("making POST request"); 55 | String contentType = "application/x-www-form-urlencoded"; 56 | String postData = "name=Alice&age=12"; 57 | 58 | httpClient.post("/", contentType, postData); 59 | 60 | // read the status code and body of the response 61 | int statusCode = httpClient.responseStatusCode(); 62 | String response = httpClient.responseBody(); 63 | 64 | Serial.print("Status code: "); 65 | Serial.println(statusCode); 66 | Serial.print("Response: "); 67 | Serial.println(response); 68 | 69 | Serial.println("Wait five seconds"); 70 | delay(5000); 71 | } 72 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimplePost_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimplePut_LAN8720/SimplePut_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimplePut_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | 12 | Simple PUT client for HttpClient 13 | Connects to server once every five seconds, sends a PUT request 14 | and a request body 15 | 16 | created 14 Feb 2016 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "192.168.2.112"; // server address 24 | int port = 8080; 25 | 26 | EthernetClient client; 27 | EthernetHttpClient httpClient(client, serverAddress, port); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | delay(2000); 33 | 34 | Serial.print("\nStarting SimplePut_LAN8720 on " + String(BOARD_NAME)); 35 | Serial.println(" with " + String(SHIELD_TYPE)); 36 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 37 | 38 | // start the ethernet connection and the server: 39 | // Use DHCP dynamic IP and random mac 40 | uint16_t index = millis() % NUMBER_OF_MAC; 41 | // Use Static IP 42 | //Ethernet.begin(mac[index], ip); 43 | Ethernet.begin(mac[index]); 44 | 45 | Serial.print(F("Using mac index = ")); 46 | Serial.println(index); 47 | 48 | Serial.print(F("Connected! IP address: ")); 49 | Serial.println(Ethernet.localIP()); 50 | } 51 | 52 | void loop() 53 | { 54 | Serial.println("making PUT request"); 55 | String contentType = "application/x-www-form-urlencoded"; 56 | String putData = "name=light&age=46"; 57 | 58 | httpClient.put("/", contentType, putData); 59 | 60 | // read the status code and body of the response 61 | int statusCode = httpClient.responseStatusCode(); 62 | String response = httpClient.responseBody(); 63 | 64 | Serial.print("Status code: "); 65 | Serial.println(statusCode); 66 | Serial.print("Response: "); 67 | Serial.println(response); 68 | 69 | Serial.println("Wait five seconds"); 70 | delay(5000); 71 | } 72 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimplePut_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleWebSocket_LAN8720/SimpleWebSocket_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleWebSocket_LAN8720.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 5 | 6 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 10 | Licensed under MIT license 11 | Simple WebSocket client for HttpClient 12 | Connects to the WebSocket server, and sends a hello 13 | message every 5 seconds 14 | 15 | created 28 Jun 2016 16 | by Sandeep Mistry 17 | modified 22 Jan 2019 18 | by Tom Igoe 19 | *****************************************************************************************************************************/ 20 | 21 | #include "defines.h" 22 | 23 | char serverAddress[] = "echo.websocket.org"; // server address 24 | int port = 80; 25 | 26 | EthernetClient client; 27 | EthernetWebSocketClient wsClient(client, serverAddress, port); 28 | 29 | int count = 0; 30 | 31 | void setup() 32 | { 33 | Serial.begin(115200); 34 | delay(2000); 35 | 36 | Serial.print("\nStarting SimpleWebSocket_LAN8720 on " + String(BOARD_NAME)); 37 | Serial.println(" with " + String(SHIELD_TYPE)); 38 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 39 | 40 | // start the ethernet connection and the server: 41 | // Use DHCP dynamic IP and random mac 42 | uint16_t index = millis() % NUMBER_OF_MAC; 43 | // Use Static IP 44 | //Ethernet.begin(mac[index], ip); 45 | Ethernet.begin(mac[index]); 46 | 47 | Serial.print(F("Using mac index = ")); 48 | Serial.println(index); 49 | 50 | Serial.print(F("Connected! IP address: ")); 51 | Serial.println(Ethernet.localIP()); 52 | } 53 | 54 | void loop() 55 | { 56 | Serial.println("starting WebSocket client"); 57 | 58 | wsClient.begin(); 59 | 60 | while (wsClient.connected()) 61 | { 62 | Serial.print("Sending Hello "); 63 | Serial.println(count); 64 | 65 | // send a hello # 66 | wsClient.beginMessage(TYPE_TEXT); 67 | wsClient.print(count); 68 | String data = " => Hello from SimpleWebSocket on " + String(BOARD_NAME) + " using LAN8720, millis = " + String( 69 | millis()); 70 | wsClient.print(data); 71 | wsClient.endMessage(); 72 | 73 | // increment count for next message 74 | count++; 75 | 76 | // check if a message is available to be received 77 | int messageSize = wsClient.parseMessage(); 78 | 79 | if (messageSize > 0) 80 | { 81 | Serial.println("Received a message:"); 82 | Serial.println(wsClient.readString()); 83 | } 84 | 85 | // wait 5 seconds 86 | delay(5000); 87 | } 88 | 89 | Serial.println("disconnected"); 90 | } 91 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/SimpleWebSocket_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HTTPClient_LAN8720/node_test_server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node_test_server", 3 | "version": "0.0.1", 4 | "author": { 5 | "name": "Tom Igoe" 6 | }, 7 | "dependencies": { 8 | "body-parser": ">=1.11.0", 9 | "express": ">=4.0.0", 10 | "multer": "*", 11 | "ws": ">=5.2.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HelloServer2_LAN8720/HelloServer2_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HelloServer2_LAN8720.h - Dead simple web-server for Ethernet shields 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | EthernetWebServer server(80); 28 | 29 | void handleRoot() 30 | { 31 | server.send(200, "text/plain", String("Hello from EthernetWebServer on ") + BOARD_NAME); 32 | } 33 | 34 | void handleNotFound() 35 | { 36 | String message = "File Not Found\n\n"; 37 | message += "URI: "; 38 | message += server.uri(); 39 | message += "\nMethod: "; 40 | message += (server.method() == HTTP_GET) ? "GET" : "POST"; 41 | message += "\nArguments: "; 42 | message += server.args(); 43 | message += "\n"; 44 | 45 | for (uint8_t i = 0; i < server.args(); i++) 46 | { 47 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 48 | } 49 | 50 | server.send(404, "text/plain", message); 51 | } 52 | 53 | void setup() 54 | { 55 | // Open serial communications and wait for port to open: 56 | Serial.begin(115200); 57 | 58 | delay(2000); 59 | 60 | Serial.println("\nStart HelloServer2_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 61 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 62 | 63 | // start the ethernet connection and the server: 64 | // Use DHCP dynamic IP and random mac 65 | uint16_t index = millis() % NUMBER_OF_MAC; 66 | // Use Static IP 67 | //Ethernet.begin(mac[index], ip); 68 | Ethernet.begin(mac[index]); 69 | 70 | Serial.print(F("Connected! IP address: ")); 71 | Serial.println(Ethernet.localIP()); 72 | 73 | server.on("/", handleRoot); 74 | 75 | server.on("/inline", []() 76 | { 77 | server.send(200, "text/plain", "This works as well"); 78 | }); 79 | 80 | server.on("/gif", []() 81 | { 82 | static const uint8_t gif[] = 83 | { 84 | 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01, 85 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00, 86 | 0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d, 87 | 0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c, 88 | 0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b 89 | }; 90 | char gif_colored[sizeof(gif)]; 91 | 92 | memcpy(gif_colored, gif, sizeof(gif)); 93 | 94 | // Set the background to a random set of colors 95 | gif_colored[16] = millis() % 256; 96 | gif_colored[17] = millis() % 256; 97 | gif_colored[18] = millis() % 256; 98 | 99 | server.send(200, (char *) "image/gif", gif_colored, sizeof(gif_colored)); 100 | }); 101 | 102 | server.onNotFound(handleNotFound); 103 | 104 | server.begin(); 105 | 106 | Serial.print("HTTP EthernetWebServer started @ IP : "); 107 | Serial.println(Ethernet.localIP()); 108 | } 109 | 110 | void loop() 111 | { 112 | server.handleClient(); 113 | } 114 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HelloServer2_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HelloServer_LAN8720/HelloServer_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HelloServer_LAN8720.ino - Dead simple web-server for Ethernet shields 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | EthernetWebServer server(80); 28 | 29 | const int led = 13; 30 | 31 | void handleRoot() 32 | { 33 | server.send(200, "text/plain", String("Hello from EthernetWebServer on ") + BOARD_NAME ); 34 | } 35 | 36 | void handleNotFound() 37 | { 38 | String message = "File Not Found\n\n"; 39 | message += "URI: "; 40 | message += server.uri(); 41 | message += "\nMethod: "; 42 | message += (server.method() == HTTP_GET) ? "GET" : "POST"; 43 | message += "\nArguments: "; 44 | message += server.args(); 45 | message += "\n"; 46 | 47 | for (uint8_t i = 0; i < server.args(); i++) 48 | { 49 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 50 | } 51 | 52 | server.send(404, "text/plain", message); 53 | digitalWrite(led, 0); 54 | } 55 | 56 | void setup() 57 | { 58 | // Open serial communications and wait for port to open: 59 | Serial.begin(115200); 60 | delay(2000); 61 | 62 | Serial.println("\nStart HelloServer_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 63 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 64 | 65 | // start the ethernet connection and the server: 66 | // Use DHCP dynamic IP and random mac 67 | uint16_t index = millis() % NUMBER_OF_MAC; 68 | // Use Static IP 69 | //Ethernet.begin(mac[index], ip); 70 | Ethernet.begin(mac[index]); 71 | 72 | Serial.print(F("Connected! IP address: ")); 73 | Serial.println(Ethernet.localIP()); 74 | 75 | server.on("/", handleRoot); 76 | 77 | server.on("/inline", []() 78 | { 79 | server.send(200, "text/plain", "This works as well"); 80 | }); 81 | 82 | server.onNotFound(handleNotFound); 83 | 84 | server.begin(); 85 | 86 | Serial.print(F("HTTP EthernetWebServer is @ IP : ")); 87 | Serial.println(Ethernet.localIP()); 88 | } 89 | 90 | void loop() 91 | { 92 | server.handleClient(); 93 | } 94 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HelloServer_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HttpBasicAuth_LAN8720/HttpBasicAuth_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HTTPBasicAuth_LAN8720.h - Dead simple web-server for Ethernet shields 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | EthernetWebServer server(80); 28 | 29 | const char* www_username = "admin"; 30 | const char* www_password = "ethernet"; 31 | 32 | void setup() 33 | { 34 | Serial.begin(115200); 35 | delay(2000); 36 | 37 | Serial.println("\nStart HTTPBasicAuth_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 38 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 39 | 40 | // start the ethernet connection and the server: 41 | // Use DHCP dynamic IP and random mac 42 | uint16_t index = millis() % NUMBER_OF_MAC; 43 | // Use Static IP 44 | //Ethernet.begin(mac[index], ip); 45 | Ethernet.begin(mac[index]); 46 | 47 | Serial.print(F("Connected! IP address: ")); 48 | Serial.println(Ethernet.localIP()); 49 | 50 | server.on("/", []() 51 | { 52 | if (!server.authenticate(www_username, www_password)) 53 | { 54 | return server.requestAuthentication(); 55 | } 56 | 57 | server.send(200, "text/plain", "Login OK"); 58 | }); 59 | 60 | server.begin(); 61 | 62 | Serial.print(F("HTTP EthernetWebServer started @ IP : ")); 63 | Serial.println(Ethernet.localIP()); 64 | 65 | Serial.print(F("Open http://")); 66 | Serial.print(Ethernet.localIP()); 67 | Serial.println(F("/ in your browser to see it working")); 68 | 69 | Serial.print(F("Login using username = ")); 70 | Serial.print(www_username); 71 | Serial.print(F(" and password = ")); 72 | Serial.println(www_password); 73 | } 74 | 75 | void loop() 76 | { 77 | server.handleClient(); 78 | } 79 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/HttpBasicAuth_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/MQTTClient_Auth_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/MQTTClient_Basic_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/MQTT_ThingStream_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/PostServer_LAN8720/PostServer_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PostServer_LAN8720.h - Dead simple web-server for Ethernet shields 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 19 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 20 | */ 21 | 22 | #include "defines.h" 23 | 24 | EthernetWebServer server(80); 25 | 26 | const int led = 13; 27 | 28 | const String postForms = 29 | "\ 30 | \ 31 | EthernetWebServer POST handling\ 32 | \ 35 | \ 36 | \ 37 |

POST plain text to /postplain/


\ 38 |
\ 39 |
\ 40 | \ 41 |
\ 42 |

POST form data to /postform/


\ 43 |
\ 44 |
\ 45 | \ 46 |
\ 47 | \ 48 | "; 49 | 50 | void handleRoot() 51 | { 52 | digitalWrite(led, 1); 53 | server.send(200, "text/html", postForms); 54 | digitalWrite(led, 0); 55 | } 56 | 57 | void handlePlain() 58 | { 59 | if (server.method() != HTTP_POST) 60 | { 61 | digitalWrite(led, 1); 62 | server.send(405, "text/plain", "Method Not Allowed"); 63 | digitalWrite(led, 0); 64 | } 65 | else 66 | { 67 | digitalWrite(led, 1); 68 | server.send(200, "text/plain", "POST body was:\n" + server.arg("plain")); 69 | digitalWrite(led, 0); 70 | } 71 | } 72 | 73 | void handleForm() 74 | { 75 | if (server.method() != HTTP_POST) 76 | { 77 | digitalWrite(led, 1); 78 | server.send(405, "text/plain", "Method Not Allowed"); 79 | digitalWrite(led, 0); 80 | } 81 | else 82 | { 83 | digitalWrite(led, 1); 84 | String message = "POST form was:\n"; 85 | 86 | for (uint8_t i = 0; i < server.args(); i++) 87 | { 88 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 89 | } 90 | 91 | server.send(200, "text/plain", message); 92 | digitalWrite(led, 0); 93 | } 94 | } 95 | 96 | void handleNotFound() 97 | { 98 | digitalWrite(led, 1); 99 | String message = "File Not Found\n\n"; 100 | message += "URI: "; 101 | message += server.uri(); 102 | message += "\nMethod: "; 103 | message += (server.method() == HTTP_GET) ? "GET" : "POST"; 104 | message += "\nArguments: "; 105 | message += server.args(); 106 | message += "\n"; 107 | 108 | for (uint8_t i = 0; i < server.args(); i++) 109 | { 110 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 111 | } 112 | 113 | server.send(404, "text/plain", message); 114 | digitalWrite(led, 0); 115 | } 116 | 117 | void setup() 118 | { 119 | pinMode(led, OUTPUT); 120 | digitalWrite(led, 0); 121 | 122 | Serial.begin(115200); 123 | delay(2000); 124 | 125 | Serial.println("\nStart POSTServer_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 126 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 127 | 128 | // start the ethernet connection and the server: 129 | // Use DHCP dynamic IP and random mac 130 | uint16_t index = millis() % NUMBER_OF_MAC; 131 | // Use Static IP 132 | //Ethernet.begin(mac[index], ip); 133 | Ethernet.begin(mac[index]); 134 | 135 | Serial.print(F("Connected! IP address: ")); 136 | Serial.println(Ethernet.localIP()); 137 | 138 | server.on("/", handleRoot); 139 | 140 | server.on("/postplain/", handlePlain); 141 | 142 | server.on("/postform/", handleForm); 143 | 144 | server.onNotFound(handleNotFound); 145 | 146 | server.begin(); 147 | 148 | Serial.print(F("HTTP EthernetWebServer started @ IP : ")); 149 | Serial.println(Ethernet.localIP()); 150 | } 151 | 152 | void loop() 153 | { 154 | server.handleClient(); 155 | } 156 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/PostServer_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/SimpleAuthentication_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/UdpNTPClient_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/UdpSendReceive_LAN8720/UdpSendReceive_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | UDPSendReceive_LAN8720.ino - Simple Arduino web server sample for ESP8266/ESP32 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | unsigned int localPort = 1883; //10002; // local port to listen on 28 | 29 | char packetBuffer[255]; // buffer to hold incoming packet 30 | char ReplyBuffer[] = "ACK"; // a string to send back 31 | 32 | // A UDP instance to let us send and receive packets over UDP 33 | EthernetUDP Udp; 34 | 35 | void setup() 36 | { 37 | Serial.begin(115200); 38 | 39 | delay(2000); 40 | 41 | Serial.println("\nStart UDPSendReceive_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 42 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 43 | 44 | // start the ethernet connection and the server: 45 | // Use DHCP dynamic IP and random mac 46 | uint16_t index = millis() % NUMBER_OF_MAC; 47 | // Use Static IP 48 | //Ethernet.begin(mac[index], ip); 49 | Ethernet.begin(mac[index]); 50 | 51 | // you're connected now, so print out the data 52 | Serial.print(F("You're connected to the network, IP = ")); 53 | Serial.println(Ethernet.localIP()); 54 | 55 | Serial.println(F("\nStarting connection to server...")); 56 | // if you get a connection, report back via serial: 57 | Udp.begin(localPort); 58 | 59 | Serial.print(F("Listening on port ")); 60 | Serial.println(localPort); 61 | } 62 | 63 | void loop() 64 | { 65 | // if there's data available, read a packet 66 | int packetSize = Udp.parsePacket(); 67 | 68 | if (packetSize) 69 | { 70 | Serial.print(F("Received packet of size ")); 71 | Serial.println(packetSize); 72 | Serial.print(F("From ")); 73 | IPAddress remoteIp = Udp.remoteIP(); 74 | Serial.print(remoteIp); 75 | Serial.print(F(", port ")); 76 | Serial.println(Udp.remotePort()); 77 | 78 | // read the packet into packetBufffer 79 | int len = Udp.read(packetBuffer, 255); 80 | 81 | if (len > 0) 82 | { 83 | packetBuffer[len] = 0; 84 | } 85 | 86 | Serial.println(F("Contents:")); 87 | Serial.println(packetBuffer); 88 | 89 | // send a reply, to the IP address and port that sent us the packet we received 90 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 91 | Udp.write(ReplyBuffer); 92 | Udp.endPacket(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/UdpSendReceive_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/WebClientRepeating_LAN8720/WebClientRepeating_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClientRepeating_LAN8720.ino - Simple Arduino web server sample for ESP8266 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | char server[] = "arduino.tips"; 28 | 29 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 30 | const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds 31 | 32 | // Initialize the Web client object 33 | EthernetClient client; 34 | 35 | // this method makes a HTTP connection to the server 36 | void httpRequest() 37 | { 38 | Serial.println(); 39 | 40 | // close any connection before send a new request 41 | // this will free the socket on the WiFi shield 42 | client.stop(); 43 | 44 | // if there's a successful connection 45 | if (client.connect(server, 80)) 46 | { 47 | Serial.println(F("Connecting...")); 48 | 49 | // send the HTTP PUT request 50 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 51 | client.println(F("Host: arduino.tips")); 52 | client.println(F("Connection: close")); 53 | client.println(); 54 | 55 | // note the time that the connection was made 56 | lastConnectionTime = millis(); 57 | } 58 | else 59 | { 60 | // if you couldn't make a connection 61 | Serial.println(F("Connection failed")); 62 | } 63 | } 64 | 65 | void setup() 66 | { 67 | // Open serial communications and wait for port to open: 68 | Serial.begin(115200); 69 | 70 | delay(2000); 71 | 72 | Serial.println("\nStart WebClientRepeating_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 73 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 74 | 75 | // start the ethernet connection and the server: 76 | // Use DHCP dynamic IP and random mac 77 | uint16_t index = millis() % NUMBER_OF_MAC; 78 | // Use Static IP 79 | //Ethernet.begin(mac[index], ip); 80 | Ethernet.begin(mac[index]); 81 | 82 | // you're connected now, so print out the data 83 | Serial.print(F("You're connected to the network, IP = ")); 84 | Serial.println(Ethernet.localIP()); 85 | } 86 | 87 | void loop() 88 | { 89 | // if there's incoming data from the net connection send it out the serial port 90 | // this is for debugging purposes only 91 | while (client.available()) 92 | { 93 | char c = client.read(); 94 | Serial.write(c); 95 | } 96 | 97 | Serial.flush(); 98 | 99 | // if 10 seconds have passed since your last connection, 100 | // then connect again and send data 101 | if (millis() - lastConnectionTime > postingInterval) 102 | { 103 | httpRequest(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/WebClientRepeating_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/WebClient_LAN8720/WebClient_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClient_LAN8720.ino - Simple Arduino web server sample for ESP8266 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | char server[] = "arduino.tips"; 28 | 29 | // Initialize the Web client object 30 | EthernetClient client; 31 | 32 | void setup() 33 | { 34 | // Open serial communications and wait for port to open: 35 | Serial.begin(115200); 36 | 37 | delay(2000); 38 | 39 | Serial.println("\nStart WebClient_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 40 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 41 | 42 | // start the ethernet connection and the server: 43 | // Use DHCP dynamic IP and random mac 44 | uint16_t index = millis() % NUMBER_OF_MAC; 45 | // Use Static IP 46 | //Ethernet.begin(mac[index], ip); 47 | Ethernet.begin(mac[index]); 48 | 49 | // you're connected now, so print out the data 50 | Serial.print(F("You're connected to the network, IP = ")); 51 | Serial.println(Ethernet.localIP()); 52 | 53 | Serial.println(); 54 | Serial.println(F("Starting connection to server...")); 55 | 56 | // if you get a connection, report back via serial 57 | if (client.connect(server, 80)) 58 | { 59 | Serial.println(F("Connected to server")); 60 | // Make a HTTP request 61 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 62 | client.println(F("Host: arduino.tips")); 63 | client.println(F("Connection: close")); 64 | client.println(); 65 | } 66 | } 67 | 68 | void printoutData() 69 | { 70 | // if there are incoming bytes available 71 | // from the server, read them and print them 72 | while (client.available()) 73 | { 74 | char c = client.read(); 75 | Serial.write(c); 76 | } 77 | 78 | Serial.flush(); 79 | } 80 | 81 | void loop() 82 | { 83 | printoutData(); 84 | 85 | // if the server's disconnected, stop the client 86 | if (!client.connected()) 87 | { 88 | Serial.println(); 89 | Serial.println(F("Disconnecting from server...")); 90 | client.stop(); 91 | 92 | // do nothing forevermore 93 | while (true); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/WebClient_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/WebServer_LAN8720/WebServer_LAN8720.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebServer_LAN8720.ino - Simple Arduino web server sample for ESP8266 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | /* 12 | Currently support 13 | 1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as : 14 | - Nucleo-144 (F429ZI, F767ZI) 15 | - Discovery (STM32F746G-DISCOVERY) 16 | - STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet, 17 | - See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1) 18 | 2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as : 19 | - BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG, 20 | NUCLEO_F7x6ZG 21 | 3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false) 22 | 4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields 23 | */ 24 | 25 | #include "defines.h" 26 | 27 | int reqCount = 0; // number of requests received 28 | 29 | EthernetServer server(80); 30 | 31 | void setup() 32 | { 33 | // Open serial communications and wait for port to open: 34 | Serial.begin(115200); 35 | 36 | delay(2000); 37 | 38 | Serial.println("\nStart WebServer_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 39 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 40 | 41 | // start the ethernet connection and the server: 42 | // Use DHCP dynamic IP and random mac 43 | uint16_t index = millis() % NUMBER_OF_MAC; 44 | // Use Static IP 45 | //Ethernet.begin(mac[index], ip); 46 | Ethernet.begin(mac[index]); 47 | 48 | // you're connected now, so print out the data 49 | Serial.print(F("You're connected to the network, IP = ")); 50 | Serial.println(Ethernet.localIP()); 51 | 52 | // start the web server on port 80 53 | server.begin(); 54 | } 55 | 56 | 57 | void loop() 58 | { 59 | // listen for incoming clients 60 | EthernetClient client = server.available(); 61 | 62 | if (client) 63 | { 64 | Serial.println(F("New client")); 65 | // an http request ends with a blank line 66 | bool currentLineIsBlank = true; 67 | 68 | while (client.connected()) 69 | { 70 | if (client.available()) 71 | { 72 | char c = client.read(); 73 | Serial.write(c); 74 | 75 | // if you've gotten to the end of the line (received a newline 76 | // character) and the line is blank, the http request has ended, 77 | // so you can send a reply 78 | if (c == '\n' && currentLineIsBlank) 79 | { 80 | Serial.println(F("Sending response")); 81 | 82 | // send a standard http response header 83 | // use \r\n instead of many println statements to speedup data send 84 | client.print( 85 | "HTTP/1.1 200 OK\r\n" 86 | "Content-Type: text/html\r\n" 87 | "Connection: close\r\n" // the connection will be closed after completion of the response 88 | "Refresh: 20\r\n" // refresh the page automatically every 20 sec 89 | "\r\n"); 90 | client.print("\r\n"); 91 | client.print("\r\n"); 92 | client.print(String("

Hello World from ") + BOARD_NAME + " and LAN8720!

\r\n"); 93 | client.print("

Hello World from "); 94 | client.print(BOARD_NAME); 95 | client.print(" and LAN8720!

\r\n"); 96 | client.print("Requests received: "); 97 | client.print(++reqCount); 98 | client.print("
\r\n"); 99 | client.print("Analog input A0: "); 100 | client.print(analogRead(0)); 101 | client.print("
\r\n"); 102 | client.print("\r\n"); 103 | break; 104 | } 105 | 106 | if (c == '\n') 107 | { 108 | // you're starting a new line 109 | currentLineIsBlank = true; 110 | } 111 | else if (c != '\r') 112 | { 113 | // you've gotten a character on the current line 114 | currentLineIsBlank = false; 115 | } 116 | } 117 | } 118 | 119 | // give the web browser time to receive the data 120 | delay(10); 121 | 122 | // close the connection: 123 | client.stop(); 124 | Serial.println(F("Client disconnected")); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /examples/STM32_LAN8720/WebServer_LAN8720/hal_conf_extra.h: -------------------------------------------------------------------------------- 1 | // Note: Must replace 2 | // .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h 3 | // as described in README.md 4 | 5 | #define HAL_ETH_MODULE_ENABLED 6 | 7 | #define LAN8742A_PHY_ADDRESS 0x01U 8 | -------------------------------------------------------------------------------- /examples/UdpSendReceive/UdpSendReceive.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | UDPSendReceive.ino - Simple Arduino web server sample for ESP8266/ESP32 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | #include "defines.h" 13 | 14 | unsigned int localPort = 1883; //10002; // local port to listen on 15 | 16 | char packetBuffer[255]; // buffer to hold incoming packet 17 | char ReplyBuffer[] = "ACK"; // a string to send back 18 | 19 | // A UDP instance to let us send and receive packets over UDP 20 | EthernetUDP Udp; 21 | 22 | void setup() 23 | { 24 | Serial.begin(115200); 25 | 26 | while (!Serial && millis() < 5000); 27 | 28 | Serial.println("\nStart UDPSendReceive on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 29 | 30 | #if USE_ETHERNET_GENERIC 31 | Serial.println(ETHERNET_GENERIC_VERSION); 32 | #endif 33 | 34 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 35 | 36 | #if !(USE_BUILTIN_ETHERNET) 37 | #if (USING_SPI2) 38 | #if defined(CUR_PIN_MISO) 39 | ET_LOGWARN(F("Default SPI pinout:")); 40 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 41 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 42 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 43 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 44 | ET_LOGWARN(F("=========================")); 45 | #endif 46 | #else 47 | ET_LOGWARN(F("Default SPI pinout:")); 48 | ET_LOGWARN1(F("MOSI:"), MOSI); 49 | ET_LOGWARN1(F("MISO:"), MISO); 50 | ET_LOGWARN1(F("SCK:"), SCK); 51 | ET_LOGWARN1(F("SS:"), SS); 52 | ET_LOGWARN(F("=========================")); 53 | #endif 54 | #endif 55 | 56 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 57 | // For other boards, to change if necessary 58 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 59 | Ethernet.init (USE_THIS_SS_PIN); 60 | 61 | #elif USE_CUSTOM_ETHERNET 62 | // You have to add initialization for your Custom Ethernet here 63 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 64 | //Ethernet.init(USE_THIS_SS_PIN); 65 | 66 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 67 | #endif 68 | 69 | // start the ethernet connection and the server: 70 | // Use DHCP dynamic IP and random mac 71 | uint16_t index = millis() % NUMBER_OF_MAC; 72 | // Use Static IP 73 | //Ethernet.begin(mac[index], ip); 74 | Ethernet.begin(mac[index]); 75 | 76 | Serial.print(F("Connected! IP address: ")); 77 | Serial.println(Ethernet.localIP()); 78 | 79 | Serial.println(F("\nStarting connection to server...")); 80 | // if you get a connection, report back via serial: 81 | Udp.begin(localPort); 82 | 83 | Serial.print(F("Listening on port ")); 84 | Serial.println(localPort); 85 | } 86 | 87 | void loop() 88 | { 89 | // if there's data available, read a packet 90 | int packetSize = Udp.parsePacket(); 91 | 92 | if (packetSize) 93 | { 94 | Serial.print(F("Received packet of size ")); 95 | Serial.println(packetSize); 96 | Serial.print(F("From ")); 97 | IPAddress remoteIp = Udp.remoteIP(); 98 | Serial.print(remoteIp); 99 | Serial.print(F(", port ")); 100 | Serial.println(Udp.remotePort()); 101 | 102 | // read the packet into packetBufffer 103 | int len = Udp.read(packetBuffer, 255); 104 | 105 | if (len > 0) 106 | { 107 | packetBuffer[len] = 0; 108 | } 109 | 110 | Serial.println(F("Contents:")); 111 | Serial.println(packetBuffer); 112 | 113 | // send a reply, to the IP address and port that sent us the packet we received 114 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 115 | Udp.write(ReplyBuffer); 116 | Udp.endPacket(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /examples/WebClient/WebClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClient.ino - Simple Arduino web server sample for ESP8266 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | #include "defines.h" 13 | 14 | char server[] = "arduino.tips"; 15 | 16 | // Initialize the Web client object 17 | EthernetClient client; 18 | 19 | void setup() 20 | { 21 | // Open serial communications and wait for port to open: 22 | Serial.begin(115200); 23 | 24 | while (!Serial && millis() < 5000); 25 | 26 | Serial.println("\nStart WebClient on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 27 | 28 | #if USE_ETHERNET_GENERIC 29 | Serial.println(ETHERNET_GENERIC_VERSION); 30 | #endif 31 | 32 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 33 | 34 | #if !(USE_BUILTIN_ETHERNET) 35 | #if (USING_SPI2) 36 | #if defined(CUR_PIN_MISO) 37 | ET_LOGWARN(F("Default SPI pinout:")); 38 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 39 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 40 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 41 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 42 | ET_LOGWARN(F("=========================")); 43 | #endif 44 | #else 45 | ET_LOGWARN(F("Default SPI pinout:")); 46 | ET_LOGWARN1(F("MOSI:"), MOSI); 47 | ET_LOGWARN1(F("MISO:"), MISO); 48 | ET_LOGWARN1(F("SCK:"), SCK); 49 | ET_LOGWARN1(F("SS:"), SS); 50 | ET_LOGWARN(F("=========================")); 51 | #endif 52 | #endif 53 | 54 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 55 | // For other boards, to change if necessary 56 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 57 | Ethernet.init (USE_THIS_SS_PIN); 58 | 59 | #elif USE_CUSTOM_ETHERNET 60 | // You have to add initialization for your Custom Ethernet here 61 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 62 | //Ethernet.init(USE_THIS_SS_PIN); 63 | 64 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 65 | #endif 66 | 67 | // start the ethernet connection and the server: 68 | // Use DHCP dynamic IP and random mac 69 | uint16_t index = millis() % NUMBER_OF_MAC; 70 | // Use Static IP 71 | //Ethernet.begin(mac[index], ip); 72 | Ethernet.begin(mac[index]); 73 | 74 | Serial.print(F("Connected! IP address: ")); 75 | Serial.println(Ethernet.localIP()); 76 | 77 | Serial.println(); 78 | Serial.println(F("Starting connection to server...")); 79 | 80 | // if you get a connection, report back via serial 81 | if (client.connect(server, 80)) 82 | { 83 | Serial.println(F("Connected to server")); 84 | // Make a HTTP request 85 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 86 | client.println(F("Host: arduino.tips")); 87 | client.println(F("Connection: close")); 88 | client.println(); 89 | } 90 | } 91 | 92 | void printoutData() 93 | { 94 | // if there are incoming bytes available 95 | // from the server, read them and print them 96 | while (client.available()) 97 | { 98 | char c = client.read(); 99 | Serial.write(c); 100 | } 101 | 102 | Serial.flush(); 103 | } 104 | 105 | void loop() 106 | { 107 | printoutData(); 108 | 109 | // if the server's disconnected, stop the client 110 | if (!client.connected()) 111 | { 112 | Serial.println(); 113 | Serial.println(F("Disconnecting from server...")); 114 | client.stop(); 115 | 116 | // do nothing forevermore 117 | while (true); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /examples/WebClientRepeating/WebClientRepeating.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClientRepeating.ino - Simple Arduino web server sample for ESP8266 AT-command shield 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | #include "defines.h" 13 | 14 | char server[] = "arduino.tips"; 15 | 16 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 17 | const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds 18 | 19 | // Initialize the Web client object 20 | EthernetClient client; 21 | 22 | // this method makes a HTTP connection to the server 23 | void httpRequest() 24 | { 25 | Serial.println(); 26 | 27 | // close any connection before send a new request 28 | // this will free the socket on the WiFi shield 29 | client.stop(); 30 | 31 | // if there's a successful connection 32 | if (client.connect(server, 80)) 33 | { 34 | Serial.println(F("Connecting...")); 35 | 36 | // send the HTTP PUT request 37 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 38 | client.println(F("Host: arduino.tips")); 39 | client.println(F("Connection: close")); 40 | client.println(); 41 | 42 | // note the time that the connection was made 43 | lastConnectionTime = millis(); 44 | } 45 | else 46 | { 47 | // if you couldn't make a connection 48 | Serial.println(F("Connection failed")); 49 | } 50 | } 51 | 52 | void setup() 53 | { 54 | // Open serial communications and wait for port to open: 55 | Serial.begin(115200); 56 | 57 | while (!Serial && millis() < 5000); 58 | 59 | Serial.println("\nStart WebClientRepeating on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE)); 60 | 61 | #if USE_ETHERNET_GENERIC 62 | Serial.println(ETHERNET_GENERIC_VERSION); 63 | #endif 64 | 65 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 66 | 67 | #if !(USE_BUILTIN_ETHERNET) 68 | #if (USING_SPI2) 69 | #if defined(CUR_PIN_MISO) 70 | ET_LOGWARN(F("Default SPI pinout:")); 71 | ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI); 72 | ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO); 73 | ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK); 74 | ET_LOGWARN1(F("SS:"), CUR_PIN_SS); 75 | ET_LOGWARN(F("=========================")); 76 | #endif 77 | #else 78 | ET_LOGWARN(F("Default SPI pinout:")); 79 | ET_LOGWARN1(F("MOSI:"), MOSI); 80 | ET_LOGWARN1(F("MISO:"), MISO); 81 | ET_LOGWARN1(F("SCK:"), SCK); 82 | ET_LOGWARN1(F("SS:"), SS); 83 | ET_LOGWARN(F("=========================")); 84 | #endif 85 | #endif 86 | 87 | #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) 88 | // For other boards, to change if necessary 89 | #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 90 | Ethernet.init (USE_THIS_SS_PIN); 91 | 92 | #elif USE_CUSTOM_ETHERNET 93 | // You have to add initialization for your Custom Ethernet here 94 | // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough 95 | //Ethernet.init(USE_THIS_SS_PIN); 96 | 97 | #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) 98 | #endif 99 | 100 | // start the ethernet connection and the server: 101 | // Use DHCP dynamic IP and random mac 102 | uint16_t index = millis() % NUMBER_OF_MAC; 103 | // Use Static IP 104 | //Ethernet.begin(mac[index], ip); 105 | Ethernet.begin(mac[index]); 106 | 107 | Serial.print(F("Connected! IP address: ")); 108 | Serial.println(Ethernet.localIP()); 109 | } 110 | 111 | void loop() 112 | { 113 | // if there's incoming data from the net connection send it out the serial port 114 | // this is for debugging purposes only 115 | while (client.available()) 116 | { 117 | char c = client.read(); 118 | Serial.write(c); 119 | } 120 | 121 | Serial.flush(); 122 | 123 | // if 10 seconds have passed since your last connection, 124 | // then connect again and send data 125 | if (millis() - lastConnectionTime > postingInterval) 126 | { 127 | httpRequest(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /examples/multiFileProject/multiFileProject.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | multiFileProject.cpp 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | // To demo how to include files in multi-file Projects 13 | 14 | #include "multiFileProject.h" 15 | -------------------------------------------------------------------------------- /examples/multiFileProject/multiFileProject.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | multiFileProject.h 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | // To demo how to include files in multi-file Projects 13 | 14 | #pragma once 15 | 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | 18 | // Can be included as many times as necessary, without `Multiple Definitions` Linker Error 19 | #include // https://github.com/khoih-prog/EthernetWebServer_STM32 20 | 21 | #include // https://github.com/khoih-prog/EthernetWebServer_STM32 22 | -------------------------------------------------------------------------------- /examples/multiFileProject/multiFileProject.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | multiFileProject.ino 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | // To demo how to include files in multi-file Projects 13 | 14 | #define ETHERNET_WEBSERVER_STM32_VERSION_MIN_TARGET "Ethernet_Generic v1.5.0" 15 | #define ETHERNET_WEBSERVER_STM32_VERSION_MIN 1005000 16 | 17 | #include "multiFileProject.h" 18 | 19 | // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error 20 | #include // https://github.com/khoih-prog/EthernetWebServer_STM32 21 | 22 | void setup() 23 | { 24 | Serial.begin(115200); 25 | 26 | while (!Serial && millis() < 5000); 27 | 28 | delay(500); 29 | 30 | Serial.println("\nStart multiFileProject"); 31 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION); 32 | 33 | #if defined(ETHERNET_WEBSERVER_STM32_VERSION_MIN) 34 | 35 | if (ETHERNET_WEBSERVER_STM32_VERSION_INT < ETHERNET_WEBSERVER_STM32_VERSION_MIN) 36 | { 37 | Serial.print("Warning. Must use this example on Version equal or later than : "); 38 | Serial.println(ETHERNET_WEBSERVER_STM32_VERSION_MIN_TARGET); 39 | } 40 | 41 | #endif 42 | 43 | Serial.print("You're OK now"); 44 | } 45 | 46 | void loop() 47 | { 48 | // put your main code here, to run repeatedly: 49 | } 50 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Datatypes (KEYWORD1) 3 | ####################################### 4 | 5 | ####################### 6 | # EthernetWebServer 7 | ####################### 8 | 9 | EthernetWebServer KEYWORD1 10 | HTTPMethod KEYWORD1 11 | HTTPUploadStatus KEYWORD1 12 | HTTPClientStatus KEYWORD1 13 | HTTPUpload KEYWORD1 14 | HTTPAuthMethod KEYWORD1 15 | EWString KEYWORD1 16 | 17 | ####################### 18 | # EthernetHttpClient 19 | ####################### 20 | 21 | EthernetHttpClient KEYWORD1 22 | 23 | ########################## 24 | # EthernetWebSocketClient 25 | ########################## 26 | 27 | EthernetWebSocketClient KEYWORD1 28 | 29 | ########################## 30 | # EthernetURLEncoderClass 31 | ########################## 32 | 33 | EthernetURLEncoderClass KEYWORD1 34 | 35 | 36 | ####################################### 37 | # Methods and Functions (KEYWORD2) 38 | ####################################### 39 | 40 | ####################### 41 | # EthernetWrapper 42 | ####################### 43 | 44 | EthernetInit KEYWORD2 45 | 46 | ####################### 47 | # EthernetWebServer 48 | ####################### 49 | 50 | begin KEYWORD2 51 | handleClient KEYWORD2 52 | close KEYWORD2 53 | stop KEYWORD2 54 | authenticate KEYWORD2 55 | requestAuthentication KEYWORD2 56 | on KEYWORD2 57 | addHandler KEYWORD2 58 | onNotFound KEYWORD2 59 | onFileUpload KEYWORD2 60 | uri KEYWORD2 61 | method KEYWORD2 62 | client KEYWORD2 63 | upload KEYWORD2 64 | arg KEYWORD2 65 | argName KEYWORD2 66 | args KEYWORD2 67 | hasArg KEYWORD2 68 | collectHeaders KEYWORD2 69 | header KEYWORD2 70 | headerName KEYWORD2 71 | headers KEYWORD2 72 | hasHeader KEYWORD2 73 | hostHeader KEYWORD2 74 | send KEYWORD2 75 | send_P KEYWORD2 76 | sendContent_P KEYWORD2 77 | setContentLength KEYWORD2 78 | sendHeader KEYWORD2 79 | sendContent KEYWORD2 80 | urlDecode KEYWORD2 81 | streamFile KEYWORD2 82 | 83 | ####################### 84 | # Parsing-impl 85 | ####################### 86 | readBytesWithTimeout KEYWORD2 87 | _parseRequest KEYWORD2 88 | _collectHeader KEYWORD2 89 | _parseArguments KEYWORD2 90 | _uploadWriteByte KEYWORD2 91 | _uploadReadByte KEYWORD2 92 | _parseForm KEYWORD2 93 | urlDecode KEYWORD2 94 | _parseFormUploadAborted KEYWORD2 95 | 96 | ####################### 97 | # RequestHandler 98 | ####################### 99 | canHandle KEYWORD2 100 | canUpload KEYWORD2 101 | handle KEYWORD2 102 | upload KEYWORD2 103 | next KEYWORD2 104 | getContentType KEYWORD2 105 | 106 | ####################### 107 | # EthernetHttpClient 108 | ####################### 109 | 110 | beginRequest KEYWORD2 111 | endRequest KEYWORD2 112 | beginBody KEYWORD2 113 | get KEYWORD2 114 | post KEYWORD2 115 | put KEYWORD2 116 | patch KEYWORD2 117 | del KEYWORD2 118 | startRequest KEYWORD2 119 | sendHeader KEYWORD2 120 | sendBasicAuth KEYWORD2 121 | responseStatusCode KEYWORD2 122 | headerAvailable KEYWORD2 123 | readHeaderValue KEYWORD2 124 | readHeader KEYWORD2 125 | skipResponseHeaders KEYWORD2 126 | endOfHeadersReached KEYWORD2 127 | endOfBodyReached KEYWORD2 128 | endOfStream KEYWORD2 129 | completed KEYWORD2 130 | contentLength KEYWORD2 131 | isResponseChunked KEYWORD2 132 | responseBody KEYWORD2 133 | connectionKeepAlive KEYWORD2 134 | noDefaultRequestHeaders KEYWORD2 135 | write KEYWORD2 136 | available KEYWORD2 137 | read KEYWORD2 138 | peek KEYWORD2 139 | flush KEYWORD2 140 | connect KEYWORD2 141 | stop KEYWORD2 142 | connected KEYWORD2 143 | httpResponseTimeout KEYWORD2 144 | setHttpResponseTimeout KEYWORD2 145 | 146 | ########################## 147 | # EthernetWebSocketClient 148 | ########################## 149 | 150 | begin KEYWORD2 151 | beginMessage KEYWORD2 152 | endMessage KEYWORD2 153 | parseMessage KEYWORD2 154 | messageType KEYWORD2 155 | isFinal KEYWORD2 156 | readString KEYWORD2 157 | ping KEYWORD2 158 | write KEYWORD2 159 | available KEYWORD2 160 | read KEYWORD2 161 | peek KEYWORD2 162 | 163 | ########################## 164 | # EthernetURLEncoderClass 165 | ########################## 166 | 167 | encode KEYWORD2 168 | 169 | 170 | ####################################### 171 | # Constants (LITERAL1) 172 | ####################################### 173 | 174 | ETHERNET_WEBSERVER_STM32_VERSION LITERAL1 175 | ETHERNET_WEBSERVER_STM32_VERSION_MAJOR LITERAL1 176 | ETHERNET_WEBSERVER_STM32_VERSION_MINOR LITERAL1 177 | ETHERNET_WEBSERVER_STM32_VERSION_PATCH LITERAL1 178 | ETHERNET_WEBSERVER_STM32_VERSION_INT LITERAL1 179 | 180 | HTTP_DOWNLOAD_UNIT_SIZE LITERAL1 181 | HTTP_UPLOAD_BUFLEN LITERAL1 182 | HTTP_MAX_DATA_WAIT LITERAL1 183 | HTTP_MAX_POST_WAIT LITERAL1 184 | HTTP_MAX_SEND_WAIT LITERAL1 185 | HTTP_MAX_CLOSE_WAIT LITERAL1 186 | AUTHORIZATION_HEADER LITERAL1 187 | 188 | _ETHERNET_WEBSERVER_LOGLEVEL_ LITERAL1 189 | 190 | 191 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EthernetWebServer_STM32", 3 | "version": "1.5.0", 4 | "keywords": "WebServer, built-in-Ethernet, STM32F, STM32L, STM32H, STM32G, STM32WB, STM32MP1, Ethernet-shield, Nucleo-144, Nucleo-64, Nucleo-32, LAN8742A, LAN8720, ENC28J60, W5x00, W5500, W5100, Ethernet, Ethernet2, Ethernet3, EthernetLarge, EtnernetENC, UIPEthernet, HTTP-Client, WebSocket-Client, server, client, websocket", 5 | "description": "Simple Ethernet WebServer, HTTP Client and WebSocket Client library for STM32F/L/H/G/WB/MP1 boards running built-in Ethernet LAN8742A, LAN8720 or Ethernet W5x00, ENC28J60 shields. Ethernet_Generic library is used as default for W5x00, Now W5x00 can use any custom hardware / software SPI", 6 | "authors": 7 | { 8 | "name": "Khoi Hoang", 9 | "url": "https://github.com/khoih-prog", 10 | "maintainer": true 11 | }, 12 | "repository": 13 | { 14 | "type": "git", 15 | "url": "https://github.com/khoih-prog/EthernetWebServer_STM32" 16 | }, 17 | "homepage": "https://github.com/khoih-prog/EthernetWebServer_STM32", 18 | "export": { 19 | "exclude": [ 20 | "linux", 21 | "extras", 22 | "tests" 23 | ] 24 | }, 25 | "dependencies": 26 | [ 27 | { 28 | "owner": "stm32duino", 29 | "name": "STM32duino LwIP", 30 | "version": "^2.1.2", 31 | "platforms": "ststm32" 32 | }, 33 | { 34 | "owner": "stm32duino", 35 | "name": "STM32Ethernet", 36 | "version": "^1.3.0", 37 | "platforms": "ststm32" 38 | }, 39 | { 40 | "owner": "khoih-prog", 41 | "name": "Functional-Vlpp", 42 | "version": "^1.0.2" 43 | }, 44 | { 45 | "owner": "khoih-prog", 46 | "name": "Ethernet_Generic", 47 | "version": "^2.7.1" 48 | } 49 | ], 50 | "frameworks": "arduino", 51 | "platforms": "ststm32", 52 | "examples": "examples/*/*/*.ino", 53 | "headers": ["EthernetWebServer_STM32.h", "EthernetWebServer_STM32.hpp", "EthernetHttpClient_STM32.h"] 54 | } 55 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=EthernetWebServer_STM32 2 | version=1.5.0 3 | author=Khoi Hoang 4 | license=MIT 5 | maintainer=Khoi Hoang 6 | sentence=EthernetWebServer_STM32 is a simple Ethernet WebServer, HTTP Client and WebSocket Client library for STM32F/L/H/G/WB/MP1 boards using built-in Ethernet LAN8742A, LAN8720, Ethernet W5x00 or ENC28J60 shields 7 | paragraph=The library supports HTTP GET and POST requests, provides argument parsing, handles one client at a time. It now provides HTTP Client and WebSocket Client. It supports Arduino STM32F/L/H/G/WB/MP1 series with 32+ Kbytes of Flash, using built-in Ethernet (Nucleo-144: F429ZI, F767ZI, Discovery: STM32F746G-DISCOVERY), or LAN8720, ENC28J60, W5x00 Ethernet shields. Ethernet_Generic library is used as default for W5x00. Now W5x00 can use any custom hardware / software SPI 8 | category=Communication 9 | url=https://github.com/khoih-prog/EthernetWebServer_STM32 10 | architectures=stm32 11 | depends=STM32duino LwIP, STM32duino STM32Ethernet, Functional-Vlpp, Ethernet_Generic 12 | includes=EthernetWebServer_STM32.h, EthernetWebServer_STM32.hpp, EthernetHttpClient_STM32.h 13 | -------------------------------------------------------------------------------- /pics/AdvancedWebServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/EthernetWebServer_STM32/232e0141115d8fb607248c2441d32e9f79cf6677/pics/AdvancedWebServer.png -------------------------------------------------------------------------------- /pics/AdvancedWebServer_LAN8720.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/EthernetWebServer_STM32/232e0141115d8fb607248c2441d32e9f79cf6677/pics/AdvancedWebServer_LAN8720.png -------------------------------------------------------------------------------- /pics/AdvancedWebServer_NUCLEO_L552ZE_Q.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/EthernetWebServer_STM32/232e0141115d8fb607248c2441d32e9f79cf6677/pics/AdvancedWebServer_NUCLEO_L552ZE_Q.png -------------------------------------------------------------------------------- /pics/LAN8720_STM32F4_Wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/EthernetWebServer_STM32/232e0141115d8fb607248c2441d32e9f79cf6677/pics/LAN8720_STM32F4_Wiring.png -------------------------------------------------------------------------------- /pics/STM32F407VET6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/EthernetWebServer_STM32/232e0141115d8fb607248c2441d32e9f79cf6677/pics/STM32F407VET6.png -------------------------------------------------------------------------------- /src/EthernetHttpClient_STM32.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | EthernetHttpClient_STM32.h - Dead simple HTTP WebClient. 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | // Library to simplify HTTP fetching on Arduino 32 | // (c) Copyright Arduino. 2016 33 | // Released under Apache License, version 2.0 34 | 35 | #pragma once 36 | 37 | #ifndef ETHERNET_HTTP_CLIENT_STM32_H 38 | #define ETHERNET_HTTP_CLIENT_STM32_H 39 | 40 | #include 41 | 42 | #include "detail/Debug_STM32.h" 43 | #include "Ethernet_HTTPClient/Ethernet_HttpClient.h" 44 | #include "Ethernet_HTTPClient/Ethernet_WebSocketClient.h" 45 | #include "Ethernet_HTTPClient/Ethernet_URLEncoder.h" 46 | 47 | #endif // ETHERNET_HTTP_CLIENT_STM32_H 48 | 49 | -------------------------------------------------------------------------------- /src/Ethernet_HTTPClient/Ethernet_URLEncoder.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Ethernet_URLEncoder.cpp - Dead simple HTTP WebClient. 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | // Library to simplify HTTP fetching on Arduino 32 | // (c) Copyright Arduino. 2019 33 | // Released under Apache License, version 2.0 34 | 35 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 0 36 | 37 | #include "detail/Debug_STM32.h" 38 | #include "Ethernet_HTTPClient/Ethernet_URLEncoder.h" 39 | 40 | EthernetURLEncoderClass::EthernetURLEncoderClass() 41 | { 42 | } 43 | 44 | EthernetURLEncoderClass::~EthernetURLEncoderClass() 45 | { 46 | } 47 | 48 | String EthernetURLEncoderClass::encode(const char* str) 49 | { 50 | return encode(str, strlen(str)); 51 | } 52 | 53 | String EthernetURLEncoderClass::encode(const String& str) 54 | { 55 | return encode(str.c_str(), str.length()); 56 | } 57 | 58 | String EthernetURLEncoderClass::encode(const char* str, int length) 59 | { 60 | String encoded; 61 | 62 | encoded.reserve(length); 63 | 64 | for (int i = 0; i < length; i++) 65 | { 66 | char c = str[i]; 67 | 68 | const char HEX_DIGIT_MAPPER[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 69 | 70 | if (isAlphaNumeric(c) || (c == '-') || (c == '.') || (c == '_') || (c == '~')) 71 | { 72 | encoded += c; 73 | } 74 | else 75 | { 76 | char s[4]; 77 | 78 | s[0] = '%'; 79 | s[1] = HEX_DIGIT_MAPPER[(c >> 4) & 0xf]; 80 | s[2] = HEX_DIGIT_MAPPER[(c & 0x0f)]; 81 | s[3] = 0; 82 | 83 | encoded += s; 84 | } 85 | } 86 | 87 | return encoded; 88 | } 89 | 90 | EthernetURLEncoderClass EthernetURLEncoder; 91 | -------------------------------------------------------------------------------- /src/Ethernet_HTTPClient/Ethernet_URLEncoder.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Ethernet_URLEncoder.h - Dead simple HTTP WebClient. 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | // Library to simplify HTTP fetching on Arduino 32 | // (c) Copyright Arduino. 2019 33 | // Released under Apache License, version 2.0 34 | 35 | #pragma once 36 | 37 | #ifndef ETHERNET_URL_ENCODER_H 38 | #define ETHERNET_URL_ENCODER_H 39 | 40 | #include 41 | 42 | #include "detail/Debug_STM32.h" 43 | 44 | 45 | class EthernetURLEncoderClass 46 | { 47 | public: 48 | EthernetURLEncoderClass(); 49 | virtual ~EthernetURLEncoderClass(); 50 | 51 | static String encode(const char* str); 52 | static String encode(const String& str); 53 | 54 | private: 55 | static String encode(const char* str, int length); 56 | }; 57 | 58 | extern EthernetURLEncoderClass EthernetURLEncoder; 59 | 60 | #endif // ETHERNET_URL_ENCODER_H 61 | -------------------------------------------------------------------------------- /src/detail/RequestHandler_STM32.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | RequestHandler_STM32.h - Dead simple web-server. 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | #ifndef REQUEST_HANDLER_STM32_H 34 | #define REQUEST_HANDLER_STM32_H 35 | 36 | #ifndef ETW_UNUSED 37 | #define ETW_UNUSED(x) (void)(x) 38 | #endif 39 | 40 | 41 | class RequestHandler 42 | { 43 | public: 44 | 45 | virtual ~RequestHandler() { } 46 | 47 | virtual bool canHandle(HTTPMethod method, String uri) 48 | { 49 | ETW_UNUSED(method); 50 | ETW_UNUSED(uri); 51 | 52 | return false; 53 | } 54 | 55 | virtual bool canUpload(String uri) 56 | { 57 | ETW_UNUSED(uri); 58 | 59 | return false; 60 | } 61 | 62 | virtual bool handle(EthernetWebServer& server, HTTPMethod requestMethod, String requestUri) 63 | { 64 | ETW_UNUSED(server); 65 | ETW_UNUSED(requestMethod); 66 | ETW_UNUSED(requestUri); 67 | 68 | return false; 69 | } 70 | 71 | virtual void upload(EthernetWebServer& server, String requestUri, HTTPUpload& upload) 72 | { 73 | ETW_UNUSED(server); 74 | ETW_UNUSED(requestUri); 75 | ETW_UNUSED(upload); 76 | } 77 | 78 | RequestHandler* next() 79 | { 80 | return _next; 81 | } 82 | 83 | void next(RequestHandler* r) 84 | { 85 | _next = r; 86 | } 87 | 88 | private: 89 | 90 | RequestHandler* _next = nullptr; 91 | }; 92 | 93 | #endif // REQUEST_HANDLER_STM32_H 94 | -------------------------------------------------------------------------------- /src/detail/mimetable.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | mimetable.h - Dead simple web-server. 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | #ifndef __MIMETABLE_H__ 34 | #define __MIMETABLE_H__ 35 | 36 | namespace mime 37 | { 38 | 39 | enum type 40 | { 41 | html, 42 | htm, 43 | css, 44 | txt, 45 | js, 46 | json, 47 | png, 48 | gif, 49 | jpg, 50 | ico, 51 | svg, 52 | ttf, 53 | otf, 54 | woff, 55 | woff2, 56 | eot, 57 | sfnt, 58 | xml, 59 | pdf, 60 | zip, 61 | gz, 62 | appcache, 63 | none, 64 | maxType 65 | }; 66 | 67 | struct Entry 68 | { 69 | const char endsWith[16]; 70 | const char mimeType[32]; 71 | }; 72 | 73 | // Table of extension->MIME strings stored in PROGMEM, needs to be global due to GCC section typing rules 74 | const Entry mimeTable[maxType] = 75 | { 76 | { ".html", "text/html" }, 77 | { ".htm", "text/html" }, 78 | { ".css", "text/css" }, 79 | { ".txt", "text/plain" }, 80 | { ".js", "application/javascript" }, 81 | { ".json", "application/json" }, 82 | { ".png", "image/png" }, 83 | { ".gif", "image/gif" }, 84 | { ".jpg", "image/jpeg" }, 85 | { ".ico", "image/x-icon" }, 86 | { ".svg", "image/svg+xml" }, 87 | { ".ttf", "application/x-font-ttf" }, 88 | { ".otf", "application/x-font-opentype" }, 89 | { ".woff", "application/font-woff" }, 90 | { ".woff2", "application/font-woff2" }, 91 | { ".eot", "application/vnd.ms-fontobject" }, 92 | { ".sfnt", "application/font-sfnt" }, 93 | { ".xml", "text/xml" }, 94 | { ".pdf", "application/pdf" }, 95 | { ".zip", "application/zip" }, 96 | { ".gz", "application/x-gzip" }, 97 | { ".appcache", "text/cache-manifest" }, 98 | { "", "application/octet-stream" } 99 | }; 100 | //extern const Entry mimeTable[maxType]; 101 | } // namespace mime 102 | 103 | #endif // #ifndef __MIMETABLE_H__ 104 | 105 | -------------------------------------------------------------------------------- /src/libb64/base64.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | base64.cpp - cpp source to a base64 encoding algorithm implementation 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | #include "base64.h" 32 | 33 | /* Simple test program 34 | #include 35 | void main() 36 | { 37 | char* in = "amcewen"; 38 | char out[22]; 39 | 40 | b64_encode(in, 15, out, 22); 41 | out[21] = '\0'; 42 | 43 | printf(out); 44 | } 45 | */ 46 | 47 | int base64_encode(const unsigned char* aInput, int aInputLen, unsigned char* aOutput, int aOutputLen) 48 | { 49 | // Work out if we've got enough space to encode the input 50 | // Every 6 bits of input becomes a byte of output 51 | if (aOutputLen < (aInputLen * 8) / 6) 52 | { 53 | // FIXME Should we return an error here, or just the length 54 | return (aInputLen * 8) / 6; 55 | } 56 | 57 | // If we get here we've got enough space to do the encoding 58 | 59 | const char* b64_dictionary = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 60 | 61 | if (aInputLen == 3) 62 | { 63 | aOutput[0] = b64_dictionary[aInput[0] >> 2]; 64 | aOutput[1] = b64_dictionary[(aInput[0] & 0x3) << 4 | (aInput[1] >> 4)]; 65 | aOutput[2] = b64_dictionary[(aInput[1] & 0x0F) << 2 | (aInput[2] >> 6)]; 66 | aOutput[3] = b64_dictionary[aInput[2] & 0x3F]; 67 | } 68 | else if (aInputLen == 2) 69 | { 70 | aOutput[0] = b64_dictionary[aInput[0] >> 2]; 71 | aOutput[1] = b64_dictionary[(aInput[0] & 0x3) << 4 | (aInput[1] >> 4)]; 72 | aOutput[2] = b64_dictionary[(aInput[1] & 0x0F) << 2]; 73 | aOutput[3] = '='; 74 | } 75 | else if (aInputLen == 1) 76 | { 77 | aOutput[0] = b64_dictionary[aInput[0] >> 2]; 78 | aOutput[1] = b64_dictionary[(aInput[0] & 0x3) << 4]; 79 | aOutput[2] = '='; 80 | aOutput[3] = '='; 81 | } 82 | else 83 | { 84 | // Break the input into 3-byte chunks and process each of them 85 | int i; 86 | 87 | for (i = 0; i < aInputLen / 3; i++) 88 | { 89 | base64_encode(&aInput[i * 3], 3, &aOutput[i * 4], 4); 90 | } 91 | 92 | if (aInputLen % 3 > 0) 93 | { 94 | // It doesn't fit neatly into a 3-byte chunk, so process what's left 95 | base64_encode(&aInput[i * 3], aInputLen % 3, &aOutput[i * 4], aOutputLen - (i * 4)); 96 | } 97 | } 98 | 99 | return ((aInputLen + 2) / 3) * 4; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/libb64/base64.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | base64.h - c source to a base64 encoding algorithm implementation 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *************************************************************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | #ifndef BASE64_H 34 | #define BASE64_H 35 | 36 | int base64_encode(const unsigned char* aInput, int aInputLen, unsigned char* aOutput, int aOutputLen); 37 | 38 | #endif // BASE64_H 39 | -------------------------------------------------------------------------------- /src/libb64/cdecode.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | cdecoder.h - c source to a base64 decoding algorithm implementation 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *****************************************************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | // Reintroduce to prevent duplication compile error if other lib/core already has LIB64 34 | // pragma once can't prevent that 35 | #ifndef BASE64_CDECODE_H 36 | #define BASE64_CDECODE_H 37 | 38 | #define base64_decode_expected_len(n) ((n * 3) / 4) 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef enum 45 | { 46 | step_a, step_b, step_c, step_d 47 | } base64_decodestep; 48 | 49 | typedef struct 50 | { 51 | base64_decodestep step; 52 | char plainchar; 53 | } base64_decodestate; 54 | 55 | void base64_init_decodestate(base64_decodestate* state_in); 56 | 57 | int base64_decode_value(int value_in); 58 | 59 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); 60 | 61 | int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out); 62 | 63 | #ifdef __cplusplus 64 | } // extern "C" 65 | #endif 66 | 67 | #endif /* BASE64_CDECODE_H */ 68 | 69 | -------------------------------------------------------------------------------- /src/libb64/cencode.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | cencoder.h - c source to a base64 decoding algorithm implementation 3 | For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module 4 | 5 | EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.0 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60 20 | ... 21 | 1.3.0 K Hoang 20/12/2021 Reduce usage of Arduino String with std::string. Use reference passing instead of value-passing 22 | 1.3.1 K Hoang 25/12/2021 Fix bug 23 | 1.3.2 K Hoang 28/12/2021 Fix wrong http status header bug and authenticate issue caused by libb64 24 | 1.3.3 K Hoang 11/01/2022 Fix libb64 fallthrough compile warning 25 | 1.3.4 K Hoang 02/03/2022 Fix decoding error bug 26 | 1.4.0 K Hoang 04/04/2022 Use Ethernet_Generic library as default for W5x00 Ethernet 27 | 1.4.1 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples 28 | 1.5.0 K Hoang 04/04/2022 Add support to custom SPI, such as SPI2, SPI3, SPI_New, etc. 29 | *****************************************************************************************************************************/ 30 | 31 | #pragma once 32 | 33 | // Reintroduce to prevent duplication compile error if other lib/core already has LIB64 34 | // pragma once can't prevent that 35 | #ifndef BASE64_CENCODE_H 36 | #define BASE64_CENCODE_H 37 | 38 | #define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3) 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef enum 45 | { 46 | step_A, step_B, step_C 47 | } base64_encodestep; 48 | 49 | typedef struct 50 | { 51 | base64_encodestep step; 52 | char result; 53 | int stepcount; 54 | } base64_encodestate; 55 | 56 | void base64_init_encodestate(base64_encodestate* state_in); 57 | 58 | char base64_encode_value(char value_in); 59 | 60 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); 61 | 62 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in); 63 | 64 | int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out); 65 | 66 | #ifdef __cplusplus 67 | } // extern "C" 68 | #endif 69 | 70 | #endif /* BASE64_CENCODE_H */ 71 | 72 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------