mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-29 10:16:21 +02:00
Merge branch 'main' of https://github.com/grindylow/ahoy
This commit is contained in:
commit
44b31f765c
11 changed files with 114 additions and 14 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
app::app() : Main() {
|
||||
DPRINTLN(F("app::app():Main"));
|
||||
mSendTicker = 0xffff;
|
||||
mSendInterval = 0;
|
||||
mMqttTicker = 0xffff;
|
||||
|
@ -40,6 +41,7 @@ app::~app(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::setup(uint32_t timeout) {
|
||||
DPRINTLN(F("app::setup"));
|
||||
Main::setup(timeout);
|
||||
|
||||
mWeb->on("/", std::bind(&app::showIndex, this));
|
||||
|
@ -150,6 +152,9 @@ void app::setup(uint32_t timeout) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::loop(void) {
|
||||
//DPRINT(F("a"));
|
||||
//DPRINTLN(F("a"));
|
||||
//app_loops++;
|
||||
Main::loop();
|
||||
|
||||
mSys->Radio.loop();
|
||||
|
@ -157,6 +162,9 @@ void app::loop(void) {
|
|||
yield();
|
||||
|
||||
if(checkTicker(&mRxTicker, 5)) {
|
||||
//DPRINTLN(F("app_loops =") + String(app_loops));
|
||||
//app_loops=0;
|
||||
//DPRINT(F("a"));
|
||||
bool rxRdy = mSys->Radio.switchRxCh();
|
||||
|
||||
if(!mSys->BufCtrl.empty()) {
|
||||
|
@ -293,6 +301,7 @@ void app::loop(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::handleIntr(void) {
|
||||
DPRINTLN(F("app::handleIntr"));
|
||||
mSys->Radio.handleIntr();
|
||||
}
|
||||
|
||||
|
@ -300,6 +309,7 @@ void app::handleIntr(void) {
|
|||
//-----------------------------------------------------------------------------
|
||||
bool app::buildPayload(uint8_t id) {
|
||||
//DPRINTLN("Payload");
|
||||
DPRINTLN(F("app::buildPayload"));
|
||||
uint16_t crc = 0xffff, crcRcv;
|
||||
if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES)
|
||||
mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES;
|
||||
|
@ -324,6 +334,8 @@ bool app::buildPayload(uint8_t id) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::processPayload(bool retransmit) {
|
||||
//DPRINTLN(F("app::processPayload"));
|
||||
//DPRINT(F("p"));
|
||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||
if(NULL != iv) {
|
||||
|
@ -381,15 +393,19 @@ void app::processPayload(bool retransmit) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showIndex(void) {
|
||||
DPRINTLN(F("app::showIndex"));
|
||||
String html = FPSTR(index_html);
|
||||
html.replace(F("{DEVICE}"), mDeviceName);
|
||||
html.replace(F("{VERSION}"), mVersion);
|
||||
html.replace(F("{TS}"), String(mSendInterval) + " ");
|
||||
html.replace(F("{JS_TS}"), String(mSendInterval * 1000));
|
||||
mWeb->send(200, "text/html", html);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showSetup(void) {
|
||||
DPRINTLN(F("app::showSetup"));
|
||||
// overrides same method in main.cpp
|
||||
|
||||
uint16_t interval;
|
||||
|
@ -518,12 +534,14 @@ void app::showSetup(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showSave(void) {
|
||||
DPRINTLN(F("app::showSave"));
|
||||
saveValues(true);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showErase() {
|
||||
DPRINTLN(F("app::showErase"));
|
||||
eraseSettings();
|
||||
showReboot();
|
||||
}
|
||||
|
@ -531,6 +549,7 @@ void app::showErase() {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showStatistics(void) {
|
||||
DPRINTLN(F("app::showStatistics"));
|
||||
String content = F("Receive success: ") + String(mRxSuccess) + "\n";
|
||||
content += F("Receive fail: ") + String(mRxFailed) + "\n";
|
||||
content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n");
|
||||
|
@ -579,6 +598,7 @@ void app::showStatistics(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showHoymiles(void) {
|
||||
DPRINTLN(F("app::showHoymiles"));
|
||||
String html = FPSTR(hoymiles_html);
|
||||
html.replace(F("{DEVICE}"), mDeviceName);
|
||||
html.replace(F("{VERSION}"), mVersion);
|
||||
|
@ -590,6 +610,7 @@ void app::showHoymiles(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::showLiveData(void) {
|
||||
DPRINTLN(F("app::showLiveData"));
|
||||
String modHtml;
|
||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||
|
@ -662,6 +683,7 @@ void app::showLiveData(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::saveValues(bool webSend = true) {
|
||||
DPRINTLN(F("app::saveValues"));
|
||||
Main::saveValues(false); // general configuration
|
||||
|
||||
if(mWeb->args() > 0) {
|
||||
|
@ -763,6 +785,7 @@ void app::saveValues(bool webSend = true) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void app::updateCrc(void) {
|
||||
DPRINTLN(F("app::updateCrc"));
|
||||
Main::updateCrc();
|
||||
|
||||
uint16_t crc;
|
||||
|
|
|
@ -43,6 +43,7 @@ class app : public Main {
|
|||
void loop(void);
|
||||
void handleIntr(void);
|
||||
|
||||
uint8_t app_loops;
|
||||
uint8_t getIrqPin(void) {
|
||||
return mSys->Radio.pinIrq;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
// access point info
|
||||
#define WIFI_AP_SSID "AHOY DTU"
|
||||
#define WIFI_AP_SSID "AHOY-DTU"
|
||||
#define WIFI_AP_PWD "esp_8266"
|
||||
// stay in access point mode all the time
|
||||
//#define AP_ONLY
|
||||
|
@ -24,7 +24,7 @@
|
|||
#define WIFI_AP_ACTIVE_TIME 60
|
||||
|
||||
// default device name
|
||||
#define DEF_DEVICE_NAME "ESP-DTU"
|
||||
#define DEF_DEVICE_NAME "AHOY-DTU"
|
||||
|
||||
// number of packets hold in buffer
|
||||
#define PACKET_BUFFER_SIZE 30
|
||||
|
|
|
@ -81,6 +81,7 @@ class Inverter {
|
|||
}
|
||||
|
||||
void init(void) {
|
||||
DPRINTLN(F("hmInverter.h:init"));
|
||||
getAssignment();
|
||||
toRadioId();
|
||||
record = new RECORDTYPE[listLen];
|
||||
|
@ -89,6 +90,7 @@ class Inverter {
|
|||
}
|
||||
|
||||
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
|
||||
DPRINTLN(F("hmInverter.h:getPosByChFld"));
|
||||
uint8_t pos = 0;
|
||||
for(; pos < listLen; pos++) {
|
||||
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
|
||||
|
@ -98,18 +100,22 @@ class Inverter {
|
|||
}
|
||||
|
||||
const char *getFieldName(uint8_t pos) {
|
||||
DPRINTLN(F("hmInverter.h:getFieldName"));
|
||||
return fields[assign[pos].fieldId];
|
||||
}
|
||||
|
||||
const char *getUnit(uint8_t pos) {
|
||||
DPRINTLN(F("hmInverter.h:getUnit"));
|
||||
return units[assign[pos].unitId];
|
||||
}
|
||||
|
||||
uint8_t getChannel(uint8_t pos) {
|
||||
DPRINTLN(F("hmInverter.h:getChannel"));
|
||||
return assign[pos].ch;
|
||||
}
|
||||
|
||||
void addValue(uint8_t pos, uint8_t buf[]) {
|
||||
DPRINTLN(F("hmInverter.h:addValue"));
|
||||
uint8_t ptr = assign[pos].start;
|
||||
uint8_t end = ptr + assign[pos].num;
|
||||
uint16_t div = assign[pos].div;
|
||||
|
@ -126,10 +132,12 @@ class Inverter {
|
|||
}
|
||||
|
||||
RECORDTYPE getValue(uint8_t pos) {
|
||||
DPRINTLN(F("hmInverter.h:getValue"));
|
||||
return record[pos];
|
||||
}
|
||||
|
||||
void doCalculations(void) {
|
||||
DPRINTLN(F("hmInverter.h:doCalculations"));
|
||||
for(uint8_t i = 0; i < listLen; i++) {
|
||||
if(CMD_CALC == assign[i].div) {
|
||||
record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
|
||||
|
@ -138,10 +146,12 @@ class Inverter {
|
|||
}
|
||||
|
||||
bool isAvailable(uint32_t timestamp) {
|
||||
DPRINTLN(F("hmInverter.h:isAvailable"));
|
||||
return ((timestamp - ts) < INACT_THRES_SEC);
|
||||
}
|
||||
|
||||
bool isProducing(uint32_t timestamp) {
|
||||
DPRINTLN(F("hmInverter.h:isProducing"));
|
||||
if(isAvailable(timestamp)) {
|
||||
uint8_t pos = getPosByChFld(CH0, FLD_PAC);
|
||||
return (getValue(pos) > INACT_PWR_THRESH);
|
||||
|
@ -150,11 +160,13 @@ class Inverter {
|
|||
}
|
||||
|
||||
uint32_t getLastTs(void) {
|
||||
DPRINTLN(F("hmInverter.h:getLastTs"));
|
||||
return ts;
|
||||
}
|
||||
|
||||
private:
|
||||
void toRadioId(void) {
|
||||
DPRINTLN(F("hmInverter.h:toRadioId"));
|
||||
radioId.u64 = 0ULL;
|
||||
radioId.b[4] = serial.b[0];
|
||||
radioId.b[3] = serial.b[1];
|
||||
|
@ -164,6 +176,7 @@ class Inverter {
|
|||
}
|
||||
|
||||
void getAssignment(void) {
|
||||
DPRINTLN(F("hmInverter.h:getAssignment"));
|
||||
if(INV_TYPE_1CH == type) {
|
||||
listLen = (uint8_t)(HM1CH_LIST_LEN);
|
||||
assign = (byteAssign_t*)hm1chAssignment;
|
||||
|
@ -196,6 +209,7 @@ class Inverter {
|
|||
|
||||
template<class T=float>
|
||||
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
DPRINTLN(F("hmInverter.h:calcYieldTotalCh0"));
|
||||
if(NULL != iv) {
|
||||
T yield = 0;
|
||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||
|
@ -209,6 +223,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
DPRINTLN(F("hmInverter.h:calcYieldDayCh0"));
|
||||
if(NULL != iv) {
|
||||
T yield = 0;
|
||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||
|
@ -222,6 +237,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
||||
DPRINTLN(F("hmInverter.h:calcUdcCh"));
|
||||
// arg0 = channel of source
|
||||
for(uint8_t i = 0; i < iv->listLen; i++) {
|
||||
if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) {
|
||||
|
@ -234,6 +250,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
DPRINTLN(F("hmInverter.h:calcPowerDcCh0"));
|
||||
if(NULL != iv) {
|
||||
T dcPower = 0;
|
||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||
|
@ -247,6 +264,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
||||
DPRINTLN(F("hmInverter.h:calcEfficiencyCh0"));
|
||||
if(NULL != iv) {
|
||||
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
|
||||
T acPower = iv->getValue(pos);
|
||||
|
@ -263,6 +281,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
|||
|
||||
template<class T=float>
|
||||
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
||||
DPRINTLN(F("hmInverter.h:calcIrradiation"));
|
||||
// arg0 = channel
|
||||
if(NULL != iv) {
|
||||
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);
|
||||
|
|
|
@ -13,10 +13,11 @@
|
|||
#define DTU_RADIO_ID ((uint64_t)0x1234567801ULL)
|
||||
#define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL)
|
||||
|
||||
#define RX_CHANNELS 5
|
||||
#define RX_LOOP_CNT 600
|
||||
|
||||
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||
|
||||
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -48,14 +49,17 @@ template <uint8_t CE_PIN, uint8_t CS_PIN, uint8_t IRQ_PIN, class BUFFER, uint64_
|
|||
class HmRadio {
|
||||
public:
|
||||
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
|
||||
DPRINTLN(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")");
|
||||
mTxChLst[0] = 40;
|
||||
//mTxChIdx = 1;
|
||||
|
||||
mRxChLst[0] = 3;
|
||||
// Depending on the program, the module can work on 2403, 2423, 2440, 2461 or 2475MHz.
|
||||
// Channel List 2403, 2423, 2440, 2461, 2475MHz
|
||||
mRxChLst[0] = 03;
|
||||
mRxChLst[1] = 23;
|
||||
mRxChLst[2] = 61;
|
||||
mRxChLst[3] = 75;
|
||||
mRxChLst[4] = 40;
|
||||
mRxChLst[2] = 40;
|
||||
mRxChLst[3] = 61;
|
||||
mRxChLst[4] = 75;
|
||||
mRxChIdx = 0;
|
||||
mRxLoopCnt = RX_LOOP_CNT;
|
||||
|
||||
|
@ -72,6 +76,7 @@ class HmRadio {
|
|||
~HmRadio() {}
|
||||
|
||||
void setup(BUFFER *ctrl) {
|
||||
DPRINTLN(F("hmRadio.h:setup"));
|
||||
pinMode(pinIrq, INPUT_PULLUP);
|
||||
|
||||
mBufCtrl = ctrl;
|
||||
|
@ -136,10 +141,12 @@ class HmRadio {
|
|||
}
|
||||
|
||||
void handleIntr(void) {
|
||||
DPRINTLN(F("hmRadio.h:handleIntr"));
|
||||
mIrqRcvd = true;
|
||||
}
|
||||
|
||||
uint8_t getDefaultChannel(void) {
|
||||
//DPRINTLN(F("hmRadio.h:getDefaultChannel"));
|
||||
return mTxChLst[0];
|
||||
}
|
||||
/*uint8_t getLastChannel(void) {
|
||||
|
@ -153,6 +160,7 @@ class HmRadio {
|
|||
}*/
|
||||
|
||||
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
||||
DPRINTLN(F("hmRadio.h:sendTimePacket"));
|
||||
sendCmdPacket(invId, 0x15, 0x80, false);
|
||||
mTxBuf[10] = 0x0b; // cid
|
||||
mTxBuf[11] = 0x00;
|
||||
|
@ -168,6 +176,7 @@ class HmRadio {
|
|||
}
|
||||
|
||||
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
|
||||
DPRINTLN(F("hmRadio.h:sendCmdPacket"));
|
||||
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
|
||||
mTxBuf[0] = mid; // message id
|
||||
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
|
||||
|
@ -180,6 +189,7 @@ class HmRadio {
|
|||
}
|
||||
|
||||
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
|
||||
DPRINTLN(F("hmRadio.h:checkPaketCrc"));
|
||||
*len = (buf[0] >> 2);
|
||||
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
|
||||
*len = MAX_RF_PAYLOAD_SIZE - 2;
|
||||
|
@ -193,7 +203,10 @@ class HmRadio {
|
|||
return valid;
|
||||
}
|
||||
|
||||
bool switchRxCh(uint16_t addLoop = 0) {
|
||||
bool switchRxCh(uint8_t addLoop = 0) {
|
||||
//DPRINTLN(F("hmRadio.h:switchRxCh"));
|
||||
//DPRINT(F("R"));
|
||||
|
||||
mRxLoopCnt += addLoop;
|
||||
if(mRxLoopCnt != 0) {
|
||||
mRxLoopCnt--;
|
||||
|
@ -207,6 +220,7 @@ class HmRadio {
|
|||
}
|
||||
|
||||
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
|
||||
//DPRINTLN(F("hmRadio.h:dumpBuf"));
|
||||
if(NULL != info)
|
||||
DPRINT(String(info));
|
||||
for(uint8_t i = 0; i < len; i++) {
|
||||
|
@ -217,6 +231,7 @@ class HmRadio {
|
|||
}
|
||||
|
||||
bool isChipConnected(void) {
|
||||
DPRINTLN(F("hmRadio.h:isChipConnected"));
|
||||
return mNrf24.isChipConnected();
|
||||
}
|
||||
|
||||
|
@ -231,6 +246,7 @@ class HmRadio {
|
|||
|
||||
private:
|
||||
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
|
||||
DPRINTLN(F("hmRadio.h:sendPacket"));
|
||||
//DPRINTLN("sent packet: #" + String(mSendCnt));
|
||||
//dumpBuf("SEN ", buf, len);
|
||||
if(mSerialDebug) {
|
||||
|
@ -273,7 +289,8 @@ class HmRadio {
|
|||
}
|
||||
|
||||
uint8_t getRxNxtChannel(void) {
|
||||
if(++mRxChIdx >= 5)
|
||||
|
||||
if(++mRxChIdx >= RX_CHANNELS)
|
||||
mRxChIdx = 0;
|
||||
return mRxChLst[mRxChIdx];
|
||||
}
|
||||
|
@ -282,7 +299,8 @@ class HmRadio {
|
|||
uint8_t mTxChLst[1];
|
||||
//uint8_t mTxChIdx;
|
||||
|
||||
uint8_t mRxChLst[5];
|
||||
uint8_t mRxChLst[RX_CHANNELS];
|
||||
|
||||
uint8_t mRxChIdx;
|
||||
uint16_t mRxLoopCnt;
|
||||
|
||||
|
|
|
@ -24,10 +24,12 @@ class HmSystem {
|
|||
}
|
||||
|
||||
void setup() {
|
||||
DPRINTLN(F("hmSystem.h:setup"));
|
||||
Radio.setup(&BufCtrl);
|
||||
}
|
||||
|
||||
INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) {
|
||||
DPRINTLN(F("hmSystem.h:addInverter"));
|
||||
if(MAX_INVERTER <= mNumInv) {
|
||||
DPRINT(F("max number of inverters reached!"));
|
||||
return NULL;
|
||||
|
@ -64,6 +66,7 @@ class HmSystem {
|
|||
}
|
||||
|
||||
INVERTERTYPE *findInverter(uint8_t buf[]) {
|
||||
DPRINTLN(F("hmSystem.h:findInverter"));
|
||||
INVERTERTYPE *p;
|
||||
for(uint8_t i = 0; i < mNumInv; i++) {
|
||||
p = &mInverter[i];
|
||||
|
@ -77,6 +80,7 @@ class HmSystem {
|
|||
}
|
||||
|
||||
INVERTERTYPE *getInverterByPos(uint8_t pos) {
|
||||
//DPRINTLN(F("hmSystem.h:getInverterByPos"));
|
||||
if(mInverter[pos].serial.u64 != 0ULL)
|
||||
return &mInverter[pos];
|
||||
else
|
||||
|
@ -84,6 +88,7 @@ class HmSystem {
|
|||
}
|
||||
|
||||
uint8_t getNumInverters(void) {
|
||||
//DPRINTLN(F("hmSystem.h:getNumInverters"));
|
||||
return mNumInv;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __INDEX_HTML_H__
|
||||
#define __INDEX_HTML_H__
|
||||
const char index_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">window.setInterval(\"getAjax('/uptime', 'uptime')\", 1000);window.setInterval(\"getAjax('/time', 'time')\", 1000);window.setInterval(\"getAjax('/cmdstat', 'cmds')\", 2000);function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/hoymiles\">Visualization</a><br/><br/><a href=\"/setup\">Setup</a><br/></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p><div id=\"note\">This project was started from <a href=\"https://www.mikrocontroller.net/topic/525778\" target=\"_blank\">this discussion. (Mikrocontroller.net)</a><br/>New updates can be found on Github: <a href=\"https://github.com/grindylow/ahoy\" target=\"_blank\">https://github.com/grindylow/ahoy</a><br/><br/>Please report issues using the feature provided by Github. </div></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY :: {VERSION}</p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p></div></body></html>";
|
||||
const char index_html[] PROGMEM = "<!doctype html><html><head><title>Index - {DEVICE}</title><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><script type=\"text/javascript\">window.setInterval(\"getAjax('/uptime', 'uptime')\", {JS_TS});window.setInterval(\"getAjax('/time', 'time')\", {JS_TS});window.setInterval(\"getAjax('/cmdstat', 'cmds')\", {JS_TS});function getAjax(url, resid) {var http = null;http = new XMLHttpRequest();if(http != null) {http.open(\"GET\", url, true);http.onreadystatechange = print;http.send(null);}function print() {if(http.readyState == 4) {document.getElementById(resid).innerHTML = http.responseText;}}}</script></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><p><a href=\"/hoymiles\">Visualization</a><br/><br/><a href=\"/setup\">Setup</a><br/></p><p><span class=\"des\">Uptime: </span><span id=\"uptime\"></span></p><p><span class=\"des\">Time: </span><span id=\"time\"></span></p><p><span class=\"des\">Statistics: </span><pre id=\"cmds\"></pre></p><p>Every {TS}seconds the values are updated</p><div id=\"note\">This project was started from <a href=\"https://www.mikrocontroller.net/topic/525778\" target=\"_blank\">this discussion. (Mikrocontroller.net)</a><br/>New updates can be found on Github: <a href=\"https://github.com/grindylow/ahoy\" target=\"_blank\">https://github.com/grindylow/ahoy</a><br/><br/>Please report issues using the feature provided by Github. </div></div><div id=\"footer\"><p class=\"left\">© 2022</p><p class=\"left\"><a href=\"/update\">Update Firmware</a></p><p class=\"right\">AHOY :: {VERSION}</p><p class=\"right\"><a href=\"/reboot\">Reboot</a></p></div></body></html>";
|
||||
#endif /*__INDEX_HTML_H__*/
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<link rel="stylesheet" type="text/css" href="style.css"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script type="text/javascript">
|
||||
window.setInterval("getAjax('/uptime', 'uptime')", 1000);
|
||||
window.setInterval("getAjax('/time', 'time')", 1000);
|
||||
window.setInterval("getAjax('/cmdstat', 'cmds')", 2000);
|
||||
window.setInterval("getAjax('/uptime', 'uptime')", {JS_TS});
|
||||
window.setInterval("getAjax('/time', 'time')", {JS_TS});
|
||||
window.setInterval("getAjax('/cmdstat', 'cmds')", {JS_TS});
|
||||
|
||||
function getAjax(url, resid) {
|
||||
var http = null;
|
||||
|
@ -37,6 +37,7 @@
|
|||
<p><span class="des">Uptime: </span><span id="uptime"></span></p>
|
||||
<p><span class="des">Time: </span><span id="time"></span></p>
|
||||
<p><span class="des">Statistics: </span><pre id="cmds"></pre></p>
|
||||
<p>Every {TS}seconds the values are updated</p>
|
||||
|
||||
<div id="note">
|
||||
This project was started from <a href="https://www.mikrocontroller.net/topic/525778" target="_blank">this discussion. (Mikrocontroller.net)</a><br/>
|
||||
|
|
|
@ -26,6 +26,7 @@ Main::Main(void) {
|
|||
|
||||
mEep = new eep();
|
||||
Serial.begin(115200);
|
||||
DPRINTLN(F("Main::Main"));
|
||||
|
||||
mUptimeSecs = 0;
|
||||
mUptimeTicker = 0xffffffff;
|
||||
|
@ -39,6 +40,7 @@ Main::Main(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::setup(uint32_t timeout) {
|
||||
DPRINTLN(F("Main::setup"));
|
||||
bool startAp = mApActive;
|
||||
mLimit = timeout;
|
||||
|
||||
|
@ -67,6 +69,7 @@ void Main::setup(uint32_t timeout) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::loop(void) {
|
||||
//DPRINT(F("M"));
|
||||
if(mApActive) {
|
||||
mDns->processNextRequest();
|
||||
#ifndef AP_ONLY
|
||||
|
@ -115,6 +118,7 @@ void Main::loop(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool Main::getConfig(void) {
|
||||
DPRINTLN(F("Main::getConfig"));
|
||||
bool mApActive = false;
|
||||
|
||||
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
|
||||
|
@ -137,6 +141,7 @@ bool Main::getConfig(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::setupAp(const char *ssid, const char *pwd) {
|
||||
DPRINTLN(F("Main::setupAp"));
|
||||
IPAddress apIp(192, 168, 1, 1);
|
||||
|
||||
DPRINTLN(F("\n---------\nAP MODE\nSSDI: ")
|
||||
|
@ -163,6 +168,7 @@ void Main::setupAp(const char *ssid, const char *pwd) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool Main::setupStation(uint32_t timeout) {
|
||||
DPRINTLN(F("Main::setupStation"));
|
||||
int32_t cnt;
|
||||
bool startAp = false;
|
||||
|
||||
|
@ -212,6 +218,7 @@ bool Main::setupStation(uint32_t timeout) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showSetup(void) {
|
||||
DPRINTLN(F("Main::showSetup"));
|
||||
String html = FPSTR(setup_html);
|
||||
html.replace(F("{SSID}"), mStationSsid);
|
||||
// PWD will be left at the default value (for protection)
|
||||
|
@ -229,18 +236,21 @@ void Main::showSetup(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showCss(void) {
|
||||
DPRINTLN(F("Main::showCss"));
|
||||
mWeb->send(200, "text/css", FPSTR(style_css));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showSave(void) {
|
||||
DPRINTLN(F("Main::showSave"));
|
||||
saveValues(true);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::saveValues(bool webSend = true) {
|
||||
DPRINTLN(F("Main::saveValues"));
|
||||
if(mWeb->args() > 0) {
|
||||
if(mWeb->arg("ssid") != "") {
|
||||
memset(mStationSsid, 0, SSID_LEN);
|
||||
|
@ -273,6 +283,7 @@ void Main::saveValues(bool webSend = true) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::updateCrc(void) {
|
||||
DPRINTLN(F("Main::updateCrc"));
|
||||
uint16_t crc;
|
||||
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
|
||||
//Serial.println("new CRC: " + String(crc, HEX));
|
||||
|
@ -282,6 +293,7 @@ void Main::updateCrc(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showUptime(void) {
|
||||
DPRINTLN(F("Main::showUptime"));
|
||||
char time[20] = {0};
|
||||
|
||||
int upTimeSc = uint32_t((mUptimeSecs) % 60);
|
||||
|
@ -297,12 +309,14 @@ void Main::showUptime(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showTime(void) {
|
||||
DPRINTLN(F("Main::showTime"));
|
||||
mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showNotFound(void) {
|
||||
DPRINTLN(F("Main::showNotFound"));
|
||||
String msg = F("File Not Found\n\nURI: ");
|
||||
msg += mWeb->uri();
|
||||
msg += F("\nMethod: ");
|
||||
|
@ -321,6 +335,7 @@ void Main::showNotFound(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showReboot(void) {
|
||||
DPRINTLN(F("Main::showReboot"));
|
||||
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>"));
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
|
@ -330,6 +345,7 @@ void Main::showReboot(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::showFactoryRst(void) {
|
||||
DPRINTLN(F("Main::showFactoryRst"));
|
||||
String content = "";
|
||||
int refresh = 3;
|
||||
if(mWeb->args() > 0) {
|
||||
|
@ -358,6 +374,7 @@ void Main::showFactoryRst(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
time_t Main::getNtpTime(void) {
|
||||
DPRINTLN(F("Main::getNtpTime"));
|
||||
time_t date = 0;
|
||||
IPAddress timeServer;
|
||||
uint8_t buf[NTP_PACKET_SIZE];
|
||||
|
@ -395,6 +412,7 @@ time_t Main::getNtpTime(void) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
void Main::sendNTPpacket(IPAddress& address) {
|
||||
DPRINTLN(F("Main::sendNTPpacket"));
|
||||
uint8_t buf[NTP_PACKET_SIZE] = {0};
|
||||
|
||||
buf[0] = B11100011; // LI, Version, Mode
|
||||
|
@ -415,6 +433,7 @@ void Main::sendNTPpacket(IPAddress& address) {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
String Main::getDateTimeStr(time_t t) {
|
||||
DPRINTLN(F("Main::getDateTimeStr"));
|
||||
char str[20] = {0};
|
||||
sprintf(str, "%04d-%02d-%02d %02d:%02d:%02d", year(t), month(t), day(t), hour(t), minute(t), second(t));
|
||||
return String(str);
|
||||
|
@ -425,6 +444,7 @@ String Main::getDateTimeStr(time_t t) {
|
|||
// calculates the daylight saving time for middle Europe. Input: Unixtime in UTC
|
||||
// from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536
|
||||
time_t Main::offsetDayLightSaving (uint32_t local_t) {
|
||||
DPRINTLN(F("Main::offsetDayLightSaving"));
|
||||
int m = month (local_t);
|
||||
if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez
|
||||
if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep
|
||||
|
|
|
@ -41,12 +41,14 @@ class Main {
|
|||
virtual void updateCrc(void);
|
||||
|
||||
inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) {
|
||||
DPRINTLN(F("main.h:buildEEpCrc"));
|
||||
uint8_t buf[length];
|
||||
mEep->read(start, buf, length);
|
||||
return crc16(buf, length);
|
||||
}
|
||||
|
||||
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
|
||||
DPRINTLN(F("main.h:checkEEpCrc"));
|
||||
uint16_t crcRd, crcCheck;
|
||||
crcCheck = buildEEpCrc(start, length);
|
||||
mEep->read(crcPos, &crcRd);
|
||||
|
@ -55,6 +57,7 @@ class Main {
|
|||
}
|
||||
|
||||
void eraseSettings(bool all = false) {
|
||||
DPRINTLN(F("main.h:eraseSettings"));
|
||||
uint8_t buf[64] = {0};
|
||||
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
|
||||
uint16_t end;
|
||||
|
@ -69,6 +72,7 @@ class Main {
|
|||
}
|
||||
|
||||
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
|
||||
//DPRINT(F("c"));
|
||||
uint32_t mil = millis();
|
||||
if(mil >= *ticker) {
|
||||
*ticker = mil + interval;
|
||||
|
@ -83,6 +87,7 @@ class Main {
|
|||
}
|
||||
|
||||
void stats(void) {
|
||||
DPRINTLN(F("main.h:stats"));
|
||||
uint32_t free;
|
||||
uint16_t max;
|
||||
uint8_t frag;
|
||||
|
|
|
@ -21,6 +21,7 @@ class mqtt {
|
|||
}
|
||||
|
||||
void setup(const char *broker, const char *topic, const char *user, const char *pwd, uint16_t port) {
|
||||
DPRINTLN(F("mqtt.h:setup"));
|
||||
mAddressSet = true;
|
||||
mClient->setServer(broker, port);
|
||||
|
||||
|
@ -30,6 +31,7 @@ class mqtt {
|
|||
}
|
||||
|
||||
void sendMsg(const char *topic, const char *msg) {
|
||||
DPRINTLN(F("mqtt.h:sendMsg"));
|
||||
if(mAddressSet) {
|
||||
char top[64];
|
||||
snprintf(top, 64, "%s/%s", mTopic, topic);
|
||||
|
@ -42,24 +44,29 @@ class mqtt {
|
|||
}
|
||||
|
||||
bool isConnected(bool doRecon = false) {
|
||||
DPRINTLN(F("mqtt.h:isConnected"));
|
||||
if(doRecon)
|
||||
reconnect();
|
||||
return mClient->connected();
|
||||
}
|
||||
|
||||
char *getUser(void) {
|
||||
DPRINTLN(F("mqtt.h:getUser"));
|
||||
return mUser;
|
||||
}
|
||||
|
||||
char *getPwd(void) {
|
||||
DPRINTLN(F("mqtt.h:getPwd"));
|
||||
return mPwd;
|
||||
}
|
||||
|
||||
char *getTopic(void) {
|
||||
DPRINTLN(F("mqtt.h:getTopic"));
|
||||
return mTopic;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//DPRINT(F("m"));
|
||||
//if(!mClient->connected())
|
||||
// reconnect();
|
||||
mClient->loop();
|
||||
|
@ -67,6 +74,7 @@ class mqtt {
|
|||
|
||||
private:
|
||||
void reconnect(void) {
|
||||
DPRINTLN(F("mqtt.h:reconnect"));
|
||||
if(!mClient->connected()) {
|
||||
String mqttId = "ESP-" + String(random(0xffff), HEX);
|
||||
if((strlen(mUser) > 0) && (strlen(mPwd) > 0))
|
||||
|
|
Loading…
Add table
Reference in a new issue