settings.h replaced

This commit is contained in:
roland 2021-03-05 15:01:07 +01:00
parent 4c1f3fde78
commit 9cc42b7c66
10 changed files with 193 additions and 126 deletions

View file

@ -1,4 +1,6 @@
# LoRa APRS Tracker
# LoRa APRS Tracker
Forked from <https://github.com/lora-aprs/LoRa_APRS_Tracker>, Peter, OE5BPA
The LoRa APRS Tracker will work with very cheep hardware which you can buy from amazon, ebay or aliexpress.
Try it out and be part of the APRS network.
@ -15,12 +17,9 @@ You can use one of the Lora32 boards:
This boards cost around 30 Euros, they are very cheap but perfect for an LoRa iGate.
Keep in minde: you need a 433MHz version!
## Compiling
## Intention
### How to compile
The best success is to use PlatformIO. Go to https://platformio.org/ and download the IDE. Just open the folder and you can compile the Firmware.
Here is a [Video](https://www.youtube.com/watch?v=clIlTEFbWLk&feature=emb_logo) tutorial in german language how to install the software.
I forked this version because of my intention to build a specialized tracker for my mobile home. It should collect data from some sensors, weather condition etc. and send it to the APRS-System in two ways: If no wifi is present, it should just send the Packet to 433 MHz. If a known wifi is present, it should try to send the packet via wifi to the APRS-System direct.
### Dependencies
@ -32,12 +31,20 @@ Here is a [Video](https://www.youtube.com/watch?v=clIlTEFbWLk&feature=emb_logo)
## Configuration
Change your configuration in settings.h
Change your configuration in /data/is-cfg,json
## Future plans
The complete configuration should move to [IotWebConf](https://github.com/prampec/IotWebConf).
At the source i forked the complete configuration may move to [IotWebConf](https://github.com/prampec/IotWebConf).
It may possible i move too...
## LoRa iGate
* [ ] add sending packet direct via wifi to aprs-net (using work from Peter, OE5BPA)
* [ ] some refactoring
* [ ] REST-API or communication with webserver
* [ ] web-page sensors information
* [ ] etc.
Look at my other project: a [LoRa iGate](https://github.com/peterus/LoRa_APRS_iGate)
# History
01.03.2021 Forked
05.03.2021 Moved configuration to json-file in filesystem

View file

@ -1,34 +1,38 @@
{
"callsign":"DF1OE-12",
"callsign":"NOCALL-10",
"debug": false,
"beacon":
{
"message":"LoRa APRS Tracker Test",
"position":
{
"latitude":52.390212,
"longitude":9.745379
},
"message":"TTGO LoRA-APRS Tracker",
"timeout": 1,
"symbol": "[",
"overlay": "/"
"overlay": "/"
},
"smart_beacon":
{
"active":false,
"turn_min":25,
"slow_rate":300,
"slow_speed":10,
"fast_rate":60,
"fast_speed":100,
"min_tx_dist":100,
"min_bcn":5
},
"wifi":
{
"active":true,
"active":false,
"AP": [
{ "SSID":"DF1OE@JO42UJ", "password":"40683742350238290821" },
{ "SSID":"DF1OE-H48", "password":"hamRadio4all" },
{ "SSID":"DF1OE/m", "password":"dataRadio#"}
{ "SSID":"yourssid", "password":"yoursecrets" }
]
},
"lora":
{
"frequency_rx":433775000,
"frequency_tx":433775000,
"frequency_rx":433775E3,
"frequency_tx":433775E3,
"power":20,
"spreading_factor":12,
"signal_bandwidth":125000,
"signal_bandwidth":125E3,
"coding_rate4":5
}
}

View file

@ -1,6 +1,6 @@
[env]
platform = espressif32
platform = https://github.com/platformio/platform-espressif32.git
framework = arduino
lib_ldf_mode = deep+
monitor_speed = 115200

View file

@ -4,8 +4,6 @@
#include <TinyGPS++.h>
#include <TimeLib.h>
#include <WiFi.h>
#include "settings.h"
#include "display.h"
#include "pins.h"
#include "power_management.h"
@ -28,6 +26,7 @@ String create_lat_aprs(RawDegrees lat);
String create_long_aprs(RawDegrees lng);
String createDateString(time_t t);
String createTimeString(time_t t);
String getSmartBeaconState();
static bool send_update = true;
@ -43,7 +42,7 @@ int lastTxTime = millis();
void setup()
{
Serial.begin(115200);
load_config();
#ifdef TTGO_T_Beam_V1_0
Wire.begin(SDA, SCL);
@ -64,13 +63,10 @@ void setup()
delay(500);
Serial.println("[INFO] LoRa APRS Tracker by OE5BPA (Peter Buchegger)");
setup_display();
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 2000);
#ifdef SB_ACTIVE
Serial.println("[INFO] Smart Beaconing Active");
// show_display("DJ1AN", "Smart Beaconing","Active", 1000);
#endif
show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "[INFO] Smart Beacon is " + getSmartBeaconState(), 2000);
load_config();
setup_gps();
setup_lora();
@ -78,28 +74,31 @@ void setup()
WiFi.mode(WIFI_OFF);
btStop();
delay(500);
Serial.println("[INFO] Smart Beacon is " + getSmartBeaconState());
Serial.println("[INFO] setup done...");
delay(500);
}
// cppcheck-suppress unusedFunction
void loop()
{
#if !defined(DEBUGMODE)
if (Config.debug == false)
while (ss.available() > 0)
{
char c = ss.read();
//Serial.print(c);
gps.encode(c);
}
#else
else
{
while (Serial.available() > 0)
{
char c = Serial.read();
//Serial.print(c);
gps.encode(c);
}
#endif
}
bool gps_time_update = gps.time.isUpdated();
bool gps_loc_update = gps.location.isUpdated();
@ -116,7 +115,8 @@ void loop()
}
#ifdef SB_ACTIVE
if (Config.smart_beacon.active)
{
send_update = false;
if ( gps_loc_update )
{
@ -135,15 +135,15 @@ void loop()
}
headingDelta = (int) ( previousHeading - currentHeading ) % 360;
int turn_slope = 100;
headingTresh = (float) SB_TURN_MIN + turn_slope / gps.speed.kmph();
headingTresh = (float) Config.smart_beacon.turn_min + turn_slope / gps.speed.kmph();
int lastTx = millis() - lastTxTime;
if ( lastTx > SB_MIN_BCN * 1000)
if ( lastTx > Config.smart_beacon.min_bcn * 1000)
{
//send_update = true;
// Check for heading more than 25 degrees
if ( (headingDelta < -SB_TURN_MIN || headingDelta > SB_TURN_MIN) && lastTxdistance > SB_MIN_TX_DIST )
if ( (headingDelta < -Config.smart_beacon.turn_min || headingDelta > Config.smart_beacon.turn_min) && lastTxdistance > Config.smart_beacon.min_tx_dist )
{
send_update = true;
}
@ -159,12 +159,20 @@ void loop()
}
}
}
#endif
}
if(send_update && gps.location.isValid() && gps_loc_update)
{
#ifdef TTGO_T_Beam_V1_0
String volts = "Bat.: " + powerManagement.getBatteryVoltageStr() + " V";
String amps = "Cur.:" + powerManagement.getBatteryChargeDischargeCurrentStr() + " mA";
String sats = String("Sats: ") + gps.satellites.value();
#endif
powerManagement.deactivateMeasurement();
nextBeaconTimeStamp = now() + (Config.beacon.timeout * SECS_PER_MIN);
String nextbcnStr = String("Nxt Bcn: ") + createTimeString(nextBeaconTimeStamp);
send_update = false;
APRSMessage msg;
@ -172,7 +180,8 @@ void loop()
msg.setDestination("APLT0");
String lat = create_lat_aprs(gps.location.rawLat());
String lng = create_long_aprs(gps.location.rawLng());
msg.getAPRSBody()->setData(String("=") + lat + Config.beacon.overlay + lng + Config.beacon.symbol + Config.beacon.message);
msg.getAPRSBody()->setData(String("=") + lat + Config.beacon.overlay + lng + Config.beacon.symbol + Config.beacon.message + " - " + volts + " - " + amps + " - " + sats);
String data = msg.encode();
Serial.println(data);
show_display("<< TX >>", data);
@ -186,14 +195,14 @@ void loop()
LoRa.endPacket();
powerManagement.activateMeasurement();
#ifdef SB_ACTIVE
lastTxLat = gps.location.lat();
lastTxLng = gps.location.lng();
previousHeading = currentHeading;
lastTxdistance = 0;
lastTxTime = millis();
#endif
if (Config.smart_beacon.active)
{
lastTxLat = gps.location.lat();
lastTxLng = gps.location.lng();
previousHeading = currentHeading;
lastTxdistance = 0;
lastTxTime = millis();
}
}
if(gps_time_update)
@ -210,37 +219,39 @@ void loop()
#ifdef TTGO_T_Beam_V1_0
, String("Bat: ") + batteryVoltage + "V " + batteryChargeCurrent + "mA"
#endif
, String("Smart Beacon is " + getSmartBeaconState())
);
#ifdef SB_ACTIVE
// Change the Tx internal based on the current speed
if ( gps.speed.kmph() < 5 )
{
txInterval = 300000; // Change Tx internal to 5 mins
}
else if ( gps.speed.kmph() < SB_SLOW_SPEED )
{
txInterval = SB_SLOW_RATE * 1000; // Change Tx interval
}
else if ( gps.speed.kmph() > SB_FAST_SPEED)
{
txInterval = SB_FAST_RATE * 1000; // Change Tx interval
}
else
{
// Interval inbetween low and high speed
txInterval = (SB_FAST_SPEED / gps.speed.kmph()) * SB_FAST_RATE * 1000;
}
#endif
if (Config.smart_beacon.active)
{
// Change the Tx internal based on the current speed
if ( gps.speed.kmph() < 5 )
{
txInterval = 300000; // Change Tx internal to 5 mins
}
else if ( gps.speed.kmph() < Config.smart_beacon.slow_speed )
{
txInterval = Config.smart_beacon.slow_rate * 1000; // Change Tx interval
}
else if ( gps.speed.kmph() > Config.smart_beacon.fast_speed)
{
txInterval = Config.smart_beacon.fast_rate * 1000; // Change Tx interval
}
else
{
// Interval inbetween low and high speed
txInterval = (Config.smart_beacon.fast_speed / gps.speed.kmph()) * Config.smart_beacon.fast_rate * 1000;
}
}
}
#if !defined(DEBUGMODE)
if(millis() > 5000 && gps.charsProcessed() < 10)
if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10))
{
Serial.println("No GPS detected!");
}
#endif
}
@ -340,3 +351,17 @@ String createTimeString(time_t t)
sprintf(line, "%02d:%02d:%02d", hour(t), minute(t), second(t));
return String(line);
}
String getSmartBeaconState()
{
String sm_beaconstate = "";
if (Config.smart_beacon.active == true)
{
sm_beaconstate = "On";
}
else
{
sm_beaconstate = "Off";
}
return sm_beaconstate;
}

View file

@ -22,20 +22,24 @@ Configuration ConfigurationManagement::readConfiguration()
File file = SPIFFS.open(mFilePath);
if(!file)
{
logPrintlnE("Failed to open file for reading...");
Serial.println("Failed to open file for reading...");
return Configuration();
}
DynamicJsonDocument data(2048);
DeserializationError error = deserializeJson(data, file);
DeserializationError error = deserializeJson(data, file); // update config in memory to get the new fields:
// writeConfiguration(conf);
if(error)
{
logPrintlnW("Failed to read file, using default configuration.");
Serial.println("Failed to read file, using default configuration.");
}
serializeJson(data, Serial);
Serial.println();
file.close();
Configuration conf;
if(data.containsKey("debug"))
conf.debug = data["debug"] | false;
if(data.containsKey("callsign"))
conf.callsign = data["callsign"].as<String>();
@ -50,11 +54,20 @@ Configuration ConfigurationManagement::readConfiguration()
}
if(data.containsKey("beacon") && data["beacon"].containsKey("message"))
conf.beacon.message = data["beacon"]["message"].as<String>();
conf.beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0;
conf.beacon.positionLongitude = data["beacon"]["position"]["longitude"] | 0.0;
conf.beacon.timeout = data["beacon"]["timeout"] | 1;
conf.beacon.overlay = data["beacon"]["overlay"].as<String>();
conf.beacon.symbol = data["beacon"]["overlay"] | "/";
conf.beacon.symbol = data["beacon"]["symbol"].as<String>();
conf.beacon.overlay = data["beacon"]["overlay"].as<String>() ;
conf.smart_beacon.active = data["smart_beacon"]["active"];
conf.smart_beacon.turn_min = data["smart_beacon"]["turn_min"];
conf.smart_beacon.slow_rate = data["smart_beacon"]["slow_rate"];
conf.smart_beacon.slow_speed = data["smart_beacon"]["slow_speed"];
conf.smart_beacon.fast_rate = data["smart_beacon"]["fast_rate"];
conf.smart_beacon.fast_speed = data["smart_beacon"]["fast_speed"];
conf.smart_beacon.min_tx_dist = data["smart_beacon"]["min_tx_dist"];
conf.smart_beacon.min_bcn = data["smart_beacon"]["min_bcn"];
conf.aprs_is.active = data["aprs_is"]["active"] | false;
if(data.containsKey("aprs_is") && data["aprs_is"].containsKey("password"))
@ -95,10 +108,6 @@ Configuration ConfigurationManagement::readConfiguration()
us.password = "ftp";
conf.ftp.users.push_back(us);
}
// update config in memory to get the new fields:
writeConfiguration(conf);
return conf;
}
@ -122,8 +131,15 @@ void ConfigurationManagement::writeConfiguration(Configuration conf)
v["password"] = ap.password;
}
data["beacon"]["message"] = conf.beacon.message;
data["beacon"]["position"]["latitude"] = conf.beacon.positionLatitude;
data["beacon"]["position"]["longitude"] = conf.beacon.positionLongitude;
data["smart_beacon"]["active"] = conf.smart_beacon.active;
data["smart_beacon"]["turn_min"] = conf.smart_beacon.turn_min;
data["smart_beacon"]["slow_rate"] = conf.smart_beacon.slow_rate;
data["smart_beacon"]["slow_speed"] = conf.smart_beacon.slow_speed;
data["smart_beacon"]["fast_rate"] = conf.smart_beacon.fast_rate;
data["smart_beacon"]["fast_speed"] = conf.smart_beacon.fast_speed;
data["smart_beacon"]["min_tx_dist"] = conf.smart_beacon.min_tx_dist;
data["smart_beacon"]["min_bcn"] = conf.smart_beacon.min_bcn ;
data["aprs_is"]["active"] = conf.aprs_is.active;
data["aprs_is"]["password"] = conf.aprs_is.password;
data["aprs_is"]["server"] = conf.aprs_is.server;

View file

@ -30,14 +30,28 @@ public:
class Beacon
{
public:
Beacon() : message("LoRa Tracker, Info: github.com/peterus/LoRa_APRS_Tracker"), positionLatitude(0.0), positionLongitude(0.0) {}
Beacon() : message("LoRa Tracker, Info: github.com/peterus/LoRa_APRS_Tracker") {}
String message;
int timeout = 1;
String symbol = ">";
String overlay = "/";
double positionLatitude;
double positionLongitude;
String symbol;
String overlay;
};
class Smart_Beacon
{
public:
Smart_Beacon() : active(true), turn_min(25), slow_rate(300), slow_speed(10), fast_rate(60), fast_speed(100), min_tx_dist(100), min_bcn(5) {}
bool active;
int turn_min;
int slow_rate;
int slow_speed;
int fast_rate;
int fast_speed;
int min_tx_dist;
int min_bcn;
};
class APRS_IS
@ -67,7 +81,7 @@ public:
class LoRa
{
public:
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {}
LoRa() : frequencyRx(433775E3), frequencyTx(433775E3), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {}
long frequencyRx;
long frequencyTx;
@ -108,11 +122,13 @@ public:
String callsign;
Wifi wifi;
Beacon beacon;
Smart_Beacon smart_beacon;
APRS_IS aprs_is;
Digi digi;
LoRa lora;
Display display;
Ftp ftp;
bool debug;
};
class ConfigurationManagement

View file

@ -4,7 +4,6 @@
#include <Adafruit_SSD1306.h>
#include "display.h"
#include "settings.h"
#include "pins.h"
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);

View file

@ -75,13 +75,38 @@ double PowerManagement::getBatteryVoltage()
return axp.getBattVoltage() / 1000.0;
}
// cppcheck-suppress unusedFunction
String PowerManagement::getBatteryVoltageStr()
{
double volts = axp.getBattVoltage() / 1000.0;
return String(volts);
}
// cppcheck-suppress unusedFunction
double PowerManagement::getBatteryChargeDischargeCurrent()
{
if(axp.isChargeing())
{
return axp.getBattChargeCurrent();
}
return -1.0 * axp.getBattDischargeCurrent();
}
// cppcheck-suppress unusedFunction
String PowerManagement::getBatteryChargeDischargeCurrentStr()
{
double amps = 0.0;
if(axp.isChargeing())
{
amps = axp.getBattChargeCurrent();
}
else
{
amps = -1.0 * axp.getBattDischargeCurrent();
};
return String(amps,'\000');
}

View file

@ -25,6 +25,9 @@ public:
double getBatteryVoltage();
double getBatteryChargeDischargeCurrent();
String getBatteryVoltageStr();
String getBatteryChargeDischargeCurrentStr();
private:
AXP20X_Class axp;
};

View file

@ -1,28 +0,0 @@
#ifndef SETTINGS_H_
#define SETTINGS_H_
//#define CALL "DF1OE-12"
//#define BEACON_MESSAGE "LoRa APRS SB Tracker test"
//#define BEACON_TIMEOUT 1 // Beacon interval in Minutes. Will be overwritten by SB_ACTIVE
//#define SYMBOL_CODE "["
//#define SYMBOL_OVERLAY "/"
// Freq and Mode Setup - 2021-02-17 YC1HVZ
// #define FREQ_SET 433775E3 //set freq in KHz XxxXxxE3 6 digit. E3 is KHz
// #define SF_SET 12 //Spreading Factor
// #define CR_SET 5 //Coding Rate
// #define BW_SET 125E3 //Bandwith -> E3 is khz
// SMART BEACONING PARAMETERS - 2020-11-22 DJ1AN
#define SB_ACTIVE // uncomment to enable Smart Beaconing
#define SB_TURN_MIN 25 // enter turn angle for smart direction depending beaconing (default=20)
#define SB_SLOW_RATE 300 // slow speed TX rate in s
#define SB_SLOW_SPEED 10 // slow speed in km/h
#define SB_FAST_RATE 60 // high speed TX rate in s
#define SB_FAST_SPEED 100 // fast speed in km/h
#define SB_MIN_TX_DIST 100 // minimum Distance between tx in m
#define SB_MIN_BCN 5 // minimum SB rate in s
//#define DEBUGMODE // uncomment to activate Debug Mode. Gets GPS Data over Serial.
#endif