2020-11-28 08:20:32 +00:00
|
|
|
#include <arduino-timer.h>
|
2019-04-25 06:17:02 +00:00
|
|
|
#include "WiFi.h"
|
2021-10-20 10:20:19 +00:00
|
|
|
|
2021-01-29 11:47:04 +00:00
|
|
|
#if __has_include("/tmp/esp32_loraprs_config.h")
|
|
|
|
#pragma message("Using external config")
|
|
|
|
#include "/tmp/esp32_loraprs_config.h"
|
|
|
|
#else
|
2021-10-20 10:20:19 +00:00
|
|
|
#pragma message("Using default built-in config")
|
2021-01-29 11:47:04 +00:00
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2019-04-25 06:17:02 +00:00
|
|
|
|
2021-01-29 11:47:04 +00:00
|
|
|
#if CFG_IS_CLIENT_MODE == true
|
|
|
|
#pragma message("Configured for client mode")
|
|
|
|
#else
|
|
|
|
#pragma message("Configured for server mode")
|
|
|
|
#endif
|
2019-04-30 18:17:07 +00:00
|
|
|
|
2021-10-20 13:30:52 +00:00
|
|
|
// When USE_RADIOLIB is defined then RadioLib will be used, otherwise arduino-LoRa will be used
|
|
|
|
// When using RadioLib, default module is SX1278, if you are using
|
|
|
|
// different module then update loraprs_service.h and loraprs_service.cpp
|
|
|
|
// search for SX1278 and replace with your module name
|
|
|
|
|
|
|
|
//#define USE_RADIOLIB
|
|
|
|
#include "loraprs_service.h"
|
|
|
|
|
2021-01-29 11:47:04 +00:00
|
|
|
void initializeConfig(LoraPrs::Config &cfg) {
|
2021-10-15 14:09:29 +00:00
|
|
|
|
2020-06-14 14:59:35 +00:00
|
|
|
// client/server mode switch
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.IsClientMode = CFG_IS_CLIENT_MODE;
|
2021-02-07 07:52:30 +00:00
|
|
|
|
2020-06-14 14:59:35 +00:00
|
|
|
// lora parameters
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.LoraFreq = CFG_LORA_FREQ;
|
|
|
|
cfg.LoraBw = CFG_LORA_BW;
|
|
|
|
cfg.LoraSf = CFG_LORA_SF;
|
|
|
|
cfg.LoraCodingRate = CFG_LORA_CR;
|
2020-06-19 14:03:31 +00:00
|
|
|
cfg.LoraSync = 0x34;
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.LoraPower = CFG_LORA_PWR;
|
2021-04-07 06:08:10 +00:00
|
|
|
cfg.LoraEnableCrc = CFG_LORA_ENABLE_CRC; // set to false for speech streaming data
|
2020-06-12 14:34:23 +00:00
|
|
|
|
2021-02-03 09:29:54 +00:00
|
|
|
// lora pinouts
|
|
|
|
cfg.LoraPinSs = CFG_LORA_PIN_SS;
|
|
|
|
cfg.LoraPinRst = CFG_LORA_PIN_RST;
|
|
|
|
cfg.LoraPinDio0 = CFG_LORA_PIN_DIO0;
|
2021-10-20 13:30:52 +00:00
|
|
|
cfg.LoraPinDio1 = CFG_LORA_PIN_DIO1; // valid for radiolib only
|
2021-04-07 06:08:10 +00:00
|
|
|
cfg.LoraUseIsr = CFG_LORA_USE_ISR; // set to true for incoming packet ISR usage (stream mode, e.g. speech)
|
2021-02-03 09:29:54 +00:00
|
|
|
|
2020-06-14 14:59:35 +00:00
|
|
|
// aprs configuration
|
2020-06-12 14:34:23 +00:00
|
|
|
cfg.AprsHost = "rotate.aprs2.net";
|
|
|
|
cfg.AprsPort = 14580;
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.AprsLogin = CFG_APRS_LOGIN;
|
|
|
|
cfg.AprsPass = CFG_APRS_PASS;
|
|
|
|
cfg.AprsFilter = CFG_APRS_FILTER; // multiple filters are space separated
|
|
|
|
cfg.AprsRawBeacon = CFG_APRS_RAW_BKN;
|
2020-06-14 14:59:35 +00:00
|
|
|
cfg.AprsRawBeaconPeriodMinutes = 20;
|
|
|
|
|
|
|
|
// bluetooth device name
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.BtName = CFG_BT_NAME;
|
2021-06-08 14:41:13 +00:00
|
|
|
cfg.BtEnableBle = CFG_BT_USE_BLE;
|
2020-06-14 14:59:35 +00:00
|
|
|
|
|
|
|
// server mode wifi paramaters
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.WifiSsid = CFG_WIFI_SSID;
|
|
|
|
cfg.WifiKey = CFG_WIFI_KEY;
|
2020-06-12 14:34:23 +00:00
|
|
|
|
2021-04-07 06:24:22 +00:00
|
|
|
// frequency correction
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.EnableAutoFreqCorrection = CFG_FREQ_CORR; // automatic tune to any incoming packet frequency
|
2021-04-07 06:24:22 +00:00
|
|
|
cfg.AutoFreqCorrectionDeltaHz = CFG_FREQ_CORR_DELTA;
|
|
|
|
|
|
|
|
// configuration flags and features
|
2020-06-14 14:59:35 +00:00
|
|
|
cfg.EnableSignalReport = true; // signal report will be added to the comment sent to aprsis
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.EnablePersistentAprsConnection = CFG_PERSISTENT_APRS; // keep aprsis connection open, otherwise connect on new data only
|
|
|
|
cfg.EnableRfToIs = CFG_RF_TO_IS; // send data from rf to aprsis
|
|
|
|
cfg.EnableIsToRf = CFG_IS_TO_RF; // send data from aprsis to rf
|
|
|
|
cfg.EnableRepeater = CFG_DIGIREPEAT; // digirepeat incoming packets
|
|
|
|
cfg.EnableBeacon = CFG_BEACON; // enable periodic AprsRawBeacon beacon to rf and aprsis if rf to aprsis is enabled
|
2021-02-05 16:57:06 +00:00
|
|
|
cfg.EnableKissExtensions = CFG_KISS_EXTENSIONS; // radio control and signal reports
|
2021-05-26 16:11:33 +00:00
|
|
|
|
|
|
|
// external ptt control
|
|
|
|
cfg.PttEnable = CFG_PTT_ENABLE;
|
|
|
|
cfg.PttPin = CFG_PTT_PIN;
|
|
|
|
cfg.PttTxDelayMs = CFG_PTT_TX_DELAY_MS;
|
|
|
|
cfg.PttTxTailMs = CFG_PTT_TX_TAIL_MS;
|
2020-06-12 14:34:23 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 11:47:04 +00:00
|
|
|
LoraPrs::Service loraPrsService;
|
|
|
|
|
|
|
|
auto watchdogLedTimer = timer_create_default();
|
|
|
|
|
2019-04-25 06:17:02 +00:00
|
|
|
void setup() {
|
2021-02-07 15:53:35 +00:00
|
|
|
pinMode(BUILTIN_LED, OUTPUT);
|
|
|
|
digitalWrite(BUILTIN_LED, 1);
|
2019-04-30 18:17:07 +00:00
|
|
|
|
2021-02-08 12:23:39 +00:00
|
|
|
Serial.begin(SERIAL_BAUD_RATE);
|
2019-04-25 06:17:02 +00:00
|
|
|
while (!Serial);
|
2021-01-29 11:47:04 +00:00
|
|
|
|
|
|
|
LoraPrs::Config config;
|
2019-04-25 06:17:02 +00:00
|
|
|
|
2021-01-29 11:47:04 +00:00
|
|
|
initializeConfig(config);
|
|
|
|
loraPrsService.setup(config);
|
2019-04-30 18:17:07 +00:00
|
|
|
|
|
|
|
watchdogLedTimer.every(LED_TOGGLE_PERIOD, toggleWatchdogLed);
|
2019-04-25 06:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2020-06-14 18:55:27 +00:00
|
|
|
loraPrsService.loop();
|
2019-04-30 18:17:07 +00:00
|
|
|
watchdogLedTimer.tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool toggleWatchdogLed(void *) {
|
2021-02-07 15:53:35 +00:00
|
|
|
digitalWrite(BUILTIN_LED, !digitalRead(BUILTIN_LED));
|
2019-04-30 18:17:07 +00:00
|
|
|
return true;
|
2019-04-25 06:17:02 +00:00
|
|
|
}
|