Browse Source

* improved tickers, only one ticker is active

* added feature to use the ESP as access point for all the time
* added serial features to setup
pull/25/head
lumapu 3 years ago
parent
commit
8f444cee2f
  1. 165
      tools/esp8266/app.cpp
  2. 13
      tools/esp8266/app.h
  3. 2
      tools/esp8266/config.h
  4. 13
      tools/esp8266/defines.h
  5. 2
      tools/esp8266/esp8266.ino
  6. 1
      tools/esp8266/hmRadio.h
  7. 2
      tools/esp8266/html/h/setup_html.h
  8. 2
      tools/esp8266/html/h/style_css.h
  9. 18
      tools/esp8266/html/setup.html
  10. 4
      tools/esp8266/html/style.css
  11. 19
      tools/esp8266/main.cpp
  12. 2
      tools/esp8266/main.h

165
tools/esp8266/app.cpp

@ -7,16 +7,20 @@
//-----------------------------------------------------------------------------
app::app() : Main() {
mSendTicker = 0xffffffff;
mSendTicker = 0xffff;
mSendInterval = 0;
mMqttTicker = 0xffffffff;
mMqttTicker = 0xffff;
mMqttInterval = 0;
mSerialTicker = 0xffffffff;
mSerialTicker = 0xffff;
mSerialInterval = 0;
mMqttActive = false;
mTicker = 0;
mShowRebootRequest = false;
mSerialValues = true;
mSerialDebug = false;
memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
//memset(mChannelStat, 0, sizeof(uint32_t) * 4);
@ -32,8 +36,8 @@ app::~app(void) {
//-----------------------------------------------------------------------------
void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
Main::setup(ssid, pwd, timeout);
void app::setup(uint32_t timeout) {
Main::setup(timeout);
mWeb->on("/", std::bind(&app::showIndex, this));
mWeb->on("/setup", std::bind(&app::showSetup, this));
@ -58,11 +62,9 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
DPRINTLN("add inverter: " + String(invName) + ", SN: " + String(invSerial, HEX) + ", type: " + String(invType));
}
}
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
if(mSendInterval < 1000)
mSendInterval = 1000;
mSendTicker = 0;
if(mSendInterval < 1)
mSendInterval = 1;
// pinout
@ -74,6 +76,17 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
// nrf24 amplifier power
mEep->read(ADDR_RF24_AMP_PWR, &mSys->Radio.AmplifierPower);
// serial console
uint8_t tmp;
mEep->read(ADDR_SER_INTERVAL, &mSerialInterval);
mEep->read(ADDR_SER_ENABLE, &tmp);
mSerialValues = (tmp == 0x01);
mEep->read(ADDR_SER_DEBUG, &tmp);
mSerialDebug = (tmp == 0x01);
if(mSerialInterval < 1)
mSerialInterval = 1;
// mqtt
uint8_t mqttAddr[MQTT_ADDR_LEN];
uint16_t mqttPort;
@ -92,13 +105,12 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) {
mMqttActive = (mqttAddr[0] > 0);
if(mMqttInterval < 1000)
mMqttInterval = 1000;
if(mMqttInterval < 1)
mMqttInterval = 1;
mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort);
mMqttTicker = 0;
mSerialTicker = 0;
mSerialInterval = mMqttInterval; // TODO: add extra setting for this!
mMqtt.sendMsg("version", mVersion);
}
@ -125,7 +137,8 @@ void app::loop(void) {
if(!mSys->BufCtrl.empty()) {
uint8_t len, rptCnt;
packet_t *p = mSys->BufCtrl.getBack();
//mSys->Radio.dumpBuf("RAW ", p->packet, MAX_RF_PAYLOAD_SIZE);
if(mSerialDebug)
mSys->Radio.dumpBuf("RAW ", p->packet, MAX_RF_PAYLOAD_SIZE);
if(mSys->Radio.checkCrc(p->packet, &len, &rptCnt)) {
// process buffer only on first occurrence
@ -161,54 +174,58 @@ void app::loop(void) {
mSys->BufCtrl.popBack();
}
if(checkTicker(&mSendTicker, mSendInterval)) {
Inverter<> *inv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
inv = mSys->getInverterByPos(i);
if(NULL != inv) {
mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp);
yield();
if(checkTicker(&mTicker, 1000)) {
if(++mSendTicker >= mSendInterval) {
mSendTicker = 0;
Inverter<> *inv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
inv = mSys->getInverterByPos(i);
if(NULL != inv) {
mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp);
yield();
}
}
}
}
// mqtt
if(mMqttActive) {
mMqtt.loop();
if(checkTicker(&mMqttTicker, mMqttInterval)) {
mMqtt.isConnected(true);
char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) {
if(0.0f != iv->getValue(i)) {
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
snprintf(val, 10, "%.3f", iv->getValue(i));
mMqtt.sendMsg(topic, val);
yield();
if(mMqttActive) {
mMqtt.loop();
if(++mMqttTicker > mMqttInterval) {
mMqttInterval = 0;
mMqtt.isConnected(true);
char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) {
if(0.0f != iv->getValue(i)) {
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
snprintf(val, 10, "%.3f", iv->getValue(i));
mMqtt.sendMsg(topic, val);
yield();
}
}
}
}
}
}
}
// Serial debug
if(checkTicker(&mSerialTicker, mSerialInterval)) {
char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) {
if(0.0f != iv->getValue(i)) {
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, iv->getFieldName(i));
snprintf(val, 10, "%.3f %s", iv->getValue(i), iv->getUnit(i));
DPRINTLN(String(topic) + ": " + String(val));
if(mSerialValues) {
if(++mSerialTicker > mSerialInterval) {
mSerialInterval = 0;
char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) {
if(0.0f != iv->getValue(i)) {
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, iv->getFieldName(i));
snprintf(val, 10, "%.3f %s", iv->getValue(i), iv->getUnit(i));
DPRINTLN(String(topic) + ": " + String(val));
}
yield();
}
}
yield();
}
}
}
@ -315,7 +332,15 @@ void app::showSetup(void) {
if(mSettingsValid) {
mEep->read(ADDR_INV_INTERVAL, &interval);
html.replace("{INV_INTERVAL}", String(interval));
html.replace("{INV_INTVL}", String(interval));
uint8_t tmp;
mEep->read(ADDR_SER_INTERVAL, &interval);
mEep->read(ADDR_SER_ENABLE, &tmp);
html.replace("{SER_INTVL}", String(interval));
html.replace("{SER_VAL_CB}", (tmp == 0x01) ? "checked" : "");
mEep->read(ADDR_SER_DEBUG, &tmp);
html.replace("{SER_DBG_CB}", (tmp == 0x01) ? "checked" : "");
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0};
uint16_t mqttPort;
@ -325,22 +350,28 @@ void app::showSetup(void) {
char addr[16] = {0};
sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]);
html.replace("{MQTT_ADDR}", String(addr));
html.replace("{MQTT_PORT}", String(mqttPort));
html.replace("{MQTT_USER}", String(mMqtt.getUser()));
html.replace("{MQTT_PWD}", String(mMqtt.getPwd()));
html.replace("{MQTT_TOPIC}", String(mMqtt.getTopic()));
html.replace("{MQTT_INTERVAL}", String(interval));
html.replace("{MQTT_ADDR}", String(addr));
html.replace("{MQTT_PORT}", String(mqttPort));
html.replace("{MQTT_USER}", String(mMqtt.getUser()));
html.replace("{MQTT_PWD}", String(mMqtt.getPwd()));
html.replace("{MQTT_TOPIC}", String(mMqtt.getTopic()));
html.replace("{MQTT_INTVL}", String(interval));
}
else {
html.replace("{INV_INTERVAL}", "1000");
html.replace("{INV_INTVL}", "5");
html.replace("{SER_VAL_CB}", "checked");
html.replace("{SER_DBG_CB}", "");
html.replace("{SER_INTVL}", "10");
html.replace("{MQTT_ADDR}", "");
html.replace("{MQTT_PORT}", "1883");
html.replace("{MQTT_USER}", "");
html.replace("{MQTT_PWD}", "");
html.replace("{MQTT_TOPIC}", "/inverter");
html.replace("{MQTT_INTERVAL}", "10000");
html.replace("{MQTT_INTVL}", "10");
html.replace("{SER_INTVL}", "10");
}
mWeb->send(200, "text/html", html);
@ -534,7 +565,7 @@ void app::saveValues(bool webSend = true) {
mWeb->arg("mqttUser").toCharArray(mqttUser, MQTT_USER_LEN);
mWeb->arg("mqttPwd").toCharArray(mqttPwd, MQTT_PWD_LEN);
mWeb->arg("mqttTopic").toCharArray(mqttTopic, MQTT_TOPIC_LEN);
interval = mWeb->arg("mqttInterval").toInt();
interval = mWeb->arg("mqttIntvl").toInt();
mqttPort = mWeb->arg("mqttPort").toInt();
mEep->write(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN);
mEep->write(ADDR_MQTT_PORT, mqttPort);
@ -543,12 +574,22 @@ void app::saveValues(bool webSend = true) {
mEep->write(ADDR_MQTT_TOPIC, mqttTopic, MQTT_TOPIC_LEN);
mEep->write(ADDR_MQTT_INTERVAL, interval);
// serial console
bool tmp;
interval = mWeb->arg("serIntvl").toInt();
mEep->write(ADDR_SER_INTERVAL, interval);
tmp = (mWeb->arg("serEn") == "on");
mEep->write(ADDR_SER_ENABLE, (uint8_t)((tmp) ? 0x01 : 0x00));
tmp = (mWeb->arg("serDbg") == "on");
mEep->write(ADDR_SER_DEBUG, (uint8_t)((tmp) ? 0x01 : 0x00));
updateCrc();
if((mWeb->arg("reboot") == "on"))
showReboot();
else {
mShowRebootRequest = true;
mWeb->send(200, "text/html", "<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"0; URL=/setup\"></head><body>"
mWeb->send(200, "text/html", "<!doctype html><html><head><title>Setup saved</title><meta http-equiv=\"refresh\" content=\"3; URL=/setup\"></head><body>"
"<p>saved</p></body></html>");
}
}

13
tools/esp8266/app.h

@ -31,7 +31,7 @@ class app : public Main {
app();
~app();
void setup(const char *ssid, const char *pwd, uint32_t timeout);
void setup(uint32_t timeout);
void loop(void);
void handleIntr(void);
@ -70,19 +70,24 @@ class app : public Main {
HmSystemType *mSys;
uint32_t mSendTicker;
uint16_t mSendTicker;
uint16_t mSendInterval;
uint32_t mCmds[DBG_CMD_LIST_LEN+1];
//uint32_t mChannelStat[4];
uint32_t mRecCnt;
// timer
uint32_t mTicker;
bool mSerialValues;
bool mSerialDebug;
// mqtt
mqtt mMqtt;
uint32_t mMqttTicker;
uint16_t mMqttTicker;
uint16_t mMqttInterval;
bool mMqttActive;
uint32_t mSerialTicker;
uint16_t mSerialTicker;
uint16_t mSerialInterval;
};

2
tools/esp8266/config.h

@ -9,6 +9,8 @@
// access point info
#define WIFI_AP_SSID "AHOY DTU"
#define WIFI_AP_PWD "esp_8266"
// stay in access point mode all the time
//#define AP_ONLY
//-------------------------------------

13
tools/esp8266/defines.h

@ -16,7 +16,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 5
#define VERSION_PATCH 6
//-------------------------------------
@ -50,6 +50,10 @@ typedef struct {
#define MQTT_INTERVAL_LEN 2 // uint16_t
#define MQTT_PORT_LEN 2 // uint16_t
#define SER_ENABLE_LEN 1 // uint8_t
#define SER_DEBUG_LEN 1 // uint8_t
#define SER_INTERVAL_LEN 2 // uint16_t
#define ADDR_START 0
#define ADDR_SSID ADDR_START
@ -72,9 +76,12 @@ typedef struct {
#define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN
#define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN
#define ADDR_MQTT_INTERVAL ADDR_MQTT_TOPIC + MQTT_TOPIC_LEN
#define ADDR_MQTT_PORT ADDR_MQTT_INTERVAL + MQTT_INTERVAL_LEN
#define ADDR_NEXT ADDR_MQTT_PORT + MQTT_PORT_LEN
#define ADDR_SER_ENABLE ADDR_MQTT_PORT + MQTT_PORT_LEN
#define ADDR_SER_DEBUG ADDR_SER_ENABLE + SER_ENABLE_LEN
#define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN
#define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN
#define ADDR_SETTINGS_CRC 400

2
tools/esp8266/esp8266.ino

@ -14,7 +14,7 @@ app myApp;
//-----------------------------------------------------------------------------
void setup() {
myApp.setup(WIFI_AP_SSID, WIFI_AP_PWD, WIFI_TRY_CONNECT_TIME);
myApp.setup(WIFI_TRY_CONNECT_TIME);
// TODO: move to HmRadio
attachInterrupt(digitalPinToInterrupt(myApp.getIrqPin()), handleIntr, FALLING);

1
tools/esp8266/hmRadio.h

@ -71,7 +71,6 @@ class HmRadio {
mBufCtrl = ctrl;
mNrf24.begin(pinCe, pinCs);
mNrf24.setAutoAck(false);
mNrf24.setRetries(0, 0);
mNrf24.setChannel(DEFAULT_RECV_CHANNEL);

2
tools/esp8266/html/h/setup_html.h

@ -1,4 +1,4 @@
#ifndef __SETUP_H__
#define __SETUP_H__
const char setup_html[] PROGMEM = "<!doctype html><html><head><title>Setup - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body><h1>Setup</h1><div id=\"setup\" class=\"content\"><div id=\"content\"><p>Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information. </p><form method=\"post\" action=\"{IP}/save\"><p class=\"des\">WiFi</p><label for=\"ssid\">SSID</label><input type=\"text\" class=\"text\" name=\"ssid\" value=\"{SSID}\"/><label for=\"pwd\">Password</label><input type=\"password\" class=\"text\" name=\"pwd\" value=\"{PWD}\"/><p class=\"des\">Device Host Name</p><label for=\"device\">Device Name</label><input type=\"text\" class=\"text\" name=\"device\" value=\"{DEVICE}\"/><a class=\"erase\" href=\"/erase\">ERASE SETTINGS (not WiFi)</a><p class=\"des\">Inverter</p>{INVERTERS}<br/><p class=\"subdes\">General</p><label for=\"invInterval\">Interval (ms)</label><input type=\"text\" class=\"text\" name=\"invInterval\" value=\"{INV_INTERVAL}\"/><p class=\"des\">Pinout (Wemos)</p>{PINOUT}<p class=\"des\">Radio (NRF24L01+)</p><label for=\"rf24Power\">Amplifier Power Level</label><select name=\"rf24Power\">{RF24}</select><p class=\"des\">MQTT</p><label for=\"mqttAddr\">Broker / Server IP</label><input type=\"text\" class=\"text\" name=\"mqttAddr\" value=\"{MQTT_ADDR}\"/><label for=\"mqttPort\">Port</label><input type=\"text\" class=\"text\" name=\"mqttPort\" value=\"{MQTT_PORT}\"/><label for=\"mqttUser\">Username (optional)</label><input type=\"text\" class=\"text\" name=\"mqttUser\" value=\"{MQTT_USER}\"/><label for=\"mqttPwd\">Password (optional)</label><input type=\"text\" class=\"text\" name=\"mqttPwd\" value=\"{MQTT_PWD}\"/><label for=\"mqttTopic\">Topic</label><input type=\"text\" class=\"text\" name=\"mqttTopic\" value=\"{MQTT_TOPIC}\"/><label for=\"mqttInterval\">Interval (ms)</label><input type=\"text\" class=\"text\" name=\"mqttInterval\" value=\"{MQTT_INTERVAL}\"/><p class=\"des\">&nbsp;</p><input type=\"checkbox\" class=\"cb\" name=\"reboot\"/><label for=\"reboot\">Reboot device after successful save</label><input type=\"submit\" value=\"save\" class=\"btn\" /></form></div></div><div id=\"footer\"><p class=\"left\"><a href=\"{IP}/\">Home</a></p><p class=\"left\"><a href=\"{IP}/update\">Update Firmware</a></p><p class=\"right\">AHOY - {VERSION}</p><p class=\"right\"><a href=\"{IP}/factory\">Factory Reset</a></p><p class=\"right\"><a href=\"{IP}/reboot\">Reboot</a></p></div></body></html>";
const char setup_html[] PROGMEM = "<!doctype html><html><head><title>Setup - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body><h1>Setup</h1><div id=\"setup\" class=\"content\"><div id=\"content\"><p>Enter the credentials to your prefered WiFi station. After rebooting the device tries to connect with this information. </p><form method=\"post\" action=\"{IP}/save\"><p class=\"des\">WiFi</p><label for=\"ssid\">SSID</label><input type=\"text\" class=\"text\" name=\"ssid\" value=\"{SSID}\"/><label for=\"pwd\">Password</label><input type=\"password\" class=\"text\" name=\"pwd\" value=\"{PWD}\"/><p class=\"des\">Device Host Name</p><label for=\"device\">Device Name</label><input type=\"text\" class=\"text\" name=\"device\" value=\"{DEVICE}\"/><a class=\"erase\" href=\"/erase\">ERASE SETTINGS (not WiFi)</a><p class=\"des\">Inverter</p>{INVERTERS}<br/><p class=\"subdes\">General</p><label for=\"invInterval\">Interval (s)</label><input type=\"text\" class=\"text\" name=\"invInterval\" value=\"{INV_INTVL}\"/><p class=\"des\">Pinout (Wemos)</p>{PINOUT}<p class=\"des\">Radio (NRF24L01+)</p><label for=\"rf24Power\">Amplifier Power Level</label><select name=\"rf24Power\">{RF24}</select><p class=\"des\">MQTT</p><label for=\"mqttAddr\">Broker / Server IP</label><input type=\"text\" class=\"text\" name=\"mqttAddr\" value=\"{MQTT_ADDR}\"/><label for=\"mqttPort\">Port</label><input type=\"text\" class=\"text\" name=\"mqttPort\" value=\"{MQTT_PORT}\"/><label for=\"mqttUser\">Username (optional)</label><input type=\"text\" class=\"text\" name=\"mqttUser\" value=\"{MQTT_USER}\"/><label for=\"mqttPwd\">Password (optional)</label><input type=\"text\" class=\"text\" name=\"mqttPwd\" value=\"{MQTT_PWD}\"/><label for=\"mqttTopic\">Topic</label><input type=\"text\" class=\"text\" name=\"mqttTopic\" value=\"{MQTT_TOPIC}\"/><label for=\"mqttIntvl\">Interval (s)</label><input type=\"text\" class=\"text\" name=\"mqttIntvl\" value=\"{MQTT_INTVL}\"/><p class=\"des\">Serial Console</p><label for=\"serEn\">print inverter data</label><input type=\"checkbox\" class=\"cb\" name=\"serEn\" {SER_VAL_CB}/><br/><label for=\"serDbg\">print RF24 debug</label><input type=\"checkbox\" class=\"cb\" name=\"serDbg\" {SER_DBG_CB}/><br/><label for=\"serIntvl\">Interval (s)</label><input type=\"text\" class=\"text\" name=\"serIntvl\" value=\"{SER_INTVL}\"/><p class=\"des\">&nbsp;</p><label for=\"reboot\">Reboot device after successful save</label><input type=\"checkbox\" class=\"cb\" name=\"reboot\"/><input type=\"submit\" value=\"save\" class=\"btn\" /></form></div></div><div id=\"footer\"><p class=\"left\"><a href=\"{IP}/\">Home</a></p><p class=\"left\"><a href=\"{IP}/update\">Update Firmware</a></p><p class=\"right\">AHOY - {VERSION}</p><p class=\"right\"><a href=\"{IP}/factory\">Factory Reset</a></p><p class=\"right\"><a href=\"{IP}/reboot\">Reboot</a></p></div></body></html>";
#endif /*__SETUP_H__*/

2
tools/esp8266/html/h/style_css.h

@ -1,4 +1,4 @@
#ifndef __STYLE_H__
#define __STYLE_H__
const char style_css[] PROGMEM = "h1 {margin:0;padding:20pt;font-size:22pt;color:#fff;background-color:#006ec0;display:block;text-transform:uppercase;}html, body {font-family:Arial;margin:0;padding:0;}p {text-align:justify;font-size:13pt;}.des {margin-top:35px;font-size:13pt;color:#006ec0;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}a:link, a:visited {text-decoration:none;font-size:13pt;color:#006ec0;}a:hover, a:focus {color:#f00;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;float:right;}#content {padding:15px 15px 60px 15px;}#footer {position:fixed;bottom:0px;height:45px;background-color:#006ec0;width:100%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding-left:20px;padding-right:20px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.btn {background-color:#006ec0;color:#fff;border:0px;float:right;margin:10px 0 30px;text-transform:uppercase;}input.cb {margin-bottom:20px;}label {width:20%;display:inline-block;font-size:12pt;padding-right:10px;margin-left:10px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:20px;padding-bottom:20px;overflow:auto;}div.ch {width:250px;min-height:420px;background-color:#006ec0;display:inline-block;margin-right:20px;margin-bottom:20px;overflow:auto;padding-bottom:20px;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:250px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:30px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:1060px;}div.ch:last-child {margin-right:0px !important;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}";
const char style_css[] PROGMEM = "h1 {margin:0;padding:20pt;font-size:22pt;color:#fff;background-color:#006ec0;display:block;text-transform:uppercase;}html, body {font-family:Arial;margin:0;padding:0;}p {text-align:justify;font-size:13pt;}.des {margin-top:35px;font-size:13pt;color:#006ec0;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}a:link, a:visited {text-decoration:none;font-size:13pt;color:#006ec0;}a:hover, a:focus {color:#f00;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;float:right;}#content {padding:15px 15px 60px 15px;}#footer {position:fixed;bottom:0px;height:45px;background-color:#006ec0;width:100%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding:0 7px 0 7px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.btn {background-color:#006ec0;color:#fff;border:0px;float:right;margin:10px 0 30px;text-transform:uppercase;}input.cb {margin-bottom:20px;}label {width:20%;display:inline-block;font-size:12pt;padding-right:10px;margin-left:10px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:20px;padding-bottom:20px;overflow:auto;}div.ch {width:250px;min-height:420px;background-color:#006ec0;display:inline-block;margin-right:20px;margin-bottom:20px;overflow:auto;padding-bottom:20px;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:250px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:30px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:1060px;}div.ch:last-child {margin-right:0px !important;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}";
#endif /*__STYLE_H__*/

18
tools/esp8266/html/setup.html

@ -28,8 +28,8 @@
<p class="des">Inverter</p>
{INVERTERS}<br/>
<p class="subdes">General</p>
<label for="invInterval">Interval (ms)</label>
<input type="text" class="text" name="invInterval" value="{INV_INTERVAL}"/>
<label for="invInterval">Interval (s)</label>
<input type="text" class="text" name="invInterval" value="{INV_INTVL}"/>
<p class="des">Pinout (Wemos)</p>
{PINOUT}
@ -49,12 +49,20 @@
<input type="text" class="text" name="mqttPwd" value="{MQTT_PWD}"/>
<label for="mqttTopic">Topic</label>
<input type="text" class="text" name="mqttTopic" value="{MQTT_TOPIC}"/>
<label for="mqttInterval">Interval (ms)</label>
<input type="text" class="text" name="mqttInterval" value="{MQTT_INTERVAL}"/>
<label for="mqttIntvl">Interval (s)</label>
<input type="text" class="text" name="mqttIntvl" value="{MQTT_INTVL}"/>
<p class="des">Serial Console</p>
<label for="serEn">print inverter data</label>
<input type="checkbox" class="cb" name="serEn" {SER_VAL_CB}/><br/>
<label for="serDbg">print RF24 debug</label>
<input type="checkbox" class="cb" name="serDbg" {SER_DBG_CB}/><br/>
<label for="serIntvl">Interval (s)</label>
<input type="text" class="text" name="serIntvl" value="{SER_INTVL}"/>
<p class="des">&nbsp;</p>
<input type="checkbox" class="cb" name="reboot"/>
<label for="reboot">Reboot device after successful save</label>
<input type="checkbox" class="cb" name="reboot"/>
<input type="submit" value="save" class="btn" />
</form>
</div>

4
tools/esp8266/html/style.css

@ -66,8 +66,7 @@ a.erase {
#footer p, #footer a {
color: #fff;
padding-left: 20px;
padding-right: 20px;
padding: 0 7px 0 7px;
font-size: 10pt !important;
}
@ -137,6 +136,7 @@ div.ch {
overflow: auto;
padding-bottom: 20px;
}
div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {
color: #fff;
display: block;

19
tools/esp8266/main.cpp

@ -34,7 +34,7 @@ Main::Main(void) {
//-----------------------------------------------------------------------------
void Main::setup(const char *ssid, const char *pwd, uint32_t timeout) {
void Main::setup(uint32_t timeout) {
bool startAp = mApActive;
mLimit = timeout;
@ -49,14 +49,14 @@ void Main::setup(const char *ssid, const char *pwd, uint32_t timeout) {
startAp = getConfig();
#ifndef AP_ONLY
if(false == startAp)
startAp = setupStation(timeout);
#else
setupAp(WIFI_AP_SSID, WIFI_AP_PWD);
#endif
if(true == startAp) {
if(strlen(pwd) < 8)
DPRINTLN("ERROR: password must be at least 8 characters long");
}
else {
if(!startAp) {
mTimestamp = getNtpTime();
DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime()));
}
@ -71,11 +71,15 @@ void Main::setup(const char *ssid, const char *pwd, uint32_t timeout) {
void Main::loop(void) {
if(mApActive) {
mDns->processNextRequest();
#ifndef AP_ONLY
if(checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) {
mApLastTick = millis();
mApActive = setupStation(mLimit);
if(mApActive)
if(mApActive) {
if(strlen(WIFI_AP_PWD) < 8)
DPRINTLN("ERROR: password must be at least 8 characters long");
setupAp(WIFI_AP_SSID, WIFI_AP_PWD);
}
}
else {
if(millis() - mApLastTick > 10000) {
@ -83,6 +87,7 @@ void Main::loop(void) {
DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds");
}
}
#endif
}
mWeb->handleClient();

2
tools/esp8266/main.h

@ -30,7 +30,7 @@ const byte mDnsPort = 53;
class Main {
public:
Main(void);
virtual void setup(const char *ssid, const char *pwd, uint32_t timeout);
virtual void setup(uint32_t timeout);
virtual void loop();
String getDateTimeStr (time_t t);

Loading…
Cancel
Save