Browse Source

change some lines

pull/1155/head
DanielR92 2 years ago
parent
commit
8a4d1250ab
  1. 2
      src/app.cpp
  2. 64
      src/plugins/zeroExport/zeroExport.h
  3. 10
      src/web/html/setup.html
  4. 2
      src/web/web.h

2
src/app.cpp

@ -255,7 +255,7 @@ void app::regularTickers(void) {
everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp");
// Plugins
if (mConfig->plugin.zexport.enabled)
everyMin(std::bind(&ZeroExportType::tickerSecond, &mzExport), "zExport");
everySec(std::bind(&ZeroExportType::tickerSecond, &mzExport), "zExport");
every(std::bind(&PubSerialType::tick, &mPubSerial), mConfig->serial.interval, "uart");
#if !defined(ETHERNET)

64
src/plugins/zeroExport/zeroExport.h

@ -9,9 +9,6 @@ class ZeroExport {
public:
ZeroExport() { }
WiFiClientSecure client;
const uint8_t fingerprint[20] = {0x5A, 0xCF, 0xFE, 0xF0, 0xF1, 0xA6, 0xF4, 0x5F, 0xD2, 0x11, 0x11, 0xC6, 0x1D, 0x2F, 0x0E, 0xBC, 0x39, 0x8D, 0x50, 0xE0};
void setup(cfgzeroExport_t *cfg, HMSYSTEM *sys, settings_t *config) {
mCfg = cfg;
mSys = sys;
@ -30,40 +27,41 @@ class ZeroExport {
}
}
void tickerMinute() {
zero();
}
private:
void zero() {
char host[20];
const char* meter = "/emeter/0";
sprintf(host, mCfg->monitor_ip, meter);
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setFingerprint(fingerprint);
HTTPClient https;
DPRINTLN(DBG_INFO, host);
if (https.begin(*client, host)) // HTTPS
{
DPRINTLN(DBG_INFO, F("[HTTPS] GET...\n"));
// start connection and send HTTP header
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
DPRINTLN(DBG_INFO, payload);
}
} else {
DPRINTLN(DBG_INFO, https.errorToString(httpCode).c_str());
char meter[] = "192.168.5.30/emeter/0";
WiFiClient client;
HTTPClient http;
DPRINTLN(DBG_INFO, meter);
http.begin(client, meter); // HTTPS
http.GET();
// Parse response
DynamicJsonDocument doc(2048);
deserializeJson(doc, http.getStream());
// Read values
DPRINTLN(DBG_INFO, doc["power"].as<String>());
// httpCode will be negative on error
/*if (httpCode > 0) {
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
DPRINTLN(DBG_INFO, payload);
}
} else {
DPRINTLN(DBG_INFO, http.errorToString(httpCode).c_str());
}*/
https.end();
}
else
{
DPRINTLN(DBG_INFO, F("[HTTPS] Unable to connect\n"));
}
http.end();
}
// private member variables

10
src/web/html/setup.html

@ -718,7 +718,7 @@
}
function parseStaticIp(obj) {
for(var i of [["ipAddr", "ip"], ["ipMask", "mask"], ["ipDns1", "dns1"], ["ipDns2", "dns2"], ["ipGateway", "gateway"], ["monitor_ipAddr", "mon_ip"]])
for(var i of [["ipAddr", "ip"], ["ipMask", "mask"], ["ipDns1", "dns1"], ["ipDns2", "dns2"], ["ipGateway", "gateway"]])
if(null != obj[i[1]])
document.getElementsByName(i[0])[0].value = obj[i[1]];
}
@ -925,11 +925,9 @@
}
function parsezeroExport(obj) {
// keep display types grouped
var opts = [[0, "None"], [1, "Shelly EM3"]];
document.getElementsByName("monitor_ipAddr")[0].value = obj["monitor_ipAddr"];
for(var i of [["monitor_ipAddr", "monitor_ipAddr"], ["en_zeroexport", "en_zeroexport"]])
if(null != obj[i[1]])
document.getElementsByName(i[0])[0].value = obj[i[1]];
}
function parse(root) {

2
src/web/web.h

@ -604,11 +604,11 @@ class Web {
mConfig->mqtt.interval = request->arg("mqttInterval").toInt();
// zero-export
mConfig->plugin.zexport.enabled = (request->arg("en_zeroexport") == "on");
if (request->arg("monitor_ipAddr") != "") {
String addr = request->arg("monitor_ipAddr");
addr.trim();
addr.toCharArray(mConfig->plugin.zexport.monitor_ip, ZEXPORT_ADDR_LEN);
mConfig->plugin.zexport.enabled = (request->arg("en_zeroexport") == "on");
} else
mConfig->plugin.zexport.monitor_ip[0] = '\0';

Loading…
Cancel
Save