From 72414cd40d8bbed76cdfbbd642464f085cc34589 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 28 Jan 2023 19:54:42 -0300 Subject: [PATCH] change beacon 2.0 --- README.md | 5 +- src/Lora_1W_APRS_Tracker.cpp | 86 +++++++++++++++++++++++++++++------ src/beacon_config.h | 74 ++++++++++++++++++++---------- src/{pins.h => pins_config.h} | 4 +- src/user_config.h | 9 ---- 5 files changed, 127 insertions(+), 51 deletions(-) rename src/{pins.h => pins_config.h} (94%) delete mode 100644 src/user_config.h diff --git a/README.md b/README.md index d60a3e8..0867926 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,10 @@ Achievements: - custom smartbeacon values for each CALLSIGN - force Tx with the "short" push of a button. - send enconded GPS data packet for shorter and realiable comunication. -- To add (shortly) working on it +- Select to send "Course + Speed" or "Altitude + Speed" in encoded APRS data packet + + +To add (shortly) working on it - turn_slope for course angle smartbeacon - oled screen (allready bought ... and waiting.. ) diff --git a/src/Lora_1W_APRS_Tracker.cpp b/src/Lora_1W_APRS_Tracker.cpp index 4e43b19..87853a0 100644 --- a/src/Lora_1W_APRS_Tracker.cpp +++ b/src/Lora_1W_APRS_Tracker.cpp @@ -14,8 +14,7 @@ https://github.com/sh123/esp32_loraprs #include #include #include -#include "user_config.h" -#include "pins.h" +#include "pins_config.h" #include "lora_config.h" #include "beacon_config.h" @@ -26,8 +25,23 @@ HardwareSerial neo6m_gps(1); TinyGPSPlus gps; OneButton UserButton1 = OneButton(BUTTON1_PIN, true, true); + +String CurrentUser[10]; static bool send_update = true; +String CALLSIGN_CONFIG_1[10] = {User1_Callsign,User1_Symbol,String(User1_SlowRate),String(User1_SlowSpeed), + String(User1_FastRate),String(User1_FastSpeed),String(User1_MinDistTx), + String(User1_MinDeltaBcn),String(User1_TurnMin),String(User1_TurnSlope)}; + +String CALLSIGN_CONFIG_2[10] = {User2_Callsign,User2_Symbol,String(User2_SlowRate),String(User2_SlowSpeed), + String(User2_FastRate),String(User2_FastSpeed),String(User2_MinDistTx), + String(User2_MinDeltaBcn),String(User2_TurnMin),String(User2_TurnSlope)}; + +String CALLSIGN_CONFIG_3[10] = {User3_Callsign,User3_Symbol,String(User3_SlowRate),String(User3_SlowSpeed), + String(User3_FastRate),String(User3_FastSpeed),String(User3_MinDistTx), + String(User3_MinDeltaBcn),String(User3_TurnMin),String(User3_TurnSlope)}; + + void setup_lora_module() { int state = radio.begin(LoraFreqTx, LoraBandWidth, LoraSpreadingFactor, LoraCodingRate, LoraSyncWord, LoraOutro, LoraPreampbleLenght); radio.setOutputPower(Lora_Power); @@ -44,24 +58,58 @@ void setup_gps_module() { neo6m_gps.begin(9600, SERIAL_8N1, GPS_TXD, GPS_RXD); } +void setup_first_user() { + for (int i = 0; i<10; i++ ) { + CurrentUser[i] = CALLSIGN_CONFIG_1[i]; + } + Serial.print("Current User --> "); + Serial.println(CurrentUser[0]); +} + static void ForcedBeaconTx() { Serial.println("Forced Beacon Tx"); send_update = true; } +static void HandleNextBeacon() { + if (CurrentUser[0] == CALLSIGN_CONFIG_1[0]){ + Serial.print("Changing CALLSIGN to --> "); + Serial.println(CALLSIGN_CONFIG_2[0]); + for (int i = 0; i<10; i++ ) { + CurrentUser[i] = CALLSIGN_CONFIG_2[i]; + } + } else if (CurrentUser[0] == CALLSIGN_CONFIG_2[0]){ + Serial.print("Changing CALLSIGN to --> "); + Serial.println(CALLSIGN_CONFIG_3[0]); + for (int i = 0; i<10; i++ ) { + CurrentUser[i] = CALLSIGN_CONFIG_3[i]; + } + } else if (CurrentUser[0] == CALLSIGN_CONFIG_3[0]){ + Serial.print("Changing CALLSIGN to --> "); + Serial.println(CALLSIGN_CONFIG_1[0]); + for (int i = 0; i<10; i++ ) { + CurrentUser[i] = CALLSIGN_CONFIG_1[i]; + } + } +} + void setup() { Serial.begin(115200); - Serial.println(F("LoRa tracker " __DATE__ " " __TIME__ " / Callsign ------> " SRC_CALLSIGN)); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); - setup_lora_module(); - setup_gps_module(); - UserButton1.attachClick(ForcedBeaconTx); WiFi.mode(WIFI_OFF); btStop(); - Serial.print("Version = "); + UserButton1.attachClick(ForcedBeaconTx); + UserButton1.attachLongPressStart(HandleNextBeacon); + Serial.println(""); + Serial.println("****** LoRa APRS Tracker ******"); + Serial.println("https://github.com/richonguzman/LoRa_1W_APRS_Tracker"); + Serial.print("Version -------> "); Serial.println(VERSION); - Serial.println("Transmission Start ---->"); + setup_first_user(); + setup_lora_module(); + setup_gps_module(); + Serial.println("---Transmission Start ---"); } uint8_t tx_buffer[256]; @@ -97,9 +145,14 @@ void loop() { //static int speed_zero_sent = 0; if (!send_update && gps_loc_update) { - uint32_t lastTx = millis() - lastTxTime; - currentHeading = gps.course.deg(); - lastTxDistance = TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), lastTxLatitude, lastTxLongitude); + uint32_t lastTx = millis() - lastTxTime; + int MinimumDistanceTx = CurrentUser[6].toInt(); + int MinimumTimeDeltaBeacon = CurrentUser[7].toInt(); + int TurnDegrees = CurrentUser[8].toInt(); + int TurnSlope = CurrentUser[9].toInt(); + currentHeading = gps.course.deg(); + lastTxDistance = TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), lastTxLatitude, lastTxLongitude); + if (lastTx >= txInterval) { if (lastTxDistance > MinimumDistanceTx) { send_update = true; @@ -137,7 +190,7 @@ void loop() { if(Tlon < 0) { Tlon= -Tlon; } String AprsPacketMsg = "!"; - AprsPacketMsg += "/"; + AprsPacketMsg += AprsOverlay; char helper_base91[] = {"0000\0"}; int i; ax25_base91enc(helper_base91, 4, aprs_lat); @@ -149,7 +202,7 @@ void loop() { AprsPacketMsg += helper_base91[i]; } - AprsPacketMsg += SYMBOL; + AprsPacketMsg += CurrentUser[1]; // Symbol if (SendAltitude) { // Send Altitude or... (APRS calculates Speed also) int Alt1, Alt2; @@ -186,7 +239,7 @@ void loop() { memset(tx_buffer, 0x00, sizeof tx_buffer); uint16_t size = 0; - size = snprintf(reinterpret_cast(tx_buffer), sizeof tx_buffer, "\x3c\xff\x01%s>%s:%s", SRC_CALLSIGN, DST_CALLSIGN, AprsPacketMsg.c_str()); + size = snprintf(reinterpret_cast(tx_buffer), sizeof tx_buffer, "\x3c\xff\x01%s>%s:%s", CurrentUser[0], AprsPath, AprsPacketMsg.c_str()); Serial.print(millis()); // Only for Serial Monitor Serial.print(F(" transmitting: ")); @@ -206,6 +259,11 @@ void loop() { } if (gps_time_update) { // updating txInterval between Slow and FastRate or in between + int SlowRate = CurrentUser[2].toInt(); + int SlowSpeed = CurrentUser[3].toInt(); + int FastRate = CurrentUser[4].toInt(); + int FastSpeed = CurrentUser[5].toInt(); + int curr_speed = (int)gps.speed.kmph(); if (curr_speed < SlowSpeed) { txInterval = SlowRate * 1000; diff --git a/src/beacon_config.h b/src/beacon_config.h index d155687..dbbccf7 100644 --- a/src/beacon_config.h +++ b/src/beacon_config.h @@ -1,31 +1,55 @@ #ifndef BEACON_CONFIG_H_ #define BEACON_CONFIG_H_ -#define SlowRate 120 // Seg -#define SlowSpeed 10 // Km/h (3 Runner , 5 Bike, 10 Car) -#define FastRate 60 // Seg -#define FastSpeed 20 // Km/h (20 Runner y Bike, 70 Car) -#define TurnDegrees 20 // Degrees before Forced Beacon Tx (20 Car , 15 Bike/Runner) -#define MinimumDistanceTx 3 // Mts (20 Runner, 100 Car/Bike) -#define MinimumTimeDeltaBeacon 5 // Seg between Tx +//#define SlowRate 120 // Seg +//#define SlowSpeed 10 // Km/h (3 Runner , 5 Bike, 10 Car) +//#define FastRate 60 // Seg +//#define FastSpeed 20 // Km/h (20 Runner y Bike, 70 Car) +//#define TurnDegrees 20 // Degrees before Forced Beacon Tx (20 Car , 15 Bike/Runner) +//#define MinimumDistanceTx 3 // Mts (20 Runner, 100 Car/Bike) +//#define MinimumTimeDeltaBeacon 5 // Seg between Tx -#define SendAltitude true // "true" adds Altitude to the APRS packet/message, "false" add Course+Speed -#define SendComment false // "true" adds comment to the APRS packet/message +#define SendAltitude true // "true" adds Altitude to the APRS packet/message, "false" add Course+Speed +#define SendComment false // "true" adds comment to the APRS packet/message -#endif +#define APRS_COMMENT "Lora Tracker 1W" // if you want to send any comment change the APRS_COMMENT + // and also beacon_config.h > SendComment = true -/* -"callsign": "NOCALL-10", - "timeout": 1, - "symbol": "b", - "overlay": "/", - "smart_beacon": { - "active": true, - "turn_min": 15, - "slow_rate": 120, - "slow_speed": 5, - "fast_rate": 60, - "fast_speed": 20, - "min_tx_dist": 100, - "min_bcn": 5 -*/ \ No newline at end of file +#define AprsPath "AP" // APRS Destination (could be also "WIDE1-1") +#define AprsOverlay "/" + +#define User1_Callsign "CD2RXU-7" +#define User1_Symbol "[" // Runner +#define User1_SlowRate 120 +#define User1_SlowSpeed 3 +#define User1_FastRate 60 +#define User1_FastSpeed 20 +#define User1_MinDistTx 50 +#define User1_MinDeltaBcn 20 +#define User1_TurnMin 8 +#define User1_TurnSlope 60 + +#define User2_Callsign "CD2RXU-8" +#define User2_Symbol "b" // Bike +#define User2_SlowRate 180 +#define User2_SlowSpeed 5 +#define User2_FastRate 60 +#define User2_FastSpeed 40 +#define User2_MinDistTx 70 +#define User2_MinDeltaBcn 12 +#define User2_TurnMin 12 +#define User2_TurnSlope 80 + +#define User3_Callsign "CD2RXU-9" +#define User3_Symbol ">" // Car +#define User3_SlowRate 120 +#define User3_SlowSpeed 10 +#define User3_FastRate 60 +#define User3_FastSpeed 70 +#define User3_MinDistTx 100 +#define User3_MinDeltaBcn 10 +#define User3_TurnMin 15 +#define User3_TurnSlope 80 + + +#endif \ No newline at end of file diff --git a/src/pins.h b/src/pins_config.h similarity index 94% rename from src/pins.h rename to src/pins_config.h index 0099ca9..331129e 100644 --- a/src/pins.h +++ b/src/pins_config.h @@ -1,5 +1,5 @@ -#ifndef PINS_H_ -#define PINS_H_ +#ifndef PINS_CONFIG_H_ +#define PINS_CONFIG_H_ #define GPS_TXD 16 // Conection Pinout for GPS #define GPS_RXD 17 diff --git a/src/user_config.h b/src/user_config.h deleted file mode 100644 index 59b95c3..0000000 --- a/src/user_config.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef USER_CONFIG_H_ -#define USER_CONFIG_H_ - -#define SRC_CALLSIGN "CD2RXU-7" // Change "CD2RXU-7" to your CALLSIGN-SSID you would use in APRS -#define DST_CALLSIGN "AP" // APRS Destination (could be also "WIDE1-1") -#define SYMBOL "[" // APRS Symbol: "[" Runner, "b" Bike, ">" Auto/Car -#define APRS_COMMENT "Lora Tracker 1W" // if you want to send any comment change the APRS_COMMENT - // and also beacon_config.h > SendComment = true -#endif \ No newline at end of file