diff --git a/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino b/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino index 6c6a24ee..fe8bab2e 100644 --- a/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino +++ b/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino @@ -47,7 +47,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -68,7 +68,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart AP_SimpleWebServer on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/examples/ConnectNoEncryption/ConnectNoEncryption.ino index 32ce7cf3..10968f09 100644 --- a/examples/ConnectNoEncryption/ConnectNoEncryption.ino +++ b/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -40,7 +40,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -53,7 +53,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart ConnectNoEncryption on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/ConnectWithWEP/ConnectWithWEP.ino b/examples/ConnectWithWEP/ConnectWithWEP.ino index 5121638c..91a30b4b 100644 --- a/examples/ConnectWithWEP/ConnectWithWEP.ino +++ b/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -49,7 +49,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -66,7 +66,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart ConnectWithWEP on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/ConnectWithWPA/ConnectWithWPA.ino b/examples/ConnectWithWPA/ConnectWithWPA.ino index 5551f949..4ceebd43 100644 --- a/examples/ConnectWithWPA/ConnectWithWPA.ino +++ b/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -38,7 +38,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -53,7 +53,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart ConnectWithWPA on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino b/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino index def8c82a..ee06c0cd 100644 --- a/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino +++ b/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino @@ -35,7 +35,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -51,7 +51,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart ConnectWithWPA2Enterprise on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/MultiServers/MultiServers.ino b/examples/MultiServers/MultiServers.ino index 582357f1..4a796c8b 100644 --- a/examples/MultiServers/MultiServers.ino +++ b/examples/MultiServers/MultiServers.ino @@ -31,7 +31,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include "defines.h" #include @@ -100,7 +100,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart MultiServers on ")); Serial.println(BOARD_TYPE); diff --git a/examples/RGB_LED_Test/RGB_LED_Test.ino b/examples/RGB_LED_Test/RGB_LED_Test.ino index f01048f7..00c1d3df 100644 --- a/examples/RGB_LED_Test/RGB_LED_Test.ino +++ b/examples/RGB_LED_Test/RGB_LED_Test.ino @@ -26,13 +26,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************************************************************/ +#if (!defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_ARCH_MBED)) + #error Only for ARDUINO_NANO_RP2040_CONNECT using arduino-pico core +#endif + //#include #include void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print("RGB_LED_Test on "); Serial.print(BOARD_NAME); diff --git a/examples/ScanNetworks/ScanNetworks.ino b/examples/ScanNetworks/ScanNetworks.ino index 3f5c623b..7b54a5c2 100644 --- a/examples/ScanNetworks/ScanNetworks.ino +++ b/examples/ScanNetworks/ScanNetworks.ino @@ -43,7 +43,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -52,7 +52,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart ScanNetworks on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino b/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino index 715a61ea..0473e156 100644 --- a/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino +++ b/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino @@ -44,7 +44,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -53,7 +53,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart ScanNetworksAdvanced on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino index eaf9c65a..138d1691 100644 --- a/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino +++ b/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -51,7 +51,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -70,7 +70,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart SimpleWebServerWiFi on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino b/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino index 2bc78141..ae95da85 100644 --- a/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino +++ b/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino @@ -39,7 +39,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -//#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +//#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include "defines.h" #include @@ -49,7 +49,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); // Print a welcome message Serial.print(F("\nStart WiFiNINA CheckFirmwareVersion on ")); Serial.println(BOARD_NAME); diff --git a/examples/WiFiAdvancedChatServer/WiFiAdvancedChatServer.ino b/examples/WiFiAdvancedChatServer/WiFiAdvancedChatServer.ino new file mode 100644 index 00000000..df7b2073 --- /dev/null +++ b/examples/WiFiAdvancedChatServer/WiFiAdvancedChatServer.ino @@ -0,0 +1,161 @@ +/**************************************************************************************************************************** + WiFiAdvancedChatServer.ino + + Advanced WiFi Chat Server + + A more advanced server that distributes any incoming messages + to all connected clients but the client the message comes from. + To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + + Circuit: + Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*****************************************************************************************************************************/ + +#include "defines.h" +#include "arduino_secrets.h" + +#include +#include + +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +int status = WL_IDLE_STATUS; + +#define TELNET_PORT 23 + +// telnet defaults to port 23 +WiFiServer server(TELNET_PORT); + +#define MAX_NUMBER_CLIENTS 8 + +WiFiClient clients[MAX_NUMBER_CLIENTS]; + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print(F("\nStart WiFiAdvancedChatServer on ")); Serial.println(BOARD_NAME); + Serial.println(WIFININA_GENERIC_VERSION); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println(F("Communication with WiFi module failed!")); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) + { + Serial.print(F("Your current firmware NINA FW v")); + Serial.println(fv); + Serial.print(F("Please upgrade the firmware to NINA FW v")); + Serial.println(WIFI_FIRMWARE_LATEST_VERSION); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) + { + Serial.print(F("Attempting to connect to Network named: ")); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + //delay(10000); + } + + // start the server: + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(WiFi.localIP()); +} + +void loop() +{ + // check for any new client connecting, and say hello (before any incoming data) + WiFiClient newClient = server.accept(); + + if (newClient) + { + for (byte i = 0; i < MAX_NUMBER_CLIENTS; i++) + { + if (!clients[i]) + { + Serial.print("We have a new client #"); + Serial.println(i); + + newClient.print("Hello, client number: "); + newClient.println(i); + + // Once we "accept", the client is no longer tracked by WiFiServer + // so we must store it into our list of clients + clients[i] = newClient; + break; + } + } + } + + // check for incoming data from all clients + for (byte i = 0; i < MAX_NUMBER_CLIENTS; i++) + { + if (clients[i] && clients[i].available() > 0) + { + #define BUFFER_SIZE 80 + + // read bytes from a client + byte buffer[BUFFER_SIZE]; + int count = clients[i].read(buffer, BUFFER_SIZE); + + // write the bytes to all other connected clients + for (byte j = 0; j < MAX_NUMBER_CLIENTS; j++) + { + if (j != i && clients[j].connected()) + { + clients[j].write(buffer, count); + } + } + } + } + + // stop any clients which disconnect + for (byte i = 0; i < MAX_NUMBER_CLIENTS; i++) + { + if (clients[i] && !clients[i].connected()) + { + Serial.print("disconnect client #"); + Serial.println(i); + clients[i].stop(); + } + } +} diff --git a/examples/WiFiAdvancedChatServer/arduino_secrets.h b/examples/WiFiAdvancedChatServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/examples/WiFiAdvancedChatServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/examples/WiFiAdvancedChatServer/defines.h b/examples/WiFiAdvancedChatServer/defines.h new file mode 100644 index 00000000..a3aef4d7 --- /dev/null +++ b/examples/WiFiAdvancedChatServer/defines.h @@ -0,0 +1,400 @@ +/**************************************************************************************************************************** + defines.h + For boards with WiFiNINA module/shield. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ + || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ + || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ + || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD51__) || defined(__SAMD51J20A__) \ + || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) \ + || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ + || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ + || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) + #if defined(WIFININA_USE_SAMD) + #undef WIFININA_USE_SAMD + #endif + #define WIFININA_USE_SAMD true +#endif + +#if defined(WIFININA_USE_SAMD) + + #if defined(ARDUINO_SAMD_ZERO) + #define BOARD_TYPE "SAMD Zero" + #elif defined(ARDUINO_SAMD_MKR1000) + #define BOARD_TYPE "SAMD MKR1000" + #elif defined(ARDUINO_SAMD_MKRWIFI1010) + #define BOARD_TYPE "SAMD MKRWIFI1010" + #elif defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_TYPE "SAMD NANO_33_IOT" + #elif defined(ARDUINO_SAMD_MKRFox1200) + #define BOARD_TYPE "SAMD MKRFox1200" + #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) + #define BOARD_TYPE "SAMD MKRWAN13X0" + #elif defined(ARDUINO_SAMD_MKRGSM1400) + #define BOARD_TYPE "SAMD MKRGSM1400" + #elif defined(ARDUINO_SAMD_MKRNB1500) + #define BOARD_TYPE "SAMD MKRNB1500" + #elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #define BOARD_TYPE "SAMD MKRVIDOR4000" + #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) + #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" + #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" + #elif defined(ADAFRUIT_METRO_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" + #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" + #elif defined(ADAFRUIT_GEMMA_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" + #elif defined(ADAFRUIT_TRINKET_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" + #elif defined(ADAFRUIT_ITSYBITSY_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" + #elif defined(ARDUINO_SAMD_HALLOWING_M0) + #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" + #elif defined(ADAFRUIT_METRO_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" + #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" + #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" + #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" + #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" + #elif defined(ADAFRUIT_PYPORTAL) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" + #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" + #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" + #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" + #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" + #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" + #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" + #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" + #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" + #elif defined(SEEED_WIO_TERMINAL) + #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" + #elif defined(SEEED_FEMTO_M0) + #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" + #elif defined(SEEED_XIAO_M0) + #define BOARD_TYPE "SAMD SEEED_XIAO_M0" + #elif defined(Wio_Lite_MG126) + #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" + #elif defined(WIO_GPS_BOARD) + #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" + #elif defined(SEEEDUINO_ZERO) + #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" + #elif defined(SEEEDUINO_LORAWAN) + #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" + #elif defined(SEEED_GROVE_UI_WIRELESS) + #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" + #elif defined(__SAMD21E18A__) + #define BOARD_TYPE "SAMD21E18A" + #elif defined(__SAMD21G18A__) + #define BOARD_TYPE "SAMD21G18A" + #elif defined(__SAMD51G19A__) + #define BOARD_TYPE "SAMD51G19A" + #elif defined(__SAMD51J19A__) + #define BOARD_TYPE "SAMD51J19A" + #elif defined(__SAMD51P19A__) + #define BOARD_TYPE "__SAMD51P19A__" + #elif defined(__SAMD51J20A__) + #define BOARD_TYPE "SAMD51J20A" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM3X8E" + #elif defined(__CPU_ARC__) + #define BOARD_TYPE "CPU_ARC" + #elif defined(__SAMD51__) + #define BOARD_TYPE "SAMD51" + #else + #define BOARD_TYPE "SAMD Unknown" + #endif + +#endif + +#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ + defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) + #if defined(WIFININA_USE_NRF52) + #undef WIFININA_USE_NRF52 + #endif + #define WIFININA_USE_NRF52 true +#endif + +#if defined(WIFININA_USE_NRF52) + + #if defined(NRF52840_FEATHER) + #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" + #elif defined(NRF52832_FEATHER) + #define BOARD_TYPE "NRF52832_FEATHER" + #elif defined(NRF52840_FEATHER_SENSE) + #define BOARD_TYPE "NRF52840_FEATHER_SENSE" + #elif defined(NRF52840_ITSYBITSY) + #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" + #elif defined(NRF52840_CIRCUITPLAY) + #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" + #elif defined(NRF52840_CLUE) + #define BOARD_TYPE "NRF52840_CLUE" + #elif defined(NRF52840_METRO) + #define BOARD_TYPE "NRF52840_METRO_EXPRESS" + #elif defined(NRF52840_PCA10056) + #define BOARD_TYPE "NORDIC_NRF52840DK" + #elif defined(NINA_B302_ublox) + #define BOARD_TYPE "NINA_B302_ublox" + #elif defined(NINA_B112_ublox) + #define BOARD_TYPE "NINA_B112_ublox" + #elif defined(PARTICLE_XENON) + #define BOARD_TYPE "PARTICLE_XENON" + #elif defined(MDBT50Q_RX) + #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" + #elif defined(ARDUINO_NRF52_ADAFRUIT) + #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" + #else + #define BOARD_TYPE "nRF52 Unknown" + #endif + +#endif + +#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + #if defined(WIFININA_USE_SAMDUE) + #undef WIFININA_USE_SAMDUE + #endif + #define WIFININA_USE_SAMDUE true +#endif + +#if defined(WIFININA_USE_SAMDUE) + + // For SAM DUE + #if defined(ARDUINO_SAM_DUE) + #define BOARD_TYPE "SAM DUE" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM SAM3X8E" + #else + #define BOARD_TYPE "SAM Unknown" + #endif + +#endif + +#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + #if defined(WIFININA_USE_STM32) + #undef WIFININA_USE_STM32 + #endif + #define WIFININA_USE_STM32 true +#endif + +#if defined(WIFININA_USE_STM32) + #if defined(STM32F0) + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" + #elif defined(STM32F1) + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" + #elif defined(STM32F2) + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" + #elif defined(STM32F3) + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" + #elif defined(STM32F4) + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" + #elif defined(STM32F7) + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" + #elif defined(STM32L0) + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" + #elif defined(STM32L1) + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" + #elif defined(STM32L4) + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" + #elif defined(STM32H7) + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" + #elif defined(STM32G0) + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" + #elif defined(STM32G4) + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" + #elif defined(STM32WB) + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" + #elif defined(STM32MP1) + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" + #else + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" + #endif + +#endif + +#ifdef CORE_TEENSY + + #if defined(WIFININA_USE_TEENSY) + #undef WIFININA_USE_TEENSY + #endif + #define WIFININA_USE_TEENSY true + + #if defined(__IMXRT1062__) + // For Teensy 4.1/4.0 + #define BOARD_TYPE "TEENSY 4.1/4.0" + #elif defined(__MK66FX1M0__) + #define BOARD_TYPE "Teensy 3.6" + #elif defined(__MK64FX512__) + #define BOARD_TYPE "Teensy 3.5" + #elif defined(__MKL26Z64__) + #define BOARD_TYPE "Teensy LC" + #elif defined(__MK20DX256__) + #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) + #elif defined(__MK20DX128__) + #define BOARD_TYPE "Teensy 3.0" + #elif defined(__AVR_AT90USB1286__) + #error Teensy 2.0++ not supported yet + #elif defined(__AVR_ATmega32U4__) + #error Teensy 2.0 not supported yet + #else + // For Other Boards + #define BOARD_TYPE "Unknown Teensy Board" + #endif + +#endif + +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) + #if defined(WIFININA_USE_RP2040) + #undef WIFININA_USE_RP2040 + #endif + #define WIFININA_USE_RP2040 true + + #if defined(ARDUINO_ARCH_MBED) + + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_NANO_RP2040_CONNECT) + #define BOARD_NAME "MBED NANO_RP2040_CONNECT" + #elif defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_NAME "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_NAME "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_NAME "MBED GENERIC_RP2040" + #else + #define BOARD_NAME "MBED Unknown RP2040" + #endif + + #endif +#endif + +#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \ + defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__)) + #define BOARD_TYPE "Arduino AVR Mega2560/ADK" + #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. + +#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \ + defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \ + defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \ + defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) ) + #define BOARD_TYPE "Arduino AVR UNO, Nano, etc." + #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. + +#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \ + defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) ) + #define BOARD_TYPE "Adafruit AVR ATMega328(P)" + #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. + +#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \ + defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \ + defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) ) + #define BOARD_TYPE "Arduino AVR ATMega32U4" + #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. + +#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \ + defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) ) + #define BOARD_TYPE "Adafruit AVR ATMega32U4" + #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc. + +#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \ + defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega32U4" + #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. + +#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega328P" + #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc. + +#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega128RFA1" + #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc. + +#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) ) + #error These AVR boards are not supported! Please check your Tools->Board setting. + +#endif + +#if ( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) ) + #if !defined(BOARD_NAME) + #if (ARDUINO_AVR_UNO_WIFI_REV2) + #define BOARD_NAME "megaAVR UNO WiFi Rev2" + #elif (ARDUINO_AVR_NANO_EVERY) + #define BOARD_NAME "megaAVR Nano Every" + #else + #define BOARD_NAME "megaAVR Unknown" + #endif + #endif +#endif + +#ifndef BOARD_TYPE + #define BOARD_TYPE "Unknown board" +#endif + +#ifndef BOARD_NAME + #define BOARD_NAME BOARD_TYPE +#endif + +#define DEBUG_WIFININA_PORT Serial +// Debug Level from 0 to 4 +#define _WIFININA_LOGLEVEL_ 1 + +#endif //defines_h diff --git a/examples/WiFiChatServer/WiFiChatServer.ino b/examples/WiFiChatServer/WiFiChatServer.ino index 0271a686..a1a58712 100644 --- a/examples/WiFiChatServer/WiFiChatServer.ino +++ b/examples/WiFiChatServer/WiFiChatServer.ino @@ -44,7 +44,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -57,7 +57,10 @@ int keyIndex = 0; // your network key Index number (needed only int status = WL_IDLE_STATUS; -WiFiServer server(23); +#define TELNET_PORT 23 + +// telnet defaults to port 23 +WiFiServer server(TELNET_PORT); boolean alreadyConnected = false; // whether or not the client was connected previously @@ -65,7 +68,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiChatServer on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/WiFiAdvancedChatServer_WiFiMulti.ino b/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/WiFiAdvancedChatServer_WiFiMulti.ino new file mode 100644 index 00000000..eb2c980c --- /dev/null +++ b/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/WiFiAdvancedChatServer_WiFiMulti.ino @@ -0,0 +1,293 @@ +/**************************************************************************************************************************** + WiFiAdvancedChatServer.ino + + Advanced WiFi Chat Server + + A more advanced server that distributes any incoming messages + to all connected clients but the client the message comes from. + To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + + Circuit: + Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*****************************************************************************************************************************/ + +#include "defines.h" +#include "arduino_secrets.h" + +#define USE_WIFI_NINA true +#define USE_WIFI101 false +#define USE_WIFI_CUSTOM false + +#include +#include +#include + +int status = WL_IDLE_STATUS; + +#define TELNET_PORT 23 + +// telnet defaults to port 23 +WiFiServer server(TELNET_PORT); + +#define MAX_NUMBER_CLIENTS 8 + +WiFiClient clients[MAX_NUMBER_CLIENTS]; + +WiFiMulti_Generic wifiMulti; + +void heartBeatPrint() +{ + static int num = 1; + + //WFM_LOGDEBUG1("\nWiFi connected, RSSI:", WiFi.RSSI()); + + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi + + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } +} + +uint8_t connectMultiWiFi() +{ +// For general board, this better be 1000 to enable connect the 1st time +#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 1000L +#define WIFI_MULTI_CONNECT_WAITING_MS 500L + + Serial.println("WiFi lost. Trying to scan and reconnect"); + + WiFi.disconnect(); + + int i = 0; + + uint8_t status = wifiMulti.run(); + + delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); + + while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) + { + status = WiFi.status(); + + if ( status == WL_CONNECTED ) + break; + else + delay(WIFI_MULTI_CONNECT_WAITING_MS); + } + + if ( status == WL_CONNECTED ) + { + WFM_LOGERROR1(F("WiFi connected after time: "), i); + WFM_LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); + WFM_LOGERROR1(F("IP address:"), WiFi.localIP() ); + } + else + { + WFM_LOGERROR(F("WiFi not connected")); + + if (wifiMulti.run() != WL_CONNECTED) + { + Serial.println("WiFi not connected!"); + delay(1000); + } + } + + return status; +} + +void check_WiFi() +{ + if ( (WiFi.status() != WL_CONNECTED) ) + { + Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); + connectMultiWiFi(); + } +} + +void check_status() +{ + static uint32_t checkstatus_timeout = 0; + static uint32_t checkwifi_timeout = 0; + + static uint32_t current_millis; + +#define WIFICHECK_INTERVAL 1000L +#define HEARTBEAT_INTERVAL 10000L + + current_millis = millis(); + + // Check WiFi every WIFICHECK_INTERVAL (1) seconds. + if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) + { + check_WiFi(); + checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; + } + + // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. + if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) + { + heartBeatPrint(); + checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; + } +} + +void printWiFiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print(F("SSID: ")); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print(F("IP Address: ")); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print(F("Signal strength (RSSI):")); + Serial.print(rssi); + Serial.println(F(" dBm")); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print(F("\nStart WiFiAdvancedChatServer on ")); Serial.println(BOARD_NAME); + Serial.println(WIFIMULTI_GENERIC_VERSION); + Serial.println(WIFININA_GENERIC_VERSION); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println(F("Communication with WiFi module failed!")); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) + { + Serial.print(F("Your current firmware NINA FW v")); + Serial.println(fv); + Serial.print(F("Please upgrade the firmware to NINA FW v")); + Serial.println(WIFI_FIRMWARE_LATEST_VERSION); + } + + wifiMulti.addAP(SECRET_SSID1, SECRET_PASS1); + wifiMulti.addAP(SECRET_SSID2, SECRET_PASS2); + wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); + wifiMulti.addAP("ssid_from_AP_4", "your_password_for_AP_4"); + + Serial.println("Connecting WiFi..."); + + if (wifiMulti.run() == WL_CONNECTED) + { + Serial.print("\nWiFi connected, IP address: "); + Serial.println(WiFi.localIP()); + } + + Serial.println(F("Connected to WiFi")); + printWiFiStatus(); + + // start the server: + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(WiFi.localIP()); +} + +void loop() +{ + check_status(); + + // check for any new client connecting, and say hello (before any incoming data) + WiFiClient newClient = server.accept(); + + if (newClient) + { + for (byte i = 0; i < MAX_NUMBER_CLIENTS; i++) + { + if (!clients[i]) + { + Serial.print("We have a new client #"); + Serial.println(i); + + newClient.print("Hello, client number: "); + newClient.println(i); + + // Once we "accept", the client is no longer tracked by WiFiServer + // so we must store it into our list of clients + clients[i] = newClient; + break; + } + } + } + + // check for incoming data from all clients + for (byte i = 0; i < MAX_NUMBER_CLIENTS; i++) + { + if (clients[i] && clients[i].available() > 0) + { + #define BUFFER_SIZE 80 + + // read bytes from a client + byte buffer[BUFFER_SIZE]; + int count = clients[i].read(buffer, BUFFER_SIZE); + + // write the bytes to all other connected clients + for (byte j = 0; j < MAX_NUMBER_CLIENTS; j++) + { + if (j != i && clients[j].connected()) + { + clients[j].write(buffer, count); + } + } + } + } + + // stop any clients which disconnect + for (byte i = 0; i < MAX_NUMBER_CLIENTS; i++) + { + if (clients[i] && !clients[i].connected()) + { + Serial.print("disconnect client #"); + Serial.println(i); + clients[i].stop(); + } + } +} diff --git a/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/arduino_secrets.h b/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/arduino_secrets.h new file mode 100644 index 00000000..cf52660b --- /dev/null +++ b/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_SSID1 "your_ssid1" +#define SECRET_PASS1 "your_pass1" +#define SECRET_SSID2 "your_ssid2" +#define SECRET_PASS2 "your_pass2" diff --git a/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/defines.h b/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/defines.h new file mode 100644 index 00000000..426fa717 --- /dev/null +++ b/examples/WiFiMulti/WiFiAdvancedChatServer_WiFiMulti/defines.h @@ -0,0 +1,402 @@ +/**************************************************************************************************************************** + defines.h + For boards with WiFiNINA module/shield. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ + || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ + || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ + || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD51__) || defined(__SAMD51J20A__) \ + || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) \ + || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ + || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ + || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) + #if defined(WIFININA_USE_SAMD) + #undef WIFININA_USE_SAMD + #endif + #define WIFININA_USE_SAMD true +#endif + +#if defined(WIFININA_USE_SAMD) + + #if defined(ARDUINO_SAMD_ZERO) + #define BOARD_TYPE "SAMD Zero" + #elif defined(ARDUINO_SAMD_MKR1000) + #define BOARD_TYPE "SAMD MKR1000" + #elif defined(ARDUINO_SAMD_MKRWIFI1010) + #define BOARD_TYPE "SAMD MKRWIFI1010" + #elif defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_TYPE "SAMD NANO_33_IOT" + #elif defined(ARDUINO_SAMD_MKRFox1200) + #define BOARD_TYPE "SAMD MKRFox1200" + #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) + #define BOARD_TYPE "SAMD MKRWAN13X0" + #elif defined(ARDUINO_SAMD_MKRGSM1400) + #define BOARD_TYPE "SAMD MKRGSM1400" + #elif defined(ARDUINO_SAMD_MKRNB1500) + #define BOARD_TYPE "SAMD MKRNB1500" + #elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #define BOARD_TYPE "SAMD MKRVIDOR4000" + #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) + #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" + #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" + #elif defined(ADAFRUIT_METRO_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" + #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" + #elif defined(ADAFRUIT_GEMMA_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" + #elif defined(ADAFRUIT_TRINKET_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" + #elif defined(ADAFRUIT_ITSYBITSY_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" + #elif defined(ARDUINO_SAMD_HALLOWING_M0) + #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" + #elif defined(ADAFRUIT_METRO_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" + #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" + #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" + #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" + #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" + #elif defined(ADAFRUIT_PYPORTAL) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" + #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" + #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" + #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" + #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" + #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" + #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" + #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" + #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" + #elif defined(SEEED_WIO_TERMINAL) + #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" + #elif defined(SEEED_FEMTO_M0) + #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" + #elif defined(SEEED_XIAO_M0) + #define BOARD_TYPE "SAMD SEEED_XIAO_M0" + #elif defined(Wio_Lite_MG126) + #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" + #elif defined(WIO_GPS_BOARD) + #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" + #elif defined(SEEEDUINO_ZERO) + #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" + #elif defined(SEEEDUINO_LORAWAN) + #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" + #elif defined(SEEED_GROVE_UI_WIRELESS) + #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" + #elif defined(__SAMD21E18A__) + #define BOARD_TYPE "SAMD21E18A" + #elif defined(__SAMD21G18A__) + #define BOARD_TYPE "SAMD21G18A" + #elif defined(__SAMD51G19A__) + #define BOARD_TYPE "SAMD51G19A" + #elif defined(__SAMD51J19A__) + #define BOARD_TYPE "SAMD51J19A" + #elif defined(__SAMD51P19A__) + #define BOARD_TYPE "__SAMD51P19A__" + #elif defined(__SAMD51J20A__) + #define BOARD_TYPE "SAMD51J20A" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM3X8E" + #elif defined(__CPU_ARC__) + #define BOARD_TYPE "CPU_ARC" + #elif defined(__SAMD51__) + #define BOARD_TYPE "SAMD51" + #else + #define BOARD_TYPE "SAMD Unknown" + #endif + +#endif + +#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ + defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) + #if defined(WIFININA_USE_NRF52) + #undef WIFININA_USE_NRF52 + #endif + #define WIFININA_USE_NRF52 true +#endif + +#if defined(WIFININA_USE_NRF52) + + #if defined(NRF52840_FEATHER) + #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" + #elif defined(NRF52832_FEATHER) + #define BOARD_TYPE "NRF52832_FEATHER" + #elif defined(NRF52840_FEATHER_SENSE) + #define BOARD_TYPE "NRF52840_FEATHER_SENSE" + #elif defined(NRF52840_ITSYBITSY) + #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" + #elif defined(NRF52840_CIRCUITPLAY) + #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" + #elif defined(NRF52840_CLUE) + #define BOARD_TYPE "NRF52840_CLUE" + #elif defined(NRF52840_METRO) + #define BOARD_TYPE "NRF52840_METRO_EXPRESS" + #elif defined(NRF52840_PCA10056) + #define BOARD_TYPE "NORDIC_NRF52840DK" + #elif defined(NINA_B302_ublox) + #define BOARD_TYPE "NINA_B302_ublox" + #elif defined(NINA_B112_ublox) + #define BOARD_TYPE "NINA_B112_ublox" + #elif defined(PARTICLE_XENON) + #define BOARD_TYPE "PARTICLE_XENON" + #elif defined(MDBT50Q_RX) + #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" + #elif defined(ARDUINO_NRF52_ADAFRUIT) + #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" + #else + #define BOARD_TYPE "nRF52 Unknown" + #endif + +#endif + +#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + #if defined(WIFININA_USE_SAMDUE) + #undef WIFININA_USE_SAMDUE + #endif + #define WIFININA_USE_SAMDUE true +#endif + +#if defined(WIFININA_USE_SAMDUE) + + // For SAM DUE + #if defined(ARDUINO_SAM_DUE) + #define BOARD_TYPE "SAM DUE" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM SAM3X8E" + #else + #define BOARD_TYPE "SAM Unknown" + #endif + +#endif + +#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + #if defined(WIFININA_USE_STM32) + #undef WIFININA_USE_STM32 + #endif + #define WIFININA_USE_STM32 true +#endif + +#if defined(WIFININA_USE_STM32) + #if defined(STM32F0) + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" + #elif defined(STM32F1) + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" + #elif defined(STM32F2) + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" + #elif defined(STM32F3) + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" + #elif defined(STM32F4) + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" + #elif defined(STM32F7) + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" + #elif defined(STM32L0) + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" + #elif defined(STM32L1) + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" + #elif defined(STM32L4) + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" + #elif defined(STM32H7) + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" + #elif defined(STM32G0) + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" + #elif defined(STM32G4) + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" + #elif defined(STM32WB) + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" + #elif defined(STM32MP1) + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" + #else + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" + #endif + +#endif + +#ifdef CORE_TEENSY + + #if defined(WIFININA_USE_TEENSY) + #undef WIFININA_USE_TEENSY + #endif + #define WIFININA_USE_TEENSY true + + #if defined(__IMXRT1062__) + // For Teensy 4.1/4.0 + #define BOARD_TYPE "TEENSY 4.1/4.0" + #elif defined(__MK66FX1M0__) + #define BOARD_TYPE "Teensy 3.6" + #elif defined(__MK64FX512__) + #define BOARD_TYPE "Teensy 3.5" + #elif defined(__MKL26Z64__) + #define BOARD_TYPE "Teensy LC" + #elif defined(__MK20DX256__) + #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) + #elif defined(__MK20DX128__) + #define BOARD_TYPE "Teensy 3.0" + #elif defined(__AVR_AT90USB1286__) + #error Teensy 2.0++ not supported yet + #elif defined(__AVR_ATmega32U4__) + #error Teensy 2.0 not supported yet + #else + // For Other Boards + #define BOARD_TYPE "Unknown Teensy Board" + #endif + +#endif + +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) + #if defined(WIFININA_USE_RP2040) + #undef WIFININA_USE_RP2040 + #endif + #define WIFININA_USE_RP2040 true + + #if defined(ARDUINO_ARCH_MBED) + + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_NANO_RP2040_CONNECT) + #define BOARD_NAME "MBED NANO_RP2040_CONNECT" + #elif defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_NAME "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_NAME "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_NAME "MBED GENERIC_RP2040" + #else + #define BOARD_NAME "MBED Unknown RP2040" + #endif + + #endif +#endif + +#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \ + defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__)) + #define BOARD_TYPE "Arduino AVR Mega2560/ADK" + #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. + +#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \ + defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \ + defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \ + defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) ) + #define BOARD_TYPE "Arduino AVR UNO, Nano, etc." + #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. + +#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \ + defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) ) + #define BOARD_TYPE "Adafruit AVR ATMega328(P)" + #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. + +#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \ + defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \ + defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) ) + #define BOARD_TYPE "Arduino AVR ATMega32U4" + #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. + +#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \ + defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) ) + #define BOARD_TYPE "Adafruit AVR ATMega32U4" + #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc. + +#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \ + defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega32U4" + #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. + +#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega328P" + #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc. + +#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega128RFA1" + #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc. + +#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) ) + #error These AVR boards are not supported! Please check your Tools->Board setting. + +#endif + +#if ( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) ) + #if !defined(BOARD_NAME) + #if (ARDUINO_AVR_UNO_WIFI_REV2) + #define BOARD_NAME "megaAVR UNO WiFi Rev2" + #elif (ARDUINO_AVR_NANO_EVERY) + #define BOARD_NAME "megaAVR Nano Every" + #else + #define BOARD_NAME "megaAVR Unknown" + #endif + #endif +#endif + +#ifndef BOARD_TYPE + #define BOARD_TYPE "Unknown board" +#endif + +#ifndef BOARD_NAME + #define BOARD_NAME BOARD_TYPE +#endif + +#define DEBUG_WIFININA_PORT Serial + +// Debug Level from 0 to 4 +#define _WIFININA_LOGLEVEL_ 1 +#define _WIFIMULTI_LOGLEVEL_ 2 + +#endif //defines_h diff --git a/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/WiFiUdpNtpClient_WiFiMulti.ino b/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/WiFiUdpNtpClient_WiFiMulti.ino new file mode 100644 index 00000000..62b21864 --- /dev/null +++ b/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/WiFiUdpNtpClient_WiFiMulti.ino @@ -0,0 +1,335 @@ +/**************************************************************************************************************************** + WiFiUdpNtpClient.ino + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*****************************************************************************************************************************/ + +#include "defines.h" +#include "arduino_secrets.h" + +// To eliminate FW warning when using not latest nina-fw version +// To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" + +#define USE_WIFI_NINA true +#define USE_WIFI101 false +#define USE_WIFI_CUSTOM false + +#include +#include +#include + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(132, 163, 96, 1); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +WiFiMulti_Generic wifiMulti; + +// send an NTP request to the time server at the given address +void sendNTPpacket(IPAddress& address) +{ + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); +} + +void heartBeatPrint() +{ + static int num = 1; + + //WFM_LOGDEBUG1("\nWiFi connected, RSSI:", WiFi.RSSI()); + + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi + + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } +} + +uint8_t connectMultiWiFi() +{ +// For general board, this better be 1000 to enable connect the 1st time +#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 1000L +#define WIFI_MULTI_CONNECT_WAITING_MS 500L + + Serial.println("WiFi lost. Trying to scan and reconnect"); + + WiFi.disconnect(); + + int i = 0; + + uint8_t status = wifiMulti.run(); + + delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); + + while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) + { + status = WiFi.status(); + + if ( status == WL_CONNECTED ) + break; + else + delay(WIFI_MULTI_CONNECT_WAITING_MS); + } + + if ( status == WL_CONNECTED ) + { + WFM_LOGERROR1(F("WiFi connected after time: "), i); + WFM_LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); + WFM_LOGERROR1(F("IP address:"), WiFi.localIP() ); + } + else + { + WFM_LOGERROR(F("WiFi not connected")); + + if (wifiMulti.run() != WL_CONNECTED) + { + Serial.println("WiFi not connected!"); + delay(1000); + } + } + + return status; +} + +void check_WiFi() +{ + if ( (WiFi.status() != WL_CONNECTED) ) + { + Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); + connectMultiWiFi(); + } +} + +void check_status() +{ + static uint32_t checkstatus_timeout = 0; + static uint32_t checkwifi_timeout = 0; + static uint32_t sendUDP_timeout = 0; + + static uint32_t current_millis; + +#define WIFICHECK_INTERVAL 1000L +#define HEARTBEAT_INTERVAL 10000L +#define SEND_UDP_INTERVAL 20000L + + current_millis = millis(); + + // Check WiFi every WIFICHECK_INTERVAL (1) seconds. + if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) + { + check_WiFi(); + checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; + } + + // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. + if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) + { + heartBeatPrint(); + checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; + } + + // Send UDP every SEND_UDP_INTERVAL (20) seconds. + if ((current_millis > sendUDP_timeout) || (sendUDP_timeout == 0)) + { + sendNTPpacket(timeServer); // send an NTP packet to a time server; + sendUDP_timeout = current_millis + SEND_UDP_INTERVAL; + } +} + +void printWiFiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print(F("SSID: ")); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print(F("IP Address: ")); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print(F("Signal strength (RSSI):")); + Serial.print(rssi); + Serial.println(F(" dBm")); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print(F("\nStart WiFiUdpNtpClient on ")); Serial.println(BOARD_NAME); + Serial.println(WIFIMULTI_GENERIC_VERSION); + Serial.println(WIFININA_GENERIC_VERSION); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println(F("Communication with WiFi module failed!")); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) + { + Serial.print(F("Your current firmware NINA FW v")); + Serial.println(fv); + Serial.print(F("Please upgrade the firmware to NINA FW v")); + Serial.println(WIFI_FIRMWARE_LATEST_VERSION); + } + + wifiMulti.addAP(SECRET_SSID1, SECRET_PASS1); + wifiMulti.addAP(SECRET_SSID2, SECRET_PASS2); + wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); + wifiMulti.addAP("ssid_from_AP_4", "your_password_for_AP_4"); + + Serial.println("Connecting WiFi..."); + + if (wifiMulti.run() == WL_CONNECTED) + { + Serial.print("\nWiFi connected, IP address: "); + Serial.println(WiFi.localIP()); + } + + Serial.println(F("Connected to WiFi")); + printWiFiStatus(); + + Serial.println(F("\nStarting connection to server...")); + Udp.begin(localPort); +} + +void getUDPPacket() +{ + if (Udp.parsePacket()) + { + Serial.println(F("\nPacket received")); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + + Serial.print(F("Seconds since Jan 1 1900 = ")); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print(F("Unix time = ")); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + // print the hour, minute and second: + Serial.print(F("The UTC time is ")); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + + if (((epoch % 3600) / 60) < 10) + { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + + if ((epoch % 60) < 10) + { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + + Serial.println(epoch % 60); // print the second + } +} + +void loop() +{ + getUDPPacket(); + check_status(); +} diff --git a/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/arduino_secrets.h b/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/arduino_secrets.h new file mode 100644 index 00000000..cf52660b --- /dev/null +++ b/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_SSID1 "your_ssid1" +#define SECRET_PASS1 "your_pass1" +#define SECRET_SSID2 "your_ssid2" +#define SECRET_PASS2 "your_pass2" diff --git a/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/defines.h b/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/defines.h new file mode 100644 index 00000000..42f9a9bb --- /dev/null +++ b/examples/WiFiMulti/WiFiUdpNtpClient_WiFiMulti/defines.h @@ -0,0 +1,402 @@ +/**************************************************************************************************************************** + defines.h + For boards with WiFiNINA module/shield. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ + || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ + || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ + || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD51__) || defined(__SAMD51J20A__) \ + || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) \ + || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ + || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ + || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) + #if defined(WIFININA_USE_SAMD) + #undef WIFININA_USE_SAMD + #endif + #define WIFININA_USE_SAMD true +#endif + +#if defined(WIFININA_USE_SAMD) + + #if defined(ARDUINO_SAMD_ZERO) + #define BOARD_TYPE "SAMD Zero" + #elif defined(ARDUINO_SAMD_MKR1000) + #define BOARD_TYPE "SAMD MKR1000" + #elif defined(ARDUINO_SAMD_MKRWIFI1010) + #define BOARD_TYPE "SAMD MKRWIFI1010" + #elif defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_TYPE "SAMD NANO_33_IOT" + #elif defined(ARDUINO_SAMD_MKRFox1200) + #define BOARD_TYPE "SAMD MKRFox1200" + #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) + #define BOARD_TYPE "SAMD MKRWAN13X0" + #elif defined(ARDUINO_SAMD_MKRGSM1400) + #define BOARD_TYPE "SAMD MKRGSM1400" + #elif defined(ARDUINO_SAMD_MKRNB1500) + #define BOARD_TYPE "SAMD MKRNB1500" + #elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #define BOARD_TYPE "SAMD MKRVIDOR4000" + #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) + #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" + #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" + #elif defined(ADAFRUIT_METRO_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" + #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" + #elif defined(ADAFRUIT_GEMMA_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" + #elif defined(ADAFRUIT_TRINKET_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" + #elif defined(ADAFRUIT_ITSYBITSY_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" + #elif defined(ARDUINO_SAMD_HALLOWING_M0) + #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" + #elif defined(ADAFRUIT_METRO_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" + #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" + #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" + #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" + #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" + #elif defined(ADAFRUIT_PYPORTAL) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" + #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" + #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" + #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" + #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" + #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" + #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" + #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" + #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" + #elif defined(SEEED_WIO_TERMINAL) + #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" + #elif defined(SEEED_FEMTO_M0) + #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" + #elif defined(SEEED_XIAO_M0) + #define BOARD_TYPE "SAMD SEEED_XIAO_M0" + #elif defined(Wio_Lite_MG126) + #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" + #elif defined(WIO_GPS_BOARD) + #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" + #elif defined(SEEEDUINO_ZERO) + #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" + #elif defined(SEEEDUINO_LORAWAN) + #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" + #elif defined(SEEED_GROVE_UI_WIRELESS) + #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" + #elif defined(__SAMD21E18A__) + #define BOARD_TYPE "SAMD21E18A" + #elif defined(__SAMD21G18A__) + #define BOARD_TYPE "SAMD21G18A" + #elif defined(__SAMD51G19A__) + #define BOARD_TYPE "SAMD51G19A" + #elif defined(__SAMD51J19A__) + #define BOARD_TYPE "SAMD51J19A" + #elif defined(__SAMD51P19A__) + #define BOARD_TYPE "__SAMD51P19A__" + #elif defined(__SAMD51J20A__) + #define BOARD_TYPE "SAMD51J20A" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM3X8E" + #elif defined(__CPU_ARC__) + #define BOARD_TYPE "CPU_ARC" + #elif defined(__SAMD51__) + #define BOARD_TYPE "SAMD51" + #else + #define BOARD_TYPE "SAMD Unknown" + #endif + +#endif + +#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ + defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) + #if defined(WIFININA_USE_NRF52) + #undef WIFININA_USE_NRF52 + #endif + #define WIFININA_USE_NRF52 true +#endif + +#if defined(WIFININA_USE_NRF52) + + #if defined(NRF52840_FEATHER) + #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" + #elif defined(NRF52832_FEATHER) + #define BOARD_TYPE "NRF52832_FEATHER" + #elif defined(NRF52840_FEATHER_SENSE) + #define BOARD_TYPE "NRF52840_FEATHER_SENSE" + #elif defined(NRF52840_ITSYBITSY) + #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" + #elif defined(NRF52840_CIRCUITPLAY) + #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" + #elif defined(NRF52840_CLUE) + #define BOARD_TYPE "NRF52840_CLUE" + #elif defined(NRF52840_METRO) + #define BOARD_TYPE "NRF52840_METRO_EXPRESS" + #elif defined(NRF52840_PCA10056) + #define BOARD_TYPE "NORDIC_NRF52840DK" + #elif defined(NINA_B302_ublox) + #define BOARD_TYPE "NINA_B302_ublox" + #elif defined(NINA_B112_ublox) + #define BOARD_TYPE "NINA_B112_ublox" + #elif defined(PARTICLE_XENON) + #define BOARD_TYPE "PARTICLE_XENON" + #elif defined(MDBT50Q_RX) + #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" + #elif defined(ARDUINO_NRF52_ADAFRUIT) + #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" + #else + #define BOARD_TYPE "nRF52 Unknown" + #endif + +#endif + +#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + #if defined(WIFININA_USE_SAMDUE) + #undef WIFININA_USE_SAMDUE + #endif + #define WIFININA_USE_SAMDUE true +#endif + +#if defined(WIFININA_USE_SAMDUE) + + // For SAM DUE + #if defined(ARDUINO_SAM_DUE) + #define BOARD_TYPE "SAM DUE" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM SAM3X8E" + #else + #define BOARD_TYPE "SAM Unknown" + #endif + +#endif + +#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + #if defined(WIFININA_USE_STM32) + #undef WIFININA_USE_STM32 + #endif + #define WIFININA_USE_STM32 true +#endif + +#if defined(WIFININA_USE_STM32) + #if defined(STM32F0) + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" + #elif defined(STM32F1) + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" + #elif defined(STM32F2) + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" + #elif defined(STM32F3) + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" + #elif defined(STM32F4) + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" + #elif defined(STM32F7) + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" + #elif defined(STM32L0) + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" + #elif defined(STM32L1) + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" + #elif defined(STM32L4) + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" + #elif defined(STM32H7) + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" + #elif defined(STM32G0) + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" + #elif defined(STM32G4) + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" + #elif defined(STM32WB) + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" + #elif defined(STM32MP1) + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" + #else + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" + #endif + +#endif + +#ifdef CORE_TEENSY + + #if defined(WIFININA_USE_TEENSY) + #undef WIFININA_USE_TEENSY + #endif + #define WIFININA_USE_TEENSY true + + #if defined(__IMXRT1062__) + // For Teensy 4.1/4.0 + #define BOARD_TYPE "TEENSY 4.1/4.0" + #elif defined(__MK66FX1M0__) + #define BOARD_TYPE "Teensy 3.6" + #elif defined(__MK64FX512__) + #define BOARD_TYPE "Teensy 3.5" + #elif defined(__MKL26Z64__) + #define BOARD_TYPE "Teensy LC" + #elif defined(__MK20DX256__) + #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) + #elif defined(__MK20DX128__) + #define BOARD_TYPE "Teensy 3.0" + #elif defined(__AVR_AT90USB1286__) + #error Teensy 2.0++ not supported yet + #elif defined(__AVR_ATmega32U4__) + #error Teensy 2.0 not supported yet + #else + // For Other Boards + #define BOARD_TYPE "Unknown Teensy Board" + #endif + +#endif + +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) + #if defined(WIFININA_USE_RP2040) + #undef WIFININA_USE_RP2040 + #endif + #define WIFININA_USE_RP2040 true + + #if defined(ARDUINO_ARCH_MBED) + + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_NANO_RP2040_CONNECT) + #define BOARD_NAME "MBED NANO_RP2040_CONNECT" + #elif defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_NAME "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_NAME "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_NAME "MBED GENERIC_RP2040" + #else + #define BOARD_NAME "MBED Unknown RP2040" + #endif + + #endif +#endif + +#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \ + defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__)) + #define BOARD_TYPE "Arduino AVR Mega2560/ADK" + #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. + +#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \ + defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \ + defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \ + defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) ) + #define BOARD_TYPE "Arduino AVR UNO, Nano, etc." + #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. + +#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \ + defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) ) + #define BOARD_TYPE "Adafruit AVR ATMega328(P)" + #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. + +#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \ + defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \ + defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) ) + #define BOARD_TYPE "Arduino AVR ATMega32U4" + #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. + +#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \ + defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) ) + #define BOARD_TYPE "Adafruit AVR ATMega32U4" + #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc. + +#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \ + defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega32U4" + #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. + +#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega328P" + #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc. + +#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega128RFA1" + #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc. + +#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) ) + #error These AVR boards are not supported! Please check your Tools->Board setting. + +#endif + +#if ( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) ) + #if !defined(BOARD_NAME) + #if (ARDUINO_AVR_UNO_WIFI_REV2) + #define BOARD_NAME "megaAVR UNO WiFi Rev2" + #elif (ARDUINO_AVR_NANO_EVERY) + #define BOARD_NAME "megaAVR Nano Every" + #else + #define BOARD_NAME "megaAVR Unknown" + #endif + #endif +#endif + +#ifndef BOARD_TYPE + #define BOARD_TYPE "Unknown board" +#endif + +#ifndef BOARD_NAME + #define BOARD_NAME BOARD_TYPE +#endif + +#define DEBUG_WIFININA_PORT Serial + +// Debug Level from 0 to 4 +#define _WIFININA_LOGLEVEL_ 1 +#define _WIFIMULTI_LOGLEVEL_ 2 + +#endif //defines_h diff --git a/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/WiFiWebClientRepeating_WiFiMulti.ino b/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/WiFiWebClientRepeating_WiFiMulti.ino new file mode 100644 index 00000000..fd9f7c96 --- /dev/null +++ b/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/WiFiWebClientRepeating_WiFiMulti.ino @@ -0,0 +1,285 @@ +/**************************************************************************************************************************** + WiFiWebClientRepeating.ino + + This sketch connects to a a web server and makes a request + using a WiFi equipped Arduino board. + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating + This code is in the public domain. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*****************************************************************************************************************************/ + +#include "defines.h" +#include "arduino_secrets.h" + +// To eliminate FW warning when using not latest nina-fw version +// To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" + +#define USE_WIFI_NINA true +#define USE_WIFI101 false +#define USE_WIFI_CUSTOM false + +#include +#include +#include + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the Wifi client library +WiFiClient client; + +// server address: +char server[] = "arduino.tips"; + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +WiFiMulti_Generic wifiMulti; + +void heartBeatPrint() +{ + static int num = 1; + + //WFM_LOGDEBUG1("\nWiFi connected, RSSI:", WiFi.RSSI()); + + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi + + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } +} + +uint8_t connectMultiWiFi() +{ +// For general board, this better be 1000 to enable connect the 1st time +#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 1000L + +#define WIFI_MULTI_CONNECT_WAITING_MS 500L + + Serial.println("WiFi lost. Trying to scan and reconnect"); + + WiFi.disconnect(); + + int i = 0; + + uint8_t status = wifiMulti.run(); + + delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); + + while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) + { + status = WiFi.status(); + + if ( status == WL_CONNECTED ) + break; + else + delay(WIFI_MULTI_CONNECT_WAITING_MS); + } + + if ( status == WL_CONNECTED ) + { + WFM_LOGERROR1(F("WiFi connected after time: "), i); + WFM_LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); + WFM_LOGERROR1(F("IP address:"), WiFi.localIP() ); + } + else + { + WFM_LOGERROR(F("WiFi not connected")); + + if (wifiMulti.run() != WL_CONNECTED) + { + Serial.println("WiFi not connected!"); + delay(1000); + } + } + + return status; +} + +void check_WiFi() +{ + if ( (WiFi.status() != WL_CONNECTED) ) + { + Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); + connectMultiWiFi(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() +{ + // close any connection before send a new request. + // This will free the socket on the Nina module + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) + { + Serial.println(F("\nConnected to server")); + // Make a HTTP request: + client.println(F("GET /asciilogo.txt HTTP/1.1")); + client.println("Host: arduino.tips"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } + else + { + // if you couldn't make a connection: + Serial.println(F("Connection failed")); + } +} + +void check_status() +{ + static uint32_t checkstatus_timeout = 0; + static uint32_t checkwifi_timeout = 0; + static uint32_t sendHTTP_timeout = 0; + + static uint32_t current_millis; + +#define WIFICHECK_INTERVAL 1000L +#define HEARTBEAT_INTERVAL 10000L +#define SEND_HTTP_INTERVAL 20000L + + current_millis = millis(); + + // Check WiFi every WIFICHECK_INTERVAL (1) seconds. + if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) + { + check_WiFi(); + checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; + } + + // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. + if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) + { + heartBeatPrint(); + checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; + } + + // Send httpRequest every SEND_HTTP_INTERVAL (20) seconds. + if ((current_millis > sendHTTP_timeout) || (sendHTTP_timeout == 0)) + { + httpRequest(); + sendHTTP_timeout = current_millis + SEND_HTTP_INTERVAL; + } +} + +void printWiFiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print(F("SSID: ")); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print(F("IP Address: ")); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print(F("Signal strength (RSSI):")); + Serial.print(rssi); + Serial.println(F(" dBm")); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print(F("\nStart WiFiWebClientRepeating on ")); Serial.println(BOARD_NAME); + Serial.println(WIFIMULTI_GENERIC_VERSION); + Serial.println(WIFININA_GENERIC_VERSION); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println(F("Communication with WiFi module failed!")); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) + { + Serial.print(F("Your current firmware NINA FW v")); + Serial.println(fv); + Serial.print(F("Please upgrade the firmware to NINA FW v")); + Serial.println(WIFI_FIRMWARE_LATEST_VERSION); + } + + wifiMulti.addAP(SECRET_SSID1, SECRET_PASS1); + wifiMulti.addAP(SECRET_SSID2, SECRET_PASS2); + wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); + wifiMulti.addAP("ssid_from_AP_4", "your_password_for_AP_4"); + + Serial.println("Connecting WiFi..."); + + if (wifiMulti.run() == WL_CONNECTED) + { + Serial.print("\nWiFi connected, IP address: "); + Serial.println(WiFi.localIP()); + } + + Serial.println(F("Connected to WiFi")); + printWiFiStatus(); +} + +void loop() +{ + check_status(); + + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) + { + char c = client.read(); + Serial.write(c); + } +} diff --git a/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/arduino_secrets.h b/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/arduino_secrets.h new file mode 100644 index 00000000..cf52660b --- /dev/null +++ b/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_SSID1 "your_ssid1" +#define SECRET_PASS1 "your_pass1" +#define SECRET_SSID2 "your_ssid2" +#define SECRET_PASS2 "your_pass2" diff --git a/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/defines.h b/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/defines.h new file mode 100644 index 00000000..42f9a9bb --- /dev/null +++ b/examples/WiFiMulti/WiFiWebClientRepeating_WiFiMulti/defines.h @@ -0,0 +1,402 @@ +/**************************************************************************************************************************** + defines.h + For boards with WiFiNINA module/shield. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ + || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ + || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ + || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD51__) || defined(__SAMD51J20A__) \ + || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) \ + || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ + || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ + || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) + #if defined(WIFININA_USE_SAMD) + #undef WIFININA_USE_SAMD + #endif + #define WIFININA_USE_SAMD true +#endif + +#if defined(WIFININA_USE_SAMD) + + #if defined(ARDUINO_SAMD_ZERO) + #define BOARD_TYPE "SAMD Zero" + #elif defined(ARDUINO_SAMD_MKR1000) + #define BOARD_TYPE "SAMD MKR1000" + #elif defined(ARDUINO_SAMD_MKRWIFI1010) + #define BOARD_TYPE "SAMD MKRWIFI1010" + #elif defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_TYPE "SAMD NANO_33_IOT" + #elif defined(ARDUINO_SAMD_MKRFox1200) + #define BOARD_TYPE "SAMD MKRFox1200" + #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) + #define BOARD_TYPE "SAMD MKRWAN13X0" + #elif defined(ARDUINO_SAMD_MKRGSM1400) + #define BOARD_TYPE "SAMD MKRGSM1400" + #elif defined(ARDUINO_SAMD_MKRNB1500) + #define BOARD_TYPE "SAMD MKRNB1500" + #elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #define BOARD_TYPE "SAMD MKRVIDOR4000" + #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) + #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" + #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" + #elif defined(ADAFRUIT_METRO_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" + #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" + #elif defined(ADAFRUIT_GEMMA_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" + #elif defined(ADAFRUIT_TRINKET_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" + #elif defined(ADAFRUIT_ITSYBITSY_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" + #elif defined(ARDUINO_SAMD_HALLOWING_M0) + #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" + #elif defined(ADAFRUIT_METRO_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" + #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" + #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" + #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" + #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" + #elif defined(ADAFRUIT_PYPORTAL) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" + #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" + #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" + #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" + #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" + #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" + #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" + #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" + #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" + #elif defined(SEEED_WIO_TERMINAL) + #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" + #elif defined(SEEED_FEMTO_M0) + #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" + #elif defined(SEEED_XIAO_M0) + #define BOARD_TYPE "SAMD SEEED_XIAO_M0" + #elif defined(Wio_Lite_MG126) + #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" + #elif defined(WIO_GPS_BOARD) + #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" + #elif defined(SEEEDUINO_ZERO) + #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" + #elif defined(SEEEDUINO_LORAWAN) + #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" + #elif defined(SEEED_GROVE_UI_WIRELESS) + #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" + #elif defined(__SAMD21E18A__) + #define BOARD_TYPE "SAMD21E18A" + #elif defined(__SAMD21G18A__) + #define BOARD_TYPE "SAMD21G18A" + #elif defined(__SAMD51G19A__) + #define BOARD_TYPE "SAMD51G19A" + #elif defined(__SAMD51J19A__) + #define BOARD_TYPE "SAMD51J19A" + #elif defined(__SAMD51P19A__) + #define BOARD_TYPE "__SAMD51P19A__" + #elif defined(__SAMD51J20A__) + #define BOARD_TYPE "SAMD51J20A" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM3X8E" + #elif defined(__CPU_ARC__) + #define BOARD_TYPE "CPU_ARC" + #elif defined(__SAMD51__) + #define BOARD_TYPE "SAMD51" + #else + #define BOARD_TYPE "SAMD Unknown" + #endif + +#endif + +#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ + defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) + #if defined(WIFININA_USE_NRF52) + #undef WIFININA_USE_NRF52 + #endif + #define WIFININA_USE_NRF52 true +#endif + +#if defined(WIFININA_USE_NRF52) + + #if defined(NRF52840_FEATHER) + #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" + #elif defined(NRF52832_FEATHER) + #define BOARD_TYPE "NRF52832_FEATHER" + #elif defined(NRF52840_FEATHER_SENSE) + #define BOARD_TYPE "NRF52840_FEATHER_SENSE" + #elif defined(NRF52840_ITSYBITSY) + #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" + #elif defined(NRF52840_CIRCUITPLAY) + #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" + #elif defined(NRF52840_CLUE) + #define BOARD_TYPE "NRF52840_CLUE" + #elif defined(NRF52840_METRO) + #define BOARD_TYPE "NRF52840_METRO_EXPRESS" + #elif defined(NRF52840_PCA10056) + #define BOARD_TYPE "NORDIC_NRF52840DK" + #elif defined(NINA_B302_ublox) + #define BOARD_TYPE "NINA_B302_ublox" + #elif defined(NINA_B112_ublox) + #define BOARD_TYPE "NINA_B112_ublox" + #elif defined(PARTICLE_XENON) + #define BOARD_TYPE "PARTICLE_XENON" + #elif defined(MDBT50Q_RX) + #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" + #elif defined(ARDUINO_NRF52_ADAFRUIT) + #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" + #else + #define BOARD_TYPE "nRF52 Unknown" + #endif + +#endif + +#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + #if defined(WIFININA_USE_SAMDUE) + #undef WIFININA_USE_SAMDUE + #endif + #define WIFININA_USE_SAMDUE true +#endif + +#if defined(WIFININA_USE_SAMDUE) + + // For SAM DUE + #if defined(ARDUINO_SAM_DUE) + #define BOARD_TYPE "SAM DUE" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM SAM3X8E" + #else + #define BOARD_TYPE "SAM Unknown" + #endif + +#endif + +#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + #if defined(WIFININA_USE_STM32) + #undef WIFININA_USE_STM32 + #endif + #define WIFININA_USE_STM32 true +#endif + +#if defined(WIFININA_USE_STM32) + #if defined(STM32F0) + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" + #elif defined(STM32F1) + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" + #elif defined(STM32F2) + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" + #elif defined(STM32F3) + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" + #elif defined(STM32F4) + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" + #elif defined(STM32F7) + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" + #elif defined(STM32L0) + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" + #elif defined(STM32L1) + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" + #elif defined(STM32L4) + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" + #elif defined(STM32H7) + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" + #elif defined(STM32G0) + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" + #elif defined(STM32G4) + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" + #elif defined(STM32WB) + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" + #elif defined(STM32MP1) + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" + #else + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" + #endif + +#endif + +#ifdef CORE_TEENSY + + #if defined(WIFININA_USE_TEENSY) + #undef WIFININA_USE_TEENSY + #endif + #define WIFININA_USE_TEENSY true + + #if defined(__IMXRT1062__) + // For Teensy 4.1/4.0 + #define BOARD_TYPE "TEENSY 4.1/4.0" + #elif defined(__MK66FX1M0__) + #define BOARD_TYPE "Teensy 3.6" + #elif defined(__MK64FX512__) + #define BOARD_TYPE "Teensy 3.5" + #elif defined(__MKL26Z64__) + #define BOARD_TYPE "Teensy LC" + #elif defined(__MK20DX256__) + #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) + #elif defined(__MK20DX128__) + #define BOARD_TYPE "Teensy 3.0" + #elif defined(__AVR_AT90USB1286__) + #error Teensy 2.0++ not supported yet + #elif defined(__AVR_ATmega32U4__) + #error Teensy 2.0 not supported yet + #else + // For Other Boards + #define BOARD_TYPE "Unknown Teensy Board" + #endif + +#endif + +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) + #if defined(WIFININA_USE_RP2040) + #undef WIFININA_USE_RP2040 + #endif + #define WIFININA_USE_RP2040 true + + #if defined(ARDUINO_ARCH_MBED) + + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_NANO_RP2040_CONNECT) + #define BOARD_NAME "MBED NANO_RP2040_CONNECT" + #elif defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_NAME "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_NAME "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_NAME "MBED GENERIC_RP2040" + #else + #define BOARD_NAME "MBED Unknown RP2040" + #endif + + #endif +#endif + +#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \ + defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__)) + #define BOARD_TYPE "Arduino AVR Mega2560/ADK" + #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. + +#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \ + defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \ + defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \ + defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) ) + #define BOARD_TYPE "Arduino AVR UNO, Nano, etc." + #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. + +#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \ + defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) ) + #define BOARD_TYPE "Adafruit AVR ATMega328(P)" + #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. + +#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \ + defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \ + defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) ) + #define BOARD_TYPE "Arduino AVR ATMega32U4" + #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. + +#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \ + defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) ) + #define BOARD_TYPE "Adafruit AVR ATMega32U4" + #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc. + +#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \ + defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega32U4" + #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. + +#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega328P" + #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc. + +#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega128RFA1" + #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc. + +#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) ) + #error These AVR boards are not supported! Please check your Tools->Board setting. + +#endif + +#if ( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) ) + #if !defined(BOARD_NAME) + #if (ARDUINO_AVR_UNO_WIFI_REV2) + #define BOARD_NAME "megaAVR UNO WiFi Rev2" + #elif (ARDUINO_AVR_NANO_EVERY) + #define BOARD_NAME "megaAVR Nano Every" + #else + #define BOARD_NAME "megaAVR Unknown" + #endif + #endif +#endif + +#ifndef BOARD_TYPE + #define BOARD_TYPE "Unknown board" +#endif + +#ifndef BOARD_NAME + #define BOARD_NAME BOARD_TYPE +#endif + +#define DEBUG_WIFININA_PORT Serial + +// Debug Level from 0 to 4 +#define _WIFININA_LOGLEVEL_ 1 +#define _WIFIMULTI_LOGLEVEL_ 2 + +#endif //defines_h diff --git a/examples/WiFiMulti/WiFiWebClient_WiFiMulti/WiFiWebClient_WiFiMulti.ino b/examples/WiFiMulti/WiFiWebClient_WiFiMulti/WiFiWebClient_WiFiMulti.ino new file mode 100644 index 00000000..f61c8db4 --- /dev/null +++ b/examples/WiFiMulti/WiFiWebClient_WiFiMulti/WiFiWebClient_WiFiMulti.ino @@ -0,0 +1,266 @@ +/**************************************************************************************************************************** + WiFiWebClient.ino + + This sketch connects to a website (http://www.google.com) + using the WiFi module. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the Wifi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the Wifi.begin() call accordingly. + + Circuit: + Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*****************************************************************************************************************************/ + +#include "defines.h" +#include "arduino_secrets.h" + +// To eliminate FW warning when using not latest nina-fw version +// To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" + +#define USE_WIFI_NINA true +#define USE_WIFI101 false +#define USE_WIFI_CUSTOM false + +#include +#include +#include + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +char server[] = "arduino.tips"; + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +WiFiMulti_Generic wifiMulti; + +void heartBeatPrint() +{ + static int num = 1; + + //WFM_LOGDEBUG1("\nWiFi connected, RSSI:", WiFi.RSSI()); + + if (WiFi.status() == WL_CONNECTED) + Serial.print(F("H")); // H means connected to WiFi + else + Serial.print(F("F")); // F means not connected to WiFi + + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } +} + +uint8_t connectMultiWiFi() +{ +// For general board, this better be 1000 to enable connect the 1st time +#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 1000L + +#define WIFI_MULTI_CONNECT_WAITING_MS 500L + + Serial.println("WiFi lost. Trying to scan and reconnect"); + + WiFi.disconnect(); + + int i = 0; + + uint8_t status = wifiMulti.run(); + + delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); + + while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) + { + status = WiFi.status(); + + if ( status == WL_CONNECTED ) + break; + else + delay(WIFI_MULTI_CONNECT_WAITING_MS); + } + + if ( status == WL_CONNECTED ) + { + WFM_LOGERROR1(F("WiFi connected after time: "), i); + WFM_LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI()); + WFM_LOGERROR1(F("IP address:"), WiFi.localIP() ); + } + else + { + WFM_LOGERROR(F("WiFi not connected")); + + if (wifiMulti.run() != WL_CONNECTED) + { + Serial.println("WiFi not connected!"); + delay(1000); + } + } + + return status; +} + +void check_WiFi() +{ + if ( (WiFi.status() != WL_CONNECTED) ) + { + Serial.println(F("\nWiFi lost. Call connectMultiWiFi in loop")); + connectMultiWiFi(); + } +} + +void check_status() +{ + static uint32_t checkstatus_timeout = 0; + static uint32_t checkwifi_timeout = 0; + + static uint32_t current_millis; + +#define WIFICHECK_INTERVAL 1000L +#define HEARTBEAT_INTERVAL 10000L + + current_millis = millis(); + + // Check WiFi every WIFICHECK_INTERVAL (1) seconds. + if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) + { + check_WiFi(); + checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; + } + + // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. + if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) + { + heartBeatPrint(); + checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; + } +} + +void printWiFiStatus() +{ + // print the SSID of the network you're attached to: + Serial.print(F("SSID: ")); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print(F("IP Address: ")); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print(F("Signal strength (RSSI):")); + Serial.print(rssi); + Serial.println(F(" dBm")); +} + +void setup() +{ + //Initialize serial and wait for port to open: + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print(F("\nStart WiFiWebClient on ")); Serial.println(BOARD_NAME); + Serial.println(WIFIMULTI_GENERIC_VERSION); + Serial.println(WIFININA_GENERIC_VERSION); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) + { + Serial.println(F("Communication with WiFi module failed!")); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) + { + Serial.print(F("Your current firmware NINA FW v")); + Serial.println(fv); + Serial.print(F("Please upgrade the firmware to NINA FW v")); + Serial.println(WIFI_FIRMWARE_LATEST_VERSION); + } + + wifiMulti.addAP(SECRET_SSID1, SECRET_PASS1); + wifiMulti.addAP(SECRET_SSID2, SECRET_PASS2); + wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); + wifiMulti.addAP("ssid_from_AP_4", "your_password_for_AP_4"); + + Serial.println("Connecting WiFi..."); + + if (wifiMulti.run() == WL_CONNECTED) + { + Serial.print("\nWiFi connected, IP address: "); + Serial.println(WiFi.localIP()); + } + + Serial.println(F("Connected to WiFi")); + printWiFiStatus(); + + Serial.println(F("\nStarting connection to server...")); + + // if you get a connection, report back via serial: + if (client.connect(server, 80)) + { + Serial.println(F("Connected to server")); + // Make a HTTP request: + client.println(F("GET /asciilogo.txt HTTP/1.1")); + client.println("Host: arduino.tips"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() +{ + check_status(); + + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) + { + char c = client.read(); + Serial.write(c); + } +} diff --git a/examples/WiFiMulti/WiFiWebClient_WiFiMulti/arduino_secrets.h b/examples/WiFiMulti/WiFiWebClient_WiFiMulti/arduino_secrets.h new file mode 100644 index 00000000..cf52660b --- /dev/null +++ b/examples/WiFiMulti/WiFiWebClient_WiFiMulti/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_SSID1 "your_ssid1" +#define SECRET_PASS1 "your_pass1" +#define SECRET_SSID2 "your_ssid2" +#define SECRET_PASS2 "your_pass2" diff --git a/examples/WiFiMulti/WiFiWebClient_WiFiMulti/defines.h b/examples/WiFiMulti/WiFiWebClient_WiFiMulti/defines.h new file mode 100644 index 00000000..bf726a47 --- /dev/null +++ b/examples/WiFiMulti/WiFiWebClient_WiFiMulti/defines.h @@ -0,0 +1,403 @@ +/**************************************************************************************************************************** + defines.h + For boards with WiFiNINA module/shield. + + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. + + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic + Licensed under MIT license + + Copyright (c) 2018 Arduino SA. All rights reserved. + Copyright (c) 2011-2014 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ + || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ + || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ + || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD51__) || defined(__SAMD51J20A__) \ + || defined(__SAMD51J19A__) || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) \ + || defined(__SAMD21E15A__) || defined(__SAMD21E16A__) || defined(__SAMD21E17A__) || defined(__SAMD21E18A__) \ + || defined(__SAMD21G15A__) || defined(__SAMD21G16A__) || defined(__SAMD21G17A__) || defined(__SAMD21G18A__) \ + || defined(__SAMD21J15A__) || defined(__SAMD21J16A__) || defined(__SAMD21J17A__) || defined(__SAMD21J18A__) ) + #if defined(WIFININA_USE_SAMD) + #undef WIFININA_USE_SAMD + #endif + #define WIFININA_USE_SAMD true +#endif + +#if defined(WIFININA_USE_SAMD) + + #if defined(ARDUINO_SAMD_ZERO) + #define BOARD_TYPE "SAMD Zero" + #elif defined(ARDUINO_SAMD_MKR1000) + #define BOARD_TYPE "SAMD MKR1000" + #elif defined(ARDUINO_SAMD_MKRWIFI1010) + #define BOARD_TYPE "SAMD MKRWIFI1010" + #elif defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_TYPE "SAMD NANO_33_IOT" + #elif defined(ARDUINO_SAMD_MKRFox1200) + #define BOARD_TYPE "SAMD MKRFox1200" + #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) + #define BOARD_TYPE "SAMD MKRWAN13X0" + #elif defined(ARDUINO_SAMD_MKRGSM1400) + #define BOARD_TYPE "SAMD MKRGSM1400" + #elif defined(ARDUINO_SAMD_MKRNB1500) + #define BOARD_TYPE "SAMD MKRNB1500" + #elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #define BOARD_TYPE "SAMD MKRVIDOR4000" + #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) + #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" + #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" + #elif defined(ADAFRUIT_METRO_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" + #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" + #elif defined(ADAFRUIT_GEMMA_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" + #elif defined(ADAFRUIT_TRINKET_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" + #elif defined(ADAFRUIT_ITSYBITSY_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" + #elif defined(ARDUINO_SAMD_HALLOWING_M0) + #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" + #elif defined(ADAFRUIT_METRO_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" + #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" + #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" + #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" + #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" + #elif defined(ADAFRUIT_PYPORTAL) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" + #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" + #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" + #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" + #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" + #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" + #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" + #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" + #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" + #elif defined(SEEED_WIO_TERMINAL) + #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" + #elif defined(SEEED_FEMTO_M0) + #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" + #elif defined(SEEED_XIAO_M0) + #define BOARD_TYPE "SAMD SEEED_XIAO_M0" + #elif defined(Wio_Lite_MG126) + #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" + #elif defined(WIO_GPS_BOARD) + #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" + #elif defined(SEEEDUINO_ZERO) + #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" + #elif defined(SEEEDUINO_LORAWAN) + #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" + #elif defined(SEEED_GROVE_UI_WIRELESS) + #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" + #elif defined(__SAMD21E18A__) + #define BOARD_TYPE "SAMD21E18A" + #elif defined(__SAMD21G18A__) + #define BOARD_TYPE "SAMD21G18A" + #elif defined(__SAMD51G19A__) + #define BOARD_TYPE "SAMD51G19A" + #elif defined(__SAMD51J19A__) + #define BOARD_TYPE "SAMD51J19A" + #elif defined(__SAMD51P19A__) + #define BOARD_TYPE "__SAMD51P19A__" + #elif defined(__SAMD51J20A__) + #define BOARD_TYPE "SAMD51J20A" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM3X8E" + #elif defined(__CPU_ARC__) + #define BOARD_TYPE "CPU_ARC" + #elif defined(__SAMD51__) + #define BOARD_TYPE "SAMD51" + #else + #define BOARD_TYPE "SAMD Unknown" + #endif + +#endif + +#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ + defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) + #if defined(WIFININA_USE_NRF52) + #undef WIFININA_USE_NRF52 + #endif + #define WIFININA_USE_NRF52 true +#endif + +#if defined(WIFININA_USE_NRF52) + + #if defined(NRF52840_FEATHER) + #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" + #elif defined(NRF52832_FEATHER) + #define BOARD_TYPE "NRF52832_FEATHER" + #elif defined(NRF52840_FEATHER_SENSE) + #define BOARD_TYPE "NRF52840_FEATHER_SENSE" + #elif defined(NRF52840_ITSYBITSY) + #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" + #elif defined(NRF52840_CIRCUITPLAY) + #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" + #elif defined(NRF52840_CLUE) + #define BOARD_TYPE "NRF52840_CLUE" + #elif defined(NRF52840_METRO) + #define BOARD_TYPE "NRF52840_METRO_EXPRESS" + #elif defined(NRF52840_PCA10056) + #define BOARD_TYPE "NORDIC_NRF52840DK" + #elif defined(NINA_B302_ublox) + #define BOARD_TYPE "NINA_B302_ublox" + #elif defined(NINA_B112_ublox) + #define BOARD_TYPE "NINA_B112_ublox" + #elif defined(PARTICLE_XENON) + #define BOARD_TYPE "PARTICLE_XENON" + #elif defined(MDBT50Q_RX) + #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" + #elif defined(ARDUINO_NRF52_ADAFRUIT) + #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" + #else + #define BOARD_TYPE "nRF52 Unknown" + #endif + +#endif + +#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + #if defined(WIFININA_USE_SAMDUE) + #undef WIFININA_USE_SAMDUE + #endif + #define WIFININA_USE_SAMDUE true +#endif + +#if defined(WIFININA_USE_SAMDUE) + + // For SAM DUE + #if defined(ARDUINO_SAM_DUE) + #define BOARD_TYPE "SAM DUE" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM SAM3X8E" + #else + #define BOARD_TYPE "SAM Unknown" + #endif + +#endif + +#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + #if defined(WIFININA_USE_STM32) + #undef WIFININA_USE_STM32 + #endif + #define WIFININA_USE_STM32 true +#endif + +#if defined(WIFININA_USE_STM32) + #if defined(STM32F0) + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" + #elif defined(STM32F1) + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" + #elif defined(STM32F2) + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" + #elif defined(STM32F3) + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" + #elif defined(STM32F4) + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" + #elif defined(STM32F7) + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" + #elif defined(STM32L0) + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" + #elif defined(STM32L1) + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" + #elif defined(STM32L4) + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" + #elif defined(STM32H7) + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" + #elif defined(STM32G0) + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" + #elif defined(STM32G4) + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" + #elif defined(STM32WB) + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" + #elif defined(STM32MP1) + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" + #else + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" + #endif + +#endif + +#ifdef CORE_TEENSY + + #if defined(WIFININA_USE_TEENSY) + #undef WIFININA_USE_TEENSY + #endif + #define WIFININA_USE_TEENSY true + + #if defined(__IMXRT1062__) + // For Teensy 4.1/4.0 + #define BOARD_TYPE "TEENSY 4.1/4.0" + #elif defined(__MK66FX1M0__) + #define BOARD_TYPE "Teensy 3.6" + #elif defined(__MK64FX512__) + #define BOARD_TYPE "Teensy 3.5" + #elif defined(__MKL26Z64__) + #define BOARD_TYPE "Teensy LC" + #elif defined(__MK20DX256__) + #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) + #elif defined(__MK20DX128__) + #define BOARD_TYPE "Teensy 3.0" + #elif defined(__AVR_AT90USB1286__) + #error Teensy 2.0++ not supported yet + #elif defined(__AVR_ATmega32U4__) + #error Teensy 2.0 not supported yet + #else + // For Other Boards + #define BOARD_TYPE "Unknown Teensy Board" + #endif + +#endif + +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) + #if defined(WIFININA_USE_RP2040) + #undef WIFININA_USE_RP2040 + #endif + #define WIFININA_USE_RP2040 true + + #if defined(ARDUINO_ARCH_MBED) + + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_NANO_RP2040_CONNECT) + #define BOARD_NAME "MBED NANO_RP2040_CONNECT" + #elif defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_NAME "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_NAME "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_NAME "MBED GENERIC_RP2040" + #else + #define BOARD_NAME "MBED Unknown RP2040" + #endif + + #endif +#endif + + +#if ( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || \ + defined(__AVR_ATmega640__) || defined(__AVR_ATmega641__)) + #define BOARD_TYPE "Arduino AVR Mega2560/ADK" + #warning Using Arduino AVR Mega, Mega640(P), Mega2560/ADK. + +#elif ( defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || \ + defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || \ + defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || \ + defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) || defined(ARDUINO_AVR_DUEMILANOVE) ) + #define BOARD_TYPE "Arduino AVR UNO, Nano, etc." + #warning Using Aduino AVR ATMega644(P), ATMega328(P) such as UNO, Nano. + +#elif ( defined(ARDUINO_AVR_FEATHER328P) || defined(ARDUINO_AVR_METRO) || defined(ARDUINO_AVR_PROTRINKET5) || defined(ARDUINO_AVR_PROTRINKET3) || \ + defined(ARDUINO_AVR_PROTRINKET5FTDI) || defined(ARDUINO_AVR_PROTRINKET3FTDI) ) + #define BOARD_TYPE "Adafruit AVR ATMega328(P)" + #warning Using Adafruit ATMega328(P), such as AVR_FEATHER328P or AVR_METRO. + +#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \ + defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \ + defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) ) + #define BOARD_TYPE "Arduino AVR ATMega32U4" + #warning Using Arduino ATMega32U4, such as Leonardo or Leonardo ETH. + +#elif ( defined(ARDUINO_AVR_FLORA8 ) || defined(ARDUINO_AVR_FEATHER32U4) || defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_ITSYBITSY32U4_5V) || \ + defined(ARDUINO_AVR_ITSYBITSY32U4_3V) || defined(ARDUINO_AVR_BLUEFRUITMICRO) || defined(ARDUINO_AVR_ADAFRUIT32U4) ) + #define BOARD_TYPE "Adafruit AVR ATMega32U4" + #warning Using Adafruit ATMega32U4, such as Feather_32u4, AVR_CIRCUITPLAY, etc. + +#elif ( defined(__AVR_ATmega32U4__) || defined(ARDUINO_AVR_MAKEYMAKEY ) || defined(ARDUINO_AVR_PROMICRO) || defined(ARDUINO_AVR_FIOV3) || \ + defined(ARDUINO_AVR_QDUINOMINI) || defined(ARDUINO_AVR_LILYPAD_ARDUINO_USB_PLUS_BOARD ) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega32U4" + #warning Using Generic ATMega32U4, such as Sparkfun AVR_MAKEYMAKEY, AVR_PROMICRO, etc. + +#elif ( defined(__AVR_ATmega328P__) || defined(ARDUINO_AVR_DIGITAL_SANDBOX ) || defined(ARDUINO_REDBOT) || defined(ARDUINO_AVR_SERIAL_7_SEGMENT) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega328P" + #warning Using Generic ATMega328P, such as Sparkfun AVR_DIGITAL_SANDBOX, REDBOT, etc. + +#elif ( defined(__AVR_ATmega128RFA1__) || defined(ARDUINO_ATMEGA128RFA1_DEV_BOARD) ) + #define BOARD_TYPE "Generic or Sparkfun AVR ATMega128RFA1" + #warning Using Generic ATMega128RFA1, such as Sparkfun ATMEGA128RFA1_DEV_BOARD, etc. + +#elif ( defined(ARDUINO_AVR_GEMMA) || defined(ARDUINO_AVR_TRINKET3) || defined(ARDUINO_AVR_TRINKET5) ) + #error These AVR boards are not supported! Please check your Tools->Board setting. + +#endif + +#if ( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) ) + #if !defined(BOARD_NAME) + #if (ARDUINO_AVR_UNO_WIFI_REV2) + #define BOARD_NAME "megaAVR UNO WiFi Rev2" + #elif (ARDUINO_AVR_NANO_EVERY) + #define BOARD_NAME "megaAVR Nano Every" + #else + #define BOARD_NAME "megaAVR Unknown" + #endif + #endif +#endif + +#ifndef BOARD_TYPE + #define BOARD_TYPE "Unknown board" +#endif + +#ifndef BOARD_NAME + #define BOARD_NAME BOARD_TYPE +#endif + +#define DEBUG_WIFININA_PORT Serial + +// Debug Level from 0 to 4 +#define _WIFININA_LOGLEVEL_ 1 +#define _WIFIMULTI_LOGLEVEL_ 2 + +#endif //defines_h diff --git a/examples/WiFiNINA_SSL_Test/WiFiNINA_SSL_Test.ino b/examples/WiFiNINA_SSL_Test/WiFiNINA_SSL_Test.ino index 061b3e1d..1f2cbda6 100644 --- a/examples/WiFiNINA_SSL_Test/WiFiNINA_SSL_Test.ino +++ b/examples/WiFiNINA_SSL_Test/WiFiNINA_SSL_Test.ino @@ -39,7 +39,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -62,7 +62,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial) ; + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiNINA_SSL_Test on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiPing/WiFiPing.ino b/examples/WiFiPing/WiFiPing.ino index 21ba95c2..42e852df 100644 --- a/examples/WiFiPing/WiFiPing.ino +++ b/examples/WiFiPing/WiFiPing.ino @@ -43,7 +43,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -64,7 +64,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiPing on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiSSLClient/WiFiSSLClient.ino b/examples/WiFiSSLClient/WiFiSSLClient.ino index eba60a8f..db66d7ab 100644 --- a/examples/WiFiSSLClient/WiFiSSLClient.ino +++ b/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -39,7 +39,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -66,7 +66,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiSSLClient on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiStorage/WiFiStorage.ino b/examples/WiFiStorage/WiFiStorage.ino index fdb1b75c..a2d30f45 100644 --- a/examples/WiFiStorage/WiFiStorage.ino +++ b/examples/WiFiStorage/WiFiStorage.ino @@ -32,7 +32,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include @@ -43,7 +43,7 @@ void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiStorage on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino index b6d518d6..a18efb69 100644 --- a/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino +++ b/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -44,7 +44,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -73,7 +73,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiUdpNtpClient on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino index 08d7208c..12fb3727 100644 --- a/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino +++ b/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -38,7 +38,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -63,7 +63,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiUdpSendReceiveString on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); diff --git a/examples/WiFiWebClient/WiFiWebClient.ino b/examples/WiFiWebClient/WiFiWebClient.ino index ab2421f5..d5a8085b 100644 --- a/examples/WiFiWebClient/WiFiWebClient.ino +++ b/examples/WiFiWebClient/WiFiWebClient.ino @@ -47,7 +47,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -62,8 +62,8 @@ int status = WL_IDLE_STATUS; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: -//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) -char server[] = "www.google.com"; // name address for Google (using DNS) +// server address: +char server[] = "arduino.tips"; // Initialize the Ethernet client library // with the IP address and port of the server @@ -74,7 +74,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiWebClient on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); @@ -118,8 +118,8 @@ void setup() { Serial.println(F("Connected to server")); // Make a HTTP request: - client.println("GET /search?q=WiFiNINA_Generic HTTP/1.1"); - client.println("Host: www.google.com"); + client.println(F("GET /asciilogo.txt HTTP/1.1")); + client.println("Host: arduino.tips"); client.println("Connection: close"); client.println(); } diff --git a/examples/WiFiWebClient/arduino_secrets.h b/examples/WiFiWebClient/arduino_secrets.h index 7864fa11..6c94b3a0 100644 --- a/examples/WiFiWebClient/arduino_secrets.h +++ b/examples/WiFiWebClient/arduino_secrets.h @@ -1,4 +1,2 @@ -#define SECRET_SSID "HueNet1" -#define SECRET_PASS "jenniqqs" -//#define SECRET_SSID "your_ssid" -//#define SECRET_PASS "your_pass" +#define SECRET_SSID "your_ssid" +#define SECRET_PASS "your_pass" diff --git a/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino index 89d9765a..702fe836 100644 --- a/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino +++ b/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -42,7 +42,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -59,8 +59,7 @@ int status = WL_IDLE_STATUS; WiFiClient client; // server address: -char server[] = "example.org"; -//IPAddress server(64,131,82,241); +char server[] = "arduino.tips"; unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds @@ -69,7 +68,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiWebClientRepeating on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION); @@ -136,11 +135,10 @@ void httpRequest() // if there's a successful connection: if (client.connect(server, 80)) { - Serial.println(F("Connecting...")); - // send the HTTP GET request: - client.println("GET / HTTP/1.1"); - client.println("Host: example.org"); - client.println("User-Agent: ArduinoWiFi/1.1"); + Serial.println(F("Connected to server")); + // Make a HTTP request: + client.println(F("GET /asciilogo.txt HTTP/1.1")); + client.println("Host: arduino.tips"); client.println("Connection: close"); client.println(); diff --git a/examples/WiFiWebServer/WiFiWebServer.ino b/examples/WiFiWebServer/WiFiWebServer.ino index 8e448b91..dd1f2863 100644 --- a/examples/WiFiWebServer/WiFiWebServer.ino +++ b/examples/WiFiWebServer/WiFiWebServer.ino @@ -43,7 +43,7 @@ // To eliminate FW warning when using not latest nina-fw version // To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version -#define WIFI_FIRMWARE_LATEST_VERSION "1.4.5" +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" #include #include @@ -62,7 +62,7 @@ void setup() { //Initialize serial and wait for port to open: Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WiFiWebServer on ")); Serial.println(BOARD_NAME); Serial.println(WIFININA_GENERIC_VERSION);