Skip to content

Commit

Permalink
Extend calculation of mydelay2() time value type to LL and add greace…
Browse files Browse the repository at this point in the history
…time delay parameter; removed BIOT_JOIN call in LOra_Setup -> done in 1. loop already
  • Loading branch information
mchresse committed Jan 22, 2022
1 parent 7066a98 commit 5148da3
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 112 deletions.
2 changes: 1 addition & 1 deletion include/beeiot.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ int GetOWsensor (int sample);
// in main.cpp
void Logdata (void);
void mydelay (int32_t tval); // Busy loop delay method (tval in ms)
void mydelay2 (int32_t tval); // light sleep delay method (tval in ms)
esp_err_t mydelay2(int32_t waitms, int32_t initdelay); // light sleep delay method (initdelay default=10)

// in max123x.cpp
uint16_t adc_read(int channel);
Expand Down
33 changes: 11 additions & 22 deletions src/BeeLora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extern int sd_get_dir(uint8_t p1, uint8_t p2, uint8_t p3, char * dirline);
// Setup_LoRa(): init BEE-client object: LoRa
//*********************************************************************
int setup_LoRa(int reentry) {
islora = 0;
islora = 0;;

#ifdef LORA_CONFIG
if(!reentry){ // after PON Reset only
Expand Down Expand Up @@ -210,24 +210,13 @@ int setup_LoRa(int reentry) {
// Assign IRQ callback on DIO0
LoRa.onReceive(onReceive); // (called by loRa.handleDio0Rise(pkglen))
BHLOG(LOGLORAR) Serial.printf(" LoRa: assign ISR to DIO0 - default: GWID:0x%02X, NodeID:0x%02X, Channel:%i\n", LoRaCfg.gwid, LoRaCfg.nodeid, LoRaCfg.chcfgid);
islora=1; // Declare: LORA Modem is active now!
islora=1; // Declare: LORA Modem is basically active now, but not joined yet!

if(!reentry){ // for Reset only
// From now on : JOIN to a GW
if(!reentry){ // AFter (Pwr-) Reset only
// From now on : Try JOIN to a GW
BeeIoTStatus = BIOT_JOIN; // have to join to a GW

// 1. Try: send a message to join to a GW
if(BeeIoTJoin(BeeIoTStatus) <= 0){
BHLOG(LOGLORAW) Serial.printf(" Lora: 1. BeeIoT JOIN failed -> remaining in BIOT_JOIN Mode\n");
// ToDo: any Retry action after a while ?
BeeIoTStatus = BIOT_JOIN; // stay in JOIN mode
LoRa.sleep(); // stop modem and clear FIFO
}else{
BeeIoTStatus = BIOT_IDLE; // we have a joined modem -> wait for RX/TX pkgs.

// Modem is joined and ready, but may be BIOT_SLEEP would be better to save power
BeeIoTSleep(); // by now we can support "Joined-Sleep" only => because WakeUp will set Idle mode
}
LoRa.sleep(); // stop modem and clear FIFO
BHLOG(LOGLORAW) Serial.printf(" Lora: remain in JOIN Mode\n");
}
#endif

Expand Down Expand Up @@ -395,7 +384,7 @@ pjoin = (beeiot_join_t *) & MyTXData; // fetch global Msg buffer
BHLOG(LOGLORAW) Serial.printf(" BeeIoTJoin: waiting for RX-CONFIG Pkg. in RXCont mode:");
while (!BeeIotRXFlag && (i<MAXRXACKWAIT*2)){ // till RX pkg arrived or max. wait time is over
BHLOG(LOGLORAW) Serial.print("o");
mydelay2(500); // count wait time in msec. -> frequency to check RXQueue
mydelay2(500,100); // count wait time in msec. -> frequency to check RXQueue
i++;
}
// notice # of JOIN Retries
Expand Down Expand Up @@ -629,7 +618,7 @@ int rc; // generic return code
BeeIoTStatus = BIOT_JOIN; // anyway next must be a JOIN Request (no Rejoin anymore)
return(-96); // by now no gateway in range -> try again later
}
mydelay2(1000); // gracetime for GW to prepare modem on new channel
mydelay2(1000, 0); // gracetime for GW to prepare modem on new channel
}

// 2. Prepare TX package with LogStatus data
Expand Down Expand Up @@ -695,7 +684,7 @@ int rc; // generic return code
ackloop=0; // preset RX-ACK wait loop counter
while(!MyMsg.ack){ // wait till TX got committed by ACK
BHLOG(LOGLORAW) Serial.print(".");
mydelay2(MSGRESWAIT); // min. wait time for ACK to arrive -> polling rate
mydelay2(MSGRESWAIT,0); // min. wait time for ACK to arrive -> polling rate

// 8. Check for ACK Wait Timeout
if(ackloop++ > MAXRXACKWAIT){ // max # of wait loops reached ? -> yes, ACK RX timed out
Expand Down Expand Up @@ -760,7 +749,7 @@ int rc; // generic return code
BHLOG(LOGLORAW) Serial.printf("\n LoRaLog: wait for add. RX1 Pkg. (RXCont):");
while (!BeeIotRXFlag & (ackloop < WAITRX1PKG*2)){ // wait till RX pkg arrived or max. wait time is over
BHLOG(LOGLORAW) Serial.print("o");
mydelay2(500); // wait time (in msec.) -> frequency to check RXQueue: 0.5sec
mydelay2(500,0); // wait time (in msec.) -> frequency to check RXQueue: 0.5sec
ackloop++;
}

Expand Down Expand Up @@ -1337,7 +1326,7 @@ int rc;
BHLOG(LOGLORAW) Serial.printf(" BIoTBCN: waiting for ACKBCN in RXCont mode:");
while (!BeeIotRXFlag && (i<WAITRX1PKG*2)){ // till RX pkg arrived or max. wait time is over
BHLOG(LOGLORAW) Serial.print("o");
mydelay2(500); // count wait time in msec. -> frequency to check RXQueue
mydelay2(500,0); // count wait time in msec. -> frequency to check RXQueue
i++;
}

Expand Down
8 changes: 4 additions & 4 deletions src/epd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if(!reentry){
display.printf (" BoardID: %08X\n", (uint32_t)bhdb.BoardID);
display.update(); //refresh display by buffer content

BHLOG(LOGEPD) mydelay2(3000);
BHLOG(LOGEPD) mydelay2(3000,0);
BHLOG(LOGEPD) Serial.println(" EPD: Draw BitmapWaveshare");
BHLOG(LOGEPD) display.setRotation(2); // 0 + 2: Portrait Mode
BHLOG(LOGEPD) display.drawExampleBitmap(BitmapWaveshare, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_BLACK);
Expand Down Expand Up @@ -324,16 +324,16 @@ void drawBitmaps_200x200(){
int16_t x = (display.width() - 200) / 2;
int16_t y = (display.height() - 200) / 2;
drawBitmapFromSD("logo200x200.bmp", x, y);
mydelay2(2000);
mydelay2(2000,0);
}

void drawBitmaps_other(){
int16_t w2 = display.width() / 2;
int16_t h2 = display.height() / 2;
drawBitmapFromSD("parrot.bmp", w2 - 64, h2 - 80);
mydelay2(2000);
mydelay2(2000,0);
drawBitmapFromSD("betty_1.bmp", w2 - 100, h2 - 160);
mydelay2(2000);
mydelay2(2000,0);
}


Expand Down
4 changes: 2 additions & 2 deletions src/i2cdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int i2c_scan(void) {
if (i%16 == 0) {
BHLOG(LOGADS) Serial.printf("\n%.2x:", i);
}
if (esprc == 0) {
if (esprc == ESP_OK) {
BHLOG(LOGADS) Serial.printf(" %.2x", i);
// if ADC: ADS111x overrules MAX123x by intention asking in that order
if(i==MAX_ADDR) {
Expand All @@ -185,5 +185,5 @@ int i2c_scan(void) {

BHLOG(LOGADS) Serial.printf("\n");

return(isadc);
return(1);
}

0 comments on commit 5148da3

Please sign in to comment.