2020-11-28 08:20:32 +00:00
|
|
|
#include <arduino-timer.h>
|
2019-04-25 06:17:02 +00:00
|
|
|
#include "WiFi.h"
|
2020-06-14 18:55:27 +00:00
|
|
|
#include "loraprs_service.h"
|
2019-04-25 06:17:02 +00:00
|
|
|
|
2019-04-30 18:17:07 +00:00
|
|
|
#define LED_BUILTIN 2
|
2021-02-03 09:29:54 +00:00
|
|
|
#define LED_TOGGLE_PERIOD 1000
|
|
|
|
|
2021-02-03 09:37:06 +00:00
|
|
|
//#define BOARD_T_BEAM // enable for TTG T-Beam board support
|
2019-04-30 18:17:07 +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
|
|
|
|
#pragma message("Using default config")
|
|
|
|
#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-01-29 11:47:04 +00:00
|
|
|
void initializeConfig(LoraPrs::Config &cfg) {
|
2020-06-12 14:34:23 +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;
|
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;
|
|
|
|
cfg.LoraEnableCrc = CFG_LORA_ENABLE_CRC; // set to false for speech 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;
|
|
|
|
|
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;
|
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
|
|
|
|
2020-06-14 14:59:35 +00:00
|
|
|
// configuration flags and features
|
2021-01-29 11:47:04 +00:00
|
|
|
cfg.EnableAutoFreqCorrection = CFG_FREQ_CORR; // automatic tune to any incoming packet frequency
|
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
|
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() {
|
2019-04-30 18:17:07 +00:00
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
|
|
digitalWrite(LED_BUILTIN, 1);
|
|
|
|
|
2019-04-25 06:17:02 +00:00
|
|
|
Serial.begin(115200);
|
|
|
|
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 *) {
|
|
|
|
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
|
|
|
return true;
|
2019-04-25 06:17:02 +00:00
|
|
|
}
|