Browse Source

Update NTP Port and added button (at now useless)

pull/204/head
DanielR92 3 years ago
parent
commit
f3ced28cb6
  1. 2
      tools/esp8266/ahoywifi.cpp
  2. 6
      tools/esp8266/app.cpp
  3. 2
      tools/esp8266/config.h
  4. 12
      tools/esp8266/hmInverter.h
  5. 50
      tools/esp8266/web.cpp
  6. 4
      tools/esp8266/web.h

2
tools/esp8266/ahoywifi.cpp

@ -227,7 +227,7 @@ void ahoywifi::sendNTPpacket(IPAddress& address) {
buf[14] = 49; buf[14] = 49;
buf[15] = 52; 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->write(buf, NTP_PACKET_SIZE);
mUdp->endPacket(); mUdp->endPacket();
} }

6
tools/esp8266/app.cpp

@ -60,10 +60,14 @@ void app::loop(void) {
if(!apActive) { if(!apActive) {
mTimestamp = mWifi->getNtpTime(); mTimestamp = mWifi->getNtpTime();
DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp)); DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp));
if(!mTimestamp) // if mTimestamp is 0
{
// Todo: when no connection, then use standard ntp
}
} }
} }
} }
mSys->Radio.loop(); mSys->Radio.loop();

2
tools/esp8266/config.h

@ -73,7 +73,7 @@
#define DEF_NTP_SERVER_NAME "pool.ntp.org" #define DEF_NTP_SERVER_NAME "pool.ntp.org"
// default ntp server port // default ntp server port
#define DEF_NTP_PORT 8888 #define DEF_NTP_PORT 123
// default mqtt interval // default mqtt interval
#define MQTT_INTERVAL 60 #define MQTT_INTERVAL 60

12
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) { RECORDTYPE getValue(uint8_t pos) {
DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getValue")); DPRINTLN(DBG_VERBOSE, F("hmInverter.h:getValue"));
return record[pos]; return record[pos];

50
tools/esp8266/web.cpp

@ -55,6 +55,10 @@ void web::setup(void) {
mWeb->on("/livedata", std::bind(&web::showLiveData, this)); mWeb->on("/livedata", std::bind(&web::showLiveData, this));
mWeb->on("/json", std::bind(&web::showJson, this)); mWeb->on("/json", std::bind(&web::showJson, this));
mWeb->on("/api", HTTP_POST, std::bind(&web::showWebApi, 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("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
} }
inv += F("</div>"); inv += F("</div>");
String ip = F("http://") + String(WiFi.localIP().toString());
inv += "<a href=\"" + ip + "/on/" + String(i) + "\" class=\"\">TurnOn</a>";
inv += "<a href=\"" + ip + "/off/" + String(i) + "\" class=\"\">TurnOff</a>";
inv += "<a href=\"" + ip + "/restart/" + String(i) + "\" class=\"\">Restart</a>";
} }
html.replace(F("{INVERTERS}"), String(inv)); html.replace(F("{INVERTERS}"), String(inv));
@ -492,3 +502,43 @@ void web::showWebApi(void)
} }
mWeb->send(200, "text/json", "{success:true}"); 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 ..."));
}

4
tools/esp8266/web.h

@ -44,6 +44,10 @@ class web {
void showJson(void); void showJson(void);
void showWebApi(void); void showWebApi(void);
void control_on(void);
void control_off(void);
void control_restart(void);
private: private:
#ifdef ESP8266 #ifdef ESP8266
ESP8266WebServer *mWeb; ESP8266WebServer *mWeb;

Loading…
Cancel
Save