2020-04-03 21:21:35 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <LoRa.h>
|
|
|
|
#include <APRS-Decoder.h>
|
|
|
|
#include <TinyGPS++.h>
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
#include "display.h"
|
2020-11-03 19:11:10 +00:00
|
|
|
#include "pins.h"
|
2020-11-01 22:19:32 +00:00
|
|
|
#include <TimeLib.h>
|
2020-04-03 21:21:35 +00:00
|
|
|
|
2020-11-03 19:08:24 +00:00
|
|
|
#ifdef TTGO_T_Beam_V1_0
|
|
|
|
#include <axp20x.h>
|
2020-05-17 14:16:53 +00:00
|
|
|
void setup_axp();
|
|
|
|
AXP20X_Class axp;
|
2020-05-11 10:16:56 +00:00
|
|
|
#endif
|
2020-04-03 21:21:35 +00:00
|
|
|
|
2020-05-17 14:16:53 +00:00
|
|
|
HardwareSerial ss(1);
|
|
|
|
TinyGPSPlus gps;
|
|
|
|
void setup_gps();
|
2020-04-03 21:21:35 +00:00
|
|
|
String create_lat_aprs(RawDegrees lat);
|
|
|
|
String create_long_aprs(RawDegrees lng);
|
|
|
|
|
2020-05-17 14:16:53 +00:00
|
|
|
void setup_lora();
|
|
|
|
|
2020-11-01 22:19:32 +00:00
|
|
|
static time_t nowTimeStamp = -1;
|
|
|
|
static time_t nextUpdateTimeStamp = -1;
|
|
|
|
static bool send_update = true;
|
|
|
|
|
2020-05-29 19:13:33 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2020-04-03 21:21:35 +00:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
setup_display();
|
|
|
|
|
|
|
|
delay(500);
|
2020-04-05 18:19:31 +00:00
|
|
|
Serial.println("[INFO] LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
|
|
|
|
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 2000);
|
2020-04-03 21:21:35 +00:00
|
|
|
|
2020-11-03 19:08:24 +00:00
|
|
|
#ifdef TTGO_T_Beam_V1_0
|
2020-05-17 14:16:53 +00:00
|
|
|
setup_axp();
|
2020-05-11 10:16:56 +00:00
|
|
|
#endif
|
2020-05-17 14:16:53 +00:00
|
|
|
setup_gps();
|
2020-04-03 21:21:35 +00:00
|
|
|
setup_lora();
|
|
|
|
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
|
2020-07-29 13:04:14 +00:00
|
|
|
String toDoubleInt(int number)
|
|
|
|
{
|
|
|
|
if(number < 10)
|
|
|
|
{
|
|
|
|
return "0" + String(number);
|
|
|
|
}
|
|
|
|
return String(number);
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:13:33 +00:00
|
|
|
// cppcheck-suppress unusedFunction
|
2020-04-03 21:21:35 +00:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
while (ss.available() > 0)
|
|
|
|
{
|
|
|
|
char c = ss.read();
|
2020-04-05 18:19:31 +00:00
|
|
|
//Serial.print(c);
|
2020-04-03 21:21:35 +00:00
|
|
|
gps.encode(c);
|
|
|
|
}
|
|
|
|
|
2020-07-29 13:04:14 +00:00
|
|
|
bool gps_time_update = false;
|
2020-04-03 21:21:35 +00:00
|
|
|
if(gps.time.isUpdated())
|
|
|
|
{
|
2020-07-29 13:04:14 +00:00
|
|
|
gps_time_update = true;
|
|
|
|
}
|
|
|
|
|
2020-11-01 22:19:32 +00:00
|
|
|
if(gps.time.isValid())
|
2020-07-29 13:04:14 +00:00
|
|
|
{
|
2020-11-01 22:19:32 +00:00
|
|
|
setTime(gps.time.hour(),gps.time.minute(),gps.time.second(),gps.date.day(),gps.date.month(),gps.date.year());
|
|
|
|
nowTimeStamp = now();
|
|
|
|
|
|
|
|
if (nextUpdateTimeStamp <= nowTimeStamp || nextUpdateTimeStamp == -1)
|
|
|
|
{
|
|
|
|
send_update = true;
|
|
|
|
}
|
2020-07-29 13:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(send_update && gps.location.isValid() && gps.location.isUpdated())
|
|
|
|
{
|
2020-11-01 22:19:32 +00:00
|
|
|
nextUpdateTimeStamp = nowTimeStamp + (BEACON_TIMEOUT * 60);
|
2020-07-29 13:04:14 +00:00
|
|
|
send_update = false;
|
|
|
|
|
|
|
|
APRSMessage msg;
|
|
|
|
msg.setSource(CALL);
|
|
|
|
msg.setDestination("APLT0");
|
|
|
|
String lat = create_lat_aprs(gps.location.rawLat());
|
|
|
|
String lng = create_long_aprs(gps.location.rawLng());
|
|
|
|
msg.getAPRSBody()->setData(String("=") + lat + "/" + lng + ">" + BEACON_MESSAGE);
|
|
|
|
String data = msg.encode();
|
|
|
|
Serial.println(data);
|
|
|
|
show_display("<< TX >>", data);
|
|
|
|
LoRa.beginPacket();
|
|
|
|
// Header:
|
|
|
|
LoRa.write('<');
|
|
|
|
LoRa.write(0xFF);
|
|
|
|
LoRa.write(0x01);
|
|
|
|
// APRS Data:
|
|
|
|
LoRa.write((const uint8_t *)data.c_str(), data.length());
|
|
|
|
LoRa.endPacket();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(gps_time_update)
|
|
|
|
{
|
2020-05-17 14:16:53 +00:00
|
|
|
show_display(CALL,
|
2020-07-29 13:04:14 +00:00
|
|
|
String("Time: ") + toDoubleInt(gps.time.hour()) + String(":") + toDoubleInt(gps.time.minute()) + String(":") + toDoubleInt(gps.time.second()),
|
|
|
|
String("Date: ") + toDoubleInt(gps.date.day()) + String(".") + toDoubleInt(gps.date.month()) + String(".") + gps.date.year(),
|
2020-04-03 21:21:35 +00:00
|
|
|
String("Sat's: ") + gps.satellites.value() + String(" HDOP: ") + gps.hdop.hdop(),
|
|
|
|
String("Lat: ") + gps.location.lat() + String(" Lng: ") + gps.location.lng(),
|
|
|
|
String("") + create_lat_aprs(gps.location.rawLat()) + String(" ") + create_long_aprs(gps.location.rawLng())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-29 13:04:14 +00:00
|
|
|
|
2020-04-03 21:21:35 +00:00
|
|
|
if(millis() > 5000 && gps.charsProcessed() < 10)
|
|
|
|
{
|
|
|
|
Serial.println("No GPS detected!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 19:08:24 +00:00
|
|
|
#ifdef TTGO_T_Beam_V1_0
|
2020-05-17 14:16:53 +00:00
|
|
|
void setup_axp()
|
|
|
|
{
|
|
|
|
Wire.begin(SDA, SCL);
|
|
|
|
if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS))
|
|
|
|
{
|
|
|
|
Serial.println("LoRa-APRS / Init / AXP192 Begin PASS");
|
|
|
|
} else {
|
|
|
|
Serial.println("LoRa-APRS / Init / AXP192 Begin FAIL");
|
|
|
|
}
|
|
|
|
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA
|
|
|
|
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS
|
|
|
|
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); // OLED
|
|
|
|
axp.setDCDC1Voltage(3300);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-03 21:21:35 +00:00
|
|
|
void setup_lora()
|
|
|
|
{
|
|
|
|
Serial.println("[INFO] Set SPI pins!");
|
2020-05-11 14:11:07 +00:00
|
|
|
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
|
|
|
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
2020-04-03 21:21:35 +00:00
|
|
|
Serial.println("[INFO] Set LoRa pins!");
|
|
|
|
|
|
|
|
long freq = 433775000;
|
|
|
|
Serial.print("[INFO] frequency: ");
|
|
|
|
Serial.println(freq);
|
|
|
|
if (!LoRa.begin(freq)) {
|
|
|
|
Serial.println("[ERROR] Starting LoRa failed!");
|
|
|
|
show_display("ERROR", "Starting LoRa failed!");
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
LoRa.setSpreadingFactor(12);
|
|
|
|
LoRa.setSignalBandwidth(125E3);
|
|
|
|
LoRa.setCodingRate4(5);
|
|
|
|
LoRa.enableCrc();
|
2020-04-08 11:03:11 +00:00
|
|
|
|
|
|
|
LoRa.setTxPower(20);
|
2020-04-03 21:21:35 +00:00
|
|
|
Serial.println("[INFO] LoRa init done!");
|
|
|
|
show_display("INFO", "LoRa init done!", 2000);
|
|
|
|
}
|
|
|
|
|
2020-05-17 14:16:53 +00:00
|
|
|
void setup_gps()
|
|
|
|
{
|
|
|
|
ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX);
|
|
|
|
}
|
|
|
|
|
2020-04-03 21:21:35 +00:00
|
|
|
String create_lat_aprs(RawDegrees lat)
|
|
|
|
{
|
|
|
|
char str[20];
|
|
|
|
char n_s = 'N';
|
|
|
|
if(lat.negative)
|
|
|
|
{
|
|
|
|
n_s = 'S';
|
|
|
|
}
|
|
|
|
sprintf(str, "%02d%05.2f%c", lat.deg, lat.billionths / 1000000000.0 * 60.0, n_s);
|
|
|
|
String lat_str(str);
|
|
|
|
return lat_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
String create_long_aprs(RawDegrees lng)
|
|
|
|
{
|
|
|
|
char str[20];
|
|
|
|
char e_w = 'E';
|
|
|
|
if(lng.negative)
|
|
|
|
{
|
|
|
|
e_w = 'W';
|
|
|
|
}
|
|
|
|
sprintf(str, "%03d%05.2f%c", lng.deg, lng.billionths / 1000000000.0 * 60.0, e_w);
|
|
|
|
String lng_str(str);
|
|
|
|
return lng_str;
|
|
|
|
}
|