diff --git a/tools/esp8266/ahoywifi.cpp b/tools/esp8266/ahoywifi.cpp
index af1729fa..5c4833de 100644
--- a/tools/esp8266/ahoywifi.cpp
+++ b/tools/esp8266/ahoywifi.cpp
@@ -227,7 +227,7 @@ void ahoywifi::sendNTPpacket(IPAddress& address) {
buf[14] = 49;
buf[15] = 52;
- mUdp->beginPacket(address, 123); // NTP request, port 123
+ mUdp->beginPacket(address, mConfig->ntpPort); // NTP request, port 123
mUdp->write(buf, NTP_PACKET_SIZE);
mUdp->endPacket();
}
diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp
index 75fe77df..a246daa3 100644
--- a/tools/esp8266/app.cpp
+++ b/tools/esp8266/app.cpp
@@ -60,10 +60,14 @@ void app::loop(void) {
if(!apActive) {
mTimestamp = mWifi->getNtpTime();
DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp));
+
+ if(!mTimestamp) // if mTimestamp is 0
+ {
+ // Todo: when no connection, then use standard ntp
+ }
}
}
}
-
mSys->Radio.loop();
diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h
index 8331c273..522f43b8 100644
--- a/tools/esp8266/config.h
+++ b/tools/esp8266/config.h
@@ -73,7 +73,7 @@
#define DEF_NTP_SERVER_NAME "pool.ntp.org"
// default ntp server port
-#define DEF_NTP_PORT 8888
+#define DEF_NTP_PORT 123
// default mqtt interval
#define MQTT_INTERVAL 60
diff --git a/tools/esp8266/hmInverter.h b/tools/esp8266/hmInverter.h
index 774fd809..14e2d53a 100644
--- a/tools/esp8266/hmInverter.h
+++ b/tools/esp8266/hmInverter.h
@@ -230,6 +230,18 @@ class Inverter {
}
}
+ void power_on() {
+ DPRINTLN(DBG_VERBOSE, F("hmInverter.h:PowerOn"));
+ }
+
+ void power_off() {
+ DPRINTLN(DBG_VERBOSE, F("hmInverter.h:PowerOff"));
+ }
+
+ void power_restart() {
+ DPRINTLN(DBG_VERBOSE, F("hmInverter.h:Restart"));
+ }
+
RECORDTYPE getValue(uint8_t pos) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getValue"));
return record[pos];
diff --git a/tools/esp8266/web.cpp b/tools/esp8266/web.cpp
index 5ccdb002..e60ee9ea 100644
--- a/tools/esp8266/web.cpp
+++ b/tools/esp8266/web.cpp
@@ -55,6 +55,10 @@ void web::setup(void) {
mWeb->on("/livedata", std::bind(&web::showLiveData, this));
mWeb->on("/json", std::bind(&web::showJson, this));
mWeb->on("/api", HTTP_POST, std::bind(&web::showWebApi, this));
+
+ mWeb->on("/on", std::bind(&web::control_on, this));
+ mWeb->on("/off", std::bind(&web::control_off, this));
+ mWeb->on("/restart", std::bind(&web::control_restart, this));
}
@@ -233,6 +237,12 @@ void web::showSetup(void) {
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
}
inv += F("");
+
+ String ip = F("http://") + String(WiFi.localIP().toString());
+
+ inv += "TurnOn";
+ inv += "TurnOff";
+ inv += "Restart";
}
html.replace(F("{INVERTERS}"), String(inv));
@@ -492,3 +502,43 @@ void web::showWebApi(void)
}
mWeb->send(200, "text/json", "{success:true}");
}
+
+//-----------------------------------------------------------------------------
+void web::control_on(void)
+{
+ Inverter<> *iv;
+ for(int i = 0; i < mWeb->args(); i++)
+ {
+ int x = mWeb->arg(i).toInt();
+ if(x > MAX_NUM_INVERTERS || x < 0) {return;}
+ iv = mMain->mSys->getInverterByPos(x, false);
+ iv->power_on();
+ }
+ mWeb->send(200, F("text/html"), F("Power On ..."));
+}
+
+void web::control_off(void)
+{
+ Inverter<> *iv;
+ for(int i = 0; i < mWeb->args(); i++)
+ {
+ int x = mWeb->arg(i).toInt();
+ if(x > MAX_NUM_INVERTERS || x < 0) {return;}
+ iv = mMain->mSys->getInverterByPos(x, false);
+ iv->power_off();
+ }
+ mWeb->send(200, F("text/html"), F("Power Off ..."));
+}
+
+void web::control_restart(void)
+{
+ Inverter<> *iv;
+ for(int i = 0; i < mWeb->args(); i++)
+ {
+ int x = mWeb->arg(i).toInt();
+ if(x > MAX_NUM_INVERTERS || x < 0) {return;}
+ iv = mMain->mSys->getInverterByPos(x, false);
+ iv->power_restart();
+ }
+ mWeb->send(200, F("text/html"), F("Rebooting ..."));
+}
diff --git a/tools/esp8266/web.h b/tools/esp8266/web.h
index ad9aa7c6..003be494 100644
--- a/tools/esp8266/web.h
+++ b/tools/esp8266/web.h
@@ -44,6 +44,10 @@ class web {
void showJson(void);
void showWebApi(void);
+ void control_on(void);
+ void control_off(void);
+ void control_restart(void);
+
private:
#ifdef ESP8266
ESP8266WebServer *mWeb;