Browse Source

* added RX channel 40

* improved RF24 ISR
* reduced AP active time to 60s (will be increase once a client is connected)
* added `yield` without success -> random reboot (cause 4)
pull/63/head^2
lumapu 3 years ago
parent
commit
c7d039ac8c
  1. 9
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/config.h
  3. 2
      tools/esp8266/defines.h
  4. 64
      tools/esp8266/hmRadio.h
  5. 4
      tools/esp8266/hmSystem.h
  6. 4
      tools/esp8266/main.cpp
  7. 3
      tools/esp8266/mqtt.h

9
tools/esp8266/app.cpp

@ -152,6 +152,8 @@ void app::setup(uint32_t timeout) {
void app::loop(void) {
Main::loop();
mSys->Radio.loop();
if(checkTicker(&mRxTicker, 5)) {
bool rxRdy = mSys->Radio.switchRxCh();
@ -187,6 +189,7 @@ void app::loop(void) {
}
mSys->BufCtrl.popBack();
yield();
}
@ -309,6 +312,7 @@ bool app::buildPayload(uint8_t id) {
else
crc = crc16(mPayload[id].data[i], mPayload[id].len[i], crc);
}
yield();
}
if(crc == crcRcv)
return true;
@ -341,7 +345,7 @@ void app::processPayload(bool retransmit) {
else
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts);
}
mSys->Radio.switchRxCh(100);
mSys->Radio.switchRxCh(300);
}
}
else {
@ -352,6 +356,7 @@ void app::processPayload(bool retransmit) {
for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId); i ++) {
memcpy(&payload[offs], mPayload[iv->id].data[i], (mPayload[iv->id].len[i]));
offs += (mPayload[iv->id].len[i]);
yield();
}
offs-=2;
if(mSerialDebug) {
@ -367,6 +372,7 @@ void app::processPayload(bool retransmit) {
}
}
}
yield();
}
}
@ -629,6 +635,7 @@ void app::showLiveData(void) {
}
}
modHtml += "</div>";
yield();
}
modHtml += F("<div class=\"ts\">Last received data requested at: ") + getDateTimeStr(iv->ts) + F("</div>");
modHtml += F("</div>");

2
tools/esp8266/config.h

@ -21,7 +21,7 @@
// time during the ESP will act as access point on connection failure (to
// station) in seconds
#define WIFI_AP_ACTIVE_TIME 3*60
#define WIFI_AP_ACTIVE_TIME 60
// default device name
#define DEF_DEVICE_NAME "ESP-DTU"

2
tools/esp8266/defines.h

@ -16,7 +16,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
#define VERSION_PATCH 13
#define VERSION_PATCH 14
//-------------------------------------

64
tools/esp8266/hmRadio.h

@ -13,7 +13,7 @@
#define DTU_RADIO_ID ((uint64_t)0x1234567801ULL)
#define DUMMY_RADIO_ID ((uint64_t)0xDEADBEEF01ULL)
#define RX_LOOP_CNT 400
#define RX_LOOP_CNT 600
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
@ -55,6 +55,7 @@ class HmRadio {
mRxChLst[1] = 23;
mRxChLst[2] = 61;
mRxChLst[3] = 75;
mRxChLst[4] = 40;
mRxChIdx = 0;
mRxLoopCnt = RX_LOOP_CNT;
@ -66,6 +67,7 @@ class HmRadio {
mSendCnt = 0;
mSerialDebug = false;
mIrqRcvd = false;
}
~HmRadio() {}
@ -102,31 +104,39 @@ class HmRadio {
}
}
void handleIntr(void) {
uint8_t pipe, len;
packet_t *p;
void loop(void) {
DISABLE_IRQ;
while(mNrf24.available(&pipe)) {
if(!mBufCtrl->full()) {
p = mBufCtrl->getFront();
memset(p->packet, 0xcc, MAX_RF_PAYLOAD_SIZE);
p->rxCh = mRxChLst[mRxChIdx];
len = mNrf24.getPayloadSize();
if(len > MAX_RF_PAYLOAD_SIZE)
len = MAX_RF_PAYLOAD_SIZE;
mNrf24.read(p->packet, len);
mBufCtrl->pushFront(p);
}
else {
bool tx_ok, tx_fail, rx_ready;
mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // reset interrupt status
mNrf24.flush_rx(); // drop the packet
break;
if(mIrqRcvd) {
mIrqRcvd = false;
bool tx_ok, tx_fail, rx_ready;
mNrf24.whatHappened(tx_ok, tx_fail, rx_ready); // resets the IRQ pin to HIGH
RESTORE_IRQ;
uint8_t pipe, len;
packet_t *p;
while(mNrf24.available(&pipe)) {
if(!mBufCtrl->full()) {
p = mBufCtrl->getFront();
p->rxCh = mRxChLst[mRxChIdx];
len = mNrf24.getPayloadSize();
if(len > MAX_RF_PAYLOAD_SIZE)
len = MAX_RF_PAYLOAD_SIZE;
mNrf24.read(p->packet, len);
mBufCtrl->pushFront(p);
}
else {
mNrf24.flush_rx(); // drop the packet
break;
}
yield();
}
}
RESTORE_IRQ;
else
RESTORE_IRQ;
}
void handleIntr(void) {
mIrqRcvd = true;
}
uint8_t getDefaultChannel(void) {
@ -183,7 +193,7 @@ class HmRadio {
return valid;
}
bool switchRxCh(uint8_t addLoop = 0) {
bool switchRxCh(uint16_t addLoop = 0) {
mRxLoopCnt += addLoop;
if(mRxLoopCnt != 0) {
mRxLoopCnt--;
@ -263,7 +273,7 @@ class HmRadio {
}
uint8_t getRxNxtChannel(void) {
if(++mRxChIdx >= 4)
if(++mRxChIdx >= 5)
mRxChIdx = 0;
return mRxChLst[mRxChIdx];
}
@ -272,13 +282,15 @@ class HmRadio {
uint8_t mTxChLst[1];
//uint8_t mTxChIdx;
uint8_t mRxChLst[4];
uint8_t mRxChLst[5];
uint8_t mRxChIdx;
uint16_t mRxLoopCnt;
RF24 mNrf24;
BUFFER *mBufCtrl;
uint8_t mTxBuf[MAX_RF_PAYLOAD_SIZE];
volatile bool mIrqRcvd;
};
#endif /*__RADIO_H__*/

4
tools/esp8266/hmSystem.h

@ -36,8 +36,8 @@ class HmSystem {
p->id = mNumInv;
p->serial.u64 = serial;
memcpy(p->chMaxPwr, chMaxPwr, (4*2));
DPRINT("SERIAL: " + String(p->serial.b[5], HEX));
DPRINTLN(" " + String(p->serial.b[4], HEX));
//DPRINT("SERIAL: " + String(p->serial.b[5], HEX));
//DPRINTLN(" " + String(p->serial.b[4], HEX));
if(p->serial.b[5] == 0x11) {
switch(p->serial.b[4]) {
case 0x21: p->type = INV_TYPE_1CH; break;

4
tools/esp8266/main.cpp

@ -105,10 +105,10 @@ void Main::loop(void) {
}
}
if(++mHeapStatCnt >= 10) {
/*if(++mHeapStatCnt >= 10) {
mHeapStatCnt = 0;
stats();
}
}*/
}
}

3
tools/esp8266/mqtt.h

@ -36,7 +36,8 @@ class mqtt {
if(!mClient->connected())
reconnect();
mClient->publish(top, msg);
if(mClient->connected())
mClient->publish(top, msg);
}
}

Loading…
Cancel
Save