Logging.ino 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * This example shows how to use WebSerial variant to send logging data to the browser.
  3. *
  4. * Before using this example, make sure to look at the WebSerial example before and its description.\
  5. *
  6. * You might want to control these flags to control the async library performance:
  7. * -D CONFIG_ASYNC_TCP_QUEUE_SIZE=128
  8. * -D CONFIG_ASYNC_TCP_RUNNING_CORE=1
  9. * -D WS_MAX_QUEUED_MESSAGES=128
  10. */
  11. #include <Arduino.h>
  12. #if defined(ESP8266)
  13. #include <ESP8266WiFi.h>
  14. #include <ESPAsyncTCP.h>
  15. #elif defined(ESP32)
  16. #include <AsyncTCP.h>
  17. #include <WiFi.h>
  18. #endif
  19. #include <DNSServer.h>
  20. #include <ESPAsyncWebServer.h>
  21. #include <WString.h>
  22. #include <WebSerial.h>
  23. AsyncWebServer server(80);
  24. static uint32_t last = millis();
  25. static uint32_t count = 0;
  26. void setup() {
  27. Serial.begin(115200);
  28. WiFi.softAP("WSLDemo");
  29. Serial.print("IP Address: ");
  30. Serial.println(WiFi.softAPIP().toString());
  31. WebSerial.onMessage([](const String& msg) { Serial.println(msg); });
  32. WebSerial.begin(&server);
  33. WebSerial.setBuffer(100);
  34. server.onNotFound([](AsyncWebServerRequest* request) { request->redirect("/webserial"); });
  35. server.begin();
  36. }
  37. void loop() {
  38. if (millis() - last > 1000) {
  39. count++;
  40. WebSerial.print(F("IP address: "));
  41. WebSerial.println(WiFi.softAPIP());
  42. WebSerial.printf("Uptime: %lums\n", millis());
  43. WebSerial.printf("Free heap: %" PRIu32 "\n", ESP.getFreeHeap());
  44. last = millis();
  45. }
  46. }