diff --git a/PylontechMonitoring.ino b/PylontechMonitoring.ino
index f6372e1..f2f807d 100644
--- a/PylontechMonitoring.ino
+++ b/PylontechMonitoring.ino
@@ -15,7 +15,6 @@
//Uncomment for static ip configuration
//#define STATIC_IP
-
// Set your Static IP address
#define IP 192.168.1.1
#define NETMASK 255.255.255.0
@@ -25,6 +24,13 @@
#define DNS 8.8.8.8
+//Uncomment for authentication page
+//#define AUTHENTICATION
+//set http Authentication
+const char* www_username = "admin";
+const char* www_password = "password";
+
+
//IMPORTANT: Uncomment this line if you want to enable MQTT (and fill correct MQTT_ values below):
#define ENABLE_MQTT
@@ -73,6 +79,18 @@ void Log(const char* msg)
g_log.Log(msg);
}
+//Define Interrupt Timer to Calculate Power meter every second (kWh)
+#define USING_TIM_DIV1 true // for shortest and most accurate timer
+ESP8266Timer ITimer;
+bool setInterval(unsigned long interval, timer_callback callback); // interval (in microseconds)
+#define TIMER_INTERVAL_MS 1000
+
+//Global Variables for the Power Meter - accessible from the calculating interrupt und from main
+unsigned long powerIN = 0; //WS gone in to the BAttery
+unsigned long powerOUT = 0; //WS gone out of the Battery
+//Global Variables for the Power Meter - Überlauf
+unsigned long powerINWh = 0; //WS gone in to the BAttery
+unsigned long powerOUTWh = 0; //WS gone out of the Battery
void setup() {
@@ -108,6 +126,11 @@ void setup() {
server.on("/req", handleReq);
server.on("/jsonOut", handleJsonOut);
server.on("/reboot", [](){
+ #ifdef AUTHENTICATION
+ if (!server.authenticate(www_username, www_password)) {
+ return server.requestAuthentication();
+ }
+ #endif
ESP.restart();
});
@@ -121,10 +144,16 @@ void setup() {
#endif
Log("Boot event");
+
}
void handleLog()
{
+ #ifdef AUTHENTICATION
+ if (!server.authenticate(www_username, www_password)) {
+ return server.requestAuthentication();
+ }
+ #endif
server.send(200, "text/html", g_log.c_str());
}
@@ -256,6 +285,11 @@ bool sendCommandAndReadSerialResponse(const char* pszCommand)
void handleReq()
{
+ #ifdef AUTHENTICATION
+ if (!server.authenticate(www_username, www_password)) {
+ return server.requestAuthentication();
+ }
+ #endif
bool respOK;
if(server.hasArg("code") == false)
{
@@ -273,6 +307,11 @@ void handleReq()
void handleJsonOut()
{
+ #ifdef AUTHENTICATION
+ if (!server.authenticate(www_username, www_password)) {
+ return server.requestAuthentication();
+ }
+ #endif
if(sendCommandAndReadSerialResponse("pwr") == false)
{
server.send(500, "text/plain", "Failed to get response to 'pwr' command");
@@ -285,7 +324,11 @@ void handleJsonOut()
}
void handleRoot() {
-
+ #ifdef AUTHENTICATION
+ if (!server.authenticate(www_username, www_password)) {
+ return server.requestAuthentication();
+ }
+ #endif
timeClient.update(); //get ntp datetime
unsigned long days = 0, hours = 0, minutes = 0;
unsigned long val = os_getCurrentTimeSec();
@@ -311,7 +354,9 @@ void handleRoot() {
strncat(szTmp, "
Runtime log