123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * This example shows how to use WebSerial variant to send logging data to the browser.
- *
- * Before using this example, make sure to look at the WebSerial example before and its description.\
- *
- * You might want to control these flags to control the async library performance:
- * -D CONFIG_ASYNC_TCP_QUEUE_SIZE=128
- * -D CONFIG_ASYNC_TCP_RUNNING_CORE=1
- * -D WS_MAX_QUEUED_MESSAGES=128
- */
- #include <Arduino.h>
- #if defined(ESP8266)
- #include <ESP8266WiFi.h>
- #include <ESPAsyncTCP.h>
- #elif defined(ESP32)
- #include <WiFi.h>
- #include <AsyncTCP.h>
- #elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
- #include <WiFi.h>
- #include <RPAsyncTCP.h>
- #endif
- #include <DNSServer.h>
- #include <ESPAsyncWebServer.h>
- #include <WString.h>
- #include <WebSerial.h>
- AsyncWebServer server(80);
- static uint32_t last = millis();
- static uint32_t count = 0;
- void setup() {
- Serial.begin(115200);
- WiFi.softAP("WSLDemo");
- Serial.print("IP Address: ");
- Serial.println(WiFi.softAPIP().toString());
- WebSerial.onMessage([](const String& msg) { Serial.println(msg); });
- WebSerial.begin(&server);
- WebSerial.setBuffer(100);
- server.onNotFound([](AsyncWebServerRequest* request) { request->redirect("/webserial"); });
- server.begin();
- }
- void loop() {
- if (millis() - last > 1000) {
- count++;
- WebSerial.print(F("IP address: "));
- WebSerial.println(WiFi.softAPIP());
- WebSerial.printf("Uptime: %lums\n", millis());
- #if defined(ESP8266)
- WebSerial.printf("Free heap: %" PRIu32 "\n", ESP.getFreeHeap());
- #elif defined(ESP32)
- WebSerial.printf("Free heap: %" PRIu32 "\n", ESP.getFreeHeap());
- #elif defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350)
- WebSerial.printf("Free heap: %" PRIu32 "\n", rp2040.getFreeHeap());
- #endif
- last = millis();
- }
- }
|