@@ 53,6 53,7 @@
#include <LEAmDNS.h>
#endif /* WANT_MDNS */
+#include <WiFiWebServer.h>
#include <StreamUtils.h>
#include <ArduinoJson.h>
@@ 69,8 70,9 @@ String ssid = PROJECTNAME "-";
#define CONFIG_PORTAL_TIMEOUT_SEC 2
-WiFiMulti_Generic wifiMulti;
+//WiFiMulti_Generic wifiMulti;
+WiFiWebServer webserver(80);
// SSID and PW for your Router
String Router_SSID;
String Router_Pass;
@@ 247,14 249,14 @@ bool initialConfig = false;
uint8_t connectMultiWiFi();
void blink(int speed, int count) {
- pinMode(16, OUTPUT);
+ pinMode(LED_BUILTIN, OUTPUT);
for(; count > 0; count--) {
- digitalWrite(16, ON);
+ digitalWrite(LED_BUILTIN, ON);
sleep(speed);
- digitalWrite(16, OFF);
+ digitalWrite(LED_BUILTIN, OFF);
sleep(speed);
}
- digitalWrite(16, ON);
+ digitalWrite(LED_BUILTIN, ON);
}
void resetFunc() {
@@ 490,11 492,33 @@ uint8_t connectMultiWiFi()
return status;
}
+void handleRoot() {
+ blink(2, SLOW);
+ webserver.send(200, F("text/plain"), F("hello from wx-sensors on pico w!\r\n"));
+}
+
+void handleNotFound() {
+ String message = "File Not Found\n\n";
+ message += "URI: ";
+ message += webserver.uri();
+ message += "\nMethod: ";
+ message += (webserver.method() == HTTP_GET) ? "GET" : "POST";
+ message += "\nArguments: ";
+ message += webserver.args();
+ message += "\n";
+ for (uint8_t i = 0; i < webserver.args(); i++) {
+ message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n";
+ }
+ webserver.send(404, "text/plain", message);
+ blink(2, SLOW);
+
+}
+
void setup()
{
// put your setup code here, to run once:
// initialize the LED digital pin as an output.
- pinMode(PIN_LED, OUTPUT);
+ pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial && millis() < 5000);
@@ 503,6 527,8 @@ void setup()
delay(200);
+ watchdog_enable(8300, false);
+
Wire1.setSDA(6);
Wire1.setSCL(7);
Wire1.begin();
@@ 523,7 549,7 @@ void setup()
WiFi.disconnect();
- digitalWrite(PIN_LED, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
+ digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
unsigned long startedAt = millis();
@@ 597,7 623,7 @@ void setup()
LOGERROR(F("Password"));
LOGERROR(CONFIG_PORTAL_PASSWORD);
- digitalWrite(PIN_LED, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
+ digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode.
RP2040W_WiFiManager.setConfigPortalTimeout(300); //If no access point name has been previously entered
@@ 625,7 651,7 @@ void setup()
initialConfig = true;
}
- digitalWrite(PIN_LED, LED_OFF); // Turn led off as we are not in configuration mode.
+ digitalWrite(LED_BUILTIN, LED_OFF); // Turn led off as we are not in configuration mode.
// reboot and try to startup with newly saved config.
resetFunc();
@@ 721,7 747,33 @@ void setup()
attachInterrupt(digitalPinToInterrupt(RAIN_PIN), rainInterrupt, FALLING);
attachInterrupt(digitalPinToInterrupt(SPEED_PIN), windInterrupt, FALLING);
- watchdog_enable(8300, false);
+ webserver.on("/", handleRoot);
+ //
+ // server.on("/inline", []() {
+ // server.send(200, "text/plain", "this works as well");
+ // });
+
+ // webserver.on("/gif", []() {
+ // static const uint8_t gif[] = {
+ // 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01,
+ // 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00,
+ // 0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d,
+ // 0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c,
+ // 0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b
+ // };
+ // char gif_colored[sizeof(gif)];
+ // memcpy_P(gif_colored, gif, sizeof(gif));
+ // // Set the background to a random set of colors
+ // gif_colored[16] = millis() % 256;
+ // gif_colored[17] = millis() % 256;
+ // gif_colored[18] = millis() % 256;
+ // webserver.send(200, "image/gif", gif_colored, sizeof(gif_colored));
+ // });
+
+ webserver.onNotFound(handleNotFound);
+
+ webserver.begin();
+
}
boolean haveStarted = false;
@@ 893,6 945,8 @@ void loop() {
rapidWind();
}
weather_report();
+
+ webserver.handleClient();
}
if (millis() > 10000 && !haveStarted) {