Browse Source

Merge branch 'dev'

pull/37/head
lumapu 2 years ago
parent
commit
7338925947
  1. 4
      tools/esp8266/CircularBuffer.h
  2. 123
      tools/esp8266/app.cpp
  3. 5
      tools/esp8266/app.h
  4. 4
      tools/esp8266/config.h
  5. 4
      tools/esp8266/defines.h
  6. 168
      tools/esp8266/hmRadio.h
  7. 7
      tools/esp8266/html/convert.py
  8. 6
      tools/esp8266/html/h/hoymiles_html.h
  9. 6
      tools/esp8266/html/h/index_html.h
  10. 6
      tools/esp8266/html/h/setup_html.h
  11. 6
      tools/esp8266/html/h/style_css.h
  12. 7
      tools/esp8266/main.cpp

4
tools/esp8266/CircularBuffer.h

@ -70,6 +70,10 @@ class CircularBuffer {
return m_fill == m_size;
}
inline uint8_t getFill(void) const {
return m_fill;
}
/** Aquire record on front of the buffer, for writing.
* After filling the record, it has to be pushed to actually
* add it to the buffer.

123
tools/esp8266/app.cpp

@ -16,14 +16,14 @@ app::app() : Main() {
mMqttActive = false;
mTicker = 0;
mRxTicker = 0;
mShowRebootRequest = false;
mSerialValues = true;
mSerialDebug = false;
memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
//memset(mChannelStat, 0, sizeof(uint32_t) * 4);
memset(mPacketIds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN);
mSys = new HmSystemType();
}
@ -63,9 +63,8 @@ void app::setup(uint32_t timeout) {
}
}
mEep->read(ADDR_INV_INTERVAL, &mSendInterval);
if(mSendInterval < 1)
mSendInterval = 1;
if(mSendInterval < 5)
mSendInterval = 5;
// pinout
mEep->read(ADDR_PINOUT, &mSys->Radio.pinCs);
@ -134,63 +133,51 @@ void app::setup(uint32_t timeout) {
void app::loop(void) {
Main::loop();
if(!mSys->BufCtrl.empty()) {
uint8_t len, rptCnt;
packet_t *p = mSys->BufCtrl.getBack();
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
if((0 != len) && (0 == rptCnt)) {
uint8_t *cmd = &p->packet[11];
//DPRINTLN("CMD " + String(*cmd, HEX));
//mSys->Radio.dumpBuf("Payload ", p->packet, len);
Inverter<> *iv = mSys->findInverter(&p->packet[3]);
if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) {
if(iv->assign[i].cmdId == *cmd)
iv->addValue(i, &p->packet[11]);
}
iv->doCalculations();
}
if(checkTicker(&mRxTicker, 5)) {
mSys->Radio.switchRxCh();
if(!mSys->BufCtrl.empty()) {
uint8_t len, rptCnt;
packet_t *p = mSys->BufCtrl.getBack();
if(*cmd == 0x01) mCmds[0]++;
else if(*cmd == 0x02) mCmds[1]++;
else if(*cmd == 0x03) mCmds[2]++;
else if(*cmd == 0x81) mCmds[3]++;
else if(*cmd == 0x82) mCmds[4]++;
else if(*cmd == 0x83) mCmds[5]++;
else if(*cmd == 0x84) mCmds[6]++;
else mCmds[7]++;
/*if(p->sendCh == 23) mChannelStat[0]++;
else if(p->sendCh == 40) mChannelStat[1]++;
else if(p->sendCh == 61) mChannelStat[2]++;
else mChannelStat[3]++;*/
}
}
mSys->BufCtrl.popBack();
}
//if(mSerialDebug)
// mSys->Radio.dumpBuf("RAW ", p->packet, MAX_RF_PAYLOAD_SIZE);
if(checkTicker(&mTicker, 1000)) {
if(++mSendTicker >= mSendInterval) {
mSendTicker = 0;
if(mSys->Radio.checkPaketCrc(p->packet, &len, &rptCnt, p->rxCh)) {
// process buffer only on first occurrence
if((0 != len) && (0 == rptCnt)) {
uint8_t *packetId = &p->packet[9];
//DPRINTLN("CMD " + String(*packetId, HEX));
if(mSerialDebug)
mSys->Radio.dumpBuf("Payload ", p->packet, len);
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();
Inverter<> *iv = mSys->findInverter(&p->packet[1]);
if(NULL != iv) {
for(uint8_t i = 0; i < iv->listLen; i++) {
if(iv->assign[i].cmdId == *packetId)
iv->addValue(i, &p->packet[9]);
}
iv->doCalculations();
//memcpy(mPayload[(*packetId & 0x7F) - 1], &p->packet[9], MAX_RF_PAYLOAD_SIZE - 11);
}
if(*packetId == 0x01) mPacketIds[0]++;
else if(*packetId == 0x02) mPacketIds[1]++;
else if(*packetId == 0x03) mPacketIds[2]++;
else if(*packetId == 0x81) mPacketIds[3]++;
else if(*packetId == 0x82) mPacketIds[4]++;
else if(*packetId == 0x83) mPacketIds[5]++;
else if(*packetId == 0x84) mPacketIds[6]++;
else mPacketIds[7]++;
}
}
mSys->BufCtrl.popBack();
}
}
if(checkTicker(&mTicker, 1000)) {
if(mMqttActive) {
mMqtt.loop();
if(++mMqttTicker > mMqttInterval) {
if(++mMqttTicker >= mMqttInterval) {
mMqttInterval = 0;
mMqtt.isConnected(true);
char topic[30], val[10];
@ -211,7 +198,7 @@ void app::loop(void) {
}
if(mSerialValues) {
if(++mSerialTicker > mSerialInterval) {
if(++mSerialTicker >= mSerialInterval) {
mSerialInterval = 0;
char topic[30], val[10];
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
@ -229,6 +216,22 @@ void app::loop(void) {
}
}
}
if(++mSendTicker >= mSendInterval) {
mSendTicker = 0;
if(!mSys->BufCtrl.empty())
DPRINTLN("recbuf not empty! #" + String(mSys->BufCtrl.getFill()));
Inverter<> *inv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
inv = mSys->getInverterByPos(i);
if(NULL != inv) {
yield();
mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp);
mRxTicker = 0;
}
}
}
}
}
@ -393,20 +396,14 @@ void app::showErase() {
//-----------------------------------------------------------------------------
void app::showStatistics(void) {
String content = "CMDs:\n";
String content = "Packets:\n";
for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) {
content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mCmds[i]) + String("\n");
content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mPacketIds[i]) + String("\n");
}
content += String("other: ") + String(mCmds[DBG_CMD_LIST_LEN]) + String("\n\n");
content += String("other: ") + String(mPacketIds[DBG_CMD_LIST_LEN]) + String("\n\n");
content += "Send Cnt: " + String(mSys->Radio.mSendCnt) + String("\n\n");
/*content += "\nCHANNELs:\n";
content += String("23: ") + String(mChannelStat[0]) + String("\n");
content += String("40: ") + String(mChannelStat[1]) + String("\n");
content += String("61: ") + String(mChannelStat[2]) + String("\n");
content += String("75: ") + String(mChannelStat[3]) + String("\n");*/
if(!mSys->Radio.isChipConnected())
content += "WARNING! your NRF24 module can't be reached, check the wiring and pinout (<a href=\"/setup\">setup</a>)\n";

5
tools/esp8266/app.h

@ -73,8 +73,7 @@ class app : public Main {
uint16_t mSendTicker;
uint16_t mSendInterval;
uint32_t mCmds[DBG_CMD_LIST_LEN+1];
//uint32_t mChannelStat[4];
uint32_t mPacketIds[DBG_CMD_LIST_LEN+1];
uint32_t mRecCnt;
// timer
@ -82,6 +81,8 @@ class app : public Main {
bool mSerialValues;
bool mSerialDebug;
uint32_t mRxTicker;
// mqtt
mqtt mMqtt;
uint16_t mMqttTicker;

4
tools/esp8266/config.h

@ -17,7 +17,7 @@
// CONFIGURATION - COMPILE TIME
//-------------------------------------
// time in seconds how long the station info (ssid + pwd) will be tried
#define WIFI_TRY_CONNECT_TIME 15
#define WIFI_TRY_CONNECT_TIME 30
// time during the ESP will act as access point on connection failure (to
// station) in seconds
@ -36,7 +36,7 @@
#define MAX_NAME_LENGTH 16
// maximum buffer length of packet received / sent to RF24 module
#define MAX_RF_PAYLOAD_SIZE 64
#define MAX_RF_PAYLOAD_SIZE 32
// changes the style of "/setup" page, visualized = nicer
#define LIVEDATA_VISUALIZED

4
tools/esp8266/defines.h

@ -16,12 +16,12 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 6
#define VERSION_PATCH 8
//-------------------------------------
typedef struct {
uint8_t sendCh;
uint8_t rxCh;
uint8_t packet[MAX_RF_PAYLOAD_SIZE];
} packet_t;

168
tools/esp8266/hmRadio.h

@ -13,6 +13,7 @@
#define DTU_RADIO_ID ((uint64_t)0x1234567801ULL)
#define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL)
#define RX_LOOP_CNT 400
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -47,13 +48,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) {
mChanOut[0] = 23;
mChanOut[1] = 40;
mChanOut[2] = 61;
mChanOut[3] = 75;
mChanIdx = 1;
mTxChLst[0] = 40;
//mTxChIdx = 1;
calcDtuCrc();
mRxChLst[0] = 3;
mRxChLst[1] = 23;
mRxChLst[2] = 61;
mRxChLst[3] = 75;
mRxChIdx = 0;
mRxLoopCnt = RX_LOOP_CNT;
//calcDtuCrc();
pinCs = CS_PIN;
pinCe = CE_PIN;
@ -65,7 +70,6 @@ class HmRadio {
~HmRadio() {}
void setup(BUFFER *ctrl) {
//DPRINTLN("HmRadio::setup, pins: " + String(pinCs) + ", " + String(pinCe) + ", " + String(pinIrq));
pinMode(pinIrq, INPUT_PULLUP);
mBufCtrl = ctrl;
@ -91,7 +95,7 @@ class HmRadio {
DPRINTLN("Radio Config:");
mNrf24.printPrettyDetails();
mSendChannel = getDefaultChannel();
mTxCh = getDefaultChannel();
if(!mNrf24.isChipConnected()) {
DPRINTLN("WARNING! your NRF24 module can't be reached, check the wiring");
@ -107,7 +111,7 @@ class HmRadio {
if(!mBufCtrl->full()) {
p = mBufCtrl->getFront();
memset(p->packet, 0xcc, MAX_RF_PAYLOAD_SIZE);
p->sendCh = mSendChannel;
p->rxCh = mRxChIdx;
len = mNrf24.getPayloadSize();
if(len > MAX_RF_PAYLOAD_SIZE)
len = MAX_RF_PAYLOAD_SIZE;
@ -125,53 +129,55 @@ class HmRadio {
}
uint8_t getDefaultChannel(void) {
return mChanOut[2];
return mTxChLst[0];
}
uint8_t getLastChannel(void) {
return mChanOut[mChanIdx];
/*uint8_t getLastChannel(void) {
return mTxChLst[mTxChIdx];
}
uint8_t getNxtChannel(void) {
if(++mChanIdx >= 4)
mChanIdx = 0;
return mChanOut[mChanIdx];
}
if(++mTxChIdx >= 4)
mTxChIdx = 0;
return mTxChLst[mTxChIdx];
}*/
void sendTimePacket(uint64_t invId, uint32_t ts) {
sendCmdPacket(invId, 0x15, 0x80, false);
mSendBuf[10] = 0x0b; // cid
mSendBuf[11] = 0x00;
CP_U32_LittleEndian(&mSendBuf[12], ts);
mSendBuf[19] = 0x05;
mTxBuf[10] = 0x0b; // cid
mTxBuf[11] = 0x00;
CP_U32_LittleEndian(&mTxBuf[12], ts);
mTxBuf[19] = 0x05;
uint16_t crc = crc16(&mSendBuf[10], 14);
mSendBuf[24] = (crc >> 8) & 0xff;
mSendBuf[25] = (crc ) & 0xff;
mSendBuf[26] = crc8(mSendBuf, 26);
uint16_t crc = crc16(&mTxBuf[10], 14);
mTxBuf[24] = (crc >> 8) & 0xff;
mTxBuf[25] = (crc ) & 0xff;
mTxBuf[26] = crc8(mTxBuf, 26);
sendPacket(invId, mSendBuf, 27);
sendPacket(invId, mTxBuf, 27, true);
}
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t cmd, bool calcCrc = true) {
memset(mSendBuf, 0, MAX_RF_PAYLOAD_SIZE);
mSendBuf[0] = mid; // message id
CP_U32_BigEndian(&mSendBuf[1], (invId >> 8));
CP_U32_BigEndian(&mSendBuf[5], (DTU_ID >> 8));
mSendBuf[9] = cmd;
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
mTxBuf[0] = mid; // message id
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
CP_U32_BigEndian(&mTxBuf[5], (DTU_ID >> 8));
mTxBuf[9] = cmd;
if(calcCrc) {
mSendBuf[10] = crc8(mSendBuf, 10);
sendPacket(invId, mSendBuf, 11);
mTxBuf[10] = crc8(mTxBuf, 10);
sendPacket(invId, mTxBuf, 11, false);
}
}
bool checkCrc(uint8_t buf[], uint8_t *len, uint8_t *rptCnt) {
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t *rptCnt, uint8_t rxCh) {
*len = (buf[0] >> 2);
for (int16_t i = MAX_RF_PAYLOAD_SIZE - 1; i >= 0; i--) {
buf[i] = ((buf[i] >> 7) | ((i > 0) ? (buf[i-1] << 1) : 0x00));
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
*len = MAX_RF_PAYLOAD_SIZE - 2;
for(uint8_t i = 1; i < (*len + 1); i++) {
buf[i-1] = (buf[i] << 1) | (buf[i+1] >> 7);
}
uint16_t crc = crc16nrf24(buf, BIT_CNT(*len + 2), 7, mDtuIdCrc);
bool valid = (crc == ((buf[*len+2] << 8) | (buf[*len+3])));
uint8_t crc = crc8(buf, *len-1);
bool valid = (crc == buf[*len-1]);
if(valid) {
if(mLastCrc == crc)
@ -181,16 +187,36 @@ class HmRadio {
*rptCnt = 0;
mLastCrc = crc;
}
mRxStat[(buf[9] & 0x7F)-1]++;
mRxChStat[(buf[9] & 0x7F)-1][rxCh & 0x7]++;
}
/*else {
DPRINT("CRC wrong: ");
DHEX(crc);
DPRINT(" != ");
DHEX(buf[*len-1]);
DPRINTLN("");
}*/
return valid;
}
bool switchRxCh(uint8_t addLoop = 0) {
mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) {
mRxLoopCnt--;
DISABLE_IRQ;
mNrf24.stopListening();
mNrf24.setChannel(getRxNxtChannel());
mNrf24.startListening();
RESTORE_IRQ;
}
return (0 == mRxLoopCnt); // receive finished
}
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
DPRINT(String(info));
for(uint8_t i = 0; i < len; i++) {
if(buf[i] < 10)
DPRINT("0");
DHEX(buf[i]);
DPRINT(" ");
}
@ -209,26 +235,41 @@ class HmRadio {
uint32_t mSendCnt;
private:
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len) {
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
//DPRINTLN("sent packet: #" + String(mSendCnt));
//dumpBuf("SEN ", buf, len);
DISABLE_IRQ;
mNrf24.stopListening();
#ifdef CHANNEL_HOP
mSendChannel = getNxtChannel();
#else
mSendChannel = getDefaultChannel();
#endif
mNrf24.setChannel(mSendChannel);
//DPRINTLN("CH: " + String(mSendChannel));
if(clear) {
uint8_t cnt = 4;
for(uint8_t i = 0; i < 4; i ++) {
DPRINT(String(mRxStat[i]) + " (");
for(uint8_t j = 0; j < 4; j++) {
DPRINT(String(mRxChStat[i][j]));
}
DPRINT(") ");
if(0 != mRxStat[i])
cnt--;
}
if(cnt == 0)
DPRINTLN(" -> all");
else
DPRINTLN(" -> missing: " + String(cnt));
memset(mRxStat, 0, 4);
memset(mRxChStat, 0, 4*8);
mRxLoopCnt = RX_LOOP_CNT;
}
mTxCh = getDefaultChannel();
mNrf24.setChannel(mTxCh);
mNrf24.openWritingPipe(invId); // TODO: deprecated
mNrf24.setCRCLength(RF24_CRC_16);
mNrf24.enableDynamicPayloads();
mNrf24.setAutoAck(true);
mNrf24.setRetries(3, 15);
mNrf24.setRetries(3, 15); // 3*250us and 15 loops -> 11.25ms
mNrf24.write(buf, len);
@ -240,14 +281,21 @@ class HmRadio {
mNrf24.disableDynamicPayloads();
mNrf24.setCRCLength(RF24_CRC_DISABLED);
mNrf24.setChannel(DEFAULT_RECV_CHANNEL);
mRxChIdx = 0;
mNrf24.setChannel(mRxChLst[mRxChIdx]);
mNrf24.startListening();
RESTORE_IRQ;
mSendCnt++;
}
void calcDtuCrc(void) {
uint8_t getRxNxtChannel(void) {
if(++mRxChIdx >= 4)
mRxChIdx = 0;
return mRxChLst[mRxChIdx];
}
/*void calcDtuCrc(void) {
uint64_t addr = DTU_RADIO_ID;
uint8_t tmp[5];
for(int8_t i = 4; i >= 0; i--) {
@ -255,18 +303,26 @@ class HmRadio {
addr >>= 8;
}
mDtuIdCrc = crc16nrf24(tmp, BIT_CNT(5));
}
}*/
uint8_t mChanOut[4];
uint8_t mChanIdx;
uint16_t mDtuIdCrc;
uint8_t mTxCh;
uint8_t mTxChLst[1];
//uint8_t mTxChIdx;
uint8_t mRxChLst[4];
uint8_t mRxChIdx;
uint8_t mRxStat[4];
uint8_t mRxChStat[4][8];
uint16_t mRxLoopCnt;
//uint16_t mDtuIdCrc;
uint16_t mLastCrc;
uint8_t mRptCnt;
RF24 mNrf24;
uint8_t mSendChannel;
BUFFER *mBufCtrl;
uint8_t mSendBuf[MAX_RF_PAYLOAD_SIZE];
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
};
#endif /*__RADIO_H__*/

7
tools/esp8266/html/convert.py

@ -15,11 +15,12 @@ def convert2Header(inFile):
data = re.sub(r"(\;|\}|\:|\{)\s+", r'\1', data) # whitespaces inner css
define = inFile.split(".")[0].upper()
define2 = inFile.split(".")[1].upper()
f = open(outName, "w")
f.write("#ifndef __{}_H__\n".format(define))
f.write("#define __{}_H__\n".format(define))
f.write("#ifndef __{}_{}_H__\n".format(define, define2))
f.write("#define __{}_{}_H__\n".format(define, define2))
f.write("const char {}[] PROGMEM = \"{}\";\n".format(inFile.replace(".", "_"), data))
f.write("#endif /*__{}_H__*/\n".format(define))
f.write("#endif /*__{}_{}_H__*/\n".format(define, define2))
f.close()
convert2Header("index.html")

6
tools/esp8266/html/h/hoymiles_html.h

@ -1,4 +1,4 @@
#ifndef __HOYMILES_H__
#define __HOYMILES_H__
#ifndef __HOYMILES_HTML_H__
#define __HOYMILES_HTML_H__
const char hoymiles_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\">getAjax('/livedata', 'livedata');window.setInterval(\"getAjax('/livedata', 'livedata')\", 10000);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><style type=\"text/css\"></style></head><body><h1>AHOY - {DEVICE}</h1><div id=\"content\" class=\"content\"><div id=\"livedata\"></div><p>Every 10 seconds the values are updated</p></div><div id=\"footer\"><p class=\"left\">&copy 2022</p><p class=\"left\"><a href=\"/\">Home</a></p><p class=\"right\">AHOY :: {VERSION}</p></div></body></html>";
#endif /*__HOYMILES_H__*/
#endif /*__HOYMILES_HTML_H__*/

6
tools/esp8266/html/h/index_html.h

@ -1,4 +1,4 @@
#ifndef __INDEX_H__
#define __INDEX_H__
#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\">&copy 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_H__*/
#endif /*__INDEX_HTML_H__*/

6
tools/esp8266/html/h/setup_html.h

@ -1,4 +1,4 @@
#ifndef __SETUP_H__
#define __SETUP_H__
#ifndef __SETUP_HTML_H__
#define __SETUP_HTML_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 (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__*/
#endif /*__SETUP_HTML_H__*/

6
tools/esp8266/html/h/style_css.h

@ -1,4 +1,4 @@
#ifndef __STYLE_H__
#define __STYLE_H__
#ifndef __STYLE_CSS_H__
#define __STYLE_CSS_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: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__*/
#endif /*__STYLE_CSS_H__*/

7
tools/esp8266/main.cpp

@ -57,13 +57,13 @@ void Main::setup(uint32_t timeout) {
#endif
if(!startAp) {
delay(5000);
mTimestamp = getNtpTime();
DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime()));
}
mUpdater->setup(mWeb);
mApActive = startAp;
}
@ -83,6 +83,11 @@ void Main::loop(void) {
}
else {
if(millis() - mApLastTick > 10000) {
uint8_t cnt = WiFi.softAPgetStationNum();
if(cnt > 0) {
DPRINTLN(String(cnt) + " clients connected, resetting AP timeout");
mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000));
}
mApLastTick = millis();
DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds");
}

Loading…
Cancel
Save