diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 26cd83d..1f0e305 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -28,30 +28,6 @@ namespace LoRa_Utils { } void setup() { - #ifdef HELTEC_V3 - SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN); - float freq = (float)Config.loramodule.iGateFreq/1000000; - int state = radio.begin(freq); - if (state == RADIOLIB_ERR_NONE) { - Serial.print("init : LoRa Module ... done!"); - } else { - Serial.println("Starting LoRa failed!"); - while (true); - } - radio.setDio1Action(setFlag); - radio.setSpreadingFactor(Config.loramodule.spreadingFactor); - radio.setBandwidth(Config.loramodule.signalBandwidth); - radio.setCodingRate(Config.loramodule.codingRate4); - state = radio.setOutputPower(Config.loramodule.power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22. - - if (state == RADIOLIB_ERR_NONE) { - Serial.println("LoRa SX1262 init done!"); - } else { - Serial.println("Starting LoRa failed!"); - while (true); - } - #endif - #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); @@ -75,10 +51,46 @@ namespace LoRa_Utils { LoRa.setTxPower(Config.loramodule.power); Serial.print("init : LoRa Module ... done!"); #endif + #ifdef HELTEC_V3 + SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN); + float freq = (float)Config.loramodule.iGateFreq/1000000; + int state = radio.begin(freq); + if (state == RADIOLIB_ERR_NONE) { + + Serial.print("Initializing SX126X LoRa Module"); + } else { + Serial.println("Starting LoRa failed!"); + while (true); + } + radio.setDio1Action(setFlag); + radio.setSpreadingFactor(Config.loramodule.spreadingFactor); + radio.setBandwidth(Config.loramodule.signalBandwidth); + radio.setCodingRate(Config.loramodule.codingRate4); + state = radio.setOutputPower(Config.loramodule.power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22. + + if (state == RADIOLIB_ERR_NONE) { + Serial.println("init : LoRa Module ... done!"); + } else { + Serial.println("Starting LoRa failed!"); + while (true); + } + #endif } void sendNewPacket(const String &typeOfMessage, const String &newPacket) { digitalWrite(greenLed,HIGH); + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) + LoRa.beginPacket(); + LoRa.write('<'); + if (typeOfMessage == "APRS") { + LoRa.write(0xFF); + } else if (typeOfMessage == "LoRa") { + LoRa.write(0xF8); + } + LoRa.write(0x01); + LoRa.write((const uint8_t *)newPacket.c_str(), newPacket.length()); + LoRa.endPacket(); + #endif #ifdef HELTEC_V3 int state = radio.transmit("\x3c\xff\x01" + newPacket); if (state == RADIOLIB_ERR_NONE) { @@ -92,18 +104,6 @@ namespace LoRa_Utils { Serial.println(state); } #endif - #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) - LoRa.beginPacket(); - LoRa.write('<'); - if (typeOfMessage == "APRS") { - LoRa.write(0xFF); - } else if (typeOfMessage == "LoRa") { - LoRa.write(0xF8); - } - LoRa.write(0x01); - LoRa.write((const uint8_t *)newPacket.c_str(), newPacket.length()); - LoRa.endPacket(); - #endif digitalWrite(greenLed,LOW); SYSLOG_Utils::log("LoRa Tx", newPacket,0,0,0); Serial.print("---> LoRa Packet Tx : "); @@ -130,12 +130,6 @@ namespace LoRa_Utils { rssi = LoRa.packetRssi(); snr = LoRa.packetSnr(); freqError = LoRa.packetFrequencyError(); - #ifndef PinPointApp - Serial.println("(RSSI:" +String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")"); - #endif - if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) { - SYSLOG_Utils::log("LoRa Rx", loraPacket, rssi, snr, freqError); - } } #endif #ifdef HELTEC_V3 @@ -145,6 +139,9 @@ namespace LoRa_Utils { int state = radio.readData(loraPacket); if (state == RADIOLIB_ERR_NONE) { Serial.println("LoRa Rx ---> " + loraPacket); + rssi = radio.getRSSI(); + snr = radio.getSNR(); + freqError = radio.getFrequencyError(); } else if (state == RADIOLIB_ERR_RX_TIMEOUT) { // timeout occurred while waiting for a packet } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { @@ -153,24 +150,37 @@ namespace LoRa_Utils { Serial.print(F("failed, code ")); Serial.println(state); } - // Syslog? RSSI SNR Freq } #endif + #ifndef PinPointApp + Serial.println("(RSSI:" +String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")"); + #endif + if (Config.syslog.active && (stationMode==1 || stationMode==2 || (stationMode==5 && WiFi.status()==WL_CONNECTED))) { + SYSLOG_Utils::log("LoRa Rx", loraPacket, rssi, snr, freqError); + } return loraPacket; } void changeFreqTx() { - // radiolib??? - delay(500); + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) LoRa.setFrequency(Config.loramodule.digirepeaterTxFreq); + #endif + #ifdef HELTEC_V3 + float freq = (float)Config.loramodule.digirepeaterTxFreq/1000000; + radio.setFrequency(freq); + #endif } void changeFreqRx() { - // radiolib??? - delay(500); + #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) LoRa.setFrequency(Config.loramodule.digirepeaterRxFreq); + #endif + #ifdef HELTEC_V3 + float freq = (float)Config.loramodule.digirepeaterRxFreq/1000000; + radio.setFrequency(freq); + #endif } } \ No newline at end of file diff --git a/src/pins_config.h b/src/pins_config.h index f0f4d0f..777916d 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -47,7 +47,7 @@ #define OLED_RESET 21 #endif -// OTHERS +// Led and other stuff #if defined(TTGO_T_LORA_V2_1) || defined(HELTEC_V2) #define greenLed 25 // Green Led #define batteryPin 35