Skip to content
Snippets Groups Projects
Commit d34f7209 authored by OtherCrashOverride's avatar OtherCrashOverride Committed by Seungchul Lee
Browse files

Add console logging.

parent 1ba0430c
No related branches found
No related tags found
No related merge requests found
...@@ -25,3 +25,7 @@ board = esp12e ...@@ -25,3 +25,7 @@ board = esp12e
upload_speed = 921600 upload_speed = 921600
board_f_cpu = 160000000L board_f_cpu = 160000000L
build_flags = -Wl,-Tesp8266.flash.4m.ld build_flags = -Wl,-Tesp8266.flash.4m.ld
lib_deps = WebSockets
Simpletimer
LiquidCrystal_I2C
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include <mcp4652.h> #include <mcp4652.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#define CONSOLE_PORT 23
WiFiServer logServer(CONSOLE_PORT);
WiFiClient logClient;
#define USE_SERIAL Serial #define USE_SERIAL Serial
#define MAX_LCD_SSID_LENGTH 12 #define MAX_LCD_SSID_LENGTH 12
...@@ -110,12 +115,46 @@ void setup() { ...@@ -110,12 +115,46 @@ void setup() {
webserver_init(); webserver_init();
timerId = timer.setInterval(1000, handler); timerId = timer.setInterval(1000, handler);
// Log
logServer.begin();
logServer.setNoDelay(true);
} }
void loop() { void loop() {
server.handleClient(); server.handleClient();
webSocket.loop(); webSocket.loop();
timer.run(); timer.run();
if (logServer.hasClient())
{
// A connection attempt is being made
if (!logClient)
{
// This is the first client to connect
logClient = logServer.available();
}
else
{
if (!logClient.connected())
{
// A previous client has disconnected.
// Connect the new client.
logClient.stop();
logClient = logServer.available();
}
else
{
// A client connection is already in use.
// Drop the new connection attempt.
WiFiClient tempClient = logServer.available();
tempClient.stop();
}
}
}
} }
void webserver_init(void) void webserver_init(void)
...@@ -667,6 +706,15 @@ void handler(void) ...@@ -667,6 +706,15 @@ void handler(void)
} }
} }
if (logClient && logClient.connected())
{
// Report the log info
String data = String(volt) + "," + String(ampere) + "," +
String(watt, 3) + "," + String(watth/3600, 3) + "\r\n";
logClient.write(data.c_str());
}
lcd_status(); lcd_status();
wifi_connection_status(); wifi_connection_status();
readSystemReset(); readSystemReset();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment