radio1
This commit is contained in:
parent
24f6f9b86b
commit
a9c74f7f1d
|
|
@ -325,7 +325,7 @@ board_build.mcu = esp32c3
|
|||
build_flags =
|
||||
-Werror -Wall
|
||||
-DESP32_C3_DIY_LoRa_GPS
|
||||
-DHAS_SX127X
|
||||
-DHAS_SX1278
|
||||
-DARDUINO_USB_MODE=1
|
||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||
lib_deps =
|
||||
|
|
|
|||
|
|
@ -212,21 +212,12 @@
|
|||
#define GPS_RX 20
|
||||
#define GPS_TX 21
|
||||
#define BATTERY_PIN 1
|
||||
#define LORA_SCK 4
|
||||
#define LORA_MISO 5
|
||||
#define LORA_MOSI 6
|
||||
#define LORA_CS 7
|
||||
#define LORA_RST 3
|
||||
#define LORA_IRQ 2
|
||||
#define RADIO_SCLK_PIN 4
|
||||
#define RADIO_MISO_PIN 5
|
||||
#define RADIO_MOSI_PIN 6
|
||||
#define RADIO_CS_PIN 7
|
||||
#define RADIO_RST_PIN 3
|
||||
#define RADIO_BUSY_PIN 2
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -5,9 +5,7 @@
|
|||
#include "boards_pinout.h"
|
||||
#include "lora_utils.h"
|
||||
#include "display.h"
|
||||
#ifdef HAS_SX127X
|
||||
#include <LoRa.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268) || defined(HAS_SX1278)
|
||||
#include <RadioLib.h>
|
||||
#endif
|
||||
|
|
@ -36,12 +34,10 @@ bool enableInterrupt = true;
|
|||
namespace LoRa_Utils {
|
||||
|
||||
void setFlag(void) {
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268) || defined(HAS_SX1278)
|
||||
if(!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
transmissionFlag = true;
|
||||
#endif
|
||||
if(!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
transmissionFlag = true;
|
||||
}
|
||||
|
||||
void changeFreq() {
|
||||
|
|
@ -51,30 +47,20 @@ namespace LoRa_Utils {
|
|||
loraIndex++;
|
||||
}
|
||||
currentLoRaType = &Config.loraTypes[loraIndex];
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268) || defined(HAS_SX1278)
|
||||
float freq = (float)currentLoRaType->frequency/1000000;
|
||||
radio.setFrequency(freq);
|
||||
radio.setSpreadingFactor(currentLoRaType->spreadingFactor);
|
||||
float signalBandwidth = currentLoRaType->signalBandwidth/1000;
|
||||
radio.setBandwidth(signalBandwidth);
|
||||
radio.setCodingRate(currentLoRaType->codingRate4);
|
||||
#if defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(HELTEC_V3_GPS) || defined(HELTEC_WIRELESS_TRACKER) || defined(TTGO_T_DECK_GPS)
|
||||
radio.setOutputPower(currentLoRaType->power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22.
|
||||
#endif
|
||||
#if defined(ESP32_DIY_1W_LoRa_GPS) || defined(OE5HWN_MeshCom)
|
||||
radio.setOutputPower(currentLoRaType->power);
|
||||
#endif
|
||||
#if defined(HAS_SX1278)
|
||||
radio.setOutputPower(currentLoRaType->power);
|
||||
#endif
|
||||
|
||||
float freq = (float)currentLoRaType->frequency/1000000;
|
||||
radio.setFrequency(freq);
|
||||
radio.setSpreadingFactor(currentLoRaType->spreadingFactor);
|
||||
float signalBandwidth = currentLoRaType->signalBandwidth/1000;
|
||||
radio.setBandwidth(signalBandwidth);
|
||||
radio.setCodingRate(currentLoRaType->codingRate4);
|
||||
#if defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(HELTEC_V3_GPS) || defined(HELTEC_WIRELESS_TRACKER) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(TTGO_T_DECK_GPS)
|
||||
radio.setOutputPower(currentLoRaType->power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22.
|
||||
#endif
|
||||
#ifdef HAS_SX127X
|
||||
LoRa.setFrequency(currentLoRaType->frequency);
|
||||
LoRa.setSpreadingFactor(currentLoRaType->spreadingFactor);
|
||||
LoRa.setSignalBandwidth(currentLoRaType->signalBandwidth);
|
||||
LoRa.setCodingRate4(currentLoRaType->codingRate4);
|
||||
LoRa.setTxPower(currentLoRaType->power);
|
||||
#if defined(HAS_1278) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(OE5HWN_MeshCom)
|
||||
radio.setOutputPower(currentLoRaType->power);
|
||||
#endif
|
||||
|
||||
String loraCountryFreq;
|
||||
switch (loraIndex) {
|
||||
case 0: loraCountryFreq = "EU/WORLD"; break;
|
||||
|
|
@ -87,77 +73,56 @@ namespace LoRa_Utils {
|
|||
}
|
||||
|
||||
void setup() {
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268) || defined(HAS_SX1278)
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "LoRa", "Set SPI pins!");
|
||||
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
|
||||
float freq = (float)currentLoRaType->frequency/1000000;
|
||||
int state = radio.begin(freq);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268)
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Initializing SX126X");
|
||||
#else
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Initializing SX127X ...");
|
||||
#endif
|
||||
} else {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
|
||||
while (true);
|
||||
}
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "LoRa", "Set SPI pins!");
|
||||
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
|
||||
float freq = (float)currentLoRaType->frequency/1000000;
|
||||
int state = radio.begin(freq);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268)
|
||||
radio.setDio1Action(setFlag);
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Initializing SX126X ...");
|
||||
#else
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Initializing SX127X ...");
|
||||
#endif
|
||||
#if defined(HAS_SX1278)// || defined(HAS_SX1276)
|
||||
radio.setDio0Action(setFlag, RISING);
|
||||
#endif
|
||||
radio.setSpreadingFactor(currentLoRaType->spreadingFactor);
|
||||
float signalBandwidth = currentLoRaType->signalBandwidth/1000;
|
||||
radio.setBandwidth(signalBandwidth);
|
||||
radio.setCodingRate(currentLoRaType->codingRate4);
|
||||
radio.setCRC(true);
|
||||
#if defined(ESP32_DIY_1W_LoRa_GPS) || defined(OE5HWN_MeshCom)
|
||||
radio.setRfSwitchPins(RADIO_RXEN, RADIO_TXEN);
|
||||
#endif
|
||||
#if defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(HELTEC_V3_GPS) || defined(HELTEC_WIRELESS_TRACKER) || defined(TTGO_T_DECK_GPS)
|
||||
state = radio.setOutputPower(currentLoRaType->power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22.
|
||||
radio.setCurrentLimit(140);
|
||||
#endif
|
||||
#if defined(ESP32_DIY_1W_LoRa_GPS) || defined(OE5HWN_MeshCom)
|
||||
state = radio.setOutputPower(currentLoRaType->power); // max value 20 (when 20dB in setup 30dB in output as 400M30S has Low Noise Amp)
|
||||
radio.setCurrentLimit(140); // check correct value for 1W !!!!
|
||||
#endif
|
||||
#if defined(HAS_SX1278)
|
||||
state = radio.setOutputPower(currentLoRaType->power);
|
||||
radio.setCurrentLimit(100); // to be validated (80 , 100)?
|
||||
#endif
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268)
|
||||
radio.setRxBoostedGainMode(true);
|
||||
#endif
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "LoRa init done!");
|
||||
radio.startReceive();
|
||||
} else {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
|
||||
while (true);
|
||||
}
|
||||
} else {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
|
||||
while (true);
|
||||
}
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268)
|
||||
radio.setDio1Action(setFlag);
|
||||
#endif
|
||||
#ifdef HAS_SX127X
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "LoRa", "Set SPI pins!");
|
||||
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
||||
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
||||
long freq = currentLoRaType->frequency;
|
||||
if (!LoRa.begin(freq)) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
|
||||
show_display("ERROR", "Starting LoRa failed!", "");
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
LoRa.setSpreadingFactor(currentLoRaType->spreadingFactor);
|
||||
LoRa.setSignalBandwidth(currentLoRaType->signalBandwidth);
|
||||
LoRa.setCodingRate4(currentLoRaType->codingRate4);
|
||||
LoRa.enableCrc();
|
||||
LoRa.setTxPower(currentLoRaType->power);
|
||||
#if defined(HAS_SX1278)// || defined(HAS_SX1276)
|
||||
radio.setDio0Action(setFlag, RISING);
|
||||
#endif
|
||||
radio.setSpreadingFactor(currentLoRaType->spreadingFactor);
|
||||
float signalBandwidth = currentLoRaType->signalBandwidth/1000;
|
||||
radio.setBandwidth(signalBandwidth);
|
||||
radio.setCodingRate(currentLoRaType->codingRate4);
|
||||
radio.setCRC(true);
|
||||
#if defined(ESP32_DIY_1W_LoRa_GPS) || defined(OE5HWN_MeshCom)
|
||||
radio.setRfSwitchPins(RADIO_RXEN, RADIO_TXEN);
|
||||
#endif
|
||||
#if defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(HELTEC_V3_GPS) || defined(HELTEC_WIRELESS_TRACKER) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(TTGO_T_DECK_GPS)
|
||||
state = radio.setOutputPower(currentLoRaType->power + 2); // values available: 10, 17, 22 --> if 20 in tracker_conf.json it will be updated to 22.
|
||||
radio.setCurrentLimit(140);
|
||||
#endif
|
||||
#if defined(ESP32_DIY_1W_LoRa_GPS) || defined(OE5HWN_MeshCom)
|
||||
state = radio.setOutputPower(currentLoRaType->power); // max value 20 (when 20dB in setup 30dB in output as 400M30S has Low Noise Amp)
|
||||
radio.setCurrentLimit(140); // check correct value for 1W !!!!
|
||||
#endif
|
||||
#if defined(HAS_SX1278)
|
||||
state = radio.setOutputPower(currentLoRaType->power);
|
||||
radio.setCurrentLimit(100); // to be validated (80 , 100)?
|
||||
#endif
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268)
|
||||
radio.setRxBoostedGainMode(true);
|
||||
#endif
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "LoRa init done!");
|
||||
#endif
|
||||
radio.startReceive();
|
||||
} else {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
void sendNewPacket(const String& newPacket) {
|
||||
|
|
@ -172,26 +137,18 @@ namespace LoRa_Utils {
|
|||
}
|
||||
if (Config.notification.ledTx) digitalWrite(Config.notification.ledTxPin, HIGH);
|
||||
if (Config.notification.buzzerActive && Config.notification.txBeep) NOTIFICATION_Utils::beaconTxBeep();
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268) || defined(HAS_SX1278)
|
||||
enableInterrupt = false;
|
||||
int state = radio.transmit("\x3c\xff\x01" + newPacket);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
//Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
enableInterrupt = true;
|
||||
radio.startReceive();
|
||||
#endif
|
||||
#ifdef HAS_SX127X
|
||||
LoRa.beginPacket();
|
||||
LoRa.write('<');
|
||||
LoRa.write(0xFF);
|
||||
LoRa.write(0x01);
|
||||
LoRa.write((const uint8_t *)newPacket.c_str(), newPacket.length());
|
||||
LoRa.endPacket();
|
||||
#endif
|
||||
|
||||
enableInterrupt = false;
|
||||
int state = radio.transmit("\x3c\xff\x01" + newPacket);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
//Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
enableInterrupt = true;
|
||||
radio.startReceive();
|
||||
|
||||
if (Config.notification.ledTx) digitalWrite(Config.notification.ledTxPin, LOW);
|
||||
if (Config.ptt.active) {
|
||||
delay(Config.ptt.postDelay);
|
||||
|
|
@ -205,38 +162,22 @@ namespace LoRa_Utils {
|
|||
ReceivedLoRaPacket receivePacket() {
|
||||
ReceivedLoRaPacket receivedLoraPacket;
|
||||
String packet = "";
|
||||
#ifdef HAS_SX127X
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
while (LoRa.available()) {
|
||||
int inChar = LoRa.read();
|
||||
packet += (char)inChar;
|
||||
if (transmissionFlag) {
|
||||
transmissionFlag = false;
|
||||
int state = radio.readData(packet);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
if(!packet.isEmpty()) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa Rx","---> %s", packet.substring(3).c_str());
|
||||
}
|
||||
receivedLoraPacket.text = packet;
|
||||
receivedLoraPacket.rssi = LoRa.packetRssi();
|
||||
receivedLoraPacket.snr = LoRa.packetSnr();
|
||||
receivedLoraPacket.freqError = LoRa.packetFrequencyError();
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa Rx", "---> %s", packet.substring(3).c_str());
|
||||
receivedLoraPacket.rssi = radio.getRSSI();
|
||||
receivedLoraPacket.snr = radio.getSNR();
|
||||
receivedLoraPacket.freqError = radio.getFrequencyError();
|
||||
} else {
|
||||
Serial.print(F("failed, code ")); // 7 = CRC mismatch
|
||||
Serial.println(state);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAS_SX1262) || defined(HAS_SX1268) || defined(HAS_SX1278)
|
||||
if (transmissionFlag) {
|
||||
transmissionFlag = false;
|
||||
int state = radio.readData(packet);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
if(!packet.isEmpty()) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa Rx","---> %s", packet.substring(3).c_str());
|
||||
}
|
||||
receivedLoraPacket.text = packet;
|
||||
receivedLoraPacket.rssi = radio.getRSSI();
|
||||
receivedLoraPacket.snr = radio.getSNR();
|
||||
receivedLoraPacket.freqError = radio.getFrequencyError();
|
||||
} else {
|
||||
Serial.print(F("failed, code ")); // 7 = CRC mismatch
|
||||
Serial.println(state);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return receivedLoraPacket;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue