Browse Source

fix #389 prevent connect to default Wifi 'YOUR_WIFI_SSID'

implemented #388 add inverter Id to the front of serial print
fix inverter serial number length in input field (api.js)
pull/421/head
lumapu 2 years ago
parent
commit
ea991a7723
  1. 17
      tools/esp8266/ahoywifi.cpp
  2. 1
      tools/esp8266/ahoywifi.h
  3. 10
      tools/esp8266/app.cpp
  4. 1
      tools/esp8266/config_override_example.h
  5. 2
      tools/esp8266/hmInverter.h
  6. 2
      tools/esp8266/hmRadio.h
  7. 2
      tools/esp8266/html/api.js

17
tools/esp8266/ahoywifi.cpp

@ -33,10 +33,16 @@ ahoywifi::ahoywifi(app *main, sysConfig_t *sysCfg, config_t *config) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void ahoywifi::setup(uint32_t timeout, bool settingValid) { void ahoywifi::setup(uint32_t timeout, bool settingValid) {
#ifdef FB_WIFI_OVERRIDDEN
mStationWifiIsDef = false;
#else
mStationWifiIsDef = (strncmp(mSysCfg->stationSsid, FB_WIFI_SSID, 14) == 0);
#endif
mWifiStationTimeout = timeout; mWifiStationTimeout = timeout;
#ifndef AP_ONLY #ifndef AP_ONLY
if(false == mApActive) if(false == mApActive)
mApActive = setupStation(mWifiStationTimeout); mApActive = (mStationWifiIsDef) ? true : setupStation(mWifiStationTimeout);
#endif #endif
if(!settingValid) { if(!settingValid) {
@ -66,7 +72,7 @@ bool ahoywifi::loop(void) {
mDns->processNextRequest(); mDns->processNextRequest();
#ifndef AP_ONLY #ifndef AP_ONLY
if(mMain->checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) { if(mMain->checkTicker(&mNextTryTs, (WIFI_AP_ACTIVE_TIME * 1000))) {
mApActive = setupStation(mWifiStationTimeout); mApActive = (mStationWifiIsDef) ? true : setupStation(mWifiStationTimeout);
if(mApActive) { if(mApActive) {
if(strlen(WIFI_AP_PWD) < 8) if(strlen(WIFI_AP_PWD) < 8)
DPRINTLN(DBG_ERROR, F("password must be at least 8 characters long")); DPRINTLN(DBG_ERROR, F("password must be at least 8 characters long"));
@ -77,12 +83,13 @@ bool ahoywifi::loop(void) {
} }
else { else {
if(millis() - mApLastTick > 10000) { if(millis() - mApLastTick > 10000) {
mApLastTick = millis();
uint8_t cnt = WiFi.softAPgetStationNum(); uint8_t cnt = WiFi.softAPgetStationNum();
if(cnt > 0) { if(cnt > 0) {
DPRINTLN(DBG_INFO, String(cnt) + F(" client connected, resetting AP timeout")); DPRINTLN(DBG_INFO, String(cnt) + F(" client connected (no timeout)"));
mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000)); mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000));
} }
mApLastTick = millis(); else
DPRINTLN(DBG_INFO, F("AP will be closed in ") + String((mNextTryTs - mApLastTick) / 1000) + F(" seconds")); DPRINTLN(DBG_INFO, F("AP will be closed in ") + String((mNextTryTs - mApLastTick) / 1000) + F(" seconds"));
} }
} }
@ -92,7 +99,7 @@ bool ahoywifi::loop(void) {
if((WiFi.status() != WL_CONNECTED) && wifiWasEstablished) { if((WiFi.status() != WL_CONNECTED) && wifiWasEstablished) {
if(!mApActive) { if(!mApActive) {
DPRINTLN(DBG_INFO, "[WiFi]: Connection Lost"); DPRINTLN(DBG_INFO, "[WiFi]: Connection Lost");
mApActive = setupStation(mWifiStationTimeout); mApActive = (mStationWifiIsDef) ? true : setupStation(mWifiStationTimeout);
} }
} }

1
tools/esp8266/ahoywifi.h

@ -48,6 +48,7 @@ class ahoywifi {
uint32_t mApLastTick; uint32_t mApLastTick;
bool mApActive; bool mApActive;
bool wifiWasEstablished; bool wifiWasEstablished;
bool mStationWifiIsDef;
}; };
#endif /*__AHOYWIFI_H__*/ #endif /*__AHOYWIFI_H__*/

10
tools/esp8266/app.cpp

@ -17,11 +17,11 @@ app::app() {
Serial.begin(115200); Serial.begin(115200);
DPRINTLN(DBG_VERBOSE, F("app::app")); DPRINTLN(DBG_VERBOSE, F("app::app"));
mEep = new eep(); mEep = new eep();
mWifi = new ahoywifi(this, &mSysConfig, &mConfig);
resetSystem(); resetSystem();
loadDefaultConfig(); loadDefaultConfig();
mWifi = new ahoywifi(this, &mSysConfig, &mConfig);
mSys = new HmSystemType(); mSys = new HmSystemType();
mSys->enableDebug(); mSys->enableDebug();
mShouldReboot = false; mShouldReboot = false;
@ -231,7 +231,7 @@ void app::loop(void) {
if (mConfig.serialDebug) if (mConfig.serialDebug)
DPRINTLN(DBG_INFO, F("enqueued cmd failed/timeout")); DPRINTLN(DBG_INFO, F("enqueued cmd failed/timeout"));
if (mConfig.serialDebug) { if (mConfig.serialDebug) {
DPRINT(DBG_INFO, F("Inverter #") + String(iv->id) + " "); DPRINT(DBG_INFO, F("(#") + String(iv->id) + ") ");
DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")"); DPRINTLN(DBG_INFO, F("no Payload received! (retransmits: ") + String(mPayload[iv->id].retransmits) + ")");
} }
} }
@ -242,18 +242,19 @@ void app::loop(void) {
yield(); yield();
if (mConfig.serialDebug) { if (mConfig.serialDebug) {
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status())); DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()));
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX)); DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") Requesting Inv SN ") + String(iv->serial.u64, HEX));
} }
if (iv->devControlRequest) { if (iv->devControlRequest) {
if (mConfig.serialDebug) if (mConfig.serialDebug)
DPRINTLN(DBG_INFO, F("Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0])); DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") Devcontrol request ") + String(iv->devControlCmd) + F(" power limit ") + String(iv->powerLimit[0]));
mSys->Radio.sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit); mSys->Radio.sendControlPacket(iv->radioId.u64, iv->devControlCmd, iv->powerLimit);
mPayload[iv->id].txCmd = iv->devControlCmd; mPayload[iv->id].txCmd = iv->devControlCmd;
iv->clearCmdQueue(); iv->clearCmdQueue();
iv->enqueCommand<InfoCommand>(SystemConfigPara); iv->enqueCommand<InfoCommand>(SystemConfigPara);
} else { } else {
uint8_t cmd = iv->getQueuedCmd(); uint8_t cmd = iv->getQueuedCmd();
DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") sendTimePacket"));
mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex); mSys->Radio.sendTimePacket(iv->radioId.u64, cmd, mPayload[iv->id].ts, iv->alarmMesIndex);
mPayload[iv->id].txCmd = cmd; mPayload[iv->id].txCmd = cmd;
mRxTicker = 0; mRxTicker = 0;
@ -333,6 +334,7 @@ void app::processPayload(bool retransmit) {
mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, mLastPacketId, true); mSys->Radio.sendCmdPacket(iv->radioId.u64, TX_REQ_INFO, mLastPacketId, true);
else { else {
mPayload[iv->id].txCmd = iv->getQueuedCmd(); mPayload[iv->id].txCmd = iv->getQueuedCmd();
DPRINTLN(DBG_INFO, F("(#") + String(iv->id) + F(") sendTimePacket"));
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex); mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].txCmd, mPayload[iv->id].ts, iv->alarmMesIndex);
} }
} }

1
tools/esp8266/config_override_example.h

@ -7,6 +7,7 @@
#define __CONFIG_OVERRIDE_H__ #define __CONFIG_OVERRIDE_H__
// override fallback WiFi info // override fallback WiFi info
#define FB_WIFI_OVERRIDDEN
// each ovveride must be preceeded with an #undef statement // each ovveride must be preceeded with an #undef statement
#undef FB_WIFI_SSID #undef FB_WIFI_SSID

2
tools/esp8266/hmInverter.h

@ -144,7 +144,7 @@ class Inverter {
template <typename T> template <typename T>
void enqueCommand(uint8_t cmd) { void enqueCommand(uint8_t cmd) {
_commandQueue.push(std::make_shared<T>(cmd)); _commandQueue.push(std::make_shared<T>(cmd));
DPRINTLN(DBG_INFO, "enqueuedCmd: " + String(cmd)); DPRINTLN(DBG_INFO, F("(#") + String(id) + F(") enqueuedCmd: ") + String(cmd));
} }
void setQueuedCmdFinished() { void setQueuedCmdFinished() {

2
tools/esp8266/hmRadio.h

@ -220,7 +220,7 @@ class HmRadio {
} }
void sendTimePacket(uint64_t invId, uint8_t cmd, uint32_t ts, uint16_t alarmMesId) { void sendTimePacket(uint64_t invId, uint8_t cmd, uint32_t ts, uint16_t alarmMesId) {
DPRINTLN(DBG_INFO, F("sendTimePacket")); DPRINTLN(DBG_VERBOSE, F("sendTimePacket"));
sendCmdPacket(invId, TX_REQ_INFO, ALL_FRAMES, false); sendCmdPacket(invId, TX_REQ_INFO, ALL_FRAMES, false);
mTxBuf[10] = cmd; // cid mTxBuf[10] = cmd; // cid
mTxBuf[11] = 0x00; mTxBuf[11] = 0x00;

2
tools/esp8266/html/api.js

@ -90,7 +90,7 @@ function inp(name, val, max=32, cl=["text"], id=null, type=null) {
e.classList.add(...cl); e.classList.add(...cl);
e.name = name; e.name = name;
e.value = val; e.value = val;
if(null != type) e.maxLength = max; if(null != max) e.maxLength = max;
if(null != id) e.id = id; if(null != id) e.id = id;
if(null != type) e.type = type; if(null != type) e.type = type;
return e; return e;

Loading…
Cancel
Save