├── .codespellrc ├── .github ├── dependabot.yml └── workflows │ ├── check-arduino.yml │ ├── compile-examples.yml │ ├── report-size-deltas.yml │ ├── spell-check.yml │ └── sync-labels.yml ├── CHANGELOG ├── README.adoc ├── docs ├── api.md └── readme.md ├── examples ├── AP_SimpleWebServer │ ├── AP_SimpleWebServer.ino │ └── arduino_secrets.h ├── CheckWifi101FirmwareVersion │ └── CheckWifi101FirmwareVersion.ino ├── ConnectNoEncryption │ ├── ConnectNoEncryption.ino │ └── arduino_secrets.h ├── ConnectWithWEP │ ├── ConnectWithWEP.ino │ └── arduino_secrets.h ├── ConnectWithWPA │ ├── ConnectWithWPA.ino │ └── arduino_secrets.h ├── FirmwareUpdater │ ├── Endianness.ino │ └── FirmwareUpdater.ino ├── MDNS_WiFiWebServer │ ├── MDNS_WiFiWebServer.ino │ └── arduino_secrets.h ├── Provisioning_WiFiWebServer │ └── Provisioning_WiFiWebServer.ino ├── ScanNetworks │ └── ScanNetworks.ino ├── ScanNetworksAdvanced │ └── ScanNetworksAdvanced.ino ├── SimpleWebServerWiFi │ ├── SimpleWebServerWiFi.ino │ └── arduino_secrets.h ├── WiFiChatServer │ ├── WiFiChatServer.ino │ └── arduino_secrets.h ├── WiFiPing │ ├── WiFiPing.ino │ └── arduino_secrets.h ├── WiFiSSLClient │ ├── WiFiSSLClient.ino │ └── arduino_secrets.h ├── WiFiUdpNtpClient │ ├── WiFiUdpNtpClient.ino │ └── arduino_secrets.h ├── WiFiUdpSendReceiveString │ ├── WiFiUdpSendReceiveString.ino │ └── arduino_secrets.h ├── WiFiWebClient │ ├── WiFiWebClient.ino │ └── arduino_secrets.h ├── WiFiWebClientRepeating │ ├── WiFiWebClientRepeating.ino │ └── arduino_secrets.h └── WiFiWebServer │ ├── WiFiWebServer.ino │ └── arduino_secrets.h ├── keywords.txt ├── library.properties └── src ├── WiFi.cpp ├── WiFi101.h ├── WiFiClient.cpp ├── WiFiClient.h ├── WiFiMDNSResponder.cpp ├── WiFiMDNSResponder.h ├── WiFiSSLClient.cpp ├── WiFiSSLClient.h ├── WiFiServer.cpp ├── WiFiServer.h ├── WiFiUdp.cpp ├── WiFiUdp.h ├── bsp ├── include │ ├── nm_bsp.h │ ├── nm_bsp_arduino.h │ ├── nm_bsp_avr.h │ ├── nm_bsp_internal.h │ └── nm_bsp_samd21.h └── source │ ├── nm_bsp_arduino.c │ └── nm_bsp_arduino_avr.c ├── bus_wrapper ├── include │ └── nm_bus_wrapper.h └── source │ └── nm_bus_wrapper_samd21.cpp ├── common ├── include │ ├── nm_common.h │ └── nm_debug.h └── source │ └── nm_common.c ├── driver ├── include │ ├── ecc_types.h │ ├── m2m_ate_mode.h │ ├── m2m_crypto.h │ ├── m2m_ota.h │ ├── m2m_periph.h │ ├── m2m_ssl.h │ ├── m2m_types.h │ └── m2m_wifi.h └── source │ ├── m2m_ate_mode.c │ ├── m2m_crypto.c │ ├── m2m_hif.c │ ├── m2m_hif.h │ ├── m2m_ota.c │ ├── m2m_periph.c │ ├── m2m_ssl.c │ ├── m2m_wifi.c │ ├── nmasic.c │ ├── nmasic.h │ ├── nmbus.c │ ├── nmbus.h │ ├── nmdrv.c │ ├── nmdrv.h │ ├── nmi2c.c │ ├── nmi2c.h │ ├── nmspi.c │ ├── nmspi.h │ ├── nmuart.c │ └── nmuart.h ├── socket ├── include │ ├── m2m_socket_host_if.h │ └── socket.h └── source │ ├── socket.c │ └── socket_internal.h ├── spi_flash ├── include │ ├── spi_flash.h │ └── spi_flash_map.h └── source │ └── spi_flash.c └── utility ├── WiFiSocket.cpp └── WiFiSocket.h /.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/bsp,./src/bus_wrapper,./src/common,./src/driver,./src/socket,./src/spi_flash 8 | -------------------------------------------------------------------------------- /.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/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@v4 20 | 21 | - name: Arduino Lint 22 | uses: arduino/arduino-lint-action@v2 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/compile-examples.yml: -------------------------------------------------------------------------------- 1 | name: Compile Examples 2 | 3 | on: 4 | pull_request: 5 | paths: 6 | - ".github/workflows/compile-examples.yml" 7 | - "examples/**" 8 | - "src/**" 9 | push: 10 | paths: 11 | - ".github/workflows/compile-examples.yml" 12 | - "examples/**" 13 | - "src/**" 14 | schedule: 15 | # Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms). 16 | - cron: "0 8 * * TUE" 17 | workflow_dispatch: 18 | repository_dispatch: 19 | 20 | jobs: 21 | build: 22 | name: ${{ matrix.board.fqbn }} 23 | runs-on: ubuntu-latest 24 | 25 | env: 26 | # sketch paths to compile (recursive) for all boards 27 | UNIVERSAL_SKETCH_PATHS: | 28 | - examples/AP_SimpleWebServer 29 | - examples/CheckWifi101FirmwareVersion 30 | - examples/ConnectNoEncryption 31 | - examples/ConnectWithWEP 32 | - examples/ConnectWithWPA 33 | - examples/MDNS_WiFiWebServer 34 | - examples/Provisioning_WiFiWebServer 35 | - examples/ScanNetworks 36 | - examples/ScanNetworksAdvanced 37 | - examples/SimpleWebServerWiFi 38 | - examples/WiFiChatServer 39 | - examples/WiFiPing 40 | - examples/WiFiSSLClient 41 | - examples/WiFiUdpNtpClient 42 | - examples/WiFiUdpSendReceiveString 43 | - examples/WiFiWebClient 44 | - examples/WiFiWebClientRepeating 45 | - examples/WiFiWebServer 46 | SKETCHES_REPORTS_PATH: sketches-reports 47 | 48 | strategy: 49 | fail-fast: false 50 | 51 | matrix: 52 | board: 53 | - fqbn: arduino:avr:uno 54 | platforms: | 55 | - name: arduino:avr 56 | firmwareUpdaterSupport: false 57 | artifact-name-suffix: arduino-avr-uno 58 | - fqbn: arduino:avr:mega 59 | platforms: | 60 | - name: arduino:avr 61 | firmwareUpdaterSupport: false 62 | artifact-name-suffix: arduino-avr-mega 63 | - fqbn: arduino:sam:arduino_due_x_dbg 64 | platforms: | 65 | - name: arduino:sam 66 | firmwareUpdaterSupport: true 67 | artifact-name-suffix: arduino-sam-arduino_due_x_dbg 68 | - fqbn: arduino:samd:arduino_zero_edbg 69 | platforms: | 70 | - name: arduino:samd 71 | firmwareUpdaterSupport: true 72 | artifact-name-suffix: arduino-samd-arduino_zero_edbg 73 | - fqbn: arduino:samd:mkr1000 74 | platforms: | 75 | - name: arduino:samd 76 | firmwareUpdaterSupport: true 77 | artifact-name-suffix: arduino-samd-mkr1000 78 | - fqbn: Intel:arc32:arduino_101 79 | platforms: | 80 | - name: Intel:arc32 81 | firmwareUpdaterSupport: true 82 | artifact-name-suffix: Intel-arc32-arduino_101 83 | 84 | # make board type-specific customizations to the matrix jobs 85 | include: 86 | - board: 87 | firmwareUpdaterSupport: true 88 | firmwareUpdater-sketch-paths: | 89 | - examples/FirmwareUpdater 90 | - board: 91 | firmwareUpdaterSupport: false 92 | firmwareUpdater-sketch-paths: "" 93 | 94 | steps: 95 | - name: Checkout 96 | uses: actions/checkout@v4 97 | 98 | - name: Compile examples 99 | uses: arduino/compile-sketches@v1 100 | with: 101 | github-token: ${{ secrets.GITHUB_TOKEN }} 102 | fqbn: ${{ matrix.board.fqbn }} 103 | platforms: ${{ matrix.board.platforms }} 104 | libraries: | 105 | # Install the WiFi101 library from the local path 106 | - source-path: ./ 107 | sketch-paths: | 108 | ${{ env.UNIVERSAL_SKETCH_PATHS }} 109 | ${{ matrix.firmwareUpdater-sketch-paths }} 110 | enable-deltas-report: true 111 | sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} 112 | 113 | - name: Save memory usage change report as artifact 114 | uses: actions/upload-artifact@v4 115 | with: 116 | if-no-files-found: error 117 | path: ${{ env.SKETCHES_REPORTS_PATH }} 118 | name: sketches-report-${{ matrix.board.artifact-name-suffix }} 119 | -------------------------------------------------------------------------------- /.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 | # Regex matching the names of the workflow artifacts created by the "Compile Examples" workflow 16 | sketches-reports-source: ^sketches-report-.+ 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@v4 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 | -------------------------------------------------------------------------------- /.github/workflows/sync-labels.yml: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md 2 | name: Sync Labels 3 | 4 | # See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows 5 | on: 6 | push: 7 | paths: 8 | - ".github/workflows/sync-labels.ya?ml" 9 | - ".github/label-configuration-files/*.ya?ml" 10 | pull_request: 11 | paths: 12 | - ".github/workflows/sync-labels.ya?ml" 13 | - ".github/label-configuration-files/*.ya?ml" 14 | schedule: 15 | # Run daily at 8 AM UTC to sync with changes to shared label configurations. 16 | - cron: "0 8 * * *" 17 | workflow_dispatch: 18 | repository_dispatch: 19 | 20 | env: 21 | CONFIGURATIONS_FOLDER: .github/label-configuration-files 22 | CONFIGURATIONS_ARTIFACT: label-configuration-files 23 | 24 | jobs: 25 | check: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout repository 30 | uses: actions/checkout@v4 31 | 32 | - name: Download JSON schema for labels configuration file 33 | id: download-schema 34 | uses: carlosperate/download-file-action@v2 35 | with: 36 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json 37 | location: ${{ runner.temp }}/label-configuration-schema 38 | 39 | - name: Install JSON schema validator 40 | run: | 41 | sudo npm install \ 42 | --global \ 43 | ajv-cli \ 44 | ajv-formats 45 | 46 | - name: Validate local labels configuration 47 | run: | 48 | # See: https://github.com/ajv-validator/ajv-cli#readme 49 | ajv validate \ 50 | --all-errors \ 51 | -c ajv-formats \ 52 | -s "${{ steps.download-schema.outputs.file-path }}" \ 53 | -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" 54 | 55 | download: 56 | needs: check 57 | runs-on: ubuntu-latest 58 | 59 | strategy: 60 | matrix: 61 | filename: 62 | # Filenames of the shared configurations to apply to the repository in addition to the local configuration. 63 | # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels 64 | - universal.yml 65 | 66 | steps: 67 | - name: Download 68 | uses: carlosperate/download-file-action@v2 69 | with: 70 | file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} 71 | 72 | - name: Pass configuration files to next job via workflow artifact 73 | uses: actions/upload-artifact@v4 74 | with: 75 | path: | 76 | *.yaml 77 | *.yml 78 | if-no-files-found: error 79 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 80 | 81 | sync: 82 | needs: download 83 | runs-on: ubuntu-latest 84 | 85 | steps: 86 | - name: Set environment variables 87 | run: | 88 | # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable 89 | echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" 90 | 91 | - name: Determine whether to dry run 92 | id: dry-run 93 | if: > 94 | github.event_name == 'pull_request' || 95 | ( 96 | ( 97 | github.event_name == 'push' || 98 | github.event_name == 'workflow_dispatch' 99 | ) && 100 | github.ref != format('refs/heads/{0}', github.event.repository.default_branch) 101 | ) 102 | run: | 103 | # Use of this flag in the github-label-sync command will cause it to only check the validity of the 104 | # configuration. 105 | echo "::set-output name=flag::--dry-run" 106 | 107 | - name: Checkout repository 108 | uses: actions/checkout@v4 109 | 110 | - name: Download configuration files artifact 111 | uses: actions/download-artifact@v4 112 | with: 113 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 114 | path: ${{ env.CONFIGURATIONS_FOLDER }} 115 | 116 | - name: Remove unneeded artifact 117 | uses: geekyeggo/delete-artifact@v5 118 | with: 119 | name: ${{ env.CONFIGURATIONS_ARTIFACT }} 120 | 121 | - name: Merge label configuration files 122 | run: | 123 | # Merge all configuration files 124 | shopt -s extglob 125 | cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" 126 | 127 | - name: Install github-label-sync 128 | run: sudo npm install --global github-label-sync 129 | 130 | - name: Sync labels 131 | env: 132 | GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 133 | run: | 134 | # See: https://github.com/Financial-Times/github-label-sync 135 | github-label-sync \ 136 | --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ 137 | ${{ steps.dry-run.outputs.flag }} \ 138 | ${{ github.repository }} 139 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | // Define the repository information in these attributes 2 | :repository-owner: arduino-libraries 3 | :repository-name: WiFi101 4 | 5 | = {repository-name} library for for the Arduino WiFi Shield 101 and MKR1000 board = 6 | 7 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] 8 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] 9 | image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] 10 | 11 | This library implements a network driver for devices based 12 | on the ATMEL WINC1500 WiFi module. 13 | 14 | For more information about this library please visit us at 15 | https://www.arduino.cc/en/Reference/{repository-name} 16 | 17 | == License == 18 | 19 | Copyright (c) Arduino LLC. All right reserved. 20 | 21 | This library is free software; you can redistribute it and/or 22 | modify it under the terms of the GNU Lesser General Public 23 | License as published by the Free Software Foundation; either 24 | version 2.1 of the License, or (at your option) any later version. 25 | 26 | This library is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | Lesser General Public License for more details. 30 | 31 | You should have received a copy of the GNU Lesser General Public 32 | License along with this library; if not, write to the Free Software 33 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 34 | -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # WiFi101 library 2 | This library allows you to use the Arduino WiFi Shield 101 and the MKR1000 board. These are powerful IoT solutions with crypto-authentication, developed with ATMEL, that connects your Arduino or Genuino to the internet wirelessly. Connecting the board or the shield to a WiFi network is simple, no further configuration in addition to the SSID and the password are required. It can serve as either a server accepting incoming connections or a client making outgoing ones. The library supports WEP and WPA2 Personal encryption. Compared to the retired WiFi Shield and the related library, this product and library support all the same methods plus the connectSSL(). 3 | 4 | The board connected to the shield communicates with the WiFi shield 101 using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53, is not used but it must be kept as an output or the SPI interface won't work. Digital pin 7 is used as a handshake pin between the WiFi shield 101 and the underlying board, and should not be used. The WiFi101 library is very similar to the [Ethernet](https://www.arduino.cc/en/Reference/Ethernet) and the library [WiFi](https://www.arduino.cc/en/Reference/WiFi), and many of the function calls are the same. 5 | 6 | For additional information on the Arduino WiFi Shield 101, see the [Getting Started](https://www.arduino.cc/en/Guide/ArduinoWiFiShield101) page and the [Arduino WiFi Shield 101 hardware page](https://www.arduino.cc/en/Main/ArduinoWiFiShield101[). For more information on MKR1000 see the [product page](https://www.arduino.cc/en/Main/ArduinoMKR1000). 7 | 8 | To use this library 9 | ``` 10 | #include 11 | #include 12 | ``` 13 | ## Note 14 | This library requires that your board or shield has a matching firmware installed. When the library is updated, also the firmware might be updated, but it is not mandatory. To avoid any issue and ensure that you have the most up to date setup, we suggest that you check your WiFi101 library with the Arduino Software (IDE) Library Manager. There is an option in the Preferences that enables the check for updates of any of the installed libraries at startup. If you haven't installed the WiFi101 library yet, you won't get notified about its updates. Anyway, you get the library status just writing its name in the search field on top of the Library Manager. 15 | 16 | 17 | When the library version installed on your computer is the latest available, you may check the firmware version of the board or the shield. We have prepared a utility sketch to check the firmware version and its matching with the library. If the firmware needs an update, another utility sketch enables the process. Below the link to the relevant tutorials. 18 | 19 | ## Utilities 20 | - [CheckWiFi101FirmwareVersion](https://www.arduino.cc/en/Tutorial/CheckWiFi101FirmwareVersion) : Reads the required firmware number required from library and matches with the one installed on the board or the shield. 21 | - [FirmwareUpdater](https://www.arduino.cc/en/Tutorial/FirmwareUpdater) : The sketch that must be loaded to allow the firmware and certificates update process through the integrated plugin of Arduino Software (IDE) rel. 1.6.10 or later. 22 | ## Examples 23 | - [ConnectNoEncryption](https://www.arduino.cc/en/Tutorial/Wifi101ConnectNoEncryption) : Demonstrates how to connect to an open network 24 | - [ConnectWithWEP](https://www.arduino.cc/en/Tutorial/Wifi101ConnectWithWEP) : Demonstrates how to connect to a network that is encrypted with WEP 25 | - [ConnectWithWPA](https://www.arduino.cc/en/Tutorial/Wifi101ConnectWithWPA) : Demonstrates how to connect to a network that is encrypted with WPA2 Personal 26 | - [ScanNetworks](https://www.arduino.cc/en/Tutorial/Wifi101ScanNetworks) : Displays all WiFi networks in range 27 | - [WiFiChatServer](https://www.arduino.cc/en/Tutorial/Wifi101WiFiChatServer) : Set up a simple chat server 28 | - [WiFiWebClient](https://www.arduino.cc/en/Tutorial/Wifi101WiFiWebClient) : Connect to a remote webserver 29 | - [WiFiWebClientRepeating](https://www.arduino.cc/en/Tutorial/Wifi101WiFiWebClientRepeating) : Make repeated HTTP calls to a webserver 30 | - [WiFiWebServer](https://www.arduino.cc/en/Tutorial/Wifi101WiFiWebServer) : Serve a webpage from the WiFi shield 31 | - [WiFiUdpSendReceiveString](https://www.arduino.cc/en/Tutorial/Wifi101WiFiUdpSendReceiveString) : Send and receive a UDP string 32 | - [UdpNTPClient](https://www.arduino.cc/en/Tutorial/Wifi101UdpNTPClient) : Query a Network Time Protocol (NTP) server using UDP 33 | -------------------------------------------------------------------------------- /examples/AP_SimpleWebServer/AP_SimpleWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi Web Server LED Blink 3 | 4 | A simple web server that lets you blink an LED via the web. 5 | This sketch will create a new access point (with no password). 6 | It will then launch a new server and print out the IP address 7 | to the Serial monitor. From there, you can open that address in a web browser 8 | to turn on and off the LED on pin 13. 9 | 10 | If the IP address of your shield is yourAddress: 11 | http://yourAddress/H turns the LED on 12 | http://yourAddress/L turns it off 13 | 14 | created 25 Nov 2012 15 | by Tom Igoe 16 | adapted to WiFi AP by Adafruit 17 | */ 18 | 19 | #include 20 | #include 21 | #include "arduino_secrets.h" 22 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 23 | char ssid[] = SECRET_SSID; // your network SSID (name) 24 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 25 | int keyIndex = 0; // your network key Index number (needed only for WEP) 26 | 27 | int led = LED_BUILTIN; 28 | int status = WL_IDLE_STATUS; 29 | WiFiServer server(80); 30 | 31 | void setup() { 32 | //Initialize serial and wait for port to open: 33 | Serial.begin(9600); 34 | while (!Serial) { 35 | ; // wait for serial port to connect. Needed for native USB port only 36 | } 37 | 38 | Serial.println("Access Point Web Server"); 39 | 40 | pinMode(led, OUTPUT); // set the LED pin mode 41 | 42 | // check for the presence of the shield: 43 | if (WiFi.status() == WL_NO_SHIELD) { 44 | Serial.println("WiFi 101 Shield not present"); 45 | // don't continue 46 | while (true); 47 | } 48 | 49 | // by default the local IP address of will be 192.168.1.1 50 | // you can override it with the following: 51 | // WiFi.config(IPAddress(10, 0, 0, 1)); 52 | 53 | // print the network name (SSID); 54 | Serial.print("Creating access point named: "); 55 | Serial.println(ssid); 56 | 57 | // Create open network. Change this line if you want to create a WEP network: 58 | status = WiFi.beginAP(ssid); 59 | if (status != WL_AP_LISTENING) { 60 | Serial.println("Creating access point failed"); 61 | // don't continue 62 | while (true); 63 | } 64 | 65 | // wait 10 seconds for connection: 66 | delay(10000); 67 | 68 | // start the web server on port 80 69 | server.begin(); 70 | 71 | // you're connected now, so print out the status 72 | printWiFiStatus(); 73 | } 74 | 75 | 76 | void loop() { 77 | // compare the previous status to the current status 78 | if (status != WiFi.status()) { 79 | // it has changed, so update the variable 80 | status = WiFi.status(); 81 | 82 | if (status == WL_AP_CONNECTED) { 83 | byte remoteMac[6]; 84 | 85 | // a device has connected to the AP 86 | Serial.print("Device connected to AP, MAC address: "); 87 | WiFi.APClientMacAddress(remoteMac); 88 | printMacAddress(remoteMac); 89 | } else { 90 | // a device has disconnected from the AP, and we are back in listening mode 91 | Serial.println("Device disconnected from AP"); 92 | } 93 | } 94 | 95 | WiFiClient client = server.available(); // listen for incoming clients 96 | 97 | if (client) { // if you get a client, 98 | Serial.println("new client"); // print a message out the serial port 99 | String currentLine = ""; // make a String to hold incoming data from the client 100 | while (client.connected()) { // loop while the client's connected 101 | if (client.available()) { // if there are bytes to read from the client, 102 | char c = client.read(); // read a byte, then 103 | Serial.write(c); // print it out the serial monitor 104 | if (c == '\n') { // if the byte is a newline character 105 | 106 | // if the current line is blank, you got two newline characters in a row. 107 | // that's the end of the client HTTP request, so send a response: 108 | if (currentLine.length() == 0) { 109 | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) 110 | // and a content-type so the client knows what's coming, then a blank line: 111 | client.println("HTTP/1.1 200 OK"); 112 | client.println("Content-type:text/html"); 113 | client.println(); 114 | 115 | // the content of the HTTP response follows the header: 116 | client.print("Click here turn the LED on
"); 117 | client.print("Click here turn the LED off
"); 118 | 119 | // The HTTP response ends with another blank line: 120 | client.println(); 121 | // break out of the while loop: 122 | break; 123 | } 124 | else { // if you got a newline, then clear currentLine: 125 | currentLine = ""; 126 | } 127 | } 128 | else if (c != '\r') { // if you got anything else but a carriage return character, 129 | currentLine += c; // add it to the end of the currentLine 130 | } 131 | 132 | // Check to see if the client request was "GET /H" or "GET /L": 133 | if (currentLine.endsWith("GET /H")) { 134 | digitalWrite(led, HIGH); // GET /H turns the LED on 135 | } 136 | if (currentLine.endsWith("GET /L")) { 137 | digitalWrite(led, LOW); // GET /L turns the LED off 138 | } 139 | } 140 | } 141 | // close the connection: 142 | client.stop(); 143 | Serial.println("client disconnected"); 144 | } 145 | } 146 | 147 | void printWiFiStatus() { 148 | // print the SSID of the network you're attached to: 149 | Serial.print("SSID: "); 150 | Serial.println(WiFi.SSID()); 151 | 152 | // print your WiFi 101 Shield's IP address: 153 | IPAddress ip = WiFi.localIP(); 154 | Serial.print("IP Address: "); 155 | Serial.println(ip); 156 | 157 | // print the received signal strength: 158 | long rssi = WiFi.RSSI(); 159 | Serial.print("signal strength (RSSI):"); 160 | Serial.print(rssi); 161 | Serial.println(" dBm"); 162 | // print where to go in a browser: 163 | Serial.print("To see this page in action, open a browser to http://"); 164 | Serial.println(ip); 165 | 166 | } 167 | 168 | void printMacAddress(byte mac[]) { 169 | for (int i = 5; i >= 0; i--) { 170 | if (mac[i] < 16) { 171 | Serial.print("0"); 172 | } 173 | Serial.print(mac[i], HEX); 174 | if (i > 0) { 175 | Serial.print(":"); 176 | } 177 | } 178 | Serial.println(); 179 | } 180 | -------------------------------------------------------------------------------- /examples/AP_SimpleWebServer/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This example checks if the firmware loaded on the WiFi101 3 | * shield is updated. 4 | * 5 | * Circuit: 6 | * - WiFi 101 Shield attached 7 | * 8 | * Created 29 July 2015 by Cristian Maglie 9 | * This code is in the public domain. 10 | */ 11 | #include 12 | #include 13 | #include 14 | 15 | void setup() { 16 | // Initialize serial 17 | Serial.begin(9600); 18 | while (!Serial) { 19 | ; // wait for serial port to connect. Needed for native USB port only 20 | } 21 | 22 | // Print a welcome message 23 | Serial.println("WiFi101 firmware check."); 24 | Serial.println(); 25 | 26 | // Check for the presence of the shield 27 | Serial.print("WiFi 101 Shield: "); 28 | if (WiFi.status() == WL_NO_SHIELD) { 29 | Serial.println("NOT PRESENT"); 30 | return; // don't continue 31 | } 32 | Serial.println("DETECTED"); 33 | 34 | // Print firmware version on the shield 35 | String fv = WiFi.firmwareVersion(); 36 | String latestFv; 37 | Serial.print("Firmware version installed: "); 38 | Serial.println(fv); 39 | 40 | if (REV(GET_CHIPID()) >= REV_3A0) { 41 | // model B 42 | latestFv = WIFI_FIRMWARE_LATEST_MODEL_B; 43 | } else { 44 | // model A 45 | latestFv = WIFI_FIRMWARE_LATEST_MODEL_A; 46 | } 47 | 48 | // Print required firmware version 49 | Serial.print("Latest firmware version available : "); 50 | Serial.println(latestFv); 51 | 52 | // Check if the latest version is installed 53 | Serial.println(); 54 | if (fv >= latestFv) { 55 | Serial.println("Check result: PASSED"); 56 | } else { 57 | Serial.println("Check result: NOT PASSED"); 58 | Serial.println(" - The firmware version on the shield does not match the"); 59 | Serial.println(" version required by the library, you may experience"); 60 | Serial.println(" issues or failures."); 61 | } 62 | } 63 | 64 | void loop() { 65 | // do nothing 66 | } 67 | -------------------------------------------------------------------------------- /examples/ConnectNoEncryption/ConnectNoEncryption.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example connects to an unencrypted WiFi network. 4 | Then it prints the MAC address of the WiFi 101 Shield, 5 | the IP address obtained, and other network details. 6 | 7 | Circuit: 8 | * WiFi 101 Shield attached 9 | 10 | created 13 July 2010 11 | by dlf (Metodo2 srl) 12 | modified 31 May 2012 13 | by Tom Igoe 14 | */ 15 | #include 16 | #include 17 | #include "arduino_secrets.h" 18 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 19 | char ssid[] = SECRET_SSID; // your network SSID (name) 20 | int status = WL_IDLE_STATUS; // the WiFi radio's status 21 | 22 | void setup() { 23 | //Initialize serial and wait for port to open: 24 | Serial.begin(9600); 25 | while (!Serial) { 26 | ; // wait for serial port to connect. Needed for native USB port only 27 | } 28 | 29 | // check for the presence of the shield: 30 | if (WiFi.status() == WL_NO_SHIELD) { 31 | Serial.println("WiFi 101 Shield not present"); 32 | // don't continue: 33 | while (true); 34 | } 35 | 36 | // attempt to connect to WiFi network: 37 | while ( status != WL_CONNECTED) { 38 | Serial.print("Attempting to connect to open SSID: "); 39 | Serial.println(ssid); 40 | status = WiFi.begin(ssid); 41 | 42 | // wait 10 seconds for connection: 43 | delay(10000); 44 | } 45 | 46 | // you're connected now, so print out the data: 47 | Serial.print("You're connected to the network"); 48 | printCurrentNet(); 49 | printWiFiData(); 50 | } 51 | 52 | void loop() { 53 | // check the network connection once every 10 seconds: 54 | delay(10000); 55 | printCurrentNet(); 56 | } 57 | 58 | void printWiFiData() { 59 | // print your WiFi 101 Shield's IP address: 60 | IPAddress ip = WiFi.localIP(); 61 | Serial.print("IP Address: "); 62 | Serial.println(ip); 63 | Serial.println(ip); 64 | 65 | // print your MAC address: 66 | byte mac[6]; 67 | WiFi.macAddress(mac); 68 | Serial.print("MAC address: "); 69 | printMacAddress(mac); 70 | 71 | // print your subnet mask: 72 | IPAddress subnet = WiFi.subnetMask(); 73 | Serial.print("NetMask: "); 74 | Serial.println(subnet); 75 | 76 | // print your gateway address: 77 | IPAddress gateway = WiFi.gatewayIP(); 78 | Serial.print("Gateway: "); 79 | Serial.println(gateway); 80 | } 81 | 82 | void printCurrentNet() { 83 | // print the SSID of the network you're attached to: 84 | Serial.print("SSID: "); 85 | Serial.println(WiFi.SSID()); 86 | 87 | // print the MAC address of the router you're attached to: 88 | byte bssid[6]; 89 | WiFi.BSSID(bssid); 90 | Serial.print("BSSID: "); 91 | printMacAddress(bssid); 92 | 93 | // print the received signal strength: 94 | long rssi = WiFi.RSSI(); 95 | Serial.print("signal strength (RSSI):"); 96 | Serial.println(rssi); 97 | 98 | // print the encryption type: 99 | byte encryption = WiFi.encryptionType(); 100 | Serial.print("Encryption Type:"); 101 | Serial.println(encryption, HEX); 102 | } 103 | 104 | void printMacAddress(byte mac[]) { 105 | for (int i = 5; i >= 0; i--) { 106 | if (mac[i] < 16) { 107 | Serial.print("0"); 108 | } 109 | Serial.print(mac[i], HEX); 110 | if (i > 0) { 111 | Serial.print(":"); 112 | } 113 | } 114 | Serial.println(); 115 | } 116 | -------------------------------------------------------------------------------- /examples/ConnectNoEncryption/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | -------------------------------------------------------------------------------- /examples/ConnectWithWEP/ConnectWithWEP.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example connects to a WEP-encrypted WiFi network. 4 | Then it prints the MAC address of the WiFi 101 Shield, 5 | the IP address obtained, and other network details. 6 | 7 | If you use 40-bit WEP, you need a key that is 10 characters long, 8 | and the characters must be hexadecimal (0-9 or A-F). 9 | e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work 10 | (too short) and ABBAISDEAF won't work (I and S are not 11 | hexadecimal characters). 12 | 13 | For 128-bit, you need a string that is 26 characters long. 14 | D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, 15 | all in the 0-9, A-F range. 16 | 17 | Circuit: 18 | * WiFi 101 Shield attached 19 | 20 | created 13 July 2010 21 | by dlf (Metodo2 srl) 22 | modified 31 May 2012 23 | by Tom Igoe 24 | */ 25 | #include 26 | #include 27 | 28 | #include "arduino_secrets.h" 29 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char key[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 32 | int keyIndex = 0; // your network key Index number 33 | int status = WL_IDLE_STATUS; // the WiFi radio's status 34 | 35 | void setup() { 36 | //Initialize serial and wait for port to open: 37 | Serial.begin(9600); 38 | while (!Serial) { 39 | ; // wait for serial port to connect. Needed for native USB port only 40 | } 41 | 42 | // check for the presence of the shield: 43 | if (WiFi.status() == WL_NO_SHIELD) { 44 | Serial.println("WiFi 101 Shield not present"); 45 | // don't continue: 46 | while (true); 47 | } 48 | 49 | // attempt to connect to WiFi network: 50 | while ( status != WL_CONNECTED) { 51 | Serial.print("Attempting to connect to WEP network, SSID: "); 52 | Serial.println(ssid); 53 | status = WiFi.begin(ssid, keyIndex, key); 54 | 55 | // wait 10 seconds for connection: 56 | delay(10000); 57 | } 58 | 59 | // once you are connected : 60 | Serial.print("You're connected to the network"); 61 | printCurrentNet(); 62 | printWiFiData(); 63 | } 64 | 65 | void loop() { 66 | // check the network connection once every 10 seconds: 67 | delay(10000); 68 | printCurrentNet(); 69 | } 70 | 71 | void printWiFiData() { 72 | // print your WiFi 101 Shield's IP address: 73 | IPAddress ip = WiFi.localIP(); 74 | Serial.print("IP Address: "); 75 | Serial.println(ip); 76 | Serial.println(ip); 77 | 78 | // print your MAC address: 79 | byte mac[6]; 80 | WiFi.macAddress(mac); 81 | Serial.print("MAC address: "); 82 | printMacAddress(mac); 83 | } 84 | 85 | void printCurrentNet() { 86 | // print the SSID of the network you're attached to: 87 | Serial.print("SSID: "); 88 | Serial.println(WiFi.SSID()); 89 | 90 | // print the MAC address of the router you're attached to: 91 | byte bssid[6]; 92 | WiFi.BSSID(bssid); 93 | Serial.print("BSSID: "); 94 | printMacAddress(bssid); 95 | 96 | // print the received signal strength: 97 | long rssi = WiFi.RSSI(); 98 | Serial.print("signal strength (RSSI):"); 99 | Serial.println(rssi); 100 | 101 | // print the encryption type: 102 | byte encryption = WiFi.encryptionType(); 103 | Serial.print("Encryption Type:"); 104 | Serial.println(encryption, HEX); 105 | Serial.println(); 106 | } 107 | 108 | void printMacAddress(byte mac[]) { 109 | for (int i = 5; i >= 0; i--) { 110 | if (mac[i] < 16) { 111 | Serial.print("0"); 112 | } 113 | Serial.print(mac[i], HEX); 114 | if (i > 0) { 115 | Serial.print(":"); 116 | } 117 | } 118 | Serial.println(); 119 | } 120 | -------------------------------------------------------------------------------- /examples/ConnectWithWEP/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/ConnectWithWPA/ConnectWithWPA.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example connects to an unencrypted WiFi network. 4 | Then it prints the MAC address of the WiFi 101 Shield, 5 | the IP address obtained, and other network details. 6 | 7 | Circuit: 8 | * WiFi 101 Shield attached 9 | 10 | created 13 July 2010 11 | by dlf (Metodo2 srl) 12 | modified 31 May 2012 13 | by Tom Igoe 14 | */ 15 | #include 16 | #include 17 | 18 | #include "arduino_secrets.h" 19 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 20 | char ssid[] = SECRET_SSID; // your network SSID (name) 21 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 22 | int status = WL_IDLE_STATUS; // the WiFi radio's status 23 | 24 | void setup() { 25 | //Initialize serial and wait for port to open: 26 | Serial.begin(9600); 27 | while (!Serial) { 28 | ; // wait for serial port to connect. Needed for native USB port only 29 | } 30 | 31 | // check for the presence of the shield: 32 | if (WiFi.status() == WL_NO_SHIELD) { 33 | Serial.println("WiFi 101 Shield not present"); 34 | // don't continue: 35 | while (true); 36 | } 37 | 38 | // attempt to connect to WiFi network: 39 | while ( status != WL_CONNECTED) { 40 | Serial.print("Attempting to connect to WPA SSID: "); 41 | Serial.println(ssid); 42 | // Connect to WPA/WPA2 network: 43 | status = WiFi.begin(ssid, pass); 44 | 45 | // wait 10 seconds for connection: 46 | delay(10000); 47 | } 48 | 49 | // you're connected now, so print out the data: 50 | Serial.print("You're connected to the network"); 51 | printCurrentNet(); 52 | printWiFiData(); 53 | 54 | } 55 | 56 | void loop() { 57 | // check the network connection once every 10 seconds: 58 | delay(10000); 59 | printCurrentNet(); 60 | } 61 | 62 | void printWiFiData() { 63 | // print your WiFi 101 Shield's IP address: 64 | IPAddress ip = WiFi.localIP(); 65 | Serial.print("IP Address: "); 66 | Serial.println(ip); 67 | Serial.println(ip); 68 | 69 | // print your MAC address: 70 | byte mac[6]; 71 | WiFi.macAddress(mac); 72 | Serial.print("MAC address: "); 73 | printMacAddress(mac); 74 | 75 | } 76 | 77 | void printCurrentNet() { 78 | // print the SSID of the network you're attached to: 79 | Serial.print("SSID: "); 80 | Serial.println(WiFi.SSID()); 81 | 82 | // print the MAC address of the router you're attached to: 83 | byte bssid[6]; 84 | WiFi.BSSID(bssid); 85 | Serial.print("BSSID: "); 86 | printMacAddress(bssid); 87 | 88 | // print the received signal strength: 89 | long rssi = WiFi.RSSI(); 90 | Serial.print("signal strength (RSSI):"); 91 | Serial.println(rssi); 92 | 93 | // print the encryption type: 94 | byte encryption = WiFi.encryptionType(); 95 | Serial.print("Encryption Type:"); 96 | Serial.println(encryption, HEX); 97 | Serial.println(); 98 | } 99 | 100 | void printMacAddress(byte mac[]) { 101 | for (int i = 5; i >= 0; i--) { 102 | if (mac[i] < 16) { 103 | Serial.print("0"); 104 | } 105 | Serial.print(mac[i], HEX); 106 | if (i > 0) { 107 | Serial.print(":"); 108 | } 109 | } 110 | Serial.println(); 111 | } 112 | -------------------------------------------------------------------------------- /examples/ConnectWithWPA/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/FirmwareUpdater/Endianness.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Endianness.ino - Network byte order conversion functions. 3 | Copyright (c) 2015 Arduino LLC. 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 | 21 | bool isBigEndian() { 22 | uint32_t test = 0x11223344; 23 | uint8_t *pTest = reinterpret_cast(&test); 24 | return pTest[0] == 0x11; 25 | } 26 | 27 | uint32_t fromNetwork32(uint32_t from) { 28 | static const bool be = isBigEndian(); 29 | if (be) { 30 | return from; 31 | } else { 32 | uint8_t *pFrom = reinterpret_cast(&from); 33 | uint32_t to; 34 | to = pFrom[0]; to <<= 8; 35 | to |= pFrom[1]; to <<= 8; 36 | to |= pFrom[2]; to <<= 8; 37 | to |= pFrom[3]; 38 | return to; 39 | } 40 | } 41 | 42 | uint16_t fromNetwork16(uint16_t from) { 43 | static bool be = isBigEndian(); 44 | if (be) { 45 | return from; 46 | } else { 47 | uint8_t *pFrom = reinterpret_cast(&from); 48 | uint16_t to; 49 | to = pFrom[0]; to <<= 8; 50 | to |= pFrom[1]; 51 | return to; 52 | } 53 | } 54 | 55 | uint32_t toNetwork32(uint32_t to) { 56 | return fromNetwork32(to); 57 | } 58 | 59 | uint16_t toNetwork16(uint16_t to) { 60 | return fromNetwork16(to); 61 | } 62 | -------------------------------------------------------------------------------- /examples/FirmwareUpdater/FirmwareUpdater.ino: -------------------------------------------------------------------------------- 1 | /* 2 | FirmwareUpdate.h - Firmware Updater for WiFi101 / WINC1500. 3 | Copyright (c) 2015 Arduino LLC. 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 | #include 21 | #include 22 | 23 | typedef struct __attribute__((__packed__)) { 24 | uint8_t command; 25 | uint32_t address; 26 | uint32_t arg1; 27 | uint16_t payloadLength; 28 | 29 | // payloadLength bytes of data follows... 30 | } UartPacket; 31 | 32 | static const int MAX_PAYLOAD_SIZE = 1024; 33 | 34 | #define CMD_READ_FLASH 0x01 35 | #define CMD_WRITE_FLASH 0x02 36 | #define CMD_ERASE_FLASH 0x03 37 | #define CMD_MAX_PAYLOAD_SIZE 0x50 38 | #define CMD_HELLO 0x99 39 | 40 | void setup() { 41 | Serial.begin(115200); 42 | 43 | nm_bsp_init(); 44 | if (m2m_wifi_download_mode() != M2M_SUCCESS) { 45 | Serial.println(F("Failed to put the WiFi module in download mode")); 46 | while (true) 47 | ; 48 | } 49 | } 50 | 51 | void receivePacket(UartPacket *pkt, uint8_t *payload) { 52 | // Read command 53 | uint8_t *p = reinterpret_cast(pkt); 54 | uint16_t l = sizeof(UartPacket); 55 | while (l > 0) { 56 | int c = Serial.read(); 57 | if (c == -1) 58 | continue; 59 | *p++ = c; 60 | l--; 61 | } 62 | 63 | // Convert parameters from network byte order to cpu byte order 64 | pkt->address = fromNetwork32(pkt->address); 65 | pkt->arg1 = fromNetwork32(pkt->arg1); 66 | pkt->payloadLength = fromNetwork16(pkt->payloadLength); 67 | 68 | // Read payload 69 | l = pkt->payloadLength; 70 | while (l > 0) { 71 | int c = Serial.read(); 72 | if (c == -1) 73 | continue; 74 | *payload++ = c; 75 | l--; 76 | } 77 | } 78 | 79 | // Allocated statically so the compiler can tell us 80 | // about the amount of used RAM 81 | static UartPacket pkt; 82 | static uint8_t payload[MAX_PAYLOAD_SIZE]; 83 | 84 | void loop() { 85 | receivePacket(&pkt, payload); 86 | 87 | if (pkt.command == CMD_HELLO) { 88 | if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788) 89 | Serial.print("v10000"); 90 | } 91 | 92 | if (pkt.command == CMD_MAX_PAYLOAD_SIZE) { 93 | uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE); 94 | Serial.write(reinterpret_cast(&res), sizeof(res)); 95 | } 96 | 97 | if (pkt.command == CMD_READ_FLASH) { 98 | uint32_t address = pkt.address; 99 | uint32_t len = pkt.arg1; 100 | if (spi_flash_read(payload, address, len) != M2M_SUCCESS) { 101 | Serial.println("ER"); 102 | } else { 103 | Serial.write(payload, len); 104 | Serial.print("OK"); 105 | } 106 | } 107 | 108 | if (pkt.command == CMD_WRITE_FLASH) { 109 | uint32_t address = pkt.address; 110 | uint32_t len = pkt.payloadLength; 111 | if (spi_flash_write(payload, address, len) != M2M_SUCCESS) { 112 | Serial.print("ER"); 113 | } else { 114 | Serial.print("OK"); 115 | } 116 | } 117 | 118 | if (pkt.command == CMD_ERASE_FLASH) { 119 | uint32_t address = pkt.address; 120 | uint32_t len = pkt.arg1; 121 | if (spi_flash_erase(address, len) != M2M_SUCCESS) { 122 | Serial.print("ER"); 123 | } else { 124 | Serial.print("OK"); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MDNS WiFi Web Server 3 | 4 | A simple web server that shows the value of the analog input pins, 5 | and exposes itself on the MDNS name 'wifi101.local'. 6 | 7 | On Linux (like Ubuntu 15.04) or OSX you can access the web page 8 | on the device in a browser at 'http://wifi101.local/'. 9 | 10 | On Windows you'll first need to install the Bonjour Printer Services 11 | from: 12 | https://support.apple.com/kb/dl999?locale=en_US 13 | Then you can access the device in a browser at 'http://wifi101.local/'. 14 | 15 | This example is written for a network using WPA encryption. For 16 | WEP or WPA, change the WiFi.begin() call accordingly. 17 | 18 | Circuit: 19 | * WiFi 101 Shield attached 20 | * Analog inputs attached to pins A0 through A5 (optional) 21 | 22 | created 13 July 2010 23 | by dlf (Metodo2 srl) 24 | modified 31 May 2012 25 | by Tom Igoe 26 | modified 27 January 2016 27 | by Tony DiCola 28 | 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "arduino_secrets.h" 36 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 37 | char ssid[] = SECRET_SSID; // your network SSID (name) 38 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 39 | int keyIndex = 0; // your network key Index number (needed only for WEP) 40 | 41 | char mdnsName[] = "wifi101"; // the MDNS name that the board will respond to 42 | // Note that the actual MDNS name will have '.local' after 43 | // the name above, so "wifi101" will be accessible on 44 | // the MDNS name "wifi101.local". 45 | 46 | int status = WL_IDLE_STATUS; 47 | 48 | // Create a MDNS responder to listen and respond to MDNS name requests. 49 | WiFiMDNSResponder mdnsResponder; 50 | 51 | WiFiServer server(80); 52 | 53 | void setup() { 54 | //Initialize serial and wait for port to open: 55 | Serial.begin(9600); 56 | while (!Serial) { 57 | ; // wait for serial port to connect. Needed for native USB port only 58 | } 59 | 60 | // check for the presence of the shield: 61 | if (WiFi.status() == WL_NO_SHIELD) { 62 | Serial.println("WiFi 101 Shield not present"); 63 | // don't continue: 64 | while (true); 65 | } 66 | 67 | // attempt to connect to WiFi network: 68 | while ( status != WL_CONNECTED) { 69 | Serial.print("Attempting to connect to SSID: "); 70 | Serial.println(ssid); 71 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 72 | status = WiFi.begin(ssid, pass); 73 | 74 | // wait 10 seconds for connection: 75 | delay(10000); 76 | } 77 | // you're connected now, so print out the status: 78 | printWiFiStatus(); 79 | 80 | server.begin(); 81 | 82 | // Setup the MDNS responder to listen to the configured name. 83 | // NOTE: You _must_ call this _after_ connecting to the WiFi network and 84 | // being assigned an IP address. 85 | if (!mdnsResponder.begin(mdnsName)) { 86 | Serial.println("Failed to start MDNS responder!"); 87 | while(1); 88 | } 89 | 90 | Serial.print("Server listening at http://"); 91 | Serial.print(mdnsName); 92 | Serial.println(".local/"); 93 | } 94 | 95 | 96 | void loop() { 97 | // Call the update() function on the MDNS responder every loop iteration to 98 | // make sure it can detect and respond to name requests. 99 | mdnsResponder.poll(); 100 | 101 | // listen for incoming clients 102 | WiFiClient client = server.available(); 103 | if (client) { 104 | Serial.println("new client"); 105 | // an HTTP request ends with a blank line 106 | bool currentLineIsBlank = true; 107 | while (client.connected()) { 108 | if (client.available()) { 109 | char c = client.read(); 110 | Serial.write(c); 111 | // if you've gotten to the end of the line (received a newline 112 | // character) and the line is blank, the HTTP request has ended, 113 | // so you can send a reply 114 | if (c == '\n' && currentLineIsBlank) { 115 | // send a standard HTTP response header 116 | client.println("HTTP/1.1 200 OK"); 117 | client.println("Content-Type: text/html"); 118 | client.println("Connection: close"); // the connection will be closed after completion of the response 119 | client.println("Refresh: 5"); // refresh the page automatically every 5 sec 120 | client.println(); 121 | client.println(""); 122 | client.println(""); 123 | // output the value of each analog input pin 124 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 125 | int sensorReading = analogRead(analogChannel); 126 | client.print("analog input "); 127 | client.print(analogChannel); 128 | client.print(" is "); 129 | client.print(sensorReading); 130 | client.println("
"); 131 | } 132 | client.println(""); 133 | break; 134 | } 135 | if (c == '\n') { 136 | // you're starting a new line 137 | currentLineIsBlank = true; 138 | } 139 | else if (c != '\r') { 140 | // you've gotten a character on the current line 141 | currentLineIsBlank = false; 142 | } 143 | } 144 | } 145 | // give the web browser time to receive the data 146 | delay(1); 147 | 148 | // close the connection: 149 | client.stop(); 150 | Serial.println("client disconnected"); 151 | } 152 | } 153 | 154 | 155 | void printWiFiStatus() { 156 | // print the SSID of the network you're attached to: 157 | Serial.print("SSID: "); 158 | Serial.println(WiFi.SSID()); 159 | 160 | // print your WiFi 101 Shield's IP address: 161 | IPAddress ip = WiFi.localIP(); 162 | Serial.print("IP Address: "); 163 | Serial.println(ip); 164 | 165 | // print the received signal strength: 166 | long rssi = WiFi.RSSI(); 167 | Serial.print("signal strength (RSSI):"); 168 | Serial.print(rssi); 169 | Serial.println(" dBm"); 170 | } 171 | -------------------------------------------------------------------------------- /examples/MDNS_WiFiWebServer/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi Web Server 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using a WiFi 101 Shield. 6 | 7 | This example is written to configure the WiFi settings using provisioning mode. 8 | It also sets up an mDNS server so the IP address of the board doesn't have to 9 | be obtained via the serial monitor. 10 | 11 | Circuit: 12 | WiFi 101 Shield attached 13 | Analog inputs attached to pins A0 through A5 (optional) 14 | 15 | created 13 July 2010 16 | by dlf (Metodo2 srl) 17 | modified 31 May 2012 18 | by Tom Igoe 19 | 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | const int ledPin = 6; // LED pin for connectivity status indicator 27 | 28 | char mdnsName[] = "wifi101"; // the MDNS name that the board will respond to 29 | // after WiFi settings have been provisioned 30 | // Note that the actual MDNS name will have '.local' after 31 | // the name above, so "wifi101" will be accessible on 32 | // the MDNS name "wifi101.local". 33 | 34 | WiFiServer server(80); 35 | 36 | // Create a MDNS responder to listen and respond to MDNS name requests. 37 | WiFiMDNSResponder mdnsResponder; 38 | 39 | void setup() { 40 | //Initialize serial: 41 | Serial.begin(9600); 42 | 43 | // check for the presence of the shield: 44 | if (WiFi.status() == WL_NO_SHIELD) { 45 | Serial.println("WiFi 101 Shield not present"); 46 | // don't continue: 47 | while (true); 48 | } 49 | 50 | // configure the LED pin for output mode 51 | pinMode(ledPin, OUTPUT); 52 | 53 | // Start in provisioning mode: 54 | // 1) This will try to connect to a previously associated access point. 55 | // 2) If this fails, an access point named "wifi101-XXXX" will be created, where XXXX 56 | // is the last 4 digits of the boards MAC address. Once you are connected to the access point, 57 | // you can configure an SSID and password by visiting http://wifi101/ 58 | WiFi.beginProvision(); 59 | 60 | while (WiFi.status() != WL_CONNECTED) { 61 | // wait while not connected 62 | 63 | // blink the led to show an unconnected status 64 | digitalWrite(ledPin, HIGH); 65 | delay(500); 66 | digitalWrite(ledPin, LOW); 67 | delay(500); 68 | } 69 | 70 | // connected, make the LED stay on 71 | digitalWrite(ledPin, HIGH); 72 | 73 | server.begin(); 74 | 75 | // Setup the MDNS responder to listen to the configured name. 76 | // NOTE: You _must_ call this _after_ connecting to the WiFi network and 77 | // being assigned an IP address. 78 | if (!mdnsResponder.begin(mdnsName)) { 79 | Serial.println("Failed to start MDNS responder!"); 80 | while(1); 81 | } 82 | 83 | Serial.print("Server listening at http://"); 84 | Serial.print(mdnsName); 85 | Serial.println(".local/"); 86 | 87 | // you're connected now, so print out the status: 88 | printWiFiStatus(); 89 | } 90 | 91 | 92 | void loop() { 93 | // Call the update() function on the MDNS responder every loop iteration to 94 | // make sure it can detect and respond to name requests. 95 | mdnsResponder.poll(); 96 | 97 | // listen for incoming clients 98 | WiFiClient client = server.available(); 99 | if (client) { 100 | Serial.println("new client"); 101 | // an HTTP request ends with a blank line 102 | bool currentLineIsBlank = true; 103 | while (client.connected()) { 104 | if (client.available()) { 105 | char c = client.read(); 106 | Serial.write(c); 107 | // if you've gotten to the end of the line (received a newline 108 | // character) and the line is blank, the HTTP request has ended, 109 | // so you can send a reply 110 | if (c == '\n' && currentLineIsBlank) { 111 | // send a standard HTTP response header 112 | client.println("HTTP/1.1 200 OK"); 113 | client.println("Content-Type: text/html"); 114 | client.println("Connection: close"); // the connection will be closed after completion of the response 115 | client.println("Refresh: 5"); // refresh the page automatically every 5 sec 116 | client.println(); 117 | client.println(""); 118 | client.println(""); 119 | // output the value of each analog input pin 120 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 121 | int sensorReading = analogRead(analogChannel); 122 | client.print("analog input "); 123 | client.print(analogChannel); 124 | client.print(" is "); 125 | client.print(sensorReading); 126 | client.println("
"); 127 | } 128 | client.println(""); 129 | break; 130 | } 131 | if (c == '\n') { 132 | // you're starting a new line 133 | currentLineIsBlank = true; 134 | } 135 | else if (c != '\r') { 136 | // you've gotten a character on the current line 137 | currentLineIsBlank = false; 138 | } 139 | } 140 | } 141 | // give the web browser time to receive the data 142 | delay(1); 143 | 144 | // close the connection: 145 | client.stop(); 146 | Serial.println("client disconnected"); 147 | } 148 | } 149 | 150 | 151 | void printWiFiStatus() { 152 | // print the SSID of the network you're attached to: 153 | Serial.print("SSID: "); 154 | Serial.println(WiFi.SSID()); 155 | 156 | // print your WiFi 101 Shield's IP address: 157 | IPAddress ip = WiFi.localIP(); 158 | Serial.print("IP Address: "); 159 | Serial.println(ip); 160 | 161 | // print the received signal strength: 162 | long rssi = WiFi.RSSI(); 163 | Serial.print("signal strength (RSSI):"); 164 | Serial.print(rssi); 165 | Serial.println(" dBm"); 166 | } 167 | -------------------------------------------------------------------------------- /examples/ScanNetworks/ScanNetworks.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example prints the WiFi 101 Shield's MAC address, and 4 | scans for available WiFi networks using the WiFi 101 Shield. 5 | Every ten seconds, it scans again. It doesn't actually 6 | connect to any network, so no encryption scheme is specified. 7 | 8 | Circuit: 9 | * WiFi 101 Shield attached 10 | 11 | created 13 July 2010 12 | by dlf (Metodo2 srl) 13 | modified 21 Junn 2012 14 | by Tom Igoe and Jaymes Dec 15 | */ 16 | 17 | 18 | #include 19 | #include 20 | 21 | void setup() { 22 | //Initialize serial and wait for port to open: 23 | Serial.begin(9600); 24 | while (!Serial) { 25 | ; // wait for serial port to connect. Needed for native USB port only 26 | } 27 | 28 | // check for the presence of the shield: 29 | if (WiFi.status() == WL_NO_SHIELD) { 30 | Serial.println("WiFi 101 Shield not present"); 31 | // don't continue: 32 | while (true); 33 | } 34 | 35 | // Print WiFi MAC address: 36 | printMacAddress(); 37 | 38 | // scan for existing networks: 39 | Serial.println("Scanning available networks..."); 40 | listNetworks(); 41 | } 42 | 43 | void loop() { 44 | delay(10000); 45 | // scan for existing networks: 46 | Serial.println("Scanning available networks..."); 47 | listNetworks(); 48 | } 49 | 50 | void printMacAddress() { 51 | // the MAC address of your WiFi 101 Shield 52 | byte mac[6]; 53 | 54 | // print your MAC address: 55 | WiFi.macAddress(mac); 56 | Serial.print("MAC: "); 57 | printMacAddress(mac); 58 | } 59 | 60 | void listNetworks() { 61 | // scan for nearby networks: 62 | Serial.println("** Scan Networks **"); 63 | int numSsid = WiFi.scanNetworks(); 64 | if (numSsid == -1) 65 | { 66 | Serial.println("Couldn't get a WiFi connection"); 67 | while (true); 68 | } 69 | 70 | // print the list of networks seen: 71 | Serial.print("number of available networks:"); 72 | Serial.println(numSsid); 73 | 74 | // print the network number and name for each network found: 75 | for (int thisNet = 0; thisNet < numSsid; thisNet++) { 76 | Serial.print(thisNet); 77 | Serial.print(") "); 78 | Serial.print(WiFi.SSID(thisNet)); 79 | Serial.print("\tSignal: "); 80 | Serial.print(WiFi.RSSI(thisNet)); 81 | Serial.print(" dBm"); 82 | Serial.print("\tEncryption: "); 83 | printEncryptionType(WiFi.encryptionType(thisNet)); 84 | Serial.flush(); 85 | } 86 | } 87 | 88 | void printEncryptionType(int thisType) { 89 | // read the encryption type and print out the name: 90 | switch (thisType) { 91 | case ENC_TYPE_WEP: 92 | Serial.println("WEP"); 93 | break; 94 | case ENC_TYPE_TKIP: 95 | Serial.println("WPA"); 96 | break; 97 | case ENC_TYPE_CCMP: 98 | Serial.println("WPA2"); 99 | break; 100 | case ENC_TYPE_NONE: 101 | Serial.println("None"); 102 | break; 103 | case ENC_TYPE_AUTO: 104 | Serial.println("Auto"); 105 | break; 106 | } 107 | } 108 | 109 | void printMacAddress(byte mac[]) { 110 | for (int i = 5; i >= 0; i--) { 111 | if (mac[i] < 16) { 112 | Serial.print("0"); 113 | } 114 | Serial.print(mac[i], HEX); 115 | if (i > 0) { 116 | Serial.print(":"); 117 | } 118 | } 119 | Serial.println(); 120 | } 121 | -------------------------------------------------------------------------------- /examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example prints the WiFi 101 Shield or MKR1000 MAC address, and 4 | scans for available WiFi networks using the WiFi 101 Shield or MKR1000 board. 5 | Every ten seconds, it scans again. It doesn't actually 6 | connect to any network, so no encryption scheme is specified. 7 | BSSID and WiFi channel are printed 8 | 9 | Circuit: 10 | WiFi 101 Shield attached or MKR1000 board 11 | 12 | This example is based on ScanNetworks 13 | 14 | created 1 Mar 2017 15 | by Arturo Guadalupi 16 | */ 17 | 18 | 19 | #include 20 | #include 21 | 22 | void setup() { 23 | //Initialize serial and wait for port to open: 24 | Serial.begin(9600); 25 | while (!Serial) { 26 | ; // wait for serial port to connect. Needed for native USB port only 27 | } 28 | 29 | // check for the presence of the shield: 30 | if (WiFi.status() == WL_NO_SHIELD) { 31 | Serial.println("WiFi 101 Shield not present"); 32 | // don't continue: 33 | while (true); 34 | } 35 | 36 | // print your MAC address: 37 | byte mac[6]; 38 | WiFi.macAddress(mac); 39 | Serial.print("MAC: "); 40 | printMacAddress(mac); 41 | 42 | // scan for existing networks: 43 | Serial.println(); 44 | Serial.println("Scanning available networks..."); 45 | listNetworks(); 46 | } 47 | 48 | void loop() { 49 | delay(10000); 50 | // scan for existing networks: 51 | Serial.println("Scanning available networks..."); 52 | listNetworks(); 53 | } 54 | 55 | void listNetworks() { 56 | // scan for nearby networks: 57 | Serial.println("** Scan Networks **"); 58 | int numSsid = WiFi.scanNetworks(); 59 | if (numSsid == -1) 60 | { 61 | Serial.println("Couldn't get a WiFi connection"); 62 | while (true); 63 | } 64 | 65 | // print the list of networks seen: 66 | Serial.print("number of available networks: "); 67 | Serial.println(numSsid); 68 | 69 | // print the network number and name for each network found: 70 | for (int thisNet = 0; thisNet < numSsid; thisNet++) { 71 | Serial.print(thisNet + 1); 72 | Serial.print(") "); 73 | Serial.print("Signal: "); 74 | Serial.print(WiFi.RSSI(thisNet)); 75 | Serial.print(" dBm"); 76 | Serial.print("\tChannel: "); 77 | Serial.print(WiFi.channel(thisNet)); 78 | byte bssid[6]; 79 | Serial.print("\t\tBSSID: "); 80 | printMacAddress(WiFi.BSSID(thisNet, bssid)); 81 | Serial.print("\tEncryption: "); 82 | printEncryptionType(WiFi.encryptionType(thisNet)); 83 | Serial.print("\t\tSSID: "); 84 | Serial.println(WiFi.SSID(thisNet)); 85 | Serial.flush(); 86 | } 87 | Serial.println(); 88 | } 89 | 90 | void printEncryptionType(int thisType) { 91 | // read the encryption type and print out the name: 92 | switch (thisType) { 93 | case ENC_TYPE_WEP: 94 | Serial.print("WEP"); 95 | break; 96 | case ENC_TYPE_TKIP: 97 | Serial.print("WPA"); 98 | break; 99 | case ENC_TYPE_CCMP: 100 | Serial.print("WPA2"); 101 | break; 102 | case ENC_TYPE_NONE: 103 | Serial.print("None"); 104 | break; 105 | case ENC_TYPE_AUTO: 106 | Serial.print("Auto"); 107 | break; 108 | } 109 | } 110 | 111 | void print2Digits(byte thisByte) { 112 | if (thisByte < 0xF) { 113 | Serial.print("0"); 114 | } 115 | Serial.print(thisByte, HEX); 116 | } 117 | 118 | void printMacAddress(byte mac[]) { 119 | for (int i = 5; i >= 0; i--) { 120 | if (mac[i] < 16) { 121 | Serial.print("0"); 122 | } 123 | Serial.print(mac[i], HEX); 124 | if (i > 0) { 125 | Serial.print(":"); 126 | } 127 | } 128 | Serial.println(); 129 | } 130 | -------------------------------------------------------------------------------- /examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi Web Server LED Blink 3 | 4 | A simple web server that lets you blink an LED via the web. 5 | This sketch will print the IP address of your WiFi 101 Shield (once connected) 6 | to the Serial monitor. From there, you can open that address in a web browser 7 | to turn on and off the LED on pin 9. 8 | 9 | If the IP address of your shield is yourAddress: 10 | http://yourAddress/H turns the LED on 11 | http://yourAddress/L turns it off 12 | 13 | This example is written for a network using WPA encryption. For 14 | WEP or WPA, change the WiFi.begin() call accordingly. 15 | 16 | Circuit: 17 | * WiFi 101 Shield attached 18 | * LED attached to pin 9 19 | 20 | created 25 Nov 2012 21 | by Tom Igoe 22 | */ 23 | #include 24 | #include 25 | 26 | #include "arduino_secrets.h" 27 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 28 | char ssid[] = SECRET_SSID; // your network SSID (name) 29 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 30 | int keyIndex = 0; // your network key Index number (needed only for WEP) 31 | 32 | int status = WL_IDLE_STATUS; 33 | WiFiServer server(80); 34 | 35 | void setup() { 36 | Serial.begin(9600); // initialize serial communication 37 | pinMode(9, OUTPUT); // set the LED pin mode 38 | 39 | // check for the presence of the shield: 40 | if (WiFi.status() == WL_NO_SHIELD) { 41 | Serial.println("WiFi 101 Shield not present"); 42 | while (true); // don't continue 43 | } 44 | 45 | // attempt to connect to WiFi network: 46 | while ( status != WL_CONNECTED) { 47 | Serial.print("Attempting to connect to Network named: "); 48 | Serial.println(ssid); // print the network name (SSID); 49 | 50 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 51 | status = WiFi.begin(ssid, pass); 52 | // wait 10 seconds for connection: 53 | delay(10000); 54 | } 55 | server.begin(); // start the web server on port 80 56 | printWiFiStatus(); // you're connected now, so print out the status 57 | } 58 | 59 | 60 | void loop() { 61 | WiFiClient client = server.available(); // listen for incoming clients 62 | 63 | if (client) { // if you get a client, 64 | Serial.println("new client"); // print a message out the serial port 65 | String currentLine = ""; // make a String to hold incoming data from the client 66 | while (client.connected()) { // loop while the client's connected 67 | if (client.available()) { // if there are bytes to read from the client, 68 | char c = client.read(); // read a byte, then 69 | Serial.write(c); // print it out the serial monitor 70 | if (c == '\n') { // if the byte is a newline character 71 | 72 | // if the current line is blank, you got two newline characters in a row. 73 | // that's the end of the client HTTP request, so send a response: 74 | if (currentLine.length() == 0) { 75 | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) 76 | // and a content-type so the client knows what's coming, then a blank line: 77 | client.println("HTTP/1.1 200 OK"); 78 | client.println("Content-type:text/html"); 79 | client.println(); 80 | 81 | // the content of the HTTP response follows the header: 82 | client.print("Click here turn the LED on pin 9 on
"); 83 | client.print("Click here turn the LED on pin 9 off
"); 84 | 85 | // The HTTP response ends with another blank line: 86 | client.println(); 87 | // break out of the while loop: 88 | break; 89 | } 90 | else { // if you got a newline, then clear currentLine: 91 | currentLine = ""; 92 | } 93 | } 94 | else if (c != '\r') { // if you got anything else but a carriage return character, 95 | currentLine += c; // add it to the end of the currentLine 96 | } 97 | 98 | // Check to see if the client request was "GET /H" or "GET /L": 99 | if (currentLine.endsWith("GET /H")) { 100 | digitalWrite(9, HIGH); // GET /H turns the LED on 101 | } 102 | if (currentLine.endsWith("GET /L")) { 103 | digitalWrite(9, LOW); // GET /L turns the LED off 104 | } 105 | } 106 | } 107 | // close the connection: 108 | client.stop(); 109 | Serial.println("client disconnected"); 110 | } 111 | } 112 | 113 | void printWiFiStatus() { 114 | // print the SSID of the network you're attached to: 115 | Serial.print("SSID: "); 116 | Serial.println(WiFi.SSID()); 117 | 118 | // print your WiFi 101 Shield's IP address: 119 | IPAddress ip = WiFi.localIP(); 120 | Serial.print("IP Address: "); 121 | Serial.println(ip); 122 | 123 | // print the received signal strength: 124 | long rssi = WiFi.RSSI(); 125 | Serial.print("signal strength (RSSI):"); 126 | Serial.print(rssi); 127 | Serial.println(" dBm"); 128 | // print where to go in a browser: 129 | Serial.print("To see this page in action, open a browser to http://"); 130 | Serial.println(ip); 131 | } 132 | -------------------------------------------------------------------------------- /examples/SimpleWebServerWiFi/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiChatServer/WiFiChatServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Chat Server 3 | 4 | A simple server that distributes any incoming messages to all 5 | connected clients. To use telnet to your device's IP address and type. 6 | You can see the client's input in the serial monitor as well. 7 | 8 | This example is written for a network using WPA encryption. For 9 | WEP or WPA, change the WiFi.begin() call accordingly. 10 | 11 | 12 | Circuit: 13 | * WiFi 101 Shield attached 14 | 15 | created 18 Dec 2009 16 | by David A. Mellis 17 | modified 31 May 2012 18 | by Tom Igoe 19 | 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "arduino_secrets.h" 26 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 27 | char ssid[] = SECRET_SSID; // your network SSID (name) 28 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 29 | 30 | int keyIndex = 0; // your network key Index number (needed only for WEP) 31 | 32 | int status = WL_IDLE_STATUS; 33 | 34 | WiFiServer server(23); 35 | 36 | bool alreadyConnected = false; // whether or not the client was connected previously 37 | 38 | void setup() { 39 | //Initialize serial and wait for port to open: 40 | Serial.begin(9600); 41 | while (!Serial) { 42 | ; // wait for serial port to connect. Needed for native USB port only 43 | } 44 | 45 | // check for the presence of the shield: 46 | if (WiFi.status() == WL_NO_SHIELD) { 47 | Serial.println("WiFi 101 Shield not present"); 48 | // don't continue: 49 | while (true); 50 | } 51 | 52 | // attempt to connect to WiFi network: 53 | while ( status != WL_CONNECTED) { 54 | Serial.print("Attempting to connect to SSID: "); 55 | Serial.println(ssid); 56 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 57 | status = WiFi.begin(ssid, pass); 58 | 59 | // wait 10 seconds for connection: 60 | delay(10000); 61 | } 62 | 63 | // start the server: 64 | server.begin(); 65 | // you're connected now, so print out the status: 66 | printWiFiStatus(); 67 | } 68 | 69 | 70 | void loop() { 71 | // wait for a new client: 72 | WiFiClient client = server.available(); 73 | 74 | 75 | // when the client sends the first byte, say hello: 76 | if (client) { 77 | if (!alreadyConnected) { 78 | // clead out the input buffer: 79 | client.flush(); 80 | Serial.println("We have a new client"); 81 | client.println("Hello, client!"); 82 | alreadyConnected = true; 83 | } 84 | 85 | if (client.available() > 0) { 86 | // read the bytes incoming from the client: 87 | char thisChar = client.read(); 88 | // echo the bytes back to the client: 89 | server.write(thisChar); 90 | // echo the bytes to the server as well: 91 | Serial.write(thisChar); 92 | } 93 | } 94 | } 95 | 96 | 97 | void printWiFiStatus() { 98 | // print the SSID of the network you're attached to: 99 | Serial.print("SSID: "); 100 | Serial.println(WiFi.SSID()); 101 | 102 | // print your WiFi 101 Shield's IP address: 103 | IPAddress ip = WiFi.localIP(); 104 | Serial.print("IP Address: "); 105 | Serial.println(ip); 106 | 107 | // print the received signal strength: 108 | long rssi = WiFi.RSSI(); 109 | Serial.print("signal strength (RSSI):"); 110 | Serial.print(rssi); 111 | Serial.println(" dBm"); 112 | } 113 | -------------------------------------------------------------------------------- /examples/WiFiChatServer/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiPing/WiFiPing.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This example connects to a encrypted WiFi network (WPA/WPA2). 4 | Then it prints the MAC address of the WiFi 101 Shield, 5 | the IP address obtained, and other network details. 6 | Then it continuously pings given host specified by IP Address or name. 7 | 8 | Circuit: 9 | WiFi 101 Shield attached / MKR1000 10 | 11 | created 13 July 2010 12 | by dlf (Metodo2 srl) 13 | modified 09 June 2016 14 | by Petar Georgiev 15 | */ 16 | #include 17 | #include 18 | 19 | #include "arduino_secrets.h" 20 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 21 | char ssid[] = SECRET_SSID; // your network SSID (name) 22 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 23 | int status = WL_IDLE_STATUS; // the WiFi radio's status 24 | 25 | // Specify IP address or hostname 26 | String hostName = "www.google.com"; 27 | int pingResult; 28 | 29 | void setup() { 30 | // Initialize serial and wait for port to open: 31 | Serial.begin(9600); 32 | while (!Serial) { 33 | ; // wait for serial port to connect. Needed for native USB port only 34 | } 35 | 36 | // check for the presence of the shield: 37 | if (WiFi.status() == WL_NO_SHIELD) { 38 | Serial.println("WiFi 101 Shield not present"); 39 | // don't continue: 40 | while (true); 41 | } 42 | 43 | // attempt to connect to WiFi network: 44 | while ( status != WL_CONNECTED) { 45 | Serial.print("Attempting to connect to WPA SSID: "); 46 | Serial.println(ssid); 47 | // Connect to WPA/WPA2 network: 48 | status = WiFi.begin(ssid, pass); 49 | 50 | // wait 5 seconds for connection: 51 | delay(5000); 52 | } 53 | 54 | // you're connected now, so print out the data: 55 | Serial.println("You're connected to the network"); 56 | printCurrentNet(); 57 | printWiFiData(); 58 | } 59 | 60 | void loop() { 61 | Serial.print("Pinging "); 62 | Serial.print(hostName); 63 | Serial.print(": "); 64 | 65 | pingResult = WiFi.ping(hostName); 66 | 67 | if (pingResult >= 0) { 68 | Serial.print("SUCCESS! RTT = "); 69 | Serial.print(pingResult); 70 | Serial.println(" ms"); 71 | } else { 72 | Serial.print("FAILED! Error code: "); 73 | Serial.println(pingResult); 74 | } 75 | 76 | delay(5000); 77 | } 78 | 79 | void printWiFiData() { 80 | // print your WiFi 101 Shield's IP address: 81 | IPAddress ip = WiFi.localIP(); 82 | Serial.print("IP address : "); 83 | Serial.println(ip); 84 | 85 | Serial.print("Subnet mask: "); 86 | Serial.println((IPAddress)WiFi.subnetMask()); 87 | 88 | Serial.print("Gateway IP : "); 89 | Serial.println((IPAddress)WiFi.gatewayIP()); 90 | 91 | // print your MAC address: 92 | byte mac[6]; 93 | WiFi.macAddress(mac); 94 | Serial.print("MAC address: "); 95 | printMacAddress(mac); 96 | } 97 | 98 | void printCurrentNet() { 99 | // print the SSID of the network you're attached to: 100 | Serial.print("SSID: "); 101 | Serial.println(WiFi.SSID()); 102 | 103 | // print the MAC address of the router you're attached to: 104 | byte bssid[6]; 105 | WiFi.BSSID(bssid); 106 | Serial.print("BSSID: "); 107 | printMacAddress(bssid); 108 | 109 | // print the received signal strength: 110 | long rssi = WiFi.RSSI(); 111 | Serial.print("signal strength (RSSI): "); 112 | Serial.println(rssi); 113 | 114 | // print the encryption type: 115 | byte encryption = WiFi.encryptionType(); 116 | Serial.print("Encryption Type: "); 117 | Serial.println(encryption, HEX); 118 | Serial.println(); 119 | } 120 | 121 | void printMacAddress(byte mac[]) { 122 | for (int i = 5; i >= 0; i--) { 123 | if (mac[i] < 16) { 124 | Serial.print("0"); 125 | } 126 | Serial.print(mac[i], HEX); 127 | if (i > 0) { 128 | Serial.print(":"); 129 | } 130 | } 131 | Serial.println(); 132 | } 133 | -------------------------------------------------------------------------------- /examples/WiFiPing/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiSSLClient/WiFiSSLClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This example creates a client object that connects and transfers 3 | data using always SSL. 4 | 5 | It is compatible with the methods normally related to plain 6 | connections, like client.connect(host, port). 7 | 8 | Written by Arturo Guadalupi 9 | last revision November 2015 10 | 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include "arduino_secrets.h" 17 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 18 | char ssid[] = SECRET_SSID; // your network SSID (name) 19 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 20 | int keyIndex = 0; // your network key Index number (needed only for WEP) 21 | 22 | int status = WL_IDLE_STATUS; 23 | // if you don't want to use DNS (and reduce your sketch size) 24 | // use the numeric IP instead of the name for the server: 25 | //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) 26 | char server[] = "www.google.com"; // name address for Google (using DNS) 27 | 28 | // Initialize the Ethernet client library 29 | // with the IP address and port of the server 30 | // that you want to connect to (port 80 is default for HTTP): 31 | WiFiSSLClient client; 32 | 33 | void setup() { 34 | //Initialize serial and wait for port to open: 35 | Serial.begin(9600); 36 | while (!Serial) { 37 | ; // wait for serial port to connect. Needed for native USB port only 38 | } 39 | 40 | // check for the presence of the shield: 41 | if (WiFi.status() == WL_NO_SHIELD) { 42 | Serial.println("WiFi 101 Shield not present"); 43 | // don't continue: 44 | while (true); 45 | } 46 | 47 | // attempt to connect to WiFi network: 48 | while (status != WL_CONNECTED) { 49 | Serial.print("Attempting to connect to SSID: "); 50 | Serial.println(ssid); 51 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 52 | status = WiFi.begin(ssid, pass); 53 | 54 | // wait 10 seconds for connection: 55 | delay(10000); 56 | } 57 | Serial.println("Connected to WiFi"); 58 | printWiFiStatus(); 59 | 60 | Serial.println("\nStarting connection to server..."); 61 | // if you get a connection, report back via serial: 62 | if (client.connect(server, 443)) { 63 | Serial.println("connected to server"); 64 | // Make a HTTP request: 65 | client.println("GET /search?q=arduino HTTP/1.1"); 66 | client.println("Host: www.google.com"); 67 | client.println("Connection: close"); 68 | client.println(); 69 | } 70 | } 71 | 72 | void loop() { 73 | // if there are incoming bytes available 74 | // from the server, read them and print them: 75 | while (client.available()) { 76 | char c = client.read(); 77 | Serial.write(c); 78 | } 79 | 80 | // if the server's disconnected, stop the client: 81 | if (!client.connected()) { 82 | Serial.println(); 83 | Serial.println("disconnecting from server."); 84 | client.stop(); 85 | 86 | // do nothing forevermore: 87 | while (true); 88 | } 89 | } 90 | 91 | 92 | void printWiFiStatus() { 93 | // print the SSID of the network you're attached to: 94 | Serial.print("SSID: "); 95 | Serial.println(WiFi.SSID()); 96 | 97 | // print your WiFi 101 Shield's IP address: 98 | IPAddress ip = WiFi.localIP(); 99 | Serial.print("IP Address: "); 100 | Serial.println(ip); 101 | 102 | // print the received signal strength: 103 | long rssi = WiFi.RSSI(); 104 | Serial.print("signal strength (RSSI):"); 105 | Serial.print(rssi); 106 | Serial.println(" dBm"); 107 | } 108 | -------------------------------------------------------------------------------- /examples/WiFiSSLClient/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Udp NTP Client 4 | 5 | Get the time from a Network Time Protocol (NTP) time server 6 | Demonstrates use of UDP sendPacket and ReceivePacket 7 | For more on NTP time servers and the messages needed to communicate with them, 8 | see http://en.wikipedia.org/wiki/Network_Time_Protocol 9 | 10 | created 4 Sep 2010 11 | by Michael Margolis 12 | modified 9 Apr 2012 13 | by Tom Igoe 14 | 15 | This code is in the public domain. 16 | 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int status = WL_IDLE_STATUS; 24 | #include "arduino_secrets.h" 25 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 26 | char ssid[] = SECRET_SSID; // your network SSID (name) 27 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 28 | int keyIndex = 0; // your network key Index number (needed only for WEP) 29 | 30 | unsigned int localPort = 2390; // local port to listen for UDP packets 31 | 32 | IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server 33 | 34 | const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message 35 | 36 | byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 37 | 38 | // A UDP instance to let us send and receive packets over UDP 39 | WiFiUDP Udp; 40 | 41 | void setup() 42 | { 43 | // Open serial communications and wait for port to open: 44 | Serial.begin(9600); 45 | while (!Serial) { 46 | ; // wait for serial port to connect. Needed for native USB port only 47 | } 48 | 49 | // check for the presence of the shield: 50 | if (WiFi.status() == WL_NO_SHIELD) { 51 | Serial.println("WiFi 101 Shield not present"); 52 | // don't continue: 53 | while (true); 54 | } 55 | 56 | // attempt to connect to WiFi network: 57 | while ( status != WL_CONNECTED) { 58 | Serial.print("Attempting to connect to SSID: "); 59 | Serial.println(ssid); 60 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 61 | status = WiFi.begin(ssid, pass); 62 | 63 | // wait 10 seconds for connection: 64 | delay(10000); 65 | } 66 | 67 | Serial.println("Connected to WiFi"); 68 | printWiFiStatus(); 69 | 70 | Serial.println("\nStarting connection to server..."); 71 | Udp.begin(localPort); 72 | } 73 | 74 | void loop() 75 | { 76 | sendNTPpacket(timeServer); // send an NTP packet to a time server 77 | // wait to see if a reply is available 78 | delay(1000); 79 | if ( Udp.parsePacket() ) { 80 | Serial.println("packet received"); 81 | // We've received a packet, read the data from it 82 | Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer 83 | 84 | //the timestamp starts at byte 40 of the received packet and is four bytes, 85 | // or two words, long. First, extract the two words: 86 | 87 | unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); 88 | unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 89 | // combine the four bytes (two words) into a long integer 90 | // this is NTP time (seconds since Jan 1 1900): 91 | unsigned long secsSince1900 = highWord << 16 | lowWord; 92 | Serial.print("Seconds since Jan 1 1900 = " ); 93 | Serial.println(secsSince1900); 94 | 95 | // now convert NTP time into everyday time: 96 | Serial.print("Unix time = "); 97 | // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: 98 | const unsigned long seventyYears = 2208988800UL; 99 | // subtract seventy years: 100 | unsigned long epoch = secsSince1900 - seventyYears; 101 | // print Unix time: 102 | Serial.println(epoch); 103 | 104 | 105 | // print the hour, minute and second: 106 | Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) 107 | Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) 108 | Serial.print(':'); 109 | if ( ((epoch % 3600) / 60) < 10 ) { 110 | // In the first 10 minutes of each hour, we'll want a leading '0' 111 | Serial.print('0'); 112 | } 113 | Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) 114 | Serial.print(':'); 115 | if ( (epoch % 60) < 10 ) { 116 | // In the first 10 seconds of each minute, we'll want a leading '0' 117 | Serial.print('0'); 118 | } 119 | Serial.println(epoch % 60); // print the second 120 | } 121 | // wait ten seconds before asking for the time again 122 | delay(10000); 123 | } 124 | 125 | // send an NTP request to the time server at the given address 126 | unsigned long sendNTPpacket(IPAddress& address) 127 | { 128 | //Serial.println("1"); 129 | // set all bytes in the buffer to 0 130 | memset(packetBuffer, 0, NTP_PACKET_SIZE); 131 | // Initialize values needed to form NTP request 132 | // (see URL above for details on the packets) 133 | //Serial.println("2"); 134 | packetBuffer[0] = 0b11100011; // LI, Version, Mode 135 | packetBuffer[1] = 0; // Stratum, or type of clock 136 | packetBuffer[2] = 6; // Polling Interval 137 | packetBuffer[3] = 0xEC; // Peer Clock Precision 138 | // 8 bytes of zero for Root Delay & Root Dispersion 139 | packetBuffer[12] = 49; 140 | packetBuffer[13] = 0x4E; 141 | packetBuffer[14] = 49; 142 | packetBuffer[15] = 52; 143 | 144 | //Serial.println("3"); 145 | 146 | // all NTP fields have been given values, now 147 | // you can send a packet requesting a timestamp: 148 | Udp.beginPacket(address, 123); //NTP requests are to port 123 149 | //Serial.println("4"); 150 | Udp.write(packetBuffer, NTP_PACKET_SIZE); 151 | //Serial.println("5"); 152 | Udp.endPacket(); 153 | //Serial.println("6"); 154 | } 155 | 156 | 157 | void printWiFiStatus() { 158 | // print the SSID of the network you're attached to: 159 | Serial.print("SSID: "); 160 | Serial.println(WiFi.SSID()); 161 | 162 | // print your WiFi 101 Shield's IP address: 163 | IPAddress ip = WiFi.localIP(); 164 | Serial.print("IP Address: "); 165 | Serial.println(ip); 166 | 167 | // print the received signal strength: 168 | long rssi = WiFi.RSSI(); 169 | Serial.print("signal strength (RSSI):"); 170 | Serial.print(rssi); 171 | Serial.println(" dBm"); 172 | } 173 | -------------------------------------------------------------------------------- /examples/WiFiUdpNtpClient/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi UDP Send and Receive String 3 | 4 | This sketch waits for an UDP packet on localPort using a WiFi 101 Shield. 5 | When a packet is received an Acknowledge packet is sent to the client on port remotePort 6 | 7 | Circuit: 8 | * WiFi 101 Shield attached 9 | 10 | created 30 December 2012 11 | by dlf (Metodo2 srl) 12 | 13 | */ 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | int status = WL_IDLE_STATUS; 21 | #include "arduino_secrets.h" 22 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 23 | char ssid[] = SECRET_SSID; // your network SSID (name) 24 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 25 | int keyIndex = 0; // your network key Index number (needed only for WEP) 26 | 27 | unsigned int localPort = 2390; // local port to listen on 28 | 29 | char packetBuffer[255]; //buffer to hold incoming packet 30 | char ReplyBuffer[] = "acknowledged"; // a string to send back 31 | 32 | WiFiUDP Udp; 33 | 34 | void setup() { 35 | //Initialize serial and wait for port to open: 36 | Serial.begin(9600); 37 | while (!Serial) { 38 | ; // wait for serial port to connect. Needed for native USB port only 39 | } 40 | 41 | // check for the presence of the shield: 42 | if (WiFi.status() == WL_NO_SHIELD) { 43 | Serial.println("WiFi 101 Shield not present"); 44 | // don't continue: 45 | while (true); 46 | } 47 | 48 | // attempt to connect to WiFi network: 49 | while ( status != WL_CONNECTED) { 50 | Serial.print("Attempting to connect to SSID: "); 51 | Serial.println(ssid); 52 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 53 | status = WiFi.begin(ssid, pass); 54 | 55 | // wait 10 seconds for connection: 56 | delay(10000); 57 | } 58 | Serial.println("Connected to WiFi"); 59 | printWiFiStatus(); 60 | 61 | Serial.println("\nStarting connection to server..."); 62 | // if you get a connection, report back via serial: 63 | Udp.begin(localPort); 64 | } 65 | 66 | void loop() { 67 | // if there's data available, read a packet 68 | int packetSize = Udp.parsePacket(); 69 | if (packetSize) 70 | { 71 | Serial.print("Received packet of size "); 72 | Serial.println(packetSize); 73 | Serial.print("From "); 74 | IPAddress remoteIp = Udp.remoteIP(); 75 | Serial.print(remoteIp); 76 | Serial.print(", port "); 77 | Serial.println(Udp.remotePort()); 78 | 79 | // read the packet into packetBufffer 80 | int len = Udp.read(packetBuffer, 255); 81 | if (len > 0) packetBuffer[len] = 0; 82 | Serial.println("Contents:"); 83 | Serial.println(packetBuffer); 84 | 85 | // send a reply, to the IP address and port that sent us the packet we received 86 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 87 | Udp.write(ReplyBuffer); 88 | Udp.endPacket(); 89 | } 90 | } 91 | 92 | 93 | void printWiFiStatus() { 94 | // print the SSID of the network you're attached to: 95 | Serial.print("SSID: "); 96 | Serial.println(WiFi.SSID()); 97 | 98 | // print your WiFi 101 Shield's IP address: 99 | IPAddress ip = WiFi.localIP(); 100 | Serial.print("IP Address: "); 101 | Serial.println(ip); 102 | 103 | // print the received signal strength: 104 | long rssi = WiFi.RSSI(); 105 | Serial.print("signal strength (RSSI):"); 106 | Serial.print(rssi); 107 | Serial.println(" dBm"); 108 | } 109 | -------------------------------------------------------------------------------- /examples/WiFiUdpSendReceiveString/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiWebClient/WiFiWebClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web client 3 | 4 | This sketch connects to a website (http://www.google.com) 5 | using a WiFi 101 Shield. 6 | 7 | This example is written for a network using WPA encryption. For 8 | WEP or WPA, change the WiFi.begin() call accordingly. 9 | 10 | This example is written for a network using WPA encryption. For 11 | WEP or WPA, change the WiFi.begin() call accordingly. 12 | 13 | Circuit: 14 | * WiFi 101 Shield attached 15 | 16 | created 13 July 2010 17 | by dlf (Metodo2 srl) 18 | modified 31 May 2012 19 | by Tom Igoe 20 | */ 21 | 22 | 23 | #include 24 | #include 25 | #include "arduino_secrets.h" 26 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 27 | char ssid[] = SECRET_SSID; // your network SSID (name) 28 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 29 | int keyIndex = 0; // your network key Index number (needed only for WEP) 30 | 31 | int status = WL_IDLE_STATUS; 32 | // if you don't want to use DNS (and reduce your sketch size) 33 | // use the numeric IP instead of the name for the server: 34 | //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) 35 | char server[] = "www.google.com"; // name address for Google (using DNS) 36 | 37 | // Initialize the Ethernet client library 38 | // with the IP address and port of the server 39 | // that you want to connect to (port 80 is default for HTTP): 40 | WiFiClient client; 41 | 42 | void setup() { 43 | //Initialize serial and wait for port to open: 44 | Serial.begin(9600); 45 | while (!Serial) { 46 | ; // wait for serial port to connect. Needed for native USB port only 47 | } 48 | 49 | // check for the presence of the shield: 50 | if (WiFi.status() == WL_NO_SHIELD) { 51 | Serial.println("WiFi 101 Shield not present"); 52 | // don't continue: 53 | while (true); 54 | } 55 | 56 | // attempt to connect to WiFi network: 57 | while (status != WL_CONNECTED) { 58 | Serial.print("Attempting to connect to SSID: "); 59 | Serial.println(ssid); 60 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 61 | status = WiFi.begin(ssid, pass); 62 | 63 | // wait 10 seconds for connection: 64 | delay(10000); 65 | } 66 | Serial.println("Connected to WiFi"); 67 | printWiFiStatus(); 68 | 69 | Serial.println("\nStarting connection to server..."); 70 | // if you get a connection, report back via serial: 71 | if (client.connect(server, 80)) { 72 | Serial.println("connected to server"); 73 | // Make a HTTP request: 74 | client.println("GET /search?q=arduino HTTP/1.1"); 75 | client.println("Host: www.google.com"); 76 | client.println("Connection: close"); 77 | client.println(); 78 | } 79 | } 80 | 81 | void loop() { 82 | // if there are incoming bytes available 83 | // from the server, read them and print them: 84 | while (client.available()) { 85 | char c = client.read(); 86 | Serial.write(c); 87 | } 88 | 89 | // if the server's disconnected, stop the client: 90 | if (!client.connected()) { 91 | Serial.println(); 92 | Serial.println("disconnecting from server."); 93 | client.stop(); 94 | 95 | // do nothing forevermore: 96 | while (true); 97 | } 98 | } 99 | 100 | 101 | void printWiFiStatus() { 102 | // print the SSID of the network you're attached to: 103 | Serial.print("SSID: "); 104 | Serial.println(WiFi.SSID()); 105 | 106 | // print your WiFi 101 Shield's IP address: 107 | IPAddress ip = WiFi.localIP(); 108 | Serial.print("IP Address: "); 109 | Serial.println(ip); 110 | 111 | // print the received signal strength: 112 | long rssi = WiFi.RSSI(); 113 | Serial.print("signal strength (RSSI):"); 114 | Serial.print(rssi); 115 | Serial.println(" dBm"); 116 | } 117 | -------------------------------------------------------------------------------- /examples/WiFiWebClient/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Repeating WiFi Web Client 3 | 4 | This sketch connects to a a web server and makes a request 5 | using an Arduino WiFi 101 Shield. 6 | 7 | Circuit: 8 | * WiFi 101 Shield attached to pins SPI pins and pin 7 9 | 10 | created 23 April 2012 11 | modified 31 May 2012 12 | by Tom Igoe 13 | modified 13 Jan 2014 14 | by Federico Vanzati 15 | 16 | http://arduino.cc/en/Tutorial/WiFiWebClientRepeating 17 | This code is in the public domain. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "arduino_secrets.h" 24 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 25 | char ssid[] = SECRET_SSID; // your network SSID (name) 26 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 27 | int keyIndex = 0; // your network key Index number (needed only for WEP) 28 | 29 | int status = WL_IDLE_STATUS; 30 | 31 | // Initialize the WiFi client library 32 | WiFiClient client; 33 | 34 | // server address: 35 | char server[] = "example.org"; 36 | //IPAddress server(64,131,82,241); 37 | 38 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 39 | const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds 40 | 41 | void setup() { 42 | //Initialize serial and wait for port to open: 43 | Serial.begin(9600); 44 | while (!Serial) { 45 | ; // wait for serial port to connect. Needed for native USB port only 46 | } 47 | 48 | // check for the presence of the shield: 49 | if (WiFi.status() == WL_NO_SHIELD) { 50 | Serial.println("WiFi 101 Shield not present"); 51 | // don't continue: 52 | while (true); 53 | } 54 | 55 | // attempt to connect to WiFi network: 56 | while ( status != WL_CONNECTED) { 57 | Serial.print("Attempting to connect to SSID: "); 58 | Serial.println(ssid); 59 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 60 | status = WiFi.begin(ssid, pass); 61 | 62 | // wait 10 seconds for connection: 63 | delay(10000); 64 | } 65 | // you're connected now, so print out the status: 66 | printWiFiStatus(); 67 | } 68 | 69 | void loop() { 70 | // if there's incoming data from the net connection. 71 | // send it out the serial port. This is for debugging 72 | // purposes only: 73 | while (client.available()) { 74 | char c = client.read(); 75 | Serial.write(c); 76 | } 77 | 78 | // if ten seconds have passed since your last connection, 79 | // then connect again and send data: 80 | if (millis() - lastConnectionTime > postingInterval) { 81 | httpRequest(); 82 | } 83 | 84 | } 85 | 86 | // this method makes a HTTP connection to the server: 87 | void httpRequest() { 88 | // close any connection before sending a new request. 89 | // This will free the socket on the WiFi 101 Shield 90 | client.stop(); 91 | 92 | // if there's a successful connection: 93 | if (client.connect(server, 80)) { 94 | Serial.println("connecting..."); 95 | // send the HTTP PUT request: 96 | client.println("GET / HTTP/1.1"); 97 | client.println("Host: example.org"); 98 | client.println("User-Agent: ArduinoWiFi/1.1"); 99 | client.println("Connection: close"); 100 | client.println(); 101 | 102 | // note the time that the connection was made: 103 | lastConnectionTime = millis(); 104 | } 105 | else { 106 | // if you couldn't make a connection: 107 | Serial.println("connection failed"); 108 | } 109 | } 110 | 111 | 112 | void printWiFiStatus() { 113 | // print the SSID of the network you're attached to: 114 | Serial.print("SSID: "); 115 | Serial.println(WiFi.SSID()); 116 | 117 | // print your WiFi 101 Shield's IP address: 118 | IPAddress ip = WiFi.localIP(); 119 | Serial.print("IP Address: "); 120 | Serial.println(ip); 121 | 122 | // print the received signal strength: 123 | long rssi = WiFi.RSSI(); 124 | Serial.print("signal strength (RSSI):"); 125 | Serial.print(rssi); 126 | Serial.println(" dBm"); 127 | } 128 | -------------------------------------------------------------------------------- /examples/WiFiWebClientRepeating/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /examples/WiFiWebServer/WiFiWebServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi Web Server 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using a WiFi 101 Shield. 6 | 7 | This example is written for a network using WPA encryption. For 8 | WEP or WPA, change the WiFi.begin() call accordingly. 9 | 10 | Circuit: 11 | * WiFi 101 Shield attached 12 | * Analog inputs attached to pins A0 through A5 (optional) 13 | 14 | created 13 July 2010 15 | by dlf (Metodo2 srl) 16 | modified 31 May 2012 17 | by Tom Igoe 18 | 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | 25 | #include "arduino_secrets.h" 26 | ///////please enter your sensitive data in the Secret tab/arduino_secrets.h 27 | char ssid[] = SECRET_SSID; // your network SSID (name) 28 | char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) 29 | int keyIndex = 0; // your network key Index number (needed only for WEP) 30 | 31 | int status = WL_IDLE_STATUS; 32 | 33 | WiFiServer server(80); 34 | 35 | void setup() { 36 | //Initialize serial and wait for port to open: 37 | Serial.begin(9600); 38 | while (!Serial) { 39 | ; // wait for serial port to connect. Needed for native USB port only 40 | } 41 | 42 | // check for the presence of the shield: 43 | if (WiFi.status() == WL_NO_SHIELD) { 44 | Serial.println("WiFi 101 Shield not present"); 45 | // don't continue: 46 | while (true); 47 | } 48 | 49 | // attempt to connect to WiFi network: 50 | while (status != WL_CONNECTED) { 51 | Serial.print("Attempting to connect to SSID: "); 52 | Serial.println(ssid); 53 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 54 | status = WiFi.begin(ssid, pass); 55 | 56 | // wait 10 seconds for connection: 57 | delay(10000); 58 | } 59 | server.begin(); 60 | // you're connected now, so print out the status: 61 | printWiFiStatus(); 62 | } 63 | 64 | 65 | void loop() { 66 | // listen for incoming clients 67 | WiFiClient client = server.available(); 68 | if (client) { 69 | Serial.println("new client"); 70 | // an HTTP request ends with a blank line 71 | bool currentLineIsBlank = true; 72 | while (client.connected()) { 73 | if (client.available()) { 74 | char c = client.read(); 75 | Serial.write(c); 76 | // if you've gotten to the end of the line (received a newline 77 | // character) and the line is blank, the HTTP request has ended, 78 | // so you can send a reply 79 | if (c == '\n' && currentLineIsBlank) { 80 | // send a standard HTTP response header 81 | client.println("HTTP/1.1 200 OK"); 82 | client.println("Content-Type: text/html"); 83 | client.println("Connection: close"); // the connection will be closed after completion of the response 84 | client.println("Refresh: 5"); // refresh the page automatically every 5 sec 85 | client.println(); 86 | client.println(""); 87 | client.println(""); 88 | // output the value of each analog input pin 89 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 90 | int sensorReading = analogRead(analogChannel); 91 | client.print("analog input "); 92 | client.print(analogChannel); 93 | client.print(" is "); 94 | client.print(sensorReading); 95 | client.println("
"); 96 | } 97 | client.println(""); 98 | break; 99 | } 100 | if (c == '\n') { 101 | // you're starting a new line 102 | currentLineIsBlank = true; 103 | } 104 | else if (c != '\r') { 105 | // you've gotten a character on the current line 106 | currentLineIsBlank = false; 107 | } 108 | } 109 | } 110 | // give the web browser time to receive the data 111 | delay(1); 112 | 113 | // close the connection: 114 | client.stop(); 115 | Serial.println("client disconnected"); 116 | } 117 | } 118 | 119 | 120 | void printWiFiStatus() { 121 | // print the SSID of the network you're attached to: 122 | Serial.print("SSID: "); 123 | Serial.println(WiFi.SSID()); 124 | 125 | // print your WiFi 101 Shield's IP address: 126 | IPAddress ip = WiFi.localIP(); 127 | Serial.print("IP Address: "); 128 | Serial.println(ip); 129 | 130 | // print the received signal strength: 131 | long rssi = WiFi.RSSI(); 132 | Serial.print("signal strength (RSSI):"); 133 | Serial.print(rssi); 134 | Serial.println(" dBm"); 135 | } 136 | -------------------------------------------------------------------------------- /examples/WiFiWebServer/arduino_secrets.h: -------------------------------------------------------------------------------- 1 | #define SECRET_SSID "" 2 | #define SECRET_PASS "" 3 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For WiFi101 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | WiFi KEYWORD1 10 | WiFi101 KEYWORD1 11 | Client KEYWORD1 12 | Server KEYWORD1 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | setPins KEYWORD2 19 | status KEYWORD2 20 | connect KEYWORD2 21 | connectSSL KEYWORD2 22 | write KEYWORD2 23 | available KEYWORD2 24 | read KEYWORD2 25 | flush KEYWORD2 26 | stop KEYWORD2 27 | connected KEYWORD2 28 | begin KEYWORD2 29 | beginProvision KEYWORD2 30 | beginOrProvision KEYWORD2 31 | beginMulticast KEYWORD2 32 | disconnect KEYWORD2 33 | macAddress KEYWORD2 34 | localIP KEYWORD2 35 | subnetMask KEYWORD2 36 | gatewayIP KEYWORD2 37 | SSID KEYWORD2 38 | BSSID KEYWORD2 39 | APClientMacAddress KEYWORD2 40 | RSSI KEYWORD2 41 | encryptionType KEYWORD2 42 | channel KEYWORD2 43 | provisioned KEYWORD2 44 | getResult KEYWORD2 45 | getSocket KEYWORD2 46 | poll KEYWORD2 47 | getTime KEYWORD2 48 | hostname KEYWORD2 49 | WiFiClient KEYWORD2 50 | WiFiServer KEYWORD2 51 | WiFiSSLClient KEYWORD2 52 | WiFiMDNSResponder KEYWORD2 53 | 54 | lowPowerMode KEYWORD2 55 | maxLowPowerMode KEYWORD2 56 | noLowPowerMode KEYWORD2 57 | setTimeout KEYWORD2 58 | 59 | ####################################### 60 | # Constants (LITERAL1) 61 | ####################################### 62 | 63 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=WiFi101 2 | version=0.16.1 3 | author=Arduino 4 | maintainer=Arduino 5 | sentence=Network driver for ATMEL WINC1500 module (used on Arduino/Genuino Wifi Shield 101 and MKR1000 boards) 6 | paragraph=This library implements a network driver for devices based on the ATMEL WINC1500 WiFi module 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/WiFi101 9 | architectures=* 10 | includes=WiFi101.h 11 | -------------------------------------------------------------------------------- /src/WiFi101.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 WIFI_H 21 | #define WIFI_H 22 | 23 | #define WIFI_FIRMWARE_LATEST_MODEL_A "19.4.4" 24 | #define WIFI_FIRMWARE_LATEST_MODEL_B "19.6.1" 25 | 26 | // for backwards compatibility 27 | #define WIFI_FIRMWARE_REQUIRED WIFI_FIRMWARE_LATEST_MODEL_B 28 | 29 | #include 30 | 31 | extern "C" { 32 | #include "driver/include/m2m_wifi.h" 33 | } 34 | 35 | #include "WiFiClient.h" 36 | #include "WiFiSSLClient.h" 37 | #include "WiFiServer.h" 38 | 39 | typedef enum { 40 | WL_NO_SHIELD = 255, 41 | WL_IDLE_STATUS = 0, 42 | WL_NO_SSID_AVAIL, 43 | WL_SCAN_COMPLETED, 44 | WL_CONNECTED, 45 | WL_CONNECT_FAILED, 46 | WL_CONNECTION_LOST, 47 | WL_DISCONNECTED, 48 | WL_AP_LISTENING, 49 | WL_AP_CONNECTED, 50 | WL_AP_FAILED, 51 | WL_PROVISIONING, 52 | WL_PROVISIONING_FAILED 53 | } wl_status_t; 54 | 55 | /* Encryption modes */ 56 | enum wl_enc_type { /* Values map to 802.11 encryption suites... */ 57 | ENC_TYPE_WEP = M2M_WIFI_SEC_WEP, 58 | ENC_TYPE_TKIP = M2M_WIFI_SEC_WPA_PSK, 59 | ENC_TYPE_CCMP = M2M_WIFI_SEC_802_1X, 60 | /* ... except these two, 7 and 8 are reserved in 802.11-2007 */ 61 | ENC_TYPE_NONE = M2M_WIFI_SEC_OPEN, 62 | ENC_TYPE_AUTO = M2M_WIFI_SEC_INVALID 63 | }; 64 | 65 | typedef enum { 66 | WL_RESET_MODE = 0, 67 | WL_STA_MODE, 68 | WL_PROV_MODE, 69 | WL_AP_MODE 70 | } wl_mode_t; 71 | 72 | typedef enum { 73 | WL_PING_DEST_UNREACHABLE = -1, 74 | WL_PING_TIMEOUT = -2, 75 | WL_PING_UNKNOWN_HOST = -3, 76 | WL_PING_ERROR = -4 77 | } wl_ping_result_t; 78 | 79 | class WiFiClass 80 | { 81 | public: 82 | WiFiClass(); 83 | 84 | void setPins(int8_t cs, int8_t irq, int8_t rst, int8_t en = -1); 85 | 86 | int init(); 87 | 88 | char* firmwareVersion(); 89 | 90 | /* Start Wifi connection with WPA/WPA2 encryption. 91 | * 92 | * param ssid: Pointer to the SSID string. 93 | * param key: Key input buffer. 94 | */ 95 | uint8_t begin(); 96 | uint8_t begin(const char *ssid); 97 | uint8_t begin(const char *ssid, uint8_t key_idx, const char* key); 98 | uint8_t begin(const char *ssid, const char *key); 99 | uint8_t begin(const String &ssid) { return begin(ssid.c_str()); } 100 | uint8_t begin(const String &ssid, uint8_t key_idx, const String &key) { return begin(ssid.c_str(), key_idx, key.c_str()); } 101 | uint8_t begin(const String &ssid, const String &key) { return begin(ssid.c_str(), key.c_str()); } 102 | 103 | /* Start Wifi in Access Point, with open security. 104 | * Only one client can connect to the AP at a time. 105 | * 106 | * param ssid: Pointer to the SSID string. 107 | * param channel: Wifi channel to use. Valid values are 1-12. 108 | */ 109 | uint8_t beginAP(const char *ssid); 110 | uint8_t beginAP(const char *ssid, uint8_t channel); 111 | uint8_t beginAP(const char *ssid, uint8_t key_idx, const char* key); 112 | uint8_t beginAP(const char *ssid, uint8_t key_idx, const char* key, uint8_t channel); 113 | uint8_t beginAP(const char *ssid, const char* key); 114 | uint8_t beginAP(const char *ssid, const char* key, uint8_t channel); 115 | 116 | uint8_t beginProvision(); 117 | uint8_t beginProvision(uint8_t channel); 118 | 119 | uint32_t provisioned(); 120 | 121 | void config(IPAddress local_ip); 122 | void config(IPAddress local_ip, IPAddress dns_server); 123 | void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway); 124 | void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); 125 | 126 | void hostname(const char* name); 127 | 128 | void disconnect(); 129 | void end(); 130 | 131 | uint8_t *macAddress(uint8_t *mac); 132 | 133 | uint32_t localIP(); 134 | uint32_t subnetMask(); 135 | uint32_t gatewayIP(); 136 | char* SSID(); 137 | int32_t RSSI(); 138 | uint8_t encryptionType(); 139 | uint8_t* BSSID(uint8_t* bssid); 140 | uint8_t* APClientMacAddress(uint8_t* mac); 141 | int8_t scanNetworks(); 142 | char* SSID(uint8_t pos); 143 | int32_t RSSI(uint8_t pos); 144 | uint8_t encryptionType(uint8_t pos); 145 | uint8_t* BSSID(uint8_t pos, uint8_t* bssid); 146 | uint8_t channel(uint8_t pos); 147 | 148 | uint8_t status(); 149 | 150 | int hostByName(const char* hostname, IPAddress& result); 151 | int hostByName(const String &hostname, IPAddress& result) { return hostByName(hostname.c_str(), result); } 152 | 153 | int ping(const char* hostname, uint8_t ttl = 128); 154 | int ping(const String &hostname, uint8_t ttl = 128); 155 | int ping(IPAddress host, uint8_t ttl = 128); 156 | 157 | unsigned long getTime(); 158 | 159 | void refresh(void); 160 | 161 | void lowPowerMode(void); 162 | void maxLowPowerMode(void); 163 | void noLowPowerMode(void); 164 | 165 | void handleEvent(uint8_t u8MsgType, void *pvMsg); 166 | void handleResolve(uint8_t * hostName, uint32_t hostIp); 167 | void handlePingResponse(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode); 168 | void setTimeout(unsigned long timeout); 169 | 170 | private: 171 | int _init; 172 | char _version[9]; 173 | 174 | uint32_t _localip; 175 | uint32_t _submask; 176 | uint32_t _gateway; 177 | int _dhcp; 178 | uint32_t _resolve; 179 | byte *_remoteMacAddress; 180 | wl_mode_t _mode; 181 | wl_status_t _status; 182 | char _scan_ssid[M2M_MAX_SSID_LEN]; 183 | uint8_t _scan_auth; 184 | uint8_t _scan_channel; 185 | char _ssid[M2M_MAX_SSID_LEN]; 186 | unsigned long _timeout; 187 | 188 | uint8_t startConnect(const char *ssid, uint8_t u8SecType, const void *pvAuthInfo); 189 | uint8_t startAP(const char *ssid, uint8_t u8SecType, const void *pvAuthInfo, uint8_t channel); 190 | uint8_t* remoteMacAddress(uint8_t* remoteMacAddress); 191 | 192 | uint8_t startProvision(const char *ssid, const char *url, uint8_t channel); 193 | }; 194 | 195 | extern WiFiClass WiFi; 196 | 197 | #endif /* WIFI_H */ 198 | -------------------------------------------------------------------------------- /src/WiFiClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiClient.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 | #include "utility/WiFiSocket.h" 21 | 22 | #include "WiFi101.h" 23 | #include "WiFiClient.h" 24 | 25 | WiFiClient::WiFiClient() 26 | { 27 | _socket = -1; 28 | } 29 | 30 | WiFiClient::WiFiClient(uint8_t sock) 31 | { 32 | // Spawn connected TCP client from TCP server socket: 33 | _socket = sock; 34 | } 35 | 36 | int WiFiClient::connectSSL(const char* host, uint16_t port) 37 | { 38 | return connect(host, port, SOCKET_FLAGS_SSL); 39 | } 40 | 41 | int WiFiClient::connectSSL(IPAddress ip, uint16_t port) 42 | { 43 | return connect(ip, port, SOCKET_FLAGS_SSL, 0); 44 | } 45 | 46 | int WiFiClient::connect(const char* host, uint16_t port) 47 | { 48 | return connect(host, port, 0); 49 | } 50 | 51 | int WiFiClient::connect(IPAddress ip, uint16_t port) 52 | { 53 | return connect(ip, port, 0, 0); 54 | } 55 | 56 | int WiFiClient::connect(const char* host, uint16_t port, uint8_t opt) 57 | { 58 | IPAddress remote_addr; 59 | if (WiFi.hostByName(host, remote_addr)) { 60 | return connect(remote_addr, port, opt, (const uint8_t *)host); 61 | } 62 | return 0; 63 | } 64 | 65 | int WiFiClient::connect(IPAddress ip, uint16_t port, uint8_t opt, const uint8_t *hostname) 66 | { 67 | struct sockaddr_in addr; 68 | 69 | // Initialize socket address structure: 70 | addr.sin_family = AF_INET; 71 | addr.sin_port = _htons(port); 72 | addr.sin_addr.s_addr = ip; 73 | 74 | if (connected()) { 75 | stop(); 76 | } 77 | 78 | // Create TCP socket: 79 | if ((_socket = WiFiSocket.create(AF_INET, SOCK_STREAM, opt)) < 0) { 80 | return 0; 81 | } 82 | 83 | if (opt & SOCKET_FLAGS_SSL && hostname) { 84 | WiFiSocket.setopt(_socket, SOL_SSL_SOCKET, SO_SSL_SNI, hostname, m2m_strlen((uint8_t *)hostname)); 85 | } 86 | 87 | // Connect to remote host: 88 | if (!WiFiSocket.connect(_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) { 89 | WiFiSocket.close(_socket); 90 | _socket = -1; 91 | return 0; 92 | } 93 | 94 | return 1; 95 | } 96 | 97 | size_t WiFiClient::write(uint8_t b) 98 | { 99 | return write(&b, 1); 100 | } 101 | 102 | size_t WiFiClient::write(const uint8_t *buf, size_t size) 103 | { 104 | if (_socket < 0 || size == 0 || !connected()) { 105 | setWriteError(); 106 | return 0; 107 | } 108 | 109 | int result = WiFiSocket.write(_socket, buf, size); 110 | 111 | if (result <= 0) { 112 | setWriteError(); 113 | return 0; 114 | } 115 | 116 | return size; 117 | } 118 | 119 | int WiFiClient::available() 120 | { 121 | if (_socket == -1) { 122 | return 0; 123 | } 124 | 125 | return WiFiSocket.available(_socket); 126 | } 127 | 128 | int WiFiClient::read() 129 | { 130 | uint8_t b; 131 | 132 | if (read(&b, sizeof(b)) != 1) { 133 | return -1; 134 | } 135 | 136 | return b; 137 | } 138 | 139 | int WiFiClient::read(uint8_t* buf, size_t size) 140 | { 141 | // sizeof(size_t) is architecture dependent 142 | // but we need a 16 bit data type here 143 | uint16_t size_tmp = available(); 144 | 145 | if (size_tmp == 0) { 146 | return -1; 147 | } 148 | 149 | if (size < size_tmp) { 150 | size_tmp = size; 151 | } 152 | 153 | int result = WiFiSocket.read(_socket, buf, size); 154 | 155 | return result; 156 | } 157 | 158 | int WiFiClient::peek() 159 | { 160 | if (!available()) { 161 | return -1; 162 | } 163 | 164 | return WiFiSocket.peek(_socket); 165 | } 166 | 167 | void WiFiClient::flush() 168 | { 169 | } 170 | 171 | void WiFiClient::stop() 172 | { 173 | if (_socket < 0) { 174 | return; 175 | } 176 | 177 | WiFiSocket.close(_socket); 178 | 179 | _socket = -1; 180 | } 181 | 182 | uint8_t WiFiClient::connected() 183 | { 184 | if (_socket < 0) { 185 | return 0; 186 | } 187 | 188 | return WiFiSocket.connected(_socket); 189 | } 190 | 191 | uint8_t WiFiClient::status() 192 | { 193 | // Deprecated. 194 | return 0; 195 | } 196 | 197 | WiFiClient::operator bool() 198 | { 199 | return _socket != -1; 200 | } 201 | 202 | bool WiFiClient::operator==(const WiFiClient &other) const 203 | { 204 | return (_socket == other._socket); 205 | } 206 | 207 | bool WiFiClient::operator!=(const WiFiClient &other) const 208 | { 209 | return (_socket != other._socket); 210 | } 211 | 212 | IPAddress WiFiClient::remoteIP() 213 | { 214 | if (_socket == -1) { 215 | return IPAddress(0, 0, 0, 0); 216 | } 217 | 218 | return WiFiSocket.remoteIP(_socket); 219 | } 220 | 221 | uint16_t WiFiClient::remotePort() 222 | { 223 | if (_socket == -1) { 224 | return 0; 225 | } 226 | 227 | return _htons(WiFiSocket.remotePort(_socket)); 228 | } 229 | -------------------------------------------------------------------------------- /src/WiFiClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiClient.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 WIFICLIENT_H 21 | #define WIFICLIENT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | extern "C" { 28 | #include "socket/include/socket.h" 29 | } 30 | 31 | class WiFiClient : public Client { 32 | 33 | public: 34 | WiFiClient(); 35 | WiFiClient(uint8_t sock); 36 | 37 | uint8_t status(); 38 | 39 | int connectSSL(IPAddress ip, uint16_t port); 40 | int connectSSL(const char* host, uint16_t port); 41 | virtual int connect(IPAddress ip, uint16_t port); 42 | virtual int connect(const char* host, uint16_t port); 43 | virtual size_t write(uint8_t); 44 | virtual size_t write(const uint8_t *buf, size_t size); 45 | virtual int available(); 46 | virtual int read(); 47 | virtual int read(uint8_t *buf, size_t size); 48 | virtual int peek(); 49 | virtual void flush(); 50 | virtual void stop(); 51 | virtual uint8_t connected(); 52 | virtual operator bool(); 53 | bool operator==(const WiFiClient &other) const; 54 | bool operator!=(const WiFiClient &other) const; 55 | 56 | using Print::write; 57 | 58 | virtual IPAddress remoteIP(); 59 | virtual uint16_t remotePort(); 60 | 61 | private: 62 | SOCKET _socket; 63 | 64 | int connect(const char* host, uint16_t port, uint8_t opt); 65 | int connect(IPAddress ip, uint16_t port, uint8_t opt, const uint8_t *hostname); 66 | }; 67 | 68 | #endif /* WIFICLIENT_H */ 69 | -------------------------------------------------------------------------------- /src/WiFiMDNSResponder.h: -------------------------------------------------------------------------------- 1 | // Port of CC3000 MDNS Responder to WINC1500. 2 | // Author: Tony DiCola 3 | // 4 | // This MDNSResponder class implements just enough MDNS functionality to respond 5 | // to name requests, for example 'foo.local'. This does not implement any other 6 | // MDNS or Bonjour functionality like services, etc. 7 | // 8 | // Copyright (c) 2016 Adafruit Industries. All right reserved. 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | 24 | #ifndef WIFIMDNSRESPONDER_H 25 | #define WIFIMDNSRESPONDER_H 26 | 27 | #include "WiFi101.h" 28 | #include "WiFiUdp.h" 29 | 30 | class WiFiMDNSResponder { 31 | public: 32 | WiFiMDNSResponder(); 33 | ~WiFiMDNSResponder(); 34 | bool begin(const char* _name, uint32_t _ttlSeconds = 3600); 35 | void poll(); 36 | 37 | private: 38 | bool parseRequest(); 39 | void replyToRequest(); 40 | 41 | private: 42 | String name; 43 | uint32_t ttlSeconds; 44 | 45 | int minimumExpectedRequestLength; 46 | 47 | // UDP socket for receiving/sending MDNS data. 48 | WiFiUDP udpSocket; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/WiFiSSLClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiSSLClient.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 | #include "WiFiSSLClient.h" 21 | 22 | WiFiSSLClient::WiFiSSLClient() : 23 | WiFiClient() 24 | { 25 | } 26 | 27 | WiFiSSLClient::WiFiSSLClient(uint8_t sock) : 28 | WiFiClient(sock) 29 | { 30 | } 31 | 32 | int WiFiSSLClient::connect(IPAddress ip, uint16_t port) 33 | { 34 | return WiFiClient::connectSSL(ip, port); 35 | } 36 | 37 | int WiFiSSLClient::connect(const char* host, uint16_t port) 38 | { 39 | return WiFiClient::connectSSL(host, port); 40 | } 41 | -------------------------------------------------------------------------------- /src/WiFiSSLClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiSSLClient.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 WIFISSLCLIENT_H 21 | #define WIFISSLCLIENT_H 22 | 23 | #include "WiFiClient.h" 24 | 25 | class WiFiSSLClient : public WiFiClient { 26 | 27 | public: 28 | WiFiSSLClient(); 29 | WiFiSSLClient(uint8_t sock); 30 | 31 | virtual int connect(IPAddress ip, uint16_t port); 32 | virtual int connect(const char* host, uint16_t port); 33 | }; 34 | 35 | #endif /* WIFISSLCLIENT_H */ 36 | -------------------------------------------------------------------------------- /src/WiFiServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiClient.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 | #include "utility/WiFiSocket.h" 21 | 22 | #include "WiFiClient.h" 23 | #include "WiFiServer.h" 24 | 25 | WiFiServer::WiFiServer(uint16_t port) : 26 | _socket(-1) 27 | { 28 | _port = port; 29 | } 30 | 31 | void WiFiServer::begin() 32 | { 33 | begin(0); 34 | } 35 | 36 | uint8_t WiFiServer::beginSSL() 37 | { 38 | return begin(SOCKET_FLAGS_SSL); 39 | } 40 | 41 | uint8_t WiFiServer::begin(uint8_t opt) 42 | { 43 | struct sockaddr_in addr; 44 | 45 | // Initialize socket address structure. 46 | addr.sin_family = AF_INET; 47 | addr.sin_port = _htons(_port); 48 | addr.sin_addr.s_addr = 0; 49 | 50 | if (_socket != -1 && WiFiSocket.listening(_socket)) { 51 | WiFiSocket.close(_socket); 52 | _socket = -1; 53 | } 54 | 55 | // Open TCP server socket. 56 | if ((_socket = WiFiSocket.create(AF_INET, SOCK_STREAM, opt)) < 0) { 57 | return 0; 58 | } 59 | 60 | // Bind socket: 61 | if (!WiFiSocket.bind(_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) { 62 | WiFiSocket.close(_socket); 63 | _socket = -1; 64 | return 0; 65 | } 66 | 67 | // Listen socket: 68 | if (!WiFiSocket.listen(_socket, 0)) { 69 | WiFiSocket.close(_socket); 70 | _socket = -1; 71 | return 0; 72 | } 73 | 74 | return 1; 75 | } 76 | 77 | WiFiClient WiFiServer::available(uint8_t* status) 78 | { 79 | if (status != NULL) { 80 | *status = 0; 81 | } 82 | 83 | if (_socket != -1 && !WiFiSocket.listening(_socket)) { 84 | _socket = -1; 85 | } 86 | 87 | if (_socket != -1) { 88 | SOCKET child = WiFiSocket.accepted(_socket); 89 | 90 | if (child > -1) { 91 | return WiFiClient(child); 92 | } 93 | 94 | for (SOCKET s = 0; s < TCP_SOCK_MAX; s++) { 95 | if (WiFiSocket.hasParent(_socket, s) && WiFiSocket.available(s)) { 96 | return WiFiClient(s); 97 | } 98 | } 99 | } 100 | 101 | return WiFiClient(); 102 | } 103 | 104 | uint8_t WiFiServer::status() { 105 | // Deprecated. 106 | return 0; 107 | } 108 | 109 | size_t WiFiServer::write(uint8_t b) 110 | { 111 | return write(&b, 1); 112 | } 113 | 114 | size_t WiFiServer::write(const uint8_t *buffer, size_t size) 115 | { 116 | if (_socket == -1) { 117 | return 0; 118 | } 119 | 120 | size_t n = 0; 121 | 122 | for (int sock = 0; sock < TCP_SOCK_MAX; sock++) { 123 | if (WiFiSocket.hasParent(_socket, sock)) { 124 | n += WiFiSocket.write(sock, buffer, size); 125 | } 126 | } 127 | 128 | return n; 129 | } 130 | -------------------------------------------------------------------------------- /src/WiFiServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiClient.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 WIFISERVER_H 21 | #define WIFISERVER_H 22 | 23 | #include 24 | #include 25 | 26 | class WiFiClient; 27 | 28 | class WiFiServer : public Server { 29 | 30 | private: 31 | SOCKET _socket; 32 | uint16_t _port; 33 | uint8_t begin(uint8_t opt); 34 | 35 | public: 36 | WiFiServer(uint16_t); 37 | WiFiClient available(uint8_t* status = NULL); 38 | void begin(); 39 | uint8_t beginSSL(); 40 | virtual size_t write(uint8_t); 41 | virtual size_t write(const uint8_t *buf, size_t size); 42 | uint8_t status(); 43 | 44 | using Print::write; 45 | 46 | }; 47 | 48 | #endif /* WIFISERVER_H */ 49 | -------------------------------------------------------------------------------- /src/WiFiUdp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiUdp.cpp - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 | #include 21 | 22 | #include "utility/WiFiSocket.h" 23 | 24 | #include "WiFi101.h" 25 | #include "WiFiUdp.h" 26 | 27 | /* Constructor. */ 28 | WiFiUDP::WiFiUDP() 29 | { 30 | _socket = -1; 31 | _sndSize = 0; 32 | _parsedPacketSize = 0; 33 | } 34 | 35 | /* Start WiFiUDP socket, listening at local port PORT */ 36 | uint8_t WiFiUDP::begin(uint16_t port) 37 | { 38 | struct sockaddr_in addr; 39 | uint32 u32EnableCallbacks = 0; 40 | 41 | _sndSize = 0; 42 | _parsedPacketSize = 0; 43 | 44 | // Initialize socket address structure. 45 | addr.sin_family = AF_INET; 46 | addr.sin_port = _htons(port); 47 | addr.sin_addr.s_addr = 0; 48 | 49 | if (_socket != -1 && WiFiSocket.bound(_socket)) { 50 | WiFiSocket.close(_socket); 51 | _socket = -1; 52 | } 53 | 54 | // Open UDP server socket. 55 | if ((_socket = WiFiSocket.create(AF_INET, SOCK_DGRAM, 0)) < 0) { 56 | return 0; 57 | } 58 | 59 | WiFiSocket.setopt(_socket, SOL_SOCKET, SO_SET_UDP_SEND_CALLBACK, &u32EnableCallbacks, 0); 60 | 61 | // Bind socket: 62 | if (!WiFiSocket.bind(_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) { 63 | WiFiSocket.close(_socket); 64 | _socket = -1; 65 | return 0; 66 | } 67 | 68 | return 1; 69 | } 70 | 71 | uint8_t WiFiUDP::beginMulticast(IPAddress ip, uint16_t port) 72 | { 73 | uint32_t multiIp = ip; 74 | 75 | if (!begin(port)) { 76 | return 0; 77 | } 78 | 79 | setsockopt(_socket, SOL_SOCKET, IP_ADD_MEMBERSHIP, &multiIp, sizeof(multiIp)); 80 | 81 | return 1; 82 | } 83 | 84 | /* return number of bytes available in the current packet, 85 | will return zero if parsePacket hasn't been called yet */ 86 | int WiFiUDP::available() 87 | { 88 | if (_socket == -1) { 89 | return 0; 90 | } 91 | 92 | if (_parsedPacketSize <= 0) { 93 | return 0; 94 | } 95 | 96 | return WiFiSocket.available(_socket); 97 | } 98 | 99 | /* Release any resources being used by this WiFiUDP instance */ 100 | void WiFiUDP::stop() 101 | { 102 | if (_socket == -1) { 103 | return; 104 | } 105 | 106 | WiFiSocket.close(_socket); 107 | _socket = -1; 108 | } 109 | 110 | int WiFiUDP::beginPacket(const char *host, uint16_t port) 111 | { 112 | IPAddress ip; 113 | 114 | if (WiFi.hostByName(host, ip)) { 115 | return beginPacket(ip, port); 116 | } 117 | 118 | return 0; 119 | } 120 | 121 | int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) 122 | { 123 | _sndIP = ip; 124 | _sndPort = port; 125 | _sndSize = 0; 126 | 127 | return 1; 128 | } 129 | 130 | int WiFiUDP::endPacket() 131 | { 132 | struct sockaddr_in addr; 133 | 134 | addr.sin_family = AF_INET; 135 | addr.sin_port = _htons(_sndPort); 136 | addr.sin_addr.s_addr = _sndIP; 137 | 138 | int result = WiFiSocket.sendto(_socket, (void *)_sndBuffer, _sndSize, 0, (struct sockaddr *)&addr, sizeof(addr)); 139 | 140 | return (result < 0) ? 0 : 1; 141 | } 142 | 143 | size_t WiFiUDP::write(uint8_t byte) 144 | { 145 | return write(&byte, 1); 146 | } 147 | 148 | size_t WiFiUDP::write(const uint8_t *buffer, size_t size) 149 | { 150 | if ((size + _sndSize) > sizeof(_sndBuffer)) { 151 | size = sizeof(_sndBuffer) - _sndSize; 152 | } 153 | 154 | memcpy(_sndBuffer + _sndSize, buffer, size); 155 | 156 | _sndSize += size; 157 | 158 | return size; 159 | } 160 | 161 | int WiFiUDP::parsePacket() 162 | { 163 | if (_socket == -1) { 164 | return 0; 165 | } 166 | 167 | if (_parsedPacketSize > 0) { 168 | // previously parsed data, discard data 169 | while (available()) { 170 | read(); 171 | } 172 | } 173 | 174 | _parsedPacketSize = WiFiSocket.available(_socket); 175 | 176 | return _parsedPacketSize; 177 | } 178 | 179 | int WiFiUDP::read() 180 | { 181 | uint8_t b; 182 | 183 | if (read(&b, sizeof(b)) != 1) { 184 | return -1; 185 | } 186 | 187 | return b; 188 | } 189 | 190 | int WiFiUDP::read(unsigned char* buf, size_t size) 191 | { 192 | // sizeof(size_t) is architecture dependent 193 | // but we need a 16 bit data type here 194 | uint16_t size_tmp = available(); 195 | 196 | if (size_tmp == 0) { 197 | return -1; 198 | } 199 | 200 | if (size < size_tmp) { 201 | size_tmp = size; 202 | } 203 | 204 | int result = WiFiSocket.read(_socket, buf, size); 205 | 206 | if (result > 0) { 207 | _parsedPacketSize -= result; 208 | } 209 | 210 | return result; 211 | } 212 | 213 | int WiFiUDP::peek() 214 | { 215 | if (!available()) { 216 | return -1; 217 | } 218 | 219 | return WiFiSocket.peek(_socket); 220 | } 221 | 222 | void WiFiUDP::flush() 223 | { 224 | } 225 | 226 | IPAddress WiFiUDP::remoteIP() 227 | { 228 | if (_socket == -1) { 229 | return IPAddress(0, 0, 0, 0); 230 | } 231 | 232 | return WiFiSocket.remoteIP(_socket); 233 | } 234 | 235 | uint16_t WiFiUDP::remotePort() 236 | { 237 | if (_socket == -1) { 238 | return 0; 239 | } 240 | 241 | return _htons(WiFiSocket.remotePort(_socket)); 242 | } 243 | -------------------------------------------------------------------------------- /src/WiFiUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiUdp.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 WIFIUDP_H 21 | #define WIFIUDP_H 22 | 23 | extern "C" { 24 | #include "socket/include/socket.h" 25 | } 26 | 27 | #include 28 | 29 | #if defined LIMITED_RAM_DEVICE 30 | #define SOCKET_BUFFER_UDP_SIZE (64u) 31 | #else 32 | #define SOCKET_BUFFER_UDP_SIZE (SOCKET_BUFFER_MAX_LENGTH) 33 | #endif 34 | 35 | class WiFiUDP : public UDP { 36 | private: 37 | SOCKET _socket; 38 | int _parsedPacketSize; 39 | uint8_t _sndBuffer[SOCKET_BUFFER_UDP_SIZE]; 40 | uint16_t _sndSize; 41 | uint16_t _sndPort; 42 | uint32_t _sndIP; 43 | 44 | public: 45 | WiFiUDP(); // Constructor 46 | virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use 47 | virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use 48 | virtual uint8_t beginMulti(IPAddress ip, uint16_t port) { return beginMulticast(ip, port); } 49 | virtual void stop(); // Finish with the UDP socket 50 | 51 | // Sending UDP packets 52 | 53 | // Start building up a packet to send to the remote host specific in ip and port 54 | // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port 55 | virtual int beginPacket(IPAddress ip, uint16_t port); 56 | // Start building up a packet to send to the remote host specific in host and port 57 | // Returns 1 if successful, 0 if there was a problem resolving the hostname or port 58 | virtual int beginPacket(const char *host, uint16_t port); 59 | // Finish off this packet and send it 60 | // Returns 1 if the packet was sent successfully, 0 if there was an error 61 | virtual int endPacket(); 62 | // Write a single byte into the packet 63 | virtual size_t write(uint8_t); 64 | // Write size bytes from buffer into the packet 65 | virtual size_t write(const uint8_t *buffer, size_t size); 66 | 67 | using Print::write; 68 | 69 | // Start processing the next available incoming packet 70 | // Returns the size of the packet in bytes, or 0 if no packets are available 71 | virtual int parsePacket(); 72 | // Number of bytes remaining in the current packet 73 | virtual int available(); 74 | // Read a single byte from the current packet 75 | virtual int read(); 76 | // Read up to len bytes from the current packet and place them into buffer 77 | // Returns the number of bytes read, or 0 if none are available 78 | virtual int read(unsigned char* buffer, size_t len); 79 | // Read up to len characters from the current packet and place them into buffer 80 | // Returns the number of characters read, or 0 if none are available 81 | virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); }; 82 | // Return the next byte from the current packet without moving on to the next byte 83 | virtual int peek(); 84 | virtual void flush(); // Finish reading the current packet 85 | 86 | // Return the IP address of the host who sent the current incoming packet 87 | virtual IPAddress remoteIP(); 88 | // Return the port of the host who sent the current incoming packet 89 | virtual uint16_t remotePort(); 90 | 91 | }; 92 | 93 | #endif /* WIFIUDP_H */ 94 | -------------------------------------------------------------------------------- /src/bsp/include/nm_bsp_arduino.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1500 BSP APIs definitions. 6 | * 7 | * Copyright (c) 2015 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NM_BSP_ARDUINO_H_ 43 | #define _NM_BSP_ARDUINO_H_ 44 | 45 | #include 46 | 47 | #include 48 | 49 | /* 50 | * Arduino variants may redefine those pins. 51 | * If no pins are specified the following defaults are used: 52 | * WINC1501_RESET_PIN - pin 5 53 | * WINC1501_INTN_PIN - pin 7 54 | * WINC1501_CHIP_EN_PIN - not connected (tied to VCC) 55 | */ 56 | #if !defined(WINC1501_RESET_PIN) 57 | #define WINC1501_RESET_PIN 5 58 | #endif 59 | #if !defined(WINC1501_INTN_PIN) 60 | #define WINC1501_INTN_PIN 7 61 | #endif 62 | #if !defined(WINC1501_SPI_CS_PIN) 63 | #define WINC1501_SPI_CS_PIN 10 64 | #endif 65 | #if !defined(WINC1501_CHIP_EN_PIN) 66 | #define WINC1501_CHIP_EN_PIN -1 67 | #endif 68 | 69 | extern int8_t gi8Winc1501CsPin; 70 | extern int8_t gi8Winc1501ResetPin; 71 | extern int8_t gi8Winc1501IntnPin; 72 | extern int8_t gi8Winc1501ChipEnPin; 73 | 74 | #endif /* _NM_BSP_ARDUINO_H_ */ 75 | -------------------------------------------------------------------------------- /src/bsp/include/nm_bsp_avr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1500 BSP APIs definitions. 6 | * 7 | * Copyright (c) 2015 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NM_BSP_AVR_H_ 43 | #define _NM_BSP_AVR_H_ 44 | 45 | #pragma once 46 | 47 | #define NM_DEBUG 0 48 | #define NM_BSP_PRINTF 49 | 50 | #define CONF_WINC_USE_SPI 1 51 | 52 | #define NM_EDGE_INTERRUPT 1 53 | 54 | #endif /* _NM_BSP_AVR_H_ */ 55 | -------------------------------------------------------------------------------- /src/bsp/include/nm_bsp_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1500 BSP APIs declarations. 6 | * 7 | * Copyright (c) 2015 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | /**@defgroup BSPDefine Defines 42 | * @ingroup nm_bsp 43 | * @{ 44 | */ 45 | #ifndef _NM_BSP_INTERNAL_H_ 46 | #define _NM_BSP_INTERNAL_H_ 47 | 48 | #ifdef ARDUINO_ARCH_AVR 49 | #define LIMITED_RAM_DEVICE 50 | #include "bsp/include/nm_bsp_avr.h" 51 | #else 52 | #include "bsp/include/nm_bsp_samd21.h" 53 | #endif 54 | 55 | #if defined(ARDUINO) && !defined(ARDUINO_SAMD_MKR1000) 56 | #define CONF_PERIPH 57 | #endif 58 | 59 | #endif //_NM_BSP_INTERNAL_H_ -------------------------------------------------------------------------------- /src/bsp/include/nm_bsp_samd21.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1500 BSP APIs definitions. 6 | * 7 | * Copyright (c) 2015 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NM_BSP_SAMD21_H_ 43 | #define _NM_BSP_SAMD21_H_ 44 | 45 | #define NM_DEBUG 0 46 | #define NM_BSP_PRINTF 47 | 48 | #define CONF_WINC_USE_SPI 1 49 | 50 | #define NM_EDGE_INTERRUPT 1 51 | 52 | #endif /* _NM_BSP_SAMD21_H_ */ 53 | -------------------------------------------------------------------------------- /src/bsp/source/nm_bsp_arduino.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains SAMD21 BSP APIs implementation. 6 | * 7 | * Copyright (c) 2014 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * 4. This software may only be redistributed and used in connection with an 27 | * Atmel microcontroller product. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 32 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 33 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | * POSSIBILITY OF SUCH DAMAGE. 40 | * 41 | * \asf_license_stop 42 | * 43 | */ 44 | 45 | #include "bsp/include/nm_bsp.h" 46 | #include "bsp/include/nm_bsp_arduino.h" 47 | #include "common/include/nm_common.h" 48 | 49 | int8_t gi8Winc1501CsPin = WINC1501_SPI_CS_PIN; 50 | int8_t gi8Winc1501ResetPin = WINC1501_RESET_PIN; 51 | int8_t gi8Winc1501IntnPin = WINC1501_INTN_PIN; 52 | int8_t gi8Winc1501ChipEnPin = WINC1501_CHIP_EN_PIN; 53 | 54 | static tpfNmBspIsr gpfIsr; 55 | 56 | void __attribute__((weak)) attachInterruptMultiArch(uint32_t pin, void *chip_isr, uint32_t mode) 57 | { 58 | attachInterrupt(pin, chip_isr, mode); 59 | } 60 | 61 | void __attribute__((weak)) detachInterruptMultiArch(uint32_t pin) 62 | { 63 | detachInterrupt(pin); 64 | } 65 | 66 | static void chip_isr(void) 67 | { 68 | if (gpfIsr) { 69 | gpfIsr(); 70 | } 71 | } 72 | 73 | /* 74 | * @fn init_chip_pins 75 | * @brief Initialize reset, chip enable and wake pin 76 | * @author M.S.M 77 | * @date 11 July 2012 78 | * @version 1.0 79 | */ 80 | static void init_chip_pins(void) 81 | { 82 | if (gi8Winc1501ResetPin > -1) 83 | { 84 | /* Configure RESETN pin as output. */ 85 | pinMode(gi8Winc1501ResetPin, OUTPUT); 86 | digitalWrite(gi8Winc1501ResetPin, HIGH); 87 | } 88 | 89 | /* Configure INTN pins as input. */ 90 | pinMode(gi8Winc1501IntnPin, INPUT); 91 | 92 | if (gi8Winc1501ChipEnPin > -1) 93 | { 94 | /* Configure CHIP_EN as pull-up */ 95 | pinMode(gi8Winc1501ChipEnPin, INPUT_PULLUP); 96 | } 97 | } 98 | 99 | static void deinit_chip_pins(void) 100 | { 101 | if (gi8Winc1501ResetPin > -1) 102 | { 103 | digitalWrite(gi8Winc1501ResetPin, LOW); 104 | pinMode(gi8Winc1501ResetPin, INPUT); 105 | } 106 | 107 | if (gi8Winc1501ChipEnPin > -1) 108 | { 109 | pinMode(gi8Winc1501ChipEnPin, INPUT); 110 | } 111 | } 112 | 113 | /* 114 | * @fn nm_bsp_init 115 | * @brief Initialize BSP 116 | * @return 0 in case of success and -1 in case of failure 117 | * @author M.S.M 118 | * @date 11 July 2012 119 | * @version 1.0 120 | */ 121 | sint8 nm_bsp_init(void) 122 | { 123 | gpfIsr = NULL; 124 | 125 | init_chip_pins(); 126 | 127 | nm_bsp_reset(); 128 | 129 | return M2M_SUCCESS; 130 | } 131 | 132 | /** 133 | * @fn nm_bsp_deinit 134 | * @brief De-iInitialize BSP 135 | * @return 0 in case of success and -1 in case of failure 136 | * @author M. Abdelmawla 137 | * @date 11 July 2012 138 | * @version 1.0 139 | */ 140 | sint8 nm_bsp_deinit(void) 141 | { 142 | deinit_chip_pins(); 143 | 144 | return M2M_SUCCESS; 145 | } 146 | 147 | /** 148 | * @fn nm_bsp_reset 149 | * @brief Reset NMC1500 SoC by setting CHIP_EN and RESET_N signals low, 150 | * CHIP_EN high then RESET_N high 151 | * @author M. Abdelmawla 152 | * @date 11 July 2012 153 | * @version 1.0 154 | */ 155 | void nm_bsp_reset(void) 156 | { 157 | if (gi8Winc1501ResetPin > -1) 158 | { 159 | digitalWrite(gi8Winc1501ResetPin, LOW); 160 | nm_bsp_sleep(100); 161 | digitalWrite(gi8Winc1501ResetPin, HIGH); 162 | nm_bsp_sleep(100); 163 | } 164 | } 165 | 166 | /* 167 | * @fn nm_bsp_sleep 168 | * @brief Sleep in units of mSec 169 | * @param[IN] u32TimeMsec 170 | * Time in milliseconds 171 | * @author M.S.M 172 | * @date 28 OCT 2013 173 | * @version 1.0 174 | */ 175 | void nm_bsp_sleep(uint32 u32TimeMsec) 176 | { 177 | while (u32TimeMsec--) { 178 | delay(1); 179 | } 180 | } 181 | 182 | /* 183 | * @fn nm_bsp_register_isr 184 | * @brief Register interrupt service routine 185 | * @param[IN] pfIsr 186 | * Pointer to ISR handler 187 | * @author M.S.M 188 | * @date 28 OCT 2013 189 | * @sa tpfNmBspIsr 190 | * @version 1.0 191 | */ 192 | void nm_bsp_register_isr(tpfNmBspIsr pfIsr) 193 | { 194 | gpfIsr = pfIsr; 195 | attachInterruptMultiArch(gi8Winc1501IntnPin, chip_isr, FALLING); 196 | } 197 | 198 | /* 199 | * @fn nm_bsp_interrupt_ctrl 200 | * @brief Enable/Disable interrupts 201 | * @param[IN] u8Enable 202 | * '0' disable interrupts. '1' enable interrupts 203 | * @author M.S.M 204 | * @date 28 OCT 2013 205 | * @version 1.0 206 | */ 207 | void nm_bsp_interrupt_ctrl(uint8 u8Enable) 208 | { 209 | if (u8Enable) { 210 | attachInterruptMultiArch(gi8Winc1501IntnPin, chip_isr, FALLING); 211 | } else { 212 | detachInterruptMultiArch(gi8Winc1501IntnPin); 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/bsp/source/nm_bsp_arduino_avr.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains SAMD21 BSP APIs implementation. 6 | * 7 | * Copyright (c) 2014 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * 4. This software may only be redistributed and used in connection with an 27 | * Atmel microcontroller product. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 32 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 33 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | * POSSIBILITY OF SUCH DAMAGE. 40 | * 41 | * \asf_license_stop 42 | * 43 | */ 44 | 45 | #ifdef ARDUINO_ARCH_AVR 46 | 47 | #include "bsp/include/nm_bsp.h" 48 | #include "bsp/include/nm_bsp_arduino.h" 49 | #include "common/include/nm_common.h" 50 | 51 | #define IS_MEGA (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)) 52 | 53 | static tpfNmBspIsr gpfIsr; 54 | 55 | volatile uint8_t *_receivePortRegister; 56 | volatile uint8_t *_pcint_maskreg; 57 | uint8_t _receiveBitMask; 58 | volatile uint8_t prev_pin_read = 1; 59 | 60 | uint8_t rx_pin_read() 61 | { 62 | return *_receivePortRegister & _receiveBitMask; 63 | } 64 | 65 | #if !IS_MEGA 66 | 67 | #if defined(PCINT0_vect) 68 | ISR(PCINT0_vect) 69 | { 70 | if (!rx_pin_read() && gpfIsr) 71 | { 72 | gpfIsr(); 73 | } 74 | } 75 | #endif 76 | 77 | #if defined(PCINT1_vect) 78 | ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect)); 79 | #endif 80 | 81 | #if defined(PCINT2_vect) 82 | ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect)); 83 | #endif 84 | 85 | #if defined(PCINT3_vect) 86 | ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect)); 87 | #endif 88 | 89 | #endif // !IS_MEGA 90 | 91 | #if defined(TIMER4_OVF_vect) 92 | ISR(TIMER4_OVF_vect) { 93 | uint8_t curr_pin_read = rx_pin_read(); 94 | if ((curr_pin_read != prev_pin_read) && !curr_pin_read && gpfIsr) 95 | { 96 | gpfIsr(); 97 | } 98 | prev_pin_read = curr_pin_read; 99 | } 100 | 101 | // stategy 3 - start a timer and perform a sort of polling 102 | void attachFakeInterruptToTimer(void) { 103 | TCCR4B = (1< I2C/UART. Parameter:tstrNmI2cDefault/tstrNmUartDefault */ 57 | #define NM_BUS_IOCTL_W ((uint8)1) /*!< Write only ==> I2C/UART. Parameter type tstrNmI2cDefault/tstrNmUartDefault*/ 58 | #define NM_BUS_IOCTL_W_SPECIAL ((uint8)2) /*!< Write two buffers within the same transaction 59 | (same start/stop conditions) ==> I2C only. Parameter:tstrNmI2cSpecial */ 60 | #define NM_BUS_IOCTL_RW ((uint8)3) /*!< Read/Write at the same time ==> SPI only. Parameter:tstrNmSpiRw */ 61 | 62 | #define NM_BUS_IOCTL_WR_RESTART ((uint8)4) /*!< Write buffer then made restart condition then read ==> I2C only. parameter:tstrNmI2cSpecial */ 63 | /** 64 | * @struct tstrNmBusCapabilities 65 | * @brief Structure holding bus capabilities information 66 | * @sa NM_BUS_TYPE_I2C, NM_BUS_TYPE_SPI 67 | */ 68 | typedef struct 69 | { 70 | uint16 u16MaxTrxSz; /*!< Maximum transfer size. Must be >= 16 bytes*/ 71 | } tstrNmBusCapabilities; 72 | 73 | /** 74 | * @struct tstrNmI2cDefault 75 | * @brief Structure holding I2C default operation parameters 76 | * @sa NM_BUS_IOCTL_R, NM_BUS_IOCTL_W 77 | */ 78 | typedef struct 79 | { 80 | uint8 u8SlaveAdr; 81 | uint8 *pu8Buf; /*!< Operation buffer */ 82 | uint16 u16Sz; /*!< Operation size */ 83 | } tstrNmI2cDefault; 84 | 85 | /** 86 | * @struct tstrNmI2cSpecial 87 | * @brief Structure holding I2C special operation parameters 88 | * @sa NM_BUS_IOCTL_W_SPECIAL 89 | */ 90 | typedef struct 91 | { 92 | uint8 u8SlaveAdr; 93 | uint8 *pu8Buf1; /*!< pointer to the 1st buffer */ 94 | uint8 *pu8Buf2; /*!< pointer to the 2nd buffer */ 95 | uint16 u16Sz1; /*!< 1st buffer size */ 96 | uint16 u16Sz2; /*!< 2nd buffer size */ 97 | } tstrNmI2cSpecial; 98 | 99 | /** 100 | * @struct tstrNmSpiRw 101 | * @brief Structure holding SPI R/W parameters 102 | * @sa NM_BUS_IOCTL_RW 103 | */ 104 | typedef struct 105 | { 106 | uint8 *pu8InBuf; /*!< pointer to input buffer. 107 | Can be set to null and in this case zeros should be sent at MOSI */ 108 | uint8 *pu8OutBuf; /*!< pointer to output buffer. 109 | Can be set to null and in this case data from MISO can be ignored */ 110 | uint16 u16Sz; /*!< Transfere size */ 111 | } tstrNmSpiRw; 112 | 113 | 114 | /** 115 | * @struct tstrNmUartDefault 116 | * @brief Structure holding UART default operation parameters 117 | * @sa NM_BUS_IOCTL_R, NM_BUS_IOCTL_W 118 | */ 119 | typedef struct 120 | { 121 | uint8 *pu8Buf; /*!< Operation buffer */ 122 | uint16 u16Sz; /*!< Operation size */ 123 | } tstrNmUartDefault; 124 | /*!< Bus capabilities. This structure must be declared at platform specific bus wrapper */ 125 | extern tstrNmBusCapabilities egstrNmBusCapabilities; 126 | 127 | 128 | #ifdef __cplusplus 129 | extern "C" { 130 | #endif 131 | /** 132 | * @fn nm_bus_init 133 | * @brief Initialize the bus wrapper 134 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 135 | */ 136 | sint8 nm_bus_init(void *); 137 | 138 | /** 139 | * @fn nm_bus_ioctl 140 | * @brief send/receive from the bus 141 | * @param [in] u8Cmd 142 | * IOCTL command for the operation 143 | * @param [in] pvParameter 144 | * Arbitrary parameter depending on IOCTL 145 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 146 | * @note For SPI only, it's important to be able to send/receive at the same time 147 | */ 148 | sint8 nm_bus_ioctl(uint8 u8Cmd, void* pvParameter); 149 | 150 | /** 151 | * @fn nm_bus_deinit 152 | * @brief De-initialize the bus wrapper 153 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 154 | */ 155 | sint8 nm_bus_deinit(void); 156 | 157 | /* 158 | * @fn nm_bus_reinit 159 | * @brief re-initialize the bus wrapper 160 | * @param [in] void *config 161 | * re-init configuration data 162 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 163 | */ 164 | sint8 nm_bus_reinit(void *); 165 | /* 166 | * @fn nm_bus_get_chip_type 167 | * @brief get chip type 168 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 169 | */ 170 | #ifdef CONF_WINC_USE_UART 171 | uint8 nm_bus_get_chip_type(void); 172 | #endif 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif /*_NM_BUS_WRAPPER_H_*/ 178 | -------------------------------------------------------------------------------- /src/bus_wrapper/source/nm_bus_wrapper_samd21.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1000 bus wrapper APIs implementation. 6 | * 7 | * Copyright (c) 2014 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * 4. This software may only be redistributed and used in connection with an 27 | * Atmel microcontroller product. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 32 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 33 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | * POSSIBILITY OF SUCH DAMAGE. 40 | * 41 | * \asf_license_stop 42 | * 43 | */ 44 | 45 | #include 46 | #include 47 | 48 | /* 49 | * Variants may define an alternative SPI instace to use for WiFi101. 50 | * If not defined the following defaults are used: 51 | * WINC1501_SPI - SPI 52 | */ 53 | #if !defined(WINC1501_SPI) 54 | #define WINC1501_SPI SPI 55 | #endif 56 | 57 | extern "C" { 58 | 59 | #include "bsp/include/nm_bsp.h" 60 | #include "bsp/include/nm_bsp_arduino.h" 61 | #include "common/include/nm_common.h" 62 | #include "bus_wrapper/include/nm_bus_wrapper.h" 63 | 64 | } 65 | 66 | #define NM_BUS_MAX_TRX_SZ 256 67 | 68 | tstrNmBusCapabilities egstrNmBusCapabilities = 69 | { 70 | NM_BUS_MAX_TRX_SZ 71 | }; 72 | 73 | static const SPISettings wifi_SPISettings(12000000L, MSBFIRST, SPI_MODE0); 74 | 75 | static sint8 spi_rw(uint8* pu8Mosi, uint8* pu8Miso, uint16 u16Sz) 76 | { 77 | uint8 u8Dummy = 0; 78 | uint8 u8SkipMosi = 0, u8SkipMiso = 0; 79 | 80 | if (!pu8Mosi) { 81 | pu8Mosi = &u8Dummy; 82 | u8SkipMosi = 1; 83 | } 84 | else if(!pu8Miso) { 85 | pu8Miso = &u8Dummy; 86 | u8SkipMiso = 1; 87 | } 88 | else { 89 | return M2M_ERR_BUS_FAIL; 90 | } 91 | 92 | WINC1501_SPI.beginTransaction(wifi_SPISettings); 93 | digitalWrite(gi8Winc1501CsPin, LOW); 94 | 95 | while (u16Sz) { 96 | *pu8Miso = WINC1501_SPI.transfer(*pu8Mosi); 97 | 98 | u16Sz--; 99 | if (!u8SkipMiso) 100 | pu8Miso++; 101 | if (!u8SkipMosi) 102 | pu8Mosi++; 103 | } 104 | 105 | digitalWrite(gi8Winc1501CsPin, HIGH); 106 | WINC1501_SPI.endTransaction(); 107 | 108 | return M2M_SUCCESS; 109 | } 110 | 111 | extern "C" { 112 | 113 | /* 114 | * @fn nm_bus_init 115 | * @brief Initialize the bus wrapper 116 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 117 | * @author M.S.M 118 | * @date 28 oct 2013 119 | * @version 1.0 120 | */ 121 | sint8 nm_bus_init(void * /* pvInitValue */) 122 | { 123 | sint8 result = M2M_SUCCESS; 124 | 125 | /* Configure SPI peripheral. */ 126 | WINC1501_SPI.begin(); 127 | 128 | /* Configure CS PIN. */ 129 | pinMode(gi8Winc1501CsPin, OUTPUT); 130 | digitalWrite(gi8Winc1501CsPin, HIGH); 131 | 132 | /* Reset WINC1500. */ 133 | nm_bsp_reset(); 134 | nm_bsp_sleep(1); 135 | 136 | return result; 137 | } 138 | 139 | /* 140 | * @fn nm_bus_ioctl 141 | * @brief send/receive from the bus 142 | * @param[IN] u8Cmd 143 | * IOCTL command for the operation 144 | * @param[IN] pvParameter 145 | * Arbitrary parameter depenging on IOCTL 146 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 147 | * @author M.S.M 148 | * @date 28 oct 2013 149 | * @note For SPI only, it's important to be able to send/receive at the same time 150 | * @version 1.0 151 | */ 152 | sint8 nm_bus_ioctl(uint8 u8Cmd, void* pvParameter) 153 | { 154 | sint8 s8Ret = 0; 155 | switch(u8Cmd) 156 | { 157 | case NM_BUS_IOCTL_RW: { 158 | tstrNmSpiRw *pstrParam = (tstrNmSpiRw *)pvParameter; 159 | s8Ret = spi_rw(pstrParam->pu8InBuf, pstrParam->pu8OutBuf, pstrParam->u16Sz); 160 | } 161 | break; 162 | default: 163 | s8Ret = -1; 164 | M2M_ERR("invalide ioclt cmd\n"); 165 | break; 166 | } 167 | 168 | return s8Ret; 169 | } 170 | 171 | /* 172 | * @fn nm_bus_deinit 173 | * @brief De-initialize the bus wrapper 174 | * @author M.S.M 175 | * @date 28 oct 2013 176 | * @version 1.0 177 | */ 178 | sint8 nm_bus_deinit(void) 179 | { 180 | WINC1501_SPI.end(); 181 | return 0; 182 | } 183 | 184 | /* 185 | * @fn nm_bus_reinit 186 | * @brief re-initialize the bus wrapper 187 | * @param [in] void *config 188 | * re-init configuration data 189 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 190 | * @author Dina El Sissy 191 | * @date 19 Sept 2012 192 | * @version 1.0 193 | */ 194 | sint8 nm_bus_reinit(void* /* config */) 195 | { 196 | return M2M_SUCCESS; 197 | } 198 | 199 | } // extern "C" 200 | 201 | -------------------------------------------------------------------------------- /src/common/include/nm_common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief WINC Driver Common API Declarations. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NM_COMMON_H_ 43 | #define _NM_COMMON_H_ 44 | 45 | #include "bsp/include/nm_bsp.h" 46 | #include "common/include/nm_debug.h" 47 | 48 | /**@defgroup CommonDefines CommonDefines 49 | * @ingroup WlanDefines 50 | */ 51 | /**@{*/ 52 | #define M2M_TIME_OUT_DELAY 10000 53 | 54 | /*states*/ 55 | #define M2M_SUCCESS ((sint8)0) 56 | #define M2M_ERR_SEND ((sint8)-1) 57 | #define M2M_ERR_RCV ((sint8)-2) 58 | #define M2M_ERR_MEM_ALLOC ((sint8)-3) 59 | #define M2M_ERR_TIME_OUT ((sint8)-4) 60 | #define M2M_ERR_INIT ((sint8)-5) 61 | #define M2M_ERR_BUS_FAIL ((sint8)-6) 62 | #define M2M_NOT_YET ((sint8)-7) 63 | #define M2M_ERR_FIRMWARE ((sint8)-8) 64 | #define M2M_SPI_FAIL ((sint8)-9) 65 | #define M2M_ERR_FIRMWARE_bURN ((sint8)-10) 66 | #define M2M_ACK ((sint8)-11) 67 | #define M2M_ERR_FAIL ((sint8)-12) 68 | #define M2M_ERR_FW_VER_MISMATCH ((sint8)-13) 69 | #define M2M_ERR_SCAN_IN_PROGRESS ((sint8)-14) 70 | #define M2M_ERR_INVALID_ARG ((sint8)-15) 71 | #define M2M_ERR_INVALID ((sint8)-16) 72 | 73 | /*i2c MAASTER ERR*/ 74 | #define I2C_ERR_LARGE_ADDRESS 0xE1UL /*the address exceed the max addressing mode in i2c flash*/ 75 | #define I2C_ERR_TX_ABRT 0xE2UL /*NO ACK from slave*/ 76 | #define I2C_ERR_OVER_SIZE 0xE3UL /**/ 77 | #define ERR_PREFIX_NMIS 0xE4UL /*wrong first four byte in flash NMIS*/ 78 | #define ERR_FIRMEWARE_EXCEED_SIZE 0xE5UL /*Total size of firmware exceed the max size 256k*/ 79 | /**/ 80 | #define PROGRAM_START 0x26961735UL 81 | #define BOOT_SUCCESS 0x10add09eUL 82 | #define BOOT_START 0x12345678UL 83 | 84 | 85 | #define NBIT31 (0x80000000) 86 | #define NBIT30 (0x40000000) 87 | #define NBIT29 (0x20000000) 88 | #define NBIT28 (0x10000000) 89 | #define NBIT27 (0x08000000) 90 | #define NBIT26 (0x04000000) 91 | #define NBIT25 (0x02000000) 92 | #define NBIT24 (0x01000000) 93 | #define NBIT23 (0x00800000) 94 | #define NBIT22 (0x00400000) 95 | #define NBIT21 (0x00200000) 96 | #define NBIT20 (0x00100000) 97 | #define NBIT19 (0x00080000) 98 | #define NBIT18 (0x00040000) 99 | #define NBIT17 (0x00020000) 100 | #define NBIT16 (0x00010000) 101 | #define NBIT15 (0x00008000) 102 | #define NBIT14 (0x00004000) 103 | #define NBIT13 (0x00002000) 104 | #define NBIT12 (0x00001000) 105 | #define NBIT11 (0x00000800) 106 | #define NBIT10 (0x00000400) 107 | #define NBIT9 (0x00000200) 108 | #define NBIT8 (0x00000100) 109 | #define NBIT7 (0x00000080) 110 | #define NBIT6 (0x00000040) 111 | #define NBIT5 (0x00000020) 112 | #define NBIT4 (0x00000010) 113 | #define NBIT3 (0x00000008) 114 | #define NBIT2 (0x00000004) 115 | #define NBIT1 (0x00000002) 116 | #define NBIT0 (0x00000001) 117 | 118 | #define M2M_MAX(A,B) ((A) > (B) ? (A) : (B)) 119 | #define M2M_SEL(x,m1,m2,m3) ((x>1)?((x>2)?(m3):(m2)):(m1)) 120 | #define WORD_ALIGN(val) (((val) & 0x03) ? ((val) + 4 - ((val) & 0x03)) : (val)) 121 | 122 | 123 | 124 | #define DATA_PKT_OFFSET 4 125 | 126 | #ifndef BIG_ENDIAN 127 | #define BYTE_0(word) ((uint8)(((word) >> 0 ) & 0x000000FFUL)) 128 | #define BYTE_1(word) ((uint8)(((word) >> 8 ) & 0x000000FFUL)) 129 | #define BYTE_2(word) ((uint8)(((word) >> 16) & 0x000000FFUL)) 130 | #define BYTE_3(word) ((uint8)(((word) >> 24) & 0x000000FFUL)) 131 | #else 132 | #define BYTE_0(word) ((uint8)(((word) >> 24) & 0x000000FFUL)) 133 | #define BYTE_1(word) ((uint8)(((word) >> 16) & 0x000000FFUL)) 134 | #define BYTE_2(word) ((uint8)(((word) >> 8 ) & 0x000000FFUL)) 135 | #define BYTE_3(word) ((uint8)(((word) >> 0 ) & 0x000000FFUL)) 136 | #endif 137 | 138 | /**@}*/ 139 | #ifdef __cplusplus 140 | extern "C" { 141 | #endif 142 | NMI_API void m2m_memcpy(uint8* pDst,uint8* pSrc,uint32 sz); 143 | NMI_API void m2m_memset(uint8* pBuf,uint8 val,uint32 sz); 144 | NMI_API uint16 m2m_strlen(uint8 * pcStr); 145 | NMI_API sint8 m2m_memcmp(uint8 *pu8Buff1,uint8 *pu8Buff2 ,uint32 u32Size); 146 | NMI_API uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len); 147 | NMI_API uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr); 148 | NMI_API uint8 m2m_checksum(uint8* buf, int sz); 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | #endif /*_NM_COMMON_H_*/ 154 | -------------------------------------------------------------------------------- /src/common/include/nm_debug.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains debug APIs declarations. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NM_DEBUG_H_ 43 | #define _NM_DEBUG_H_ 44 | 45 | #include "bsp/include/nm_bsp.h" 46 | #include "bsp/include/nm_bsp_internal.h" 47 | 48 | /**@defgroup DebugDefines DebugDefines 49 | * @ingroup WlanDefines 50 | */ 51 | /**@{*/ 52 | 53 | 54 | #define M2M_LOG_NONE 0 55 | #define M2M_LOG_ERROR 1 56 | #define M2M_LOG_INFO 2 57 | #define M2M_LOG_REQ 3 58 | #define M2M_LOG_DBG 4 59 | 60 | #if (defined __APS3_CORTUS__) 61 | #define M2M_LOG_LEVEL M2M_LOG_INFO 62 | #else 63 | #define M2M_LOG_LEVEL M2M_LOG_REQ 64 | #endif 65 | 66 | 67 | #define M2M_ERR(...) 68 | #define M2M_INFO(...) 69 | #define M2M_REQ(...) 70 | #define M2M_DBG(...) 71 | #define M2M_PRINT(...) 72 | 73 | #if (CONF_WINC_DEBUG == 1) 74 | #undef M2M_PRINT 75 | #define M2M_PRINT(...) do{CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) 76 | #if (M2M_LOG_LEVEL >= M2M_LOG_ERROR) 77 | #undef M2M_ERR 78 | #define M2M_ERR(...) do{CONF_WINC_PRINTF("(APP)(ERR)[%s][%d]",__FUNCTION__,__LINE__); CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) 79 | #if (M2M_LOG_LEVEL >= M2M_LOG_INFO) 80 | #undef M2M_INFO 81 | #define M2M_INFO(...) do{CONF_WINC_PRINTF("(APP)(INFO)"); CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) 82 | #if (M2M_LOG_LEVEL >= M2M_LOG_REQ) 83 | #undef M2M_REQ 84 | #define M2M_REQ(...) do{CONF_WINC_PRINTF("(APP)(R)"); CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) 85 | #if (M2M_LOG_LEVEL >= M2M_LOG_DBG) 86 | #undef M2M_DBG 87 | #define M2M_DBG(...) do{CONF_WINC_PRINTF("(APP)(DBG)[%s][%d]",__FUNCTION__,__LINE__); CONF_WINC_PRINTF(__VA_ARGS__);CONF_WINC_PRINTF("\r");}while(0) 88 | #endif /*M2M_LOG_DBG*/ 89 | #endif /*M2M_LOG_REQ*/ 90 | #endif /*M2M_LOG_INFO*/ 91 | #endif /*M2M_LOG_ERROR*/ 92 | #endif /*CONF_WINC_DEBUG */ 93 | 94 | /**@}*/ 95 | #endif /* _NM_DEBUG_H_ */ 96 | -------------------------------------------------------------------------------- /src/common/source/nm_common.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains common APIs declarations. 6 | * 7 | * Copyright (c) 2016 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | #include "common/include/nm_common.h" 42 | 43 | void m2m_memcpy(uint8* pDst,uint8* pSrc,uint32 sz) 44 | { 45 | if(sz == 0) return; 46 | do 47 | { 48 | *pDst = *pSrc; 49 | pDst++; 50 | pSrc++; 51 | }while(--sz); 52 | } 53 | uint8 m2m_checksum(uint8* buf, int sz) 54 | { 55 | uint8 cs = 0; 56 | while(--sz) 57 | { 58 | cs ^= *buf; 59 | buf++; 60 | } 61 | 62 | return cs; 63 | } 64 | 65 | void m2m_memset(uint8* pBuf,uint8 val,uint32 sz) 66 | { 67 | if(sz == 0) return; 68 | do 69 | { 70 | *pBuf = val; 71 | pBuf++; 72 | }while(--sz); 73 | } 74 | 75 | uint16 m2m_strlen(uint8 * pcStr) 76 | { 77 | uint16 u16StrLen = 0; 78 | while(*pcStr) 79 | { 80 | u16StrLen ++; 81 | pcStr++; 82 | } 83 | return u16StrLen; 84 | } 85 | 86 | uint8 m2m_strncmp(uint8 *pcS1, uint8 *pcS2, uint16 u16Len) 87 | { 88 | for ( ; u16Len > 0; pcS1++, pcS2++, --u16Len) 89 | if (*pcS1 != *pcS2) 90 | return ((*(uint8 *)pcS1 < *(uint8 *)pcS2) ? -1 : +1); 91 | else if (*pcS1 == '\0') 92 | return 0; 93 | return 0; 94 | } 95 | 96 | /* Finds the occurance of pcStr in pcIn. 97 | If pcStr is part of pcIn it returns a valid pointer to the start of pcStr within pcIn. 98 | Otherwise a NULL Pointer is returned. 99 | */ 100 | uint8 * m2m_strstr(uint8 *pcIn, uint8 *pcStr) 101 | { 102 | uint8 u8c; 103 | uint16 u16StrLen; 104 | 105 | u8c = *pcStr++; 106 | if (!u8c) 107 | return (uint8 *) pcIn; // Trivial empty string case 108 | 109 | u16StrLen = m2m_strlen(pcStr); 110 | do { 111 | uint8 u8Sc; 112 | 113 | do { 114 | u8Sc = *pcIn++; 115 | if (!u8Sc) 116 | return (uint8 *) 0; 117 | } while (u8Sc != u8c); 118 | } while (m2m_strncmp(pcIn, pcStr, u16StrLen) != 0); 119 | 120 | return (uint8 *) (pcIn - 1); 121 | } 122 | 123 | sint8 m2m_memcmp(uint8 *pu8Buff1,uint8 *pu8Buff2 ,uint32 u32Size) 124 | { 125 | uint32 i; 126 | sint8 s8Result = 0; 127 | for(i = 0 ; i < u32Size ; i++) 128 | { 129 | if(pu8Buff1[i] != pu8Buff2[i]) 130 | { 131 | s8Result = 1; 132 | break; 133 | } 134 | } 135 | return s8Result; 136 | } 137 | -------------------------------------------------------------------------------- /src/driver/source/m2m_periph.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief NMC1500 Peripherials Application Interface. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | 43 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 44 | INCLUDES 45 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 46 | 47 | #include "driver/include/m2m_periph.h" 48 | #include "driver/source/nmasic.h" 49 | #include "m2m_hif.h" 50 | 51 | #ifdef CONF_PERIPH 52 | 53 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 54 | MACROS 55 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 56 | #define GPIO_OP_DIR 0 57 | #define GPIO_OP_SET 1 58 | #define GPIO_OP_GET 2 59 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 60 | DATA TYPES 61 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 62 | 63 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 64 | STATIC FUNCTIONS 65 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 66 | static sint8 get_gpio_idx(uint8 u8GpioNum) 67 | { 68 | if(u8GpioNum >= M2M_PERIPH_GPIO_MAX) return -1; 69 | if(u8GpioNum == M2M_PERIPH_GPIO15) { return 15; 70 | } else if(u8GpioNum == M2M_PERIPH_GPIO16) { return 16; 71 | } else if(u8GpioNum == M2M_PERIPH_GPIO18) { return 18; 72 | } else if(u8GpioNum == M2M_PERIPH_GPIO3) { return 3; 73 | } else if(u8GpioNum == M2M_PERIPH_GPIO4) { return 4; 74 | } else if(u8GpioNum == M2M_PERIPH_GPIO5) { return 5; 75 | } else if(u8GpioNum == M2M_PERIPH_GPIO6) { return 6; 76 | } else { 77 | return -2; 78 | } 79 | } 80 | /* 81 | * GPIO read/write skeleton with wakeup/sleep capability. 82 | */ 83 | static sint8 gpio_ioctl(uint8 op, uint8 u8GpioNum, uint8 u8InVal, uint8 * pu8OutVal) 84 | { 85 | sint8 ret, gpio; 86 | 87 | ret = hif_chip_wake(); 88 | if(ret != M2M_SUCCESS) goto _EXIT; 89 | 90 | gpio = get_gpio_idx(u8GpioNum); 91 | if(gpio < 0) goto _EXIT1; 92 | 93 | if(op == GPIO_OP_DIR) { 94 | ret = set_gpio_dir((uint8)gpio, u8InVal); 95 | } else if(op == GPIO_OP_SET) { 96 | ret = set_gpio_val((uint8)gpio, u8InVal); 97 | } else if(op == GPIO_OP_GET) { 98 | ret = get_gpio_val((uint8)gpio, pu8OutVal); 99 | } 100 | if(ret != M2M_SUCCESS) goto _EXIT1; 101 | 102 | _EXIT1: 103 | ret = hif_chip_sleep(); 104 | _EXIT: 105 | return ret; 106 | } 107 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 108 | FUNCTION IMPLEMENTATION 109 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 110 | 111 | 112 | sint8 m2m_periph_init(tstrPerphInitParam * param) 113 | { 114 | #ifdef ARDUINO 115 | (void)param; // Silence "unused" warning 116 | #endif 117 | return M2M_SUCCESS; 118 | } 119 | 120 | sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir) 121 | { 122 | return gpio_ioctl(GPIO_OP_DIR, u8GpioNum, u8GpioDir, NULL); 123 | } 124 | 125 | sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal) 126 | { 127 | return gpio_ioctl(GPIO_OP_SET, u8GpioNum, u8GpioVal, NULL); 128 | } 129 | 130 | sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 * pu8GpioVal) 131 | { 132 | return gpio_ioctl(GPIO_OP_GET, u8GpioNum, 0, pu8GpioVal); 133 | } 134 | 135 | sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn) 136 | { 137 | #ifdef ARDUINO 138 | (void)u8GpioNum; // Silence "unused" warning 139 | (void)u8PullupEn; 140 | #endif 141 | /* TBD */ 142 | return M2M_SUCCESS; 143 | } 144 | 145 | sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam * param) 146 | { 147 | #ifdef ARDUINO 148 | // Silence "unused" warning 149 | (void)param; 150 | #endif 151 | /* TBD */ 152 | return M2M_SUCCESS; 153 | } 154 | 155 | sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint8 flags) 156 | { 157 | #ifdef ARDUINO 158 | // Silence "unused" warning 159 | (void)u8SlaveAddr; 160 | (void)pu8Buf; 161 | (void)u16BufLen; 162 | (void)flags; 163 | #endif 164 | /* TBD */ 165 | return M2M_SUCCESS; 166 | } 167 | 168 | sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 * pu8Buf, uint16 u16BufLen, uint16 * pu16ReadLen, uint8 flags) 169 | { 170 | #ifdef ARDUINO 171 | // Silence "unused" warning 172 | (void)u8SlaveAddr; 173 | (void)pu8Buf; 174 | (void)u16BufLen; 175 | (void)pu16ReadLen; 176 | (void)flags; 177 | #endif 178 | /* TBD */ 179 | return M2M_SUCCESS; 180 | } 181 | 182 | 183 | sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable) 184 | { 185 | return pullup_ctrl(pinmask, enable); 186 | } 187 | #endif /* CONF_PERIPH */ -------------------------------------------------------------------------------- /src/driver/source/nmasic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1500 ASIC specific internal APIs. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | #ifndef _NMASIC_H_ 42 | #define _NMASIC_H_ 43 | 44 | #include "common/include/nm_common.h" 45 | 46 | #define NMI_PERIPH_REG_BASE 0x1000 47 | #define NMI_CHIPID (NMI_PERIPH_REG_BASE) 48 | #define rNMI_GP_REG_0 (0x149c) 49 | #define rNMI_GP_REG_1 (0x14A0) 50 | #define rNMI_GP_REG_2 (0xc0008) 51 | #define rNMI_GLB_RESET (0x1400) 52 | #define rNMI_BOOT_RESET_MUX (0x1118) 53 | #define NMI_STATE_REG (0x108c) 54 | #define BOOTROM_REG (0xc000c) 55 | #define NMI_REV_REG (0x207ac) /*Also, Used to load ATE firmware from SPI Flash and to ensure that it is running too*/ 56 | #define NMI_REV_REG_ATE (0x1048) /*Revision info register in case of ATE FW*/ 57 | #define M2M_WAIT_FOR_HOST_REG (0x207bc) 58 | #define M2M_FINISH_INIT_STATE 0x02532636UL 59 | #define M2M_FINISH_BOOT_ROM 0x10add09eUL 60 | #define M2M_START_FIRMWARE 0xef522f61UL 61 | #define M2M_START_PS_FIRMWARE 0x94992610UL 62 | 63 | #define M2M_ATE_FW_START_VALUE (0x3C1CD57D) /*Also, Change this value in boot_firmware if it will be changed here*/ 64 | #define M2M_ATE_FW_IS_UP_VALUE (0xD75DC1C3) /*Also, Change this value in ATE (Burst) firmware if it will be changed here*/ 65 | 66 | #define REV_2B0 (0x2B0) 67 | #define REV_B0 (0x2B0) 68 | #define REV_3A0 (0x3A0) 69 | #define GET_CHIPID() nmi_get_chipid() 70 | #define ISNMC1000(id) ((((id) & 0xfffff000) == 0x100000) ? 1 : 0) 71 | #define ISNMC1500(id) ((((id) & 0xfffff000) == 0x150000) ? 1 : 0) 72 | #define ISNMC3000(id) ((((id) & 0xfff00000) == 0x300000) ? 1 : 0) 73 | #define REV(id) (((id) & 0x00000fff )) 74 | #define EFUSED_MAC(value) (value & 0xffff0000) 75 | 76 | #define rHAVE_SDIO_IRQ_GPIO_BIT (NBIT0) 77 | #define rHAVE_USE_PMU_BIT (NBIT1) 78 | #define rHAVE_SLEEP_CLK_SRC_RTC_BIT (NBIT2) 79 | #define rHAVE_SLEEP_CLK_SRC_XO_BIT (NBIT3) 80 | #define rHAVE_EXT_PA_INV_TX_RX (NBIT4) 81 | #define rHAVE_LEGACY_RF_SETTINGS (NBIT5) 82 | #define rHAVE_LOGS_DISABLED_BIT (NBIT6) 83 | #define rHAVE_ETHERNET_MODE_BIT (NBIT7) 84 | #define rHAVE_RESERVED1_BIT (NBIT8) 85 | 86 | typedef struct{ 87 | uint32 u32Mac_efuse_mib; 88 | uint32 u32Firmware_Ota_rev; 89 | }tstrGpRegs; 90 | 91 | #ifdef __cplusplus 92 | extern "C" { 93 | #endif 94 | 95 | /* 96 | * @fn cpu_halt 97 | * @brief 98 | */ 99 | sint8 cpu_halt(void); 100 | /* 101 | * @fn chip_sleep 102 | * @brief 103 | */ 104 | sint8 chip_sleep(void); 105 | /* 106 | * @fn chip_wake 107 | * @brief 108 | */ 109 | sint8 chip_wake(void); 110 | /* 111 | * @fn chip_idle 112 | * @brief 113 | */ 114 | void chip_idle(void); 115 | /* 116 | * @fn enable_interrupts 117 | * @brief 118 | */ 119 | sint8 enable_interrupts(void); 120 | /* 121 | * @fn cpu_start 122 | * @brief 123 | */ 124 | sint8 cpu_start(void); 125 | /* 126 | * @fn nmi_get_chipid 127 | * @brief 128 | */ 129 | uint32 nmi_get_chipid(void); 130 | /* 131 | * @fn nmi_get_rfrevid 132 | * @brief 133 | */ 134 | uint32 nmi_get_rfrevid(void); 135 | /* 136 | * @fn restore_pmu_settings_after_global_reset 137 | * @brief 138 | */ 139 | void restore_pmu_settings_after_global_reset(void); 140 | /* 141 | * @fn nmi_update_pll 142 | * @brief 143 | */ 144 | void nmi_update_pll(void); 145 | /* 146 | * @fn nmi_set_sys_clk_src_to_xo 147 | * @brief 148 | */ 149 | void nmi_set_sys_clk_src_to_xo(void); 150 | /* 151 | * @fn chip_reset 152 | * @brief 153 | */ 154 | sint8 chip_reset(void); 155 | /* 156 | * @fn wait_for_bootrom 157 | * @brief 158 | */ 159 | sint8 wait_for_bootrom(uint8); 160 | /* 161 | * @fn wait_for_firmware_start 162 | * @brief 163 | */ 164 | sint8 wait_for_firmware_start(uint8); 165 | /* 166 | * @fn chip_deinit 167 | * @brief 168 | */ 169 | sint8 chip_deinit(void); 170 | /* 171 | * @fn chip_reset_and_cpu_halt 172 | * @brief 173 | */ 174 | sint8 chip_reset_and_cpu_halt(void); 175 | /* 176 | * @fn set_gpio_dir 177 | * @brief 178 | */ 179 | sint8 set_gpio_dir(uint8 gpio, uint8 dir); 180 | /* 181 | * @fn set_gpio_val 182 | * @brief 183 | */ 184 | sint8 set_gpio_val(uint8 gpio, uint8 val); 185 | /* 186 | * @fn get_gpio_val 187 | * @brief 188 | */ 189 | sint8 get_gpio_val(uint8 gpio, uint8* val); 190 | /* 191 | * @fn pullup_ctrl 192 | * @brief 193 | */ 194 | sint8 pullup_ctrl(uint32 pinmask, uint8 enable); 195 | /* 196 | * @fn nmi_get_otp_mac_address 197 | * @brief 198 | */ 199 | sint8 nmi_get_otp_mac_address(uint8 *pu8MacAddr, uint8 * pu8IsValid); 200 | /* 201 | * @fn nmi_get_mac_address 202 | * @brief 203 | */ 204 | sint8 nmi_get_mac_address(uint8 *pu8MacAddr); 205 | /* 206 | * @fn chip_apply_conf 207 | * @brief 208 | */ 209 | sint8 chip_apply_conf(uint32 u32conf); 210 | 211 | #ifdef __cplusplus 212 | } 213 | #endif 214 | 215 | #endif /*_NMASIC_H_*/ 216 | -------------------------------------------------------------------------------- /src/driver/source/nmbus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1000 bus APIs implementation. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NMBUS_H_ 43 | #define _NMBUS_H_ 44 | 45 | #include "common/include/nm_common.h" 46 | #include "bus_wrapper/include/nm_bus_wrapper.h" 47 | 48 | 49 | 50 | #ifdef __cplusplus 51 | extern "C"{ 52 | #endif 53 | /** 54 | * @fn nm_bus_iface_init 55 | * @brief Initialize bus interface 56 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 57 | */ 58 | sint8 nm_bus_iface_init(void *); 59 | 60 | 61 | /** 62 | * @fn nm_bus_iface_deinit 63 | * @brief Deinitialize bus interface 64 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 65 | */ 66 | sint8 nm_bus_iface_deinit(void); 67 | 68 | /** 69 | * @fn nm_bus_reset 70 | * @brief reset bus interface 71 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 72 | * @version 1.0 73 | */ 74 | sint8 nm_bus_reset(void); 75 | 76 | /** 77 | * @fn nm_bus_iface_reconfigure 78 | * @brief reconfigure bus interface 79 | * @return M2M_SUCCESS in case of success and M2M_ERR_BUS_FAIL in case of failure 80 | */ 81 | sint8 nm_bus_iface_reconfigure(void *ptr); 82 | 83 | /** 84 | * @fn nm_read_reg 85 | * @brief Read register 86 | * @param [in] u32Addr 87 | * Register address 88 | * @return Register value 89 | */ 90 | uint32 nm_read_reg(uint32 u32Addr); 91 | 92 | /** 93 | * @fn nm_read_reg_with_ret 94 | * @brief Read register with error code return 95 | * @param [in] u32Addr 96 | * Register address 97 | * @param [out] pu32RetVal 98 | * Pointer to u32 variable used to return the read value 99 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 100 | */ 101 | sint8 nm_read_reg_with_ret(uint32 u32Addr, uint32* pu32RetVal); 102 | 103 | /** 104 | * @fn nm_write_reg 105 | * @brief write register 106 | * @param [in] u32Addr 107 | * Register address 108 | * @param [in] u32Val 109 | * Value to be written to the register 110 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 111 | */ 112 | sint8 nm_write_reg(uint32 u32Addr, uint32 u32Val); 113 | 114 | /** 115 | * @fn nm_read_block 116 | * @brief Read block of data 117 | * @param [in] u32Addr 118 | * Start address 119 | * @param [out] puBuf 120 | * Pointer to a buffer used to return the read data 121 | * @param [in] u32Sz 122 | * Number of bytes to read. The buffer size must be >= u32Sz 123 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 124 | */ 125 | sint8 nm_read_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz); 126 | 127 | /** 128 | * @fn nm_write_block 129 | * @brief Write block of data 130 | * @param [in] u32Addr 131 | * Start address 132 | * @param [in] puBuf 133 | * Pointer to the buffer holding the data to be written 134 | * @param [in] u32Sz 135 | * Number of bytes to write. The buffer size must be >= u32Sz 136 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 137 | */ 138 | sint8 nm_write_block(uint32 u32Addr, uint8 *puBuf, uint32 u32Sz); 139 | 140 | 141 | 142 | 143 | #ifdef __cplusplus 144 | } 145 | #endif 146 | 147 | #endif /* _NMBUS_H_ */ 148 | -------------------------------------------------------------------------------- /src/driver/source/nmdrv.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1500 M2M driver APIs declarations. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NMDRV_H_ 43 | #define _NMDRV_H_ 44 | 45 | #include "common/include/nm_common.h" 46 | 47 | /** 48 | * @struct tstrM2mRev 49 | * @brief Structure holding firmware version parameters and build date/time 50 | */ 51 | typedef struct { 52 | uint32 u32Chipid; /* HW revision which will be basically the chip ID */ 53 | uint8 u8FirmwareMajor; /* Version Major Number which represents the official release base */ 54 | uint8 u8FirmwareMinor; /* Version Minor Number which represents the engineering release base */ 55 | uint8 u8FirmwarePatch; /* Version pathc Number which represents the pathces release base */ 56 | uint8 u8DriverMajor; /* Version Major Number which represents the official release base */ 57 | uint8 u8DriverMinor; /* Version Minor Number which represents the engineering release base */ 58 | uint8 u8DriverPatch; /* Version Patch Number which represents the pathces release base */ 59 | uint8 BuildDate[sizeof(__DATE__)]; 60 | uint8 BuildTime[sizeof(__TIME__)]; 61 | uint8 _PAD8_; 62 | uint16 u16FirmwareSvnNum; 63 | uint16 _PAD16_[2]; 64 | } tstrM2mRev; 65 | 66 | /** 67 | * @struct tstrM2mBinaryHeader 68 | * @brief Structure holding compatibility version info for firmware binaries 69 | */ 70 | typedef struct { 71 | tstrM2mRev binVerInfo; 72 | uint32 flashOffset; 73 | uint32 payloadSize; 74 | } tstrM2mBinaryHeader; 75 | 76 | #ifdef __cplusplus 77 | extern "C" { 78 | #endif 79 | /** 80 | * @fn nm_get_firmware_info(tstrM2mRev* M2mRev) 81 | * @brief Get Firmware version info 82 | * @param [out] M2mRev 83 | * pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters 84 | * @version 1.0 85 | */ 86 | sint8 nm_get_firmware_info(tstrM2mRev* M2mRev); 87 | /** 88 | * @fn nm_get_firmware_full_info(tstrM2mRev* pstrRev) 89 | * @brief Get Firmware version info 90 | * @param [out] M2mRev 91 | * pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters 92 | * @version 1.0 93 | */ 94 | sint8 nm_get_firmware_full_info(tstrM2mRev* pstrRev); 95 | /** 96 | * @fn nm_get_ota_firmware_info(tstrM2mRev* pstrRev) 97 | * @brief Get Firmware version info 98 | * @param [out] M2mRev 99 | * pointer holds address of structure "tstrM2mRev" that contains the firmware version parameters 100 | 101 | * @version 1.0 102 | */ 103 | sint8 nm_get_ota_firmware_info(tstrM2mRev* pstrRev); 104 | /* 105 | * @fn nm_drv_init 106 | * @brief Initialize NMC1000 driver 107 | * @return ZERO in case of success and Negative error code in case of failure 108 | */ 109 | sint8 nm_drv_init_download_mode(void); 110 | 111 | /* 112 | * @fn nm_drv_init 113 | * @brief Initialize NMC1000 driver 114 | * @return M2M_SUCCESS in case of success and Negative error code in case of failure 115 | * @param [in] arg 116 | * Generic argument TBD 117 | * @return ZERO in case of success and Negative error code in case of failure 118 | 119 | */ 120 | sint8 nm_drv_init(void * arg); 121 | 122 | /** 123 | * @fn nm_drv_deinit 124 | * @brief Deinitialize NMC1000 driver 125 | * @author M. Abdelmawla 126 | * @param [in] arg 127 | * Generic argument TBD 128 | * @return ZERO in case of success and Negative error code in case of failure 129 | */ 130 | sint8 nm_drv_deinit(void * arg); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /*_NMDRV_H_*/ 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/driver/source/nmi2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1000 I2C protocol bus APIs implementation. 6 | * 7 | * Copyright (c) 2016 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NMI2C_H_ 43 | #define _NMI2C_H_ 44 | 45 | #include "common/include/nm_common.h" 46 | 47 | /** 48 | * @fn nm_i2c_read_reg 49 | * @brief Read register 50 | * @param [in] u32Addr 51 | * Register address 52 | * @return Register value 53 | */ 54 | uint32 nm_i2c_read_reg(uint32 u32Addr); 55 | 56 | /** 57 | * @fn nm_i2c_read_reg_with_ret 58 | * @brief Read register with error code return 59 | * @param [in] u32Addr 60 | * Register address 61 | * @param [out] pu32RetVal 62 | * Pointer to u32 variable used to return the read value 63 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 64 | */ 65 | sint8 nm_i2c_read_reg_with_ret(uint32 u32Addr, uint32* pu32RetVal); 66 | 67 | /** 68 | * @fn nm_i2c_write_reg 69 | * @brief write register 70 | * @param [in] u32Addr 71 | * Register address 72 | * @param [in] u32Val 73 | * Value to be written to the register 74 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 75 | */ 76 | sint8 nm_i2c_write_reg(uint32 u32Addr, uint32 u32Val); 77 | 78 | /** 79 | * @fn nm_i2c_read_block 80 | * @brief Read block of data 81 | * @param [in] u32Addr 82 | * Start address 83 | * @param [out] puBuf 84 | * Pointer to a buffer used to return the read data 85 | * @param [in] u16Sz 86 | * Number of bytes to read. The buffer size must be >= u16Sz 87 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 88 | */ 89 | sint8 nm_i2c_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz); 90 | 91 | /** 92 | * @fn nm_i2c_write_block 93 | * @brief Write block of data 94 | * @param [in] u32Addr 95 | * Start address 96 | * @param [in] puBuf 97 | * Pointer to the buffer holding the data to be written 98 | * @param [in] u16Sz 99 | * Number of bytes to write. The buffer size must be >= u16Sz 100 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 101 | */ 102 | sint8 nm_i2c_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz); 103 | 104 | #endif /* _NMI2C_H_ */ 105 | -------------------------------------------------------------------------------- /src/driver/source/nmspi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1000 SPI protocol bus APIs implementation. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NMSPI_H_ 43 | #define _NMSPI_H_ 44 | 45 | #include "common/include/nm_common.h" 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /** 52 | * @fn nm_spi_init 53 | * @brief Initialize the SPI 54 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 55 | */ 56 | sint8 nm_spi_init(void); 57 | /** 58 | * @fn nm_spi_reset 59 | * @brief reset the SPI 60 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 61 | */ 62 | sint8 nm_spi_reset(void); 63 | 64 | /** 65 | * @fn nm_spi_deinit 66 | * @brief DeInitialize the SPI 67 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 68 | */ 69 | sint8 nm_spi_deinit(void); 70 | 71 | /** 72 | * @fn nm_spi_read_reg 73 | * @brief Read register 74 | * @param [in] u32Addr 75 | * Register address 76 | * @return Register value 77 | */ 78 | uint32 nm_spi_read_reg(uint32 u32Addr); 79 | 80 | /** 81 | * @fn nm_spi_read_reg_with_ret 82 | * @brief Read register with error code return 83 | * @param [in] u32Addr 84 | * Register address 85 | * @param [out] pu32RetVal 86 | * Pointer to u32 variable used to return the read value 87 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 88 | */ 89 | sint8 nm_spi_read_reg_with_ret(uint32 u32Addr, uint32* pu32RetVal); 90 | 91 | /** 92 | * @fn nm_spi_write_reg 93 | * @brief write register 94 | * @param [in] u32Addr 95 | * Register address 96 | * @param [in] u32Val 97 | * Value to be written to the register 98 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 99 | */ 100 | sint8 nm_spi_write_reg(uint32 u32Addr, uint32 u32Val); 101 | 102 | /** 103 | * @fn nm_spi_read_block 104 | * @brief Read block of data 105 | * @param [in] u32Addr 106 | * Start address 107 | * @param [out] puBuf 108 | * Pointer to a buffer used to return the read data 109 | * @param [in] u16Sz 110 | * Number of bytes to read. The buffer size must be >= u16Sz 111 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 112 | */ 113 | sint8 nm_spi_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz); 114 | 115 | /** 116 | * @fn nm_spi_write_block 117 | * @brief Write block of data 118 | * @param [in] u32Addr 119 | * Start address 120 | * @param [in] puBuf 121 | * Pointer to the buffer holding the data to be written 122 | * @param [in] u16Sz 123 | * Number of bytes to write. The buffer size must be >= u16Sz 124 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 125 | */ 126 | sint8 nm_spi_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz); 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif /* _NMSPI_H_ */ 133 | -------------------------------------------------------------------------------- /src/driver/source/nmuart.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief This module contains NMC1000 UART protocol bus APIs implementation. 6 | * 7 | * Copyright (c) 2016 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | 42 | #ifndef _NMUART_H_ 43 | #define _NMUART_H_ 44 | 45 | #include "common/include/nm_common.h" 46 | 47 | /* 48 | * @fn nm_uart_sync_cmd 49 | * @brief Check COM Port 50 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 51 | */ 52 | sint8 nm_uart_sync_cmd(void); 53 | /** 54 | * @fn nm_uart_read_reg 55 | * @brief Read register 56 | * @param [in] u32Addr 57 | * Register address 58 | * @return Register value 59 | */ 60 | uint32 nm_uart_read_reg(uint32 u32Addr); 61 | 62 | /** 63 | * @fn nm_uart_read_reg_with_ret 64 | * @brief Read register with error code return 65 | * @param [in] u32Addr 66 | * Register address 67 | * @param [out] pu32RetVal 68 | * Pointer to u32 variable used to return the read value 69 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 70 | */ 71 | sint8 nm_uart_read_reg_with_ret(uint32 u32Addr, uint32* pu32RetVal); 72 | 73 | /** 74 | * @fn nm_uart_write_reg 75 | * @brief write register 76 | * @param [in] u32Addr 77 | * Register address 78 | * @param [in] u32Val 79 | * Value to be written to the register 80 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 81 | */ 82 | sint8 nm_uart_write_reg(uint32 u32Addr, uint32 u32Val); 83 | 84 | /** 85 | * @fn nm_uart_read_block 86 | * @brief Read block of data 87 | * @param [in] u32Addr 88 | * Start address 89 | * @param [out] puBuf 90 | * Pointer to a buffer used to return the read data 91 | * @param [in] u16Sz 92 | * Number of bytes to read. The buffer size must be >= u16Sz 93 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 94 | */ 95 | sint8 nm_uart_read_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz); 96 | 97 | /** 98 | * @fn nm_uart_write_block 99 | * @brief Write block of data 100 | * @param [in] u32Addr 101 | * Start address 102 | * @param [in] puBuf 103 | * Pointer to the buffer holding the data to be written 104 | * @param [in] u16Sz 105 | * Number of bytes to write. The buffer size must be >= u16Sz 106 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 107 | */ 108 | sint8 nm_uart_write_block(uint32 u32Addr, uint8 *puBuf, uint16 u16Sz); 109 | 110 | /** 111 | * @fn nm_uart_reconfigure 112 | * @brief Reconfigures the UART interface 113 | * @param [in] ptr 114 | * Pointer to a DWORD containing baudrate at this moment. 115 | * @return ZERO in case of success and M2M_ERR_BUS_FAIL in case of failure 116 | */ 117 | sint8 nm_uart_reconfigure(void *ptr); 118 | #endif /* _NMI2C_H_ */ 119 | -------------------------------------------------------------------------------- /src/socket/source/socket_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * \file 4 | * 5 | * \brief BSD compatible socket interface internal types. 6 | * 7 | * Copyright (c) 2016-2017 Atmel Corporation. All rights reserved. 8 | * 9 | * \asf_license_start 10 | * 11 | * \page License 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions are met: 15 | * 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 23 | * 3. The name of Atmel may not be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 29 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | * POSSIBILITY OF SUCH DAMAGE. 37 | * 38 | * \asf_license_stop 39 | * 40 | */ 41 | #ifndef __SOCKET_INTERNAL_H__ 42 | #define __SOCKET_INTERNAL_H__ 43 | 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 50 | INCLUDES 51 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 52 | 53 | #include "socket/include/socket.h" 54 | #include "socket/include/m2m_socket_host_if.h" 55 | 56 | 57 | /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 58 | FUNCTION PROTOTYPES 59 | *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 60 | 61 | NMI_API void Socket_ReadSocketData(SOCKET sock, tstrSocketRecvMsg *pstrRecv,uint8 u8SocketMsg, 62 | uint32 u32StartAddress,uint16 u16ReadCount); 63 | #ifdef ARDUINO 64 | NMI_API void Socket_ReadSocketData_Small(void); 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif /* __cplusplus */ 70 | 71 | #endif /* __SOCKET_H__ */ 72 | -------------------------------------------------------------------------------- /src/utility/WiFiSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiSocket.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. 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 WIFISOCKET_H 21 | #define WIFISOCKET_H 22 | 23 | extern "C" { 24 | #include "socket/include/socket.h" 25 | #include "socket/include/m2m_socket_host_if.h" 26 | } 27 | 28 | #include 29 | #include 30 | 31 | class WiFiSocketClass { 32 | public: 33 | WiFiSocketClass(); 34 | virtual ~WiFiSocketClass(); 35 | 36 | SOCKET create(uint16 u16Domain, uint8 u8Type, uint8 u8Flags); 37 | sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); 38 | sint8 listen(SOCKET sock, uint8 backlog); 39 | sint8 setopt(SOCKET socket, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen); 40 | sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); 41 | uint8 connected(SOCKET sock); 42 | uint8 listening(SOCKET sock); 43 | uint8 bound(SOCKET sock); 44 | int available(SOCKET sock); 45 | int peek(SOCKET sock); 46 | int read(SOCKET sock, uint8_t* buf, size_t size); 47 | size_t write(SOCKET sock, const uint8_t *buf, size_t size); 48 | sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen); 49 | IPAddress remoteIP(SOCKET sock); 50 | uint16_t remotePort(SOCKET sock); 51 | sint8 close(SOCKET sock); 52 | SOCKET accepted(SOCKET sock); 53 | int hasParent(SOCKET sock, SOCKET child); 54 | 55 | static void eventCallback(SOCKET sock, uint8 u8Msg, void *pvMsg); 56 | 57 | private: 58 | void handleEvent(SOCKET sock, uint8 u8Msg, void *pvMsg); 59 | int fillRecvBuffer(SOCKET sock); 60 | 61 | struct 62 | { 63 | uint8_t state; 64 | SOCKET parent; 65 | tstrSocketRecvMsg recvMsg; 66 | struct { 67 | uint8_t* data; 68 | uint8_t* head; 69 | int length; 70 | } buffer; 71 | struct sockaddr _lastSendtoAddr; 72 | } _info[MAX_SOCKET]; 73 | }; 74 | 75 | extern WiFiSocketClass WiFiSocket; 76 | 77 | #endif 78 | --------------------------------------------------------------------------------