|
| 1 | +/**************************************************************************************************************************** |
| 2 | + WiFiWebServer_BigData.ino |
| 3 | +
|
| 4 | + A simple web server that shows the value of the analog input pins. |
| 5 | +
|
| 6 | + This example is written for a network using WPA encryption. For |
| 7 | + WEP or WPA, change the Wifi.begin() call accordingly. |
| 8 | +
|
| 9 | + Circuit: |
| 10 | + Analog inputs attached to pins A0 through A5 (optional) |
| 11 | +
|
| 12 | + created 13 July 2010 |
| 13 | + by dlf (Metodo2 srl) |
| 14 | + modified 31 May 2012 |
| 15 | + by Tom Igoe |
| 16 | +
|
| 17 | + Based on and modified from WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA |
| 18 | + to support nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, etc. boards besides Nano-33 IoT, MKRWIFI1010, MKRVIDOR400, etc. |
| 19 | +
|
| 20 | + Built by Khoi Hoang https://github.com/khoih-prog/WiFiNINA_Generic |
| 21 | + Licensed under MIT license |
| 22 | +
|
| 23 | + Copyright (c) 2018 Arduino SA. All rights reserved. |
| 24 | + Copyright (c) 2011-2014 Arduino LLC. All right reserved. |
| 25 | +
|
| 26 | + This library is free software; you can redistribute it and/or |
| 27 | + modify it under the terms of the GNU Lesser General Public |
| 28 | + License as published by the Free Software Foundation; either |
| 29 | + version 2.1 of the License, or (at your option) any later version. |
| 30 | +
|
| 31 | + This library is distributed in the hope that it will be useful, |
| 32 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 34 | + Lesser General Public License for more details. |
| 35 | +
|
| 36 | + You should have received a copy of the GNU Lesser General Public |
| 37 | + License along with this library; if not, write to the Free Software |
| 38 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 39 | + *****************************************************************************************************************************/ |
| 40 | + |
| 41 | +#include "defines.h" |
| 42 | +#include "arduino_secrets.h" |
| 43 | + |
| 44 | +// To eliminate FW warning when using not latest nina-fw version |
| 45 | +// To use whenever WiFi101-FirmwareUpdater-Plugin is not sync'ed with nina-fw version |
| 46 | +#define WIFI_FIRMWARE_LATEST_VERSION "1.4.8" |
| 47 | + |
| 48 | +#include <SPI.h> |
| 49 | +#include <WiFiNINA_Generic.h> |
| 50 | +#include <WiFiWebServer.h> |
| 51 | + |
| 52 | +///////please enter your sensitive data in the Secret tab/arduino_secrets.h |
| 53 | +char ssid[] = SECRET_SSID; // your network SSID (name) |
| 54 | +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP), length must be 8+ |
| 55 | + |
| 56 | +int keyIndex = 0; // your network key Index number (needed only for WEP) |
| 57 | + |
| 58 | +int status = WL_IDLE_STATUS; |
| 59 | + |
| 60 | +WiFiWebServer server(80); |
| 61 | + |
| 62 | +// Adjust according to yout board's heap size. Too large => crash |
| 63 | +// Nano_RO2040_Connect =< can use 3.0f or more |
| 64 | +// Nano_33_IoT => 2.5f |
| 65 | +#if defined(ARDUINO_NANO_RP2040_CONNECT) |
| 66 | + #define MULTIPLY_FACTOR 3.0f |
| 67 | +#elif defined(ARDUINO_SAMD_NANO_33_IOT) |
| 68 | + #define MULTIPLY_FACTOR 2.5f |
| 69 | +#else |
| 70 | + #define MULTIPLY_FACTOR 1.0f |
| 71 | +#endif |
| 72 | + |
| 73 | +// In bytes |
| 74 | +#define STRING_SIZE (8192 * MULTIPLY_FACTOR) |
| 75 | + |
| 76 | +#define BUFFER_SIZE 512 |
| 77 | +char temp[BUFFER_SIZE]; |
| 78 | + |
| 79 | +void createPage(String &pageInput) |
| 80 | +{ |
| 81 | + int sec = millis() / 1000; |
| 82 | + int min = sec / 60; |
| 83 | + int hr = min / 60; |
| 84 | + int day = hr / 24; |
| 85 | + |
| 86 | + snprintf(temp, BUFFER_SIZE - 1, |
| 87 | + "<html>\ |
| 88 | +<head>\ |
| 89 | +<meta http-equiv='refresh' content='5'/>\ |
| 90 | +<title>WiFiWebServer_BigData-%s</title>\ |
| 91 | +<style>\ |
| 92 | +body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\ |
| 93 | +</style>\ |
| 94 | +</head>\ |
| 95 | +<body>\ |
| 96 | +<h2>WiFiWebServer_NINA!</h2>\ |
| 97 | +<h3>running on %s</h3>\ |
| 98 | +<p>Uptime: %d d %02d:%02d:%02d</p>\ |
| 99 | +</body>\ |
| 100 | +</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60); |
| 101 | + |
| 102 | + pageInput = temp; |
| 103 | +} |
| 104 | + |
| 105 | +String out; |
| 106 | + |
| 107 | +void handleRoot() |
| 108 | +{ |
| 109 | + //out.reserve(STRING_SIZE); |
| 110 | + |
| 111 | + // clear the String to start over |
| 112 | + out = String(); |
| 113 | + |
| 114 | + createPage(out); |
| 115 | + |
| 116 | + out += "<html><body>\r\n<table><tr><th>INDEX</th><th>DATA</th></tr>"; |
| 117 | + |
| 118 | + for (uint16_t lineIndex = 0; lineIndex < (100 * MULTIPLY_FACTOR); lineIndex++) |
| 119 | + { |
| 120 | + out += "<tr><td>"; |
| 121 | + out += String(lineIndex); |
| 122 | + out += "</td><td>"; |
| 123 | + out += "WiFiWebServer_BigData_ABCDEFGHIJKLMNOPQRSTUVWXYZ</td></tr>"; |
| 124 | + } |
| 125 | + |
| 126 | + out += "</table></body></html>\r\n"; |
| 127 | + |
| 128 | + Serial.print(F("String Len = ")); Serial.println(out.length()); |
| 129 | + |
| 130 | + server.send(200, F("text/html"), out); |
| 131 | +} |
| 132 | + |
| 133 | +void handleNotFound() |
| 134 | +{ |
| 135 | + String message = F("File Not Found\n\n"); |
| 136 | + |
| 137 | + message += F("URI: "); |
| 138 | + message += server.uri(); |
| 139 | + message += F("\nMethod: "); |
| 140 | + message += (server.method() == HTTP_GET) ? F("GET") : F("POST"); |
| 141 | + message += F("\nArguments: "); |
| 142 | + message += server.args(); |
| 143 | + message += F("\n"); |
| 144 | + |
| 145 | + for (uint8_t i = 0; i < server.args(); i++) |
| 146 | + { |
| 147 | + message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; |
| 148 | + } |
| 149 | + |
| 150 | + server.send(404, F("text/plain"), message); |
| 151 | +} |
| 152 | + |
| 153 | +void printWiFiStatus() |
| 154 | +{ |
| 155 | + // print the SSID of the network you're attached to: |
| 156 | + Serial.print(F("SSID: ")); |
| 157 | + Serial.println(WiFi.SSID()); |
| 158 | + |
| 159 | + // print your board's IP address: |
| 160 | + IPAddress ip = WiFi.localIP(); |
| 161 | + Serial.print(F("IP Address: ")); |
| 162 | + Serial.println(ip); |
| 163 | + |
| 164 | + // print the received signal strength: |
| 165 | + long rssi = WiFi.RSSI(); |
| 166 | + Serial.print(F("Signal strength (RSSI):")); |
| 167 | + Serial.print(rssi); |
| 168 | + Serial.println(F(" dBm")); |
| 169 | +} |
| 170 | + |
| 171 | +void setup() |
| 172 | +{ |
| 173 | + out.reserve(STRING_SIZE); |
| 174 | + |
| 175 | + //Initialize serial and wait for port to open: |
| 176 | + Serial.begin(115200); |
| 177 | + |
| 178 | + while (!Serial && millis() < 5000); |
| 179 | + |
| 180 | + delay(200); |
| 181 | + |
| 182 | + Serial.print(F("\nStart WiFiWebServer_BigData on ")); |
| 183 | + Serial.println(BOARD_NAME); |
| 184 | + Serial.println(WIFININA_GENERIC_VERSION); |
| 185 | + Serial.println(WIFI_WEBSERVER_VERSION); |
| 186 | + |
| 187 | + // check for the WiFi module: |
| 188 | + if (WiFi.status() == WL_NO_MODULE) |
| 189 | + { |
| 190 | + Serial.println(F("Communication with WiFi module failed!")); |
| 191 | + |
| 192 | + // don't continue |
| 193 | + while (true); |
| 194 | + } |
| 195 | + |
| 196 | + String fv = WiFi.firmwareVersion(); |
| 197 | + |
| 198 | + if (fv < WIFI_FIRMWARE_LATEST_VERSION) |
| 199 | + { |
| 200 | + Serial.print(F("Your current firmware NINA FW v")); |
| 201 | + Serial.println(fv); |
| 202 | + Serial.print(F("Please upgrade the firmware to NINA FW v")); |
| 203 | + Serial.println(WIFI_FIRMWARE_LATEST_VERSION); |
| 204 | + } |
| 205 | + |
| 206 | + // attempt to connect to Wifi network: |
| 207 | + while (status != WL_CONNECTED) |
| 208 | + { |
| 209 | + Serial.print(F("Attempting to connect to SSID: ")); |
| 210 | + Serial.println(ssid); |
| 211 | + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: |
| 212 | + status = WiFi.begin(ssid, pass); |
| 213 | + |
| 214 | + // wait 10 seconds for connection: |
| 215 | + //delay(10000); |
| 216 | + } |
| 217 | + |
| 218 | + // you're connected now, so print out the status: |
| 219 | + printWiFiStatus(); |
| 220 | + |
| 221 | + server.on(F("/"), handleRoot); |
| 222 | + |
| 223 | + server.on(F("/inline"), []() |
| 224 | + { |
| 225 | + server.send(200, F("text/plain"), F("This works as well")); |
| 226 | + }); |
| 227 | + |
| 228 | + server.onNotFound(handleNotFound); |
| 229 | + |
| 230 | + server.begin(); |
| 231 | +} |
| 232 | + |
| 233 | +void loop() |
| 234 | +{ |
| 235 | + server.handleClient(); |
| 236 | +} |
0 commit comments