mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-08-11 11:23:35 +02:00
more code improvments for heltec v3
This commit is contained in:
+57
-47
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user