mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-18 03:16:12 +02:00
* merged showSetup (app + main)
This commit is contained in:
parent
778f209eb5
commit
15402dbd99
6 changed files with 213 additions and 371 deletions
|
@ -16,51 +16,10 @@ app::app() {
|
|||
mWeb = new ESP8266WebServer(80);
|
||||
mUdp = new WiFiUDP();
|
||||
mEep = new eep();
|
||||
|
||||
loadDefaultConfig();
|
||||
|
||||
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
|
||||
mSettingsValid = checkEEpCrc(ADDR_START_SETTINGS, ((ADDR_NEXT)-(ADDR_START_SETTINGS)), ADDR_SETTINGS_CRC);
|
||||
|
||||
mWifiStationTimeout = 10;
|
||||
mNextTryTs = 0;
|
||||
mApLastTick = 0;
|
||||
|
||||
|
||||
Serial.begin(115200);
|
||||
DPRINTLN(DBG_VERBOSE, F("Main::Main"));
|
||||
|
||||
mUptimeSecs = 0;
|
||||
mUptimeTicker = 0xffffffff;
|
||||
mUptimeInterval = 1000;
|
||||
|
||||
#ifdef AP_ONLY
|
||||
mTimestamp = 1;
|
||||
#else
|
||||
mTimestamp = 0;
|
||||
#endif
|
||||
|
||||
mHeapStatCnt = 0;
|
||||
|
||||
mSendTicker = 0xffff;
|
||||
mMqttTicker = 0xffff;
|
||||
mMqttInterval = MQTT_INTERVAL;
|
||||
mSerialTicker = 0xffff;
|
||||
mMqttActive = false;
|
||||
|
||||
mTicker = 0;
|
||||
mRxTicker = 0;
|
||||
|
||||
mSendLastIvId = 0;
|
||||
|
||||
mShowRebootRequest = false;
|
||||
|
||||
|
||||
memset(mPayload, 0, (MAX_NUM_INVERTERS * sizeof(invPayload_t)));
|
||||
mRxFailed = 0;
|
||||
mRxSuccess = 0;
|
||||
mFrameCnt = 0;
|
||||
mLastPacketId = 0x00;
|
||||
resetSystem();
|
||||
loadDefaultConfig();
|
||||
|
||||
mSys = new HmSystemType();
|
||||
}
|
||||
|
@ -72,6 +31,50 @@ app::~app(void) {
|
|||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::setup(uint32_t timeout) {
|
||||
DPRINTLN(DBG_VERBOSE, F("app::setup"));
|
||||
mWifiStationTimeout = timeout;
|
||||
|
||||
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
|
||||
mSettingsValid = checkEEpCrc(ADDR_START_SETTINGS, ((ADDR_NEXT)-(ADDR_START_SETTINGS)), ADDR_SETTINGS_CRC);
|
||||
loadEEpconfig();
|
||||
|
||||
#ifndef AP_ONLY
|
||||
if(false == sysConfig.apActive)
|
||||
sysConfig.apActive = setupStation(mWifiStationTimeout);
|
||||
#endif
|
||||
|
||||
//mWeb->on("/setup", std::bind(&app::showSetup, this));
|
||||
//mWeb->on("/save", std::bind(&app::showSave, this));
|
||||
mWeb->on("/cmdstat", std::bind(&app::showStatistics, this));
|
||||
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
||||
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
||||
mWeb->on("/json", std::bind(&app::showJSON, this));
|
||||
mWeb->on("/api",HTTP_POST, std::bind(&app::webapi, this));
|
||||
|
||||
#ifndef AP_ONLY
|
||||
setupMqtt();
|
||||
#endif
|
||||
|
||||
mSys->setup(&config);
|
||||
|
||||
if(!mWifiSettingsValid)
|
||||
DPRINTLN(DBG_WARN, F("your settings are not valid! check [IP]/setup"));
|
||||
else {
|
||||
DPRINTLN(DBG_INFO, F("\n\n----------------------------------------"));
|
||||
DPRINTLN(DBG_INFO, F("Welcome to AHOY!"));
|
||||
DPRINT(DBG_INFO, F("\npoint your browser to http://"));
|
||||
if(sysConfig.apActive)
|
||||
DBGPRINTLN(F("192.168.1.1"));
|
||||
else
|
||||
DBGPRINTLN(WiFi.localIP());
|
||||
DPRINTLN(DBG_INFO, F("to configure your device"));
|
||||
DPRINTLN(DBG_INFO, F("----------------------------------------\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::MainLoop(void) {
|
||||
//DPRINTLN(DBG_VERBOSE, F("M"));
|
||||
|
@ -125,47 +128,6 @@ void app::MainLoop(void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::setup(uint32_t timeout) {
|
||||
DPRINTLN(DBG_VERBOSE, F("app::setup"));
|
||||
mWifiStationTimeout = timeout;
|
||||
|
||||
|
||||
#ifndef AP_ONLY
|
||||
if(false == sysConfig.apActive)
|
||||
sysConfig.apActive = setupStation(mWifiStationTimeout);
|
||||
#endif
|
||||
|
||||
//mWeb->on("/setup", std::bind(&app::showSetup, this));
|
||||
//mWeb->on("/save", std::bind(&app::showSave, this));
|
||||
mWeb->on("/cmdstat", std::bind(&app::showStatistics, this));
|
||||
mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this));
|
||||
mWeb->on("/livedata", std::bind(&app::showLiveData, this));
|
||||
mWeb->on("/json", std::bind(&app::showJSON, this));
|
||||
mWeb->on("/api",HTTP_POST, std::bind(&app::webapi, this));
|
||||
|
||||
loadEEpconfig();
|
||||
setupMqtt();
|
||||
|
||||
mSys->setup();
|
||||
|
||||
if(!mWifiSettingsValid)
|
||||
DPRINTLN(DBG_WARN, F("your settings are not valid! check [IP]/setup"));
|
||||
else {
|
||||
DPRINTLN(DBG_INFO, F("\n\n----------------------------------------"));
|
||||
DPRINTLN(DBG_INFO, F("Welcome to AHOY!"));
|
||||
DPRINT(DBG_INFO, F("\npoint your browser to http://"));
|
||||
if(sysConfig.apActive)
|
||||
DBGPRINTLN(F("192.168.1.1"));
|
||||
else
|
||||
DBGPRINTLN(WiFi.localIP());
|
||||
DPRINTLN(DBG_INFO, F("to configure your device"));
|
||||
DPRINTLN(DBG_INFO, F("----------------------------------------\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::loop(void) {
|
||||
DPRINTLN(DBG_VERBOSE, F("app::loop"));
|
||||
|
@ -532,148 +494,6 @@ void app::processPayload(bool retransmit) {
|
|||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/*void app::showSetup(void) {
|
||||
DPRINTLN(DBG_VERBOSE, F("app::showSetup"));
|
||||
// overrides same method in main.cpp
|
||||
|
||||
String html = FPSTR(setup_html);
|
||||
html.replace(F("{SSID}"), mStationSsid);
|
||||
// PWD will be left at the default value (for protection)
|
||||
// -> the PWD will only be changed if it does not match the placeholder "{PWD}"
|
||||
|
||||
html.replace(F("{DEVICE}"), String(mDeviceName));
|
||||
html.replace(F("{VERSION}"), String(mVersion));
|
||||
if(mApActive)
|
||||
html.replace(F("{IP}"), String(F("http://192.168.1.1")));
|
||||
else
|
||||
html.replace(F("{IP}"), ("http://" + String(WiFi.localIP().toString())));
|
||||
|
||||
String inv;
|
||||
uint64_t invSerial;
|
||||
char name[MAX_NAME_LENGTH + 1] = {0};
|
||||
uint16_t modPwr[4];
|
||||
uint16_t invActivePowerLimit = -1;
|
||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||
mEep->read(ADDR_INV_ADDR + (i * 8), &invSerial);
|
||||
mEep->read(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), name, MAX_NAME_LENGTH);
|
||||
mEep->read(ADDR_INV_CH_PWR + (i * 2 * 4), modPwr, 4);
|
||||
mEep->read(ADDR_INV_PWR_LIM + (i * 2),(uint16_t *) &invActivePowerLimit);
|
||||
inv += F("<p class=\"subdes\">Inverter ") + String(i) + "</p>";
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("Addr\">Address</label>");
|
||||
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Addr\" value=\"");
|
||||
if(0ULL != invSerial)
|
||||
inv += String(invSerial, HEX);
|
||||
inv += F("\"/ maxlength=\"12\" onkeyup=\"checkSerial()\">");
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("Name\">Name</label>");
|
||||
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Name\" value=\"");
|
||||
inv += String(name);
|
||||
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("ActivePowerLimit\">Active Power Limit (W)</label>");
|
||||
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("ActivePowerLimit\" value=\"");
|
||||
if (name[0] == 0){
|
||||
// If this value will be "saved" on next reboot the command to set the power limit will not be executed.
|
||||
inv += String(65535);
|
||||
} else {
|
||||
inv += String(invActivePowerLimit);
|
||||
}
|
||||
inv += F("\"/ maxlength=\"") + String(6) + "\">";
|
||||
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("ModPwr0\" name=\"lbl") + String(i);
|
||||
inv += F("ModPwr\">Max Module Power (Wp)</label>");
|
||||
for(uint8_t j = 0; j < 4; j++) {
|
||||
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModPwr") + String(j) + F("\" value=\"");
|
||||
inv += String(modPwr[j]);
|
||||
inv += F("\"/ maxlength=\"4\">");
|
||||
}
|
||||
inv += F("<br/><label for=\"inv") + String(i) + F("ModName0\" name=\"lbl") + String(i);
|
||||
inv += F("ModName\">Module Name</label>");
|
||||
for(uint8_t j = 0; j < 4; j++) {
|
||||
mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, name, MAX_NAME_LENGTH);
|
||||
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModName") + String(j) + F("\" value=\"");
|
||||
inv += String(name);
|
||||
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||
}
|
||||
}
|
||||
html.replace(F("{INVERTERS}"), String(inv));
|
||||
|
||||
|
||||
// pinout
|
||||
String pinout;
|
||||
for(uint8_t i = 0; i < 3; i++) {
|
||||
pinout += F("<label for=\"") + String(pinArgNames[i]) + "\">" + String(pinNames[i]) + F("</label>");
|
||||
pinout += F("<select name=\"") + String(pinArgNames[i]) + "\">";
|
||||
for(uint8_t j = 0; j <= 16; j++) {
|
||||
pinout += F("<option value=\"") + String(j) + "\"";
|
||||
switch(i) {
|
||||
default: if(j == mSys->Radio.pinCs) pinout += F(" selected"); break;
|
||||
case 1: if(j == mSys->Radio.pinCe) pinout += F(" selected"); break;
|
||||
case 2: if(j == mSys->Radio.pinIrq) pinout += F(" selected"); break;
|
||||
}
|
||||
pinout += ">" + String(wemosPins[j]) + F("</option>");
|
||||
}
|
||||
pinout += F("</select>");
|
||||
}
|
||||
html.replace(F("{PINOUT}"), String(pinout));
|
||||
|
||||
|
||||
// nrf24l01+
|
||||
String rf24;
|
||||
for(uint8_t i = 0; i <= 3; i++) {
|
||||
rf24 += F("<option value=\"") + String(i) + "\"";
|
||||
if(i == mSys->Radio.AmplifierPower)
|
||||
rf24 += F(" selected");
|
||||
rf24 += ">" + String(rf24AmpPower[i]) + F("</option>");
|
||||
}
|
||||
html.replace(F("{RF24}"), String(rf24));
|
||||
|
||||
|
||||
if(mSettingsValid) {
|
||||
html.replace(F("{INV_INTVL}"), String(mSendInterval));
|
||||
html.replace(F("{INV_RETRIES}"), String(maxRetransPerPyld));
|
||||
|
||||
uint8_t tmp;
|
||||
mEep->read(ADDR_SER_ENABLE, &tmp);
|
||||
html.replace(F("{SER_INTVL}"), String(mSerialInterval));
|
||||
html.replace(F("{SER_VAL_CB}"), (tmp == 0x01) ? "checked" : "");
|
||||
mEep->read(ADDR_SER_DEBUG, &tmp);
|
||||
html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : "");
|
||||
|
||||
char ntpAddr[NTP_ADDR_LEN] = {0};
|
||||
uint16_t ntpPort;
|
||||
mEep->read(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN);
|
||||
mEep->read(ADDR_NTP_PORT, &ntpPort);
|
||||
html.replace(F("{NTP_ADDR}"), String(ntpAddr));
|
||||
html.replace(F("{NTP_PORT}"), String(ntpPort));
|
||||
|
||||
char mqttAddr[MQTT_ADDR_LEN] = {0};
|
||||
uint16_t mqttPort;
|
||||
mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN);
|
||||
mEep->read(ADDR_MQTT_PORT, &mqttPort);
|
||||
|
||||
html.replace(F("{MQTT_ADDR}"), String(mqttAddr));
|
||||
html.replace(F("{MQTT_PORT}"), String(mMqtt.getPort()));
|
||||
html.replace(F("{MQTT_USER}"), String(mMqtt.getUser()));
|
||||
html.replace(F("{MQTT_PWD}"), String(mMqtt.getPwd()));
|
||||
html.replace(F("{MQTT_TOPIC}"), String(mMqtt.getTopic()));
|
||||
html.replace(F("{MQTT_INTVL}"), String(mMqttInterval));
|
||||
}
|
||||
|
||||
mWeb->send(200, F("text/html"), html);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showSave(void) {
|
||||
DPRINTLN(DBG_VERBOSE, F("app::showSave"));
|
||||
//saveValues(true);
|
||||
}*/
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
|
||||
// callback handling on subscribed devcontrol topic
|
||||
|
@ -1080,6 +900,46 @@ bool app::setupStation(uint32_t timeout) {
|
|||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::resetSystem(void) {
|
||||
mWifiStationTimeout = 10;
|
||||
mNextTryTs = 0;
|
||||
mApLastTick = 0;
|
||||
|
||||
mUptimeSecs = 0;
|
||||
mUptimeTicker = 0xffffffff;
|
||||
mUptimeInterval = 1000;
|
||||
|
||||
#ifdef AP_ONLY
|
||||
mTimestamp = 1;
|
||||
#else
|
||||
mTimestamp = 0;
|
||||
#endif
|
||||
|
||||
mHeapStatCnt = 0;
|
||||
|
||||
mSendTicker = 0xffff;
|
||||
mMqttTicker = 0xffff;
|
||||
mMqttInterval = MQTT_INTERVAL;
|
||||
mSerialTicker = 0xffff;
|
||||
mMqttActive = false;
|
||||
|
||||
mTicker = 0;
|
||||
mRxTicker = 0;
|
||||
|
||||
mSendLastIvId = 0;
|
||||
|
||||
mShowRebootRequest = false;
|
||||
|
||||
|
||||
memset(mPayload, 0, (MAX_NUM_INVERTERS * sizeof(invPayload_t)));
|
||||
mRxFailed = 0;
|
||||
mRxSuccess = 0;
|
||||
mFrameCnt = 0;
|
||||
mLastPacketId = 0x00;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::loadDefaultConfig(void) {
|
||||
memset(&sysConfig, 0, sizeof(sysConfig_t));
|
||||
|
@ -1151,7 +1011,7 @@ void app::loadEEpconfig(void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: the original mqttinterval value is not needed any more
|
||||
mMqttInterval += config.sendInterval;
|
||||
}
|
||||
}
|
||||
|
@ -1199,7 +1059,7 @@ void app::setupMqtt(void) {
|
|||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::saveValues(uint32_t saveMask = 0) {
|
||||
void app::saveValues(void) {
|
||||
DPRINTLN(DBG_VERBOSE, F("app::saveValues"));
|
||||
|
||||
mEep->write(ADDR_CFG_SYS, (uint8_t*)&sysConfig, CFG_SYS_LEN);
|
||||
|
@ -1221,77 +1081,6 @@ void app::saveValues(uint32_t saveMask = 0) {
|
|||
|
||||
updateCrc();
|
||||
mEep->commit();
|
||||
|
||||
/*if(CHK_MSK(saveMask, SAVE_SSID))
|
||||
mEep->write(ADDR_SSID, sysConfig.stationSsid, SSID_LEN);
|
||||
if(CHK_MSK(saveMask, SAVE_PWD))
|
||||
mEep->write(ADDR_PWD, sysConfig.stationPwd, SSID_LEN);
|
||||
if(CHK_MSK(saveMask, SAVE_DEVICE_NAME))
|
||||
mEep->write(ADDR_DEVNAME, sysConfig.deviceName, DEVNAME_LEN);
|
||||
|
||||
if(CHK_MSK(saveMask, SAVE_INVERTERS)) {
|
||||
Inverter<> *iv;
|
||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||
iv = mSys->getInverterByPos(i);
|
||||
if(NULL != iv) {
|
||||
mEep->write(ADDR_INV_ADDR + (i * 8), iv->serial.u64);
|
||||
mEep->write(ADDR_INV_PWR_LIM + i * 2, iv->powerLimit[0]);
|
||||
mEep->write(ADDR_INV_NAME + (i * MAX_NAME_LENGTH), iv->name, MAX_NAME_LENGTH);
|
||||
// max channel power / name
|
||||
for(uint8_t j = 0; j < 4; j++) {
|
||||
mEep->write(ADDR_INV_CH_PWR + (i * 2 * 4) + (j*2), iv->chMaxPwr[j]);
|
||||
mEep->write(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(CHK_MSK(saveMask, SAVE_INV_SEND_INTERVAL))
|
||||
mEep->write(ADDR_INV_INTERVAL, config.sendInterval);
|
||||
if(CHK_MSK(saveMask, SAVE_INV_RETRY))
|
||||
mEep->write(ADDR_INV_MAX_RTRY, config.maxRetransPerPyld);
|
||||
|
||||
|
||||
if(CHK_MSK(saveMask, SAVE_PINOUT)) {
|
||||
uint8_t pin;
|
||||
for(uint8_t i = 0; i < 3; i ++) {
|
||||
switch(i) {
|
||||
default: pin = mSys->Radio.pinCs; break;
|
||||
case 1: pin = mSys->Radio.pinCe; break;
|
||||
case 2: pin = mSys->Radio.pinIrq; break;
|
||||
}
|
||||
mEep->write(ADDR_PINOUT + i, pin);
|
||||
}
|
||||
}
|
||||
|
||||
if(CHK_MSK(saveMask, SAVE_RF24))
|
||||
mEep->write(ADDR_RF24_AMP_PWR, mSys->Radio.AmplifierPower);
|
||||
|
||||
if(CHK_MSK(saveMask, SAVE_NTP)) {
|
||||
mEep->write(ADDR_NTP_ADDR, config.ntpAddr, NTP_ADDR_LEN);
|
||||
mEep->write(ADDR_NTP_PORT, config.ntpPort);
|
||||
}
|
||||
|
||||
if(CHK_MSK(saveMask, SAVE_MQTT)) {
|
||||
mEep->write(ADDR_MQTT_ADDR, config.mqtt.broker, MQTT_ADDR_LEN);
|
||||
mEep->write(ADDR_MQTT_PORT, config.mqtt.port);
|
||||
mEep->write(ADDR_MQTT_USER, config.mqtt.user, MQTT_USER_LEN);
|
||||
mEep->write(ADDR_MQTT_PWD, config.mqtt.pwd, MQTT_PWD_LEN);
|
||||
mEep->write(ADDR_MQTT_TOPIC, config.mqtt.topic, MQTT_TOPIC_LEN);
|
||||
}
|
||||
|
||||
if(CHK_MSK(saveMask, SAVE_SERIAL)) {
|
||||
DPRINT(DBG_INFO, "Serial debug is ");
|
||||
if(config.serialDebug) DPRINTLN(DBG_INFO, "on"); else DPRINTLN(DBG_INFO, "off");
|
||||
mSys->Radio.mSerialDebug = config.serialDebug;
|
||||
mEep->write(ADDR_SER_INTERVAL, config.serialInterval);
|
||||
mEep->write(ADDR_SER_ENABLE, (uint8_t)((config.serialShowIv) ? 0x01 : 0x00));
|
||||
mEep->write(ADDR_SER_DEBUG, (uint8_t)((config.serialDebug) ? 0x01 : 0x00));
|
||||
}
|
||||
|
||||
if(0 < saveMask) {
|
||||
updateCrc();
|
||||
mEep->commit();
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
// #define __MQTT_NO_DISCOVERCONFIG__ // das versenden der MQTTDiscoveryConfig abschalten ( gehört eigentlich ins Setup )
|
||||
|
||||
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
||||
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN, BufferType> RadioType;
|
||||
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, BufferType> RadioType;
|
||||
typedef Inverter<float> InverterType;
|
||||
typedef HmSystem<RadioType, BufferType, MAX_NUM_INVERTERS, InverterType> HmSystemType;
|
||||
|
||||
|
@ -67,20 +67,6 @@ const byte mDnsPort = 53;
|
|||
#define TIMEZONE 1 // Central European time +1
|
||||
|
||||
|
||||
#define SAVE_SSID 0x00000001
|
||||
#define SAVE_PWD 0x00000002
|
||||
#define SAVE_DEVICE_NAME 0x00000004
|
||||
#define SAVE_INVERTERS 0x00000008
|
||||
#define SAVE_INV_SEND_INTERVAL 0x00000010
|
||||
#define SAVE_INV_RETRY 0x00000020
|
||||
#define SAVE_PINOUT 0x00000040
|
||||
#define SAVE_RF24 0x00000080
|
||||
#define SAVE_NTP 0x00000100
|
||||
#define SAVE_MQTT 0x00000200
|
||||
#define SAVE_SERIAL 0x00000400
|
||||
|
||||
#define CHK_MSK(v, m) ((m & v) == m)
|
||||
|
||||
class app {
|
||||
public:
|
||||
app();
|
||||
|
@ -90,12 +76,11 @@ class app {
|
|||
void loop(void);
|
||||
void handleIntr(void);
|
||||
void cbMqtt(char* topic, byte* payload, unsigned int length);
|
||||
void saveValues(void);
|
||||
|
||||
uint8_t app_loops;
|
||||
uint8_t getIrqPin(void) {
|
||||
return mSys->Radio.pinIrq;
|
||||
return config.pinIrq;
|
||||
}
|
||||
HmSystemType *mSys;
|
||||
|
||||
uint64_t Serial2u64(const char *val) {
|
||||
char tmp[3] = {0};
|
||||
|
@ -111,7 +96,6 @@ class app {
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
void saveValues(uint32_t saveMask);
|
||||
|
||||
String getDateTimeStr(time_t t) {
|
||||
char str[20] = {0};
|
||||
|
@ -146,6 +130,8 @@ class app {
|
|||
mEep->commit();
|
||||
}
|
||||
|
||||
uint8_t app_loops;
|
||||
HmSystemType *mSys;
|
||||
ESP8266WebServer *mWeb;
|
||||
sysConfig_t sysConfig;
|
||||
config_t config;
|
||||
|
@ -156,6 +142,7 @@ class app {
|
|||
void setupAp(const char *ssid, const char *pwd);
|
||||
bool setupStation(uint32_t timeout);
|
||||
|
||||
void resetSystem(void);
|
||||
void loadDefaultConfig(void);
|
||||
void loadEEpconfig(void);
|
||||
void setupMqtt(void);
|
||||
|
|
|
@ -170,6 +170,10 @@ typedef struct {
|
|||
// nrf24
|
||||
uint16_t sendInterval;
|
||||
uint8_t maxRetransPerPyld;
|
||||
uint8_t pinCs;
|
||||
uint8_t pinCe;
|
||||
uint8_t pinIrq;
|
||||
uint8_t amplifierPower;
|
||||
|
||||
// ntp
|
||||
char ntpAddr[NTP_ADDR_LEN];
|
||||
|
@ -187,7 +191,7 @@ typedef struct {
|
|||
// eeprom new
|
||||
#define CFG_MQTT_LEN MQTT_ADDR_LEN + 2 + MQTT_USER_LEN + MQTT_PWD_LEN +MQTT_TOPIC_LEN
|
||||
#define CFG_SYS_LEN DEVNAME_LEN + SSID_LEN + PWD_LEN + 1
|
||||
#define CFG_LEN 2 + 1 + NTP_ADDR_LEN + 2 + CFG_MQTT_LEN + 2 + 1 + 1
|
||||
#define CFG_LEN 7 + NTP_ADDR_LEN + 2 + CFG_MQTT_LEN + 4
|
||||
|
||||
#define ADDR_START 0
|
||||
#define ADDR_CFG_SYS ADDR_START
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#define ALL_FRAMES 0x80
|
||||
#define SINGLE_FRAME 0x81
|
||||
|
||||
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||
const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -55,7 +55,7 @@ const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
|||
//-----------------------------------------------------------------------------
|
||||
// HM Radio class
|
||||
//-----------------------------------------------------------------------------
|
||||
template <uint8_t CE_PIN, uint8_t CS_PIN, uint8_t IRQ_PIN, class BUFFER, uint64_t DTU_ID=DTU_RADIO_ID>
|
||||
template <uint8_t CE_PIN, uint8_t CS_PIN, class BUFFER, uint64_t DTU_ID=DTU_RADIO_ID>
|
||||
class HmRadio {
|
||||
public:
|
||||
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
|
||||
|
@ -73,11 +73,6 @@ class HmRadio {
|
|||
mRxChIdx = 0; // Start RX with 03
|
||||
mRxLoopCnt = RF_LOOP_CNT;
|
||||
|
||||
pinCs = CS_PIN;
|
||||
pinCe = CE_PIN;
|
||||
pinIrq = IRQ_PIN;
|
||||
|
||||
AmplifierPower = 1;
|
||||
mSendCnt = 0;
|
||||
|
||||
mSerialDebug = false;
|
||||
|
@ -85,13 +80,13 @@ class HmRadio {
|
|||
}
|
||||
~HmRadio() {}
|
||||
|
||||
void setup(BUFFER *ctrl) {
|
||||
void setup(config_t *config, BUFFER *ctrl) {
|
||||
DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup"));
|
||||
pinMode(pinIrq, INPUT_PULLUP);
|
||||
pinMode(config->pinIrq, INPUT_PULLUP);
|
||||
|
||||
mBufCtrl = ctrl;
|
||||
|
||||
mNrf24.begin(pinCe, pinCs);
|
||||
mNrf24.begin(config->pinCe, config->pinCs);
|
||||
mNrf24.setRetries(0, 0);
|
||||
|
||||
mNrf24.setChannel(DEFAULT_RECV_CHANNEL);
|
||||
|
@ -106,8 +101,8 @@ class HmRadio {
|
|||
// enable only receiving interrupts
|
||||
mNrf24.maskIRQ(true, true, false);
|
||||
|
||||
DPRINTLN(DBG_INFO, F("RF24 Amp Pwr: RF24_PA_") + String(rf24AmpPower[AmplifierPower]));
|
||||
mNrf24.setPALevel(AmplifierPower & 0x03);
|
||||
DPRINTLN(DBG_INFO, F("RF24 Amp Pwr: RF24_PA_") + String(rf24AmpPowerNames[config->amplifierPower]));
|
||||
mNrf24.setPALevel(config->amplifierPower & 0x03);
|
||||
mNrf24.startListening();
|
||||
|
||||
DPRINTLN(DBG_INFO, F("Radio Config:"));
|
||||
|
@ -277,11 +272,8 @@ class HmRadio {
|
|||
return mNrf24.isChipConnected();
|
||||
}
|
||||
|
||||
uint8_t pinCs;
|
||||
uint8_t pinCe;
|
||||
uint8_t pinIrq;
|
||||
|
||||
uint8_t AmplifierPower;
|
||||
|
||||
uint32_t mSendCnt;
|
||||
|
||||
bool mSerialDebug;
|
||||
|
|
|
@ -30,9 +30,9 @@ class HmSystem {
|
|||
// TODO: cleanup
|
||||
}
|
||||
|
||||
void setup() {
|
||||
void setup(config_t *config) {
|
||||
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:setup"));
|
||||
Radio.setup(&BufCtrl);
|
||||
Radio.setup(config, &BufCtrl);
|
||||
}
|
||||
|
||||
INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) {
|
||||
|
|
|
@ -136,6 +136,97 @@ class web {
|
|||
else
|
||||
html.replace("{IP}", (F("http://") + String(WiFi.localIP().toString())));
|
||||
|
||||
String inv = "";
|
||||
Inverter<> *iv;
|
||||
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
|
||||
iv = mMain->mSys->getInverterByPos(i);
|
||||
|
||||
inv += F("<p class=\"subdes\">Inverter ") + String(i) + "</p>";
|
||||
inv += F("<label for=\"inv") + String(i) + F("Addr\">Address</label>");
|
||||
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Addr\" value=\"");
|
||||
if(NULL != iv)
|
||||
inv += String(iv->serial.u64, HEX);
|
||||
inv += F("\"/ maxlength=\"12\" onkeyup=\"checkSerial()\">");
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("Name\">Name</label>");
|
||||
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("Name\" value=\"");
|
||||
if(NULL != iv)
|
||||
inv += String(iv->name);
|
||||
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("ActivePowerLimit\">Active Power Limit (W)</label>");
|
||||
inv += F("<input type=\"text\" class=\"text\" name=\"inv") + String(i) + F("ActivePowerLimit\" value=\"");
|
||||
if(NULL != iv)
|
||||
inv += String(iv->powerLimit[0]);
|
||||
inv += F("\"/ maxlength=\"") + String(6) + "\">";
|
||||
|
||||
inv += F("<label for=\"inv") + String(i) + F("ModPwr0\" name=\"lbl") + String(i);
|
||||
inv += F("ModPwr\">Max Module Power (Wp)</label>");
|
||||
for(uint8_t j = 0; j < 4; j++) {
|
||||
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModPwr") + String(j) + F("\" value=\"");
|
||||
if(NULL != iv)
|
||||
inv += String(iv->chMaxPwr[j]);
|
||||
inv += F("\"/ maxlength=\"4\">");
|
||||
}
|
||||
inv += F("<br/><label for=\"inv") + String(i) + F("ModName0\" name=\"lbl") + String(i);
|
||||
inv += F("ModName\">Module Name</label>");
|
||||
for(uint8_t j = 0; j < 4; j++) {
|
||||
inv += F("<input type=\"text\" class=\"text sh\" name=\"inv") + String(i) + F("ModName") + String(j) + F("\" value=\"");
|
||||
if(NULL != iv)
|
||||
inv += String(iv->chName[j]);
|
||||
inv += F("\"/ maxlength=\"") + String(MAX_NAME_LENGTH) + "\">";
|
||||
}
|
||||
}
|
||||
html.replace(F("{INVERTERS}"), String(inv));
|
||||
|
||||
|
||||
// pinout
|
||||
String pinout;
|
||||
for(uint8_t i = 0; i < 3; i++) {
|
||||
pinout += F("<label for=\"") + String(pinArgNames[i]) + "\">" + String(pinNames[i]) + F("</label>");
|
||||
pinout += F("<select name=\"") + String(pinArgNames[i]) + "\">";
|
||||
for(uint8_t j = 0; j <= 16; j++) {
|
||||
pinout += F("<option value=\"") + String(j) + "\"";
|
||||
switch(i) {
|
||||
default: if(j == mMain->config.pinCs) pinout += F(" selected"); break;
|
||||
case 1: if(j == mMain->config.pinCe) pinout += F(" selected"); break;
|
||||
case 2: if(j == mMain->config.pinIrq) pinout += F(" selected"); break;
|
||||
}
|
||||
pinout += ">" + String(wemosPins[j]) + F("</option>");
|
||||
}
|
||||
pinout += F("</select>");
|
||||
}
|
||||
html.replace(F("{PINOUT}"), String(pinout));
|
||||
|
||||
|
||||
// nrf24l01+
|
||||
String rf24;
|
||||
for(uint8_t i = 0; i <= 3; i++) {
|
||||
rf24 += F("<option value=\"") + String(i) + "\"";
|
||||
if(i == mMain->config.amplifierPower)
|
||||
rf24 += F(" selected");
|
||||
rf24 += ">" + String(rf24AmpPowerNames[i]) + F("</option>");
|
||||
}
|
||||
html.replace(F("{RF24}"), String(rf24));
|
||||
|
||||
|
||||
html.replace(F("{INV_INTVL}"), String(mMain->config.sendInterval));
|
||||
html.replace(F("{INV_RETRIES}"), String(mMain->config.maxRetransPerPyld));
|
||||
|
||||
html.replace(F("{SER_INTVL}"), String(mMain->config.serialInterval));
|
||||
html.replace(F("{SER_VAL_CB}"), (mMain->config.serialShowIv) ? "checked" : "");
|
||||
html.replace(F("{SER_DBG_CB}"), (mMain->config.serialDebug) ? "checked" : "");
|
||||
|
||||
html.replace(F("{NTP_ADDR}"), String(mMain->config.ntpAddr));
|
||||
html.replace(F("{NTP_PORT}"), String(mMain->config.ntpPort));
|
||||
|
||||
html.replace(F("{MQTT_ADDR}"), String(mMain->config.mqtt.broker));
|
||||
html.replace(F("{MQTT_PORT}"), String(mMain->config.mqtt.port));
|
||||
html.replace(F("{MQTT_USER}"), String(mMain->config.mqtt.user));
|
||||
html.replace(F("{MQTT_PWD}"), String(mMain->config.mqtt.pwd));
|
||||
html.replace(F("{MQTT_TOPIC}"), String(mMain->config.mqtt.topic));
|
||||
html.replace(F("{MQTT_INTVL}"), String("0"));
|
||||
|
||||
mWeb->send(200, F("text/html"), html);
|
||||
}
|
||||
|
||||
|
@ -143,22 +234,15 @@ class web {
|
|||
DPRINTLN(DBG_VERBOSE, F("showSave"));
|
||||
|
||||
if(mWeb->args() > 0) {
|
||||
uint32_t saveMask = 0;
|
||||
char buf[20] = {0};
|
||||
|
||||
// general
|
||||
if(mWeb->arg("ssid") != "") {
|
||||
if(mWeb->arg("ssid") != "")
|
||||
mWeb->arg("ssid").toCharArray(mMain->sysConfig.stationSsid, SSID_LEN);
|
||||
saveMask |= SAVE_SSID;
|
||||
}
|
||||
if(mWeb->arg("pwd") != "{PWD}") {
|
||||
if(mWeb->arg("pwd") != "{PWD}")
|
||||
mWeb->arg("pwd").toCharArray(mMain->sysConfig.stationPwd, PWD_LEN);
|
||||
saveMask |= SAVE_PWD;
|
||||
}
|
||||
if(mWeb->arg("device") != "") {
|
||||
if(mWeb->arg("device") != "")
|
||||
mWeb->arg("device").toCharArray(mMain->sysConfig.deviceName, DEVNAME_LEN);
|
||||
saveMask |= SAVE_DEVICE_NAME;
|
||||
}
|
||||
|
||||
// inverter
|
||||
Inverter<> *iv;
|
||||
|
@ -168,8 +252,6 @@ class web {
|
|||
mWeb->arg("inv" + String(i) + "Addr").toCharArray(buf, 20);
|
||||
if(strlen(buf) == 0)
|
||||
memset(buf, 0, 20);
|
||||
else
|
||||
saveMask |= SAVE_INVERTERS;
|
||||
iv->serial.u64 = mMain->Serial2u64(buf);
|
||||
|
||||
// active power limit
|
||||
|
@ -186,36 +268,29 @@ class web {
|
|||
mWeb->arg("inv" + String(i) + "ModName" + String(j)).toCharArray(iv->chName[j], MAX_NAME_LENGTH);
|
||||
}
|
||||
}
|
||||
if(mWeb->arg("invInterval") != "") {
|
||||
if(mWeb->arg("invInterval") != "")
|
||||
mMain->config.sendInterval = mWeb->arg("invInterval").toInt();
|
||||
saveMask |= SAVE_INV_SEND_INTERVAL;
|
||||
}
|
||||
if(mWeb->arg("invRetry") != "") {
|
||||
if(mWeb->arg("invRetry") != "")
|
||||
mMain->config.sendInterval = mWeb->arg("invRetry").toInt();
|
||||
saveMask |= SAVE_INV_RETRY;
|
||||
}
|
||||
|
||||
// pinout
|
||||
uint8_t pin;
|
||||
for(uint8_t i = 0; i < 3; i ++) {
|
||||
pin = mWeb->arg(String(pinArgNames[i])).toInt();
|
||||
switch(i) {
|
||||
default: mMain->mSys->Radio.pinCs = pin; break;
|
||||
case 1: mMain->mSys->Radio.pinCe = pin; break;
|
||||
case 2: mMain->mSys->Radio.pinIrq = pin; break;
|
||||
default: mMain->config.pinCs = pin; break;
|
||||
case 1: mMain->config.pinCe = pin; break;
|
||||
case 2: mMain->config.pinIrq = pin; break;
|
||||
}
|
||||
}
|
||||
saveMask |= SAVE_PINOUT;
|
||||
|
||||
// nrf24 amplifier power
|
||||
mMain->mSys->Radio.AmplifierPower = mWeb->arg("rf24Power").toInt() & 0x03;
|
||||
saveMask |= SAVE_RF24;
|
||||
mMain->config.amplifierPower = mWeb->arg("rf24Power").toInt() & 0x03;
|
||||
|
||||
// ntp
|
||||
if(mWeb->arg("ntpAddr") != "") {
|
||||
mWeb->arg("ntpAddr").toCharArray(mMain->config.ntpAddr, NTP_ADDR_LEN);
|
||||
mMain->config.ntpPort = mWeb->arg("ntpPort").toInt() & 0xffff;
|
||||
saveMask |= SAVE_NTP;
|
||||
}
|
||||
|
||||
// mqtt
|
||||
|
@ -225,7 +300,6 @@ class web {
|
|||
mWeb->arg("mqttPwd").toCharArray(mMain->config.mqtt.pwd, MQTT_PWD_LEN);
|
||||
mWeb->arg("mqttTopic").toCharArray(mMain->config.mqtt.topic, MQTT_TOPIC_LEN);
|
||||
mMain->config.mqtt.port = mWeb->arg("mqttPort").toInt();
|
||||
saveMask |= SAVE_MQTT;
|
||||
}
|
||||
|
||||
// serial console
|
||||
|
@ -234,11 +308,9 @@ class web {
|
|||
|
||||
mMain->config.serialDebug = (mWeb->arg("serEn") == "on");
|
||||
mMain->config.serialShowIv = (mWeb->arg("serDbg") == "on");
|
||||
saveMask |= SAVE_SERIAL;
|
||||
}
|
||||
|
||||
|
||||
mMain->saveValues(saveMask);
|
||||
mMain->saveValues();
|
||||
|
||||
if(mWeb->arg("reboot") == "on")
|
||||
showReboot();
|
||||
|
@ -249,8 +321,6 @@ class web {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
ESP8266WebServer *mWeb;
|
||||
ESP8266HTTPUpdateServer *mUpdater;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue