Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lora and Serial Port #659

Open
arifainchtein opened this issue Aug 12, 2023 · 1 comment
Open

Lora and Serial Port #659

arifainchtein opened this issue Aug 12, 2023 · 1 comment

Comments

@arifainchtein
Copy link

arifainchtein commented Aug 12, 2023

Hello,
I have a custom made board with Ra-02 and Esp32. I connect this board to a raspberry pi via usb.
This board acts as a receiver of data from two other boards also with esp32 and Ra-02. These senders each send a struct to the receiver in either 10 sec interval for Sender 1 and 30 seconds interval for sender 2.

In the pi i run a program that sends Serial port messages asking for data. These request happen every 10 seconds or so.
When a request for data arrives in the esp32 it serializes the s1 and s2 structs and sends them via the serial port.

The problem i am having is that if Lora receives a message while the serial port is active the esp 32 crashes. Otherwise it works perfectly.
I have tried setting lora as transmission when receiving Serial commands (so as to make sure it does not receive) and then setting it to receive when the serial port transaction is happening but that did not seem to fix the issue.

I also tried setting NoInterrupts() and Interrupts() at the beginning and end of the serial transaction and that literally crash the esp32 and it rebooted itself.
Is there a way to turn on and off the Lora radio so that i can insure that the radio is off when i am doing serial communications?

here is the code that receives the lora message:

void processLora(int packetSize){
  receivingLora=true;
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("rec lora:");
  lcd.print( packetSize);
  if (packetSize == 0) return; 
  if(inSerial){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("In Serial");
    return;
  }
   if(!timeSet){
     lcd.clear();
     lcd.setCursor(0,2);
      lcd.print("currentTimerRecord is null");
      return;
    }
    int hour = currentTimerRecord.hour;
    int minute = currentTimerRecord.minute;
    int displaytime = (hour * 100) + minute;
    if(packetSize==sizeof(GloriaTankFlowPumpData)){
      memset(&gloriaTankFlowPumpData, 0, sizeof(GloriaTankFlowPumpData));
      LoRa.readBytes((uint8_t*)&gloriaTankFlowPumpData,sizeof(GloriaTankFlowPumpData));
      lcd.setCursor(0,2);
      lcd.print("GTF:");
      lcd.print(gloriaTankFlowPumpData.devicename);
       gloriaTankFlowPumpData.rssi = LoRa.packetRssi();
      gloriaTankFlowPumpData.snr = LoRa.packetSnr();
      lcd.setCursor(0,3);
       lcd.print("sn:");
      lcd.print(gloriaTankFlowPumpData.snr);
      lcd.print("  rs:");
      lcd.print(gloriaTankFlowPumpData.rssi);
      long messageReceivedTime = timeManager.getCurrentTimeInSeconds(currentTimerRecord);
      lastReceptionRTCInfoRecord.year = currentTimerRecord.year;
      lastReceptionRTCInfoRecord.month = currentTimerRecord.month;
      lastReceptionRTCInfoRecord.date = currentTimerRecord.date;
      lastReceptionRTCInfoRecord.hour = currentTimerRecord.hour;
      lastReceptionRTCInfoRecord.minute = currentTimerRecord.minute;
      lastReceptionRTCInfoRecord.second = currentTimerRecord.second;
      gloriaTankFlowPumpData.secondsTime=messageReceivedTime;
      const uint8_t glorianame[] = {
          SEG_A | SEG_C | SEG_D| SEG_E | SEG_F | SEG_G ,  // G
          SEG_D | SEG_E | SEG_F,  // L
          SEG_F | SEG_D | SEG_A | SEG_B | SEG_C| SEG_E,  // O
          SEG_E | SEG_G  // r
      };
      display1.setSegments(glorianame, 4, 0);
      display2.clear();
      display3.showNumberDec(gloriaTankFlowPumpData.rssi, false);
      //display4.showNumberDec(gloriaTankFlowPumpData.snr, false);  
      //  display5.showNumberDec(displaytime  , false);
      display4.showNumberDec(4444, false);
      display5.showNumberDec(5555  , false);
      display6.showNumberDec(6666, false);
      gloriaTankFlowPumpNewData=true;
     }else  if(packetSize==sizeof(PanchoTankFlowData)){
        memset(&panchoTankFlowData, 0, sizeof(PanchoTankFlowData));
       LoRa.readBytes((uint8_t*)&panchoTankFlowData,sizeof(PanchoTankFlowData));
       lcd.setCursor(0,2);
      lcd.print("PTF:");
      lcd.print(panchoTankFlowData.devicename);
      panchoTankFlowData.rssi = LoRa.packetRssi();
      panchoTankFlowData.snr = LoRa.packetSnr();
    // Serial.println(panchoTankFlowData.secondsTime);
    // Serial.println(panchoTankFlowData.rssi);
    // Serial.println(panchoTankFlowData.snr);
        const uint8_t panchoname[] = {
		      SEG_A | SEG_B | SEG_E| SEG_F | SEG_G,  // P
		      SEG_A | SEG_B | SEG_C | SEG_E | SEG_F| SEG_G,  // A
		      SEG_C | SEG_E | SEG_G,  // n
		      SEG_D | SEG_E | SEG_G  // c
      };
	display1.setSegments(panchoname, 4, 0);
        display2.clear();
        display3.showNumberDec(panchoTankFlowData.rssi, false);
        display5.showNumberDec(displaytime, false);
        int startValue=0;
        int endValue=4;
        for(int i=startValue;i<endValue;i++){
	        if(panchoTankFlowData.flowRate>0){
		        leds[i] = CRGB(0, 0, 255);
	        }else {
		        leds[i] = CRGB(0, 0, 0);
	        }
        }
	FastLED.show();
	delay(1000);
	for(int i=0;i<8;i++){
		leds[i] = CRGB(0, 0, 0);
	}
	FastLED.show();
      }else{
		badPacketCount++;
		lcd.print("  receive bad data size= ");
		lcd.print(packetSize);
      }
      loraPacketSize=0;
      receivingLora=false;
}

Do you have any suggestions as to why or how to fix this issue?

thanks

@keithr0
Copy link

keithr0 commented Aug 13, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants