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