2020-10-11 22:09:34 +00:00
|
|
|
#include <map>
|
|
|
|
|
2020-03-18 18:49:59 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <WiFiMulti.h>
|
|
|
|
#include <NTPClient.h>
|
|
|
|
#include <WiFiUdp.h>
|
2020-03-19 12:59:51 +00:00
|
|
|
#include <ArduinoOTA.h>
|
2020-03-18 18:49:59 +00:00
|
|
|
#include <APRS-IS.h>
|
2020-11-03 22:35:19 +00:00
|
|
|
#include <SPIFFS.h>
|
|
|
|
#include <ESP-FTP-Server-Lib.h>
|
|
|
|
#include <FTPFilesystem.h>
|
2020-06-04 20:27:44 +00:00
|
|
|
|
|
|
|
#include "LoRa_APRS.h"
|
2020-03-18 18:49:59 +00:00
|
|
|
|
2020-07-24 13:29:14 +00:00
|
|
|
#include "pins.h"
|
2020-03-18 22:24:23 +00:00
|
|
|
#include "display.h"
|
2020-07-22 20:21:54 +00:00
|
|
|
#include "configuration.h"
|
2020-03-18 18:49:59 +00:00
|
|
|
|
2020-05-11 09:57:42 +00:00
|
|
|
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
|
2020-10-11 22:09:34 +00:00
|
|
|
#include "power_management.h"
|
2020-06-01 09:23:48 +00:00
|
|
|
PowerManagement powerManagement;
|
2020-05-08 22:10:34 +00:00
|
|
|
#endif
|
2020-03-18 18:49:59 +00:00
|
|
|
|
2020-09-20 20:15:16 +00:00
|
|
|
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
|
|
|
hw_timer_t * timer = NULL;
|
2020-10-11 22:09:34 +00:00
|
|
|
volatile uint secondsSinceLastAPRSISBeacon = 0;
|
|
|
|
volatile uint secondsSinceLastDigiBeacon = 0;
|
|
|
|
volatile uint secondsSinceStartup = 0;
|
2020-10-26 21:52:52 +00:00
|
|
|
volatile uint secondsSinceDisplay = 0;
|
2020-09-20 20:15:16 +00:00
|
|
|
|
2020-10-11 22:09:34 +00:00
|
|
|
WiFiMulti WiFiMulti;
|
|
|
|
WiFiUDP ntpUDP;
|
|
|
|
NTPClient timeClient(ntpUDP, 60*60);
|
2020-11-03 22:35:19 +00:00
|
|
|
FTPServer ftpServer;
|
2020-10-11 22:09:34 +00:00
|
|
|
Configuration Config;
|
|
|
|
APRS_IS * aprs_is = 0;
|
|
|
|
LoRa_APRS lora_aprs;
|
|
|
|
std::shared_ptr<APRSMessage> BeaconMsg;
|
|
|
|
|
|
|
|
String create_lat_aprs(double lat);
|
|
|
|
String create_long_aprs(double lng);
|
2020-03-19 12:29:21 +00:00
|
|
|
|
2020-07-22 20:21:54 +00:00
|
|
|
void load_config();
|
2020-04-03 21:32:10 +00:00
|
|
|
void setup_wifi();
|
|
|
|
void setup_ota();
|
|
|
|
void setup_lora();
|
|
|
|
void setup_ntp();
|
2020-07-22 20:21:54 +00:00
|
|
|
void setup_aprs_is();
|
2020-09-20 20:15:16 +00:00
|
|
|
void setup_timer();
|
2020-11-03 22:35:19 +00:00
|
|
|
void setup_ftp();
|
2020-04-03 21:32:10 +00:00
|
|
|
|
2020-10-11 22:09:34 +00:00
|
|
|
std::map<uint, std::shared_ptr<APRSMessage>> lastMessages;
|
2020-05-08 21:09:44 +00:00
|
|
|
|
2020-05-29 19:13:11 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2020-03-18 18:49:59 +00:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2020-06-01 09:23:48 +00:00
|
|
|
|
|
|
|
#if defined(ARDUINO_T_Beam) && !defined(ARDUINO_T_Beam_V0_7)
|
|
|
|
Wire.begin(SDA, SCL);
|
|
|
|
if (!powerManagement.begin(Wire))
|
|
|
|
{
|
|
|
|
Serial.println("LoRa-APRS / Init / AXP192 Begin PASS");
|
|
|
|
} else {
|
|
|
|
Serial.println("LoRa-APRS / Init / AXP192 Begin FAIL");
|
|
|
|
}
|
|
|
|
powerManagement.activateLoRa();
|
|
|
|
powerManagement.activateOLED();
|
|
|
|
powerManagement.deactivateGPS();
|
|
|
|
#endif
|
|
|
|
|
2020-03-19 21:02:24 +00:00
|
|
|
setup_display();
|
2020-03-18 22:24:23 +00:00
|
|
|
|
2020-03-18 18:49:59 +00:00
|
|
|
delay(500);
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.println("[INFO] LoRa APRS iGate & Digi by OE5BPA (Peter Buchegger)");
|
|
|
|
show_display("OE5BPA", "LoRa APRS iGate & Digi", "by Peter Buchegger", 3000);
|
2020-03-18 18:49:59 +00:00
|
|
|
|
2020-07-22 20:21:54 +00:00
|
|
|
load_config();
|
2020-04-03 21:32:10 +00:00
|
|
|
setup_lora();
|
2020-10-12 19:43:37 +00:00
|
|
|
if(Config.wifi.active)
|
|
|
|
{
|
|
|
|
setup_wifi();
|
|
|
|
setup_ota();
|
|
|
|
setup_ntp();
|
2020-11-03 22:35:19 +00:00
|
|
|
setup_ftp();
|
2020-10-12 19:43:37 +00:00
|
|
|
}
|
2020-11-01 00:28:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// make sure wifi and bt is off if we don't need it:
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
btStop();
|
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
if(Config.aprs_is.active) setup_aprs_is();
|
2020-09-20 20:15:16 +00:00
|
|
|
setup_timer();
|
2020-05-08 21:09:44 +00:00
|
|
|
|
2020-10-26 21:52:52 +00:00
|
|
|
if(Config.display.overwritePin != 0)
|
|
|
|
{
|
|
|
|
pinMode(Config.display.overwritePin, INPUT);
|
|
|
|
pinMode(Config.display.overwritePin, INPUT_PULLUP);
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:49:59 +00:00
|
|
|
delay(500);
|
2020-11-03 22:34:36 +00:00
|
|
|
Serial.println("[INFO] setup done...");
|
2020-10-26 21:52:52 +00:00
|
|
|
secondsSinceDisplay = 0;
|
2020-03-18 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 19:13:11 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2020-03-18 18:49:59 +00:00
|
|
|
void loop()
|
|
|
|
{
|
2020-10-26 21:52:52 +00:00
|
|
|
static bool display_is_on = true;
|
|
|
|
if(Config.display.overwritePin != 0 && !digitalRead(Config.display.overwritePin))
|
|
|
|
{
|
|
|
|
secondsSinceDisplay = 0;
|
|
|
|
display_is_on = true;
|
|
|
|
setup_display();
|
|
|
|
} else
|
|
|
|
if(!Config.display.alwaysOn && secondsSinceDisplay > Config.display.timeout && display_is_on)
|
|
|
|
{
|
|
|
|
turn_off_display();
|
|
|
|
display_is_on = false;
|
|
|
|
Serial.println("-");
|
|
|
|
}
|
|
|
|
|
2020-10-11 22:09:34 +00:00
|
|
|
static bool beacon_aprs_is = Config.aprs_is.active && Config.aprs_is.beacon;
|
|
|
|
static bool beacon_digi = Config.digi.active && Config.digi.beacon;
|
|
|
|
|
|
|
|
if(Config.aprs_is.active && Config.aprs_is.beacon && secondsSinceLastAPRSISBeacon >= (Config.aprs_is.beaconTimeout*60))
|
2020-09-20 20:15:16 +00:00
|
|
|
{
|
|
|
|
portENTER_CRITICAL(&timerMux);
|
2020-10-11 22:09:34 +00:00
|
|
|
secondsSinceLastAPRSISBeacon -= (Config.aprs_is.beaconTimeout*60);
|
2020-09-20 20:15:16 +00:00
|
|
|
portEXIT_CRITICAL(&timerMux);
|
2020-10-11 22:09:34 +00:00
|
|
|
beacon_aprs_is = true;
|
2020-09-20 20:15:16 +00:00
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
if(Config.digi.active && Config.digi.beacon && secondsSinceLastDigiBeacon >= (Config.digi.beaconTimeout*60))
|
|
|
|
{
|
|
|
|
portENTER_CRITICAL(&timerMux);
|
|
|
|
secondsSinceLastDigiBeacon -= (Config.digi.beaconTimeout*60);
|
|
|
|
portEXIT_CRITICAL(&timerMux);
|
|
|
|
beacon_digi = true;
|
|
|
|
}
|
|
|
|
|
2020-11-03 22:35:19 +00:00
|
|
|
ftpServer.handle();
|
|
|
|
static bool configWasOpen = false;
|
|
|
|
if(configWasOpen && ftpServer.countConnections() == 0)
|
|
|
|
{
|
|
|
|
Serial.println("[WARN] Configuration maybe changed via FTP, will restart now...");
|
|
|
|
Serial.println();
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
if(ftpServer.countConnections() > 0)
|
|
|
|
{
|
|
|
|
configWasOpen = true;
|
|
|
|
}
|
|
|
|
|
2020-10-11 22:09:34 +00:00
|
|
|
if(Config.wifi.active) ArduinoOTA.handle();
|
|
|
|
if(Config.wifi.active && WiFiMulti.run() != WL_CONNECTED)
|
2020-03-18 18:49:59 +00:00
|
|
|
{
|
2020-10-26 21:52:52 +00:00
|
|
|
setup_display(); secondsSinceDisplay = 0; display_is_on = true;
|
2020-03-18 18:49:59 +00:00
|
|
|
Serial.println("[ERROR] WiFi not connected!");
|
2020-03-19 21:02:24 +00:00
|
|
|
show_display("ERROR", "WiFi not connected!");
|
2020-03-18 18:49:59 +00:00
|
|
|
delay(1000);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
if(Config.aprs_is.active && !aprs_is->connected())
|
2020-03-18 18:49:59 +00:00
|
|
|
{
|
2020-10-26 21:52:52 +00:00
|
|
|
setup_display(); secondsSinceDisplay = 0; display_is_on = true;
|
2020-03-18 18:49:59 +00:00
|
|
|
Serial.print("[INFO] connecting to server: ");
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.print(Config.aprs_is.server);
|
2020-03-18 18:49:59 +00:00
|
|
|
Serial.print(" on port: ");
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.println(Config.aprs_is.port);
|
2020-03-19 21:02:24 +00:00
|
|
|
show_display("INFO", "Connecting to server");
|
2020-10-11 22:09:34 +00:00
|
|
|
if(!aprs_is->connect(Config.aprs_is.server, Config.aprs_is.port))
|
2020-03-18 18:49:59 +00:00
|
|
|
{
|
|
|
|
Serial.println("[ERROR] Connection failed.");
|
|
|
|
Serial.println("[INFO] Waiting 5 seconds before retrying...");
|
2020-03-19 21:02:24 +00:00
|
|
|
show_display("ERROR", "Server connection failed!", "waiting 5 sec");
|
2020-03-18 18:49:59 +00:00
|
|
|
delay(5000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Serial.println("[INFO] Connected to server!");
|
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
if(Config.aprs_is.active && aprs_is->available() > 0)
|
2020-03-18 18:49:59 +00:00
|
|
|
{
|
2020-07-22 20:21:54 +00:00
|
|
|
String str = aprs_is->getMessage();
|
2020-03-18 18:49:59 +00:00
|
|
|
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
2020-03-18 22:24:23 +00:00
|
|
|
Serial.println(str);
|
2020-03-18 18:49:59 +00:00
|
|
|
}
|
2020-06-04 20:27:44 +00:00
|
|
|
if(lora_aprs.hasMessage())
|
2020-03-18 18:49:59 +00:00
|
|
|
{
|
2020-06-04 20:27:44 +00:00
|
|
|
std::shared_ptr<APRSMessage> msg = lora_aprs.getMessage();
|
|
|
|
|
2020-10-26 21:52:52 +00:00
|
|
|
setup_display(); secondsSinceDisplay = 0; display_is_on = true;
|
2020-10-31 23:42:20 +00:00
|
|
|
show_display(Config.callsign, timeClient.getFormattedTime() + " LoRa", "RSSI: " + String(lora_aprs.packetRssi()) + ", SNR: " + String(lora_aprs.packetSnr()), msg->toString());
|
2020-05-11 11:41:33 +00:00
|
|
|
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
|
|
|
Serial.print(" Received packet '");
|
2020-06-04 20:27:44 +00:00
|
|
|
Serial.print(msg->toString());
|
2020-03-18 18:49:59 +00:00
|
|
|
Serial.print("' with RSSI ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.print(lora_aprs.packetRssi());
|
2020-03-18 18:49:59 +00:00
|
|
|
Serial.print(" and SNR ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.println(lora_aprs.packetSnr());
|
2020-03-18 22:24:23 +00:00
|
|
|
|
2020-10-11 22:09:34 +00:00
|
|
|
if(Config.aprs_is.active)
|
|
|
|
{
|
|
|
|
aprs_is->sendMessage(msg->encode());
|
|
|
|
}
|
|
|
|
if(Config.digi.active)
|
|
|
|
{
|
|
|
|
if(msg->getSource().indexOf(Config.callsign) != -1)
|
|
|
|
{
|
|
|
|
Serial.print("Message already received as repeater: '");
|
|
|
|
Serial.print(msg->toString());
|
|
|
|
Serial.print("' with RSSI ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.print(lora_aprs.packetRssi());
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.print(" and SNR ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.println(lora_aprs.packetSnr());
|
2020-10-11 22:09:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lets try not to flood the LoRa frequency in limiting the same messages:
|
|
|
|
std::map<uint, std::shared_ptr<APRSMessage>>::iterator foundMsg = std::find_if(lastMessages.begin(), lastMessages.end(), [&](std::pair<const unsigned int, std::shared_ptr<APRSMessage> > & old_msg)
|
|
|
|
{
|
|
|
|
if(msg->getSource() == old_msg.second->getSource() &&
|
|
|
|
msg->getDestination() == old_msg.second->getDestination() &&
|
|
|
|
msg->getAPRSBody()->getData() == old_msg.second->getAPRSBody()->getData())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if(foundMsg == lastMessages.end())
|
|
|
|
{
|
2020-10-26 21:52:52 +00:00
|
|
|
setup_display(); secondsSinceDisplay = 0; display_is_on = true;
|
2020-10-31 23:42:20 +00:00
|
|
|
show_display(Config.callsign, "RSSI: " + String(lora_aprs.packetRssi()) + ", SNR: " + String(lora_aprs.packetSnr()), msg->toString(), 0);
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.print("Received packet '");
|
|
|
|
Serial.print(msg->toString());
|
|
|
|
Serial.print("' with RSSI ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.print(lora_aprs.packetRssi());
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.print(" and SNR ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.println(lora_aprs.packetSnr());
|
2020-10-11 22:09:34 +00:00
|
|
|
msg->setPath(String(Config.callsign) + "*");
|
|
|
|
lora_aprs.sendMessage(msg);
|
|
|
|
lastMessages.insert({secondsSinceStartup, msg});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Serial.print("Message already received (timeout): '");
|
|
|
|
Serial.print(msg->toString());
|
|
|
|
Serial.print("' with RSSI ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.print(lora_aprs.packetRssi());
|
2020-10-11 22:09:34 +00:00
|
|
|
Serial.print(" and SNR ");
|
2020-10-31 23:42:20 +00:00
|
|
|
Serial.println(lora_aprs.packetSnr());
|
2020-10-11 22:09:34 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(Config.digi.active)
|
|
|
|
{
|
|
|
|
for(std::map<uint, std::shared_ptr<APRSMessage>>::iterator iter = lastMessages.begin(); iter != lastMessages.end(); )
|
|
|
|
{
|
|
|
|
if(secondsSinceStartup >= iter->first + Config.digi.forwardTimeout*60)
|
|
|
|
{
|
|
|
|
iter = lastMessages.erase(iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-12 19:45:57 +00:00
|
|
|
++iter;
|
2020-10-11 22:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-22 20:21:54 +00:00
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
if(beacon_digi)
|
2020-09-20 20:15:16 +00:00
|
|
|
{
|
2020-10-11 22:09:34 +00:00
|
|
|
beacon_digi = false;
|
2020-10-26 21:52:52 +00:00
|
|
|
setup_display(); secondsSinceDisplay = 0; display_is_on = true;
|
2020-10-11 22:09:34 +00:00
|
|
|
show_display(Config.callsign, "Beacon to HF...");
|
|
|
|
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
|
|
|
Serial.print(BeaconMsg->encode());
|
|
|
|
lora_aprs.sendMessage(BeaconMsg);
|
|
|
|
Serial.println("finished TXing...");
|
2020-10-26 21:52:52 +00:00
|
|
|
show_display(Config.callsign, "Standby...");
|
2020-10-11 22:09:34 +00:00
|
|
|
}
|
|
|
|
if(beacon_aprs_is)
|
|
|
|
{
|
|
|
|
beacon_aprs_is = false;
|
2020-10-26 21:52:52 +00:00
|
|
|
setup_display(); secondsSinceDisplay = 0; display_is_on = true;
|
2020-10-11 22:09:34 +00:00
|
|
|
show_display(Config.callsign, "Beacon to APRS IS Server...");
|
|
|
|
Serial.print("[" + timeClient.getFormattedTime() + "] ");
|
|
|
|
Serial.print(BeaconMsg->encode());
|
|
|
|
aprs_is->sendMessage(BeaconMsg);
|
2020-10-26 21:52:52 +00:00
|
|
|
show_display(Config.callsign, "Standby...");
|
2020-09-20 20:15:16 +00:00
|
|
|
}
|
2020-07-22 20:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void load_config()
|
|
|
|
{
|
2020-10-11 22:09:34 +00:00
|
|
|
ConfigurationManagement confmg("/is-cfg.json");
|
|
|
|
Config = confmg.readConfiguration();
|
|
|
|
if(Config.callsign == "NOCALL-10")
|
2020-07-22 20:21:54 +00:00
|
|
|
{
|
|
|
|
Serial.println("[ERROR] You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!");
|
|
|
|
show_display("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!");
|
|
|
|
while (true)
|
|
|
|
{}
|
2020-03-18 18:49:59 +00:00
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
|
|
|
|
if(Config.aprs_is.active && !Config.wifi.active)
|
|
|
|
{
|
|
|
|
Serial.println("[ERROR] You have to activate Wifi for APRS IS to work, please check your settings!");
|
|
|
|
show_display("ERROR", "You have to activate Wifi for APRS IS to work, please check your settings!");
|
|
|
|
while (true)
|
|
|
|
{}
|
|
|
|
}
|
2020-10-26 21:52:52 +00:00
|
|
|
|
|
|
|
if(KEY_BUILTIN != 0 && Config.display.overwritePin == 0)
|
|
|
|
{
|
|
|
|
Config.display.overwritePin = KEY_BUILTIN;
|
|
|
|
}
|
2020-11-03 22:34:36 +00:00
|
|
|
Serial.println("[INFO] Configuration loaded!");
|
2020-03-18 18:49:59 +00:00
|
|
|
}
|
2020-04-03 21:32:10 +00:00
|
|
|
|
|
|
|
void setup_wifi()
|
|
|
|
{
|
|
|
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
2020-10-11 22:09:34 +00:00
|
|
|
WiFi.setHostname(Config.callsign.c_str());
|
|
|
|
for(Configuration::Wifi::AP ap : Config.wifi.APs)
|
|
|
|
{
|
2020-11-03 22:34:36 +00:00
|
|
|
Serial.print("[INFO] Looking for AP: ");
|
|
|
|
Serial.println(ap.SSID);
|
2020-10-11 22:09:34 +00:00
|
|
|
WiFiMulti.addAP(ap.SSID.c_str(), ap.password.c_str());
|
|
|
|
}
|
2020-04-03 21:32:10 +00:00
|
|
|
Serial.print("[INFO] Waiting for WiFi");
|
|
|
|
show_display("INFO", "Waiting for WiFi");
|
|
|
|
while(WiFiMulti.run() != WL_CONNECTED)
|
|
|
|
{
|
|
|
|
Serial.print(".");
|
|
|
|
show_display("INFO", "Waiting for WiFi", "....");
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
Serial.println("[INFO] WiFi connected");
|
|
|
|
Serial.print("[INFO] IP address: ");
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
show_display("INFO", "WiFi connected", "IP: ", WiFi.localIP().toString(), 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_ota()
|
|
|
|
{
|
|
|
|
ArduinoOTA
|
|
|
|
.onStart([]()
|
|
|
|
{
|
|
|
|
String type;
|
|
|
|
if (ArduinoOTA.getCommand() == U_FLASH)
|
|
|
|
type = "sketch";
|
|
|
|
else // U_SPIFFS
|
|
|
|
type = "filesystem";
|
|
|
|
Serial.println("Start updating " + type);
|
|
|
|
show_display("OTA UPDATE", "Start update", type);
|
|
|
|
})
|
|
|
|
.onEnd([]()
|
|
|
|
{
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("End");
|
|
|
|
})
|
|
|
|
.onProgress([](unsigned int progress, unsigned int total)
|
|
|
|
{
|
|
|
|
Serial.print("Progress: ");
|
|
|
|
Serial.print(progress / (total / 100));
|
|
|
|
Serial.println("%");
|
|
|
|
show_display("OTA UPDATE", "Progress: ", String(progress / (total / 100)) + "%");
|
|
|
|
})
|
|
|
|
.onError([](ota_error_t error) {
|
|
|
|
Serial.print("Error[");
|
|
|
|
Serial.print(error);
|
|
|
|
Serial.print("]: ");
|
|
|
|
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
|
|
|
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
|
|
|
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
|
|
|
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
|
|
|
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
|
|
|
});
|
2020-10-11 22:09:34 +00:00
|
|
|
ArduinoOTA.setHostname(Config.callsign.c_str());
|
2020-04-03 21:32:10 +00:00
|
|
|
ArduinoOTA.begin();
|
2020-11-03 22:34:36 +00:00
|
|
|
Serial.println("[INFO] OTA init done!");
|
2020-04-03 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup_lora()
|
|
|
|
{
|
2020-10-31 23:42:20 +00:00
|
|
|
lora_aprs.setRxFrequency(Config.lora.frequencyRx);
|
|
|
|
lora_aprs.setTxFrequency(Config.lora.frequencyTx);
|
|
|
|
if (!lora_aprs.begin(lora_aprs.getRxFrequency()))
|
2020-06-04 20:27:44 +00:00
|
|
|
{
|
2020-04-03 21:32:10 +00:00
|
|
|
Serial.println("[ERROR] Starting LoRa failed!");
|
|
|
|
show_display("ERROR", "Starting LoRa failed!");
|
|
|
|
while (1);
|
|
|
|
}
|
2020-10-26 21:52:52 +00:00
|
|
|
lora_aprs.setTxPower(Config.lora.power);
|
2020-11-01 00:26:06 +00:00
|
|
|
lora_aprs.setSpreadingFactor(Config.lora.spreadingFactor);
|
|
|
|
lora_aprs.setSignalBandwidth(Config.lora.signalBandwidth);
|
|
|
|
lora_aprs.setCodingRate4(Config.lora.codingRate4);
|
2020-04-03 21:32:10 +00:00
|
|
|
Serial.println("[INFO] LoRa init done!");
|
|
|
|
show_display("INFO", "LoRa init done!", 2000);
|
2020-10-11 22:09:34 +00:00
|
|
|
|
|
|
|
BeaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
|
|
|
BeaconMsg->setSource(Config.callsign);
|
|
|
|
BeaconMsg->setDestination("APLG0");
|
|
|
|
String lat = create_lat_aprs(Config.beacon.positionLatitude);
|
|
|
|
String lng = create_long_aprs(Config.beacon.positionLongitude);
|
|
|
|
BeaconMsg->getAPRSBody()->setData(String("=") + lat + "I" + lng + "&" + Config.beacon.message);
|
2020-04-03 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup_ntp()
|
|
|
|
{
|
|
|
|
timeClient.begin();
|
|
|
|
if(!timeClient.forceUpdate())
|
|
|
|
{
|
|
|
|
Serial.println("[WARN] NTP Client force update issue!");
|
|
|
|
show_display("WARN", "NTP Client force update issue!", 2000);
|
|
|
|
}
|
|
|
|
Serial.println("[INFO] NTP Client init done!");
|
|
|
|
show_display("INFO", "NTP Client init done!", 2000);
|
|
|
|
}
|
2020-07-22 20:21:54 +00:00
|
|
|
|
|
|
|
void setup_aprs_is()
|
|
|
|
{
|
2020-10-11 22:09:34 +00:00
|
|
|
aprs_is = new APRS_IS(Config.callsign, Config.aprs_is.password , "ESP32-APRS-IS", "0.1");
|
2020-07-22 20:21:54 +00:00
|
|
|
}
|
2020-09-20 20:15:16 +00:00
|
|
|
|
|
|
|
void IRAM_ATTR onTimer()
|
|
|
|
{
|
|
|
|
portENTER_CRITICAL_ISR(&timerMux);
|
2020-10-11 22:09:34 +00:00
|
|
|
secondsSinceLastAPRSISBeacon++;
|
|
|
|
secondsSinceLastDigiBeacon++;
|
|
|
|
secondsSinceStartup++;
|
2020-10-26 21:52:52 +00:00
|
|
|
secondsSinceDisplay++;
|
2020-09-20 20:15:16 +00:00
|
|
|
portEXIT_CRITICAL_ISR(&timerMux);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_timer()
|
|
|
|
{
|
|
|
|
timer = timerBegin(0, 80, true);
|
|
|
|
timerAlarmWrite(timer, 1000000, true);
|
|
|
|
timerAttachInterrupt(timer, &onTimer, true);
|
|
|
|
timerAlarmEnable(timer);
|
|
|
|
}
|
2020-10-11 22:09:34 +00:00
|
|
|
|
2020-11-03 22:35:19 +00:00
|
|
|
void setup_ftp()
|
|
|
|
{
|
|
|
|
#define FTP_USER "ftp"
|
|
|
|
#define FTP_PASSWORD "ftp"
|
|
|
|
ftpServer.addUser(FTP_USER, FTP_PASSWORD);
|
|
|
|
ftpServer.addFilesystem("SPIFFS", &SPIFFS);
|
|
|
|
ftpServer.begin();
|
|
|
|
Serial.println("[INFO] FTP Server init done!");
|
|
|
|
}
|
|
|
|
|
2020-10-11 22:09:34 +00:00
|
|
|
String create_lat_aprs(double lat)
|
|
|
|
{
|
|
|
|
char str[20];
|
|
|
|
char n_s = 'N';
|
|
|
|
if(lat < 0)
|
|
|
|
{
|
|
|
|
n_s = 'S';
|
|
|
|
}
|
|
|
|
lat = std::abs(lat);
|
|
|
|
sprintf(str, "%02d%05.2f%c", (int)lat, (lat - (double)((int)lat)) * 60.0, n_s);
|
|
|
|
String lat_str(str);
|
|
|
|
return lat_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
String create_long_aprs(double lng)
|
|
|
|
{
|
|
|
|
char str[20];
|
|
|
|
char e_w = 'E';
|
|
|
|
if(lng < 0)
|
|
|
|
{
|
|
|
|
e_w = 'W';
|
|
|
|
}
|
|
|
|
lng = std::abs(lng);
|
|
|
|
sprintf(str, "%03d%05.2f%c", (int)lng, (lng - (double)((int)lng)) * 60.0, e_w);
|
|
|
|
String lng_str(str);
|
|
|
|
return lng_str;
|
|
|
|
}
|