From 7bbea4eeaa9473bdcdd1b45aeb8ab13e5391422f Mon Sep 17 00:00:00 2001 From: Manuel Roesel Date: Sun, 6 Feb 2022 16:11:53 +0100 Subject: [PATCH] legacy validation bugfix / new relay feature --- README.md | 72 +++++++++++--- ognbase/APRS.h | 224 ++++++++++++++++++++++---------------------- ognbase/Log.cpp | 2 +- ognbase/MONIT.cpp | 2 +- ognbase/OLED.cpp | 18 +++- ognbase/PVALID.cpp | 41 ++++++-- ognbase/RF.cpp | 44 ++++++++- ognbase/RF.h | 2 + ognbase/Traffic.cpp | 27 +++++- ognbase/Web.cpp | 10 +- ognbase/WiFi.cpp | 5 +- ognbase/config.cpp | 26 ++++- ognbase/global.h | 3 + ognbase/ognbase.ino | 217 ++++++++++++++++++++++++------------------ ognbase/version.h | 10 +- 15 files changed, 459 insertions(+), 244 deletions(-) diff --git a/README.md b/README.md index a631af1..2726e07 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ There are also a few drawbacks to the traditional OGN receivers. Several protoco ## Harwdare * LILYGO TTGO T-Beam (Lora, GPS, Bluetooth, Wifi, OLED) * [TTGO T-Beam Aliexpress](https://s.click.aliexpress.com/e/_dTnxWSv) -* TTGO LoRa32 (**TESTING** - Lora, Bluetooth, Wifi, OLED) +* TTGO LoRa32 (Lora, Bluetooth, Wifi, OLED) ## Features: * Power consumption around 20 mA in sleep mode - 120mA on normal mode * 40 - 60 mA without GPS * OLED status messages * ntp time sync - no gps needed -* Deep Sleep +* Deep Sleep (only TTGO) * Auto wakeup on RX packages * Wakeup Timer * No additional computer necessary - only Wifi ; @@ -31,6 +31,9 @@ There are also a few drawbacks to the traditional OGN receivers. Several protoco * low cost hardware * Frequency hopping in legacy mode and ogn (868.2 / 868.4) - Thanks Nick * needs GPS fix +* Relay function - send data over air to basestation (2 TTGO/TBEAM needed) +* Private mode - encrypt FANET data with you own key + * modified SoftRF needed ## Planed Features * Protocol hopping - aprs messages are sent every 5 seconds - **in progress** @@ -59,7 +62,9 @@ NBP can also be encrypted. V0.1.0-25 ### Packet validation in LEGACY mode V0.1.0-24 -It is possible that a legacy packet is marked as valid by the crc check, although it is damaged. This can result in position jumps. A new validation routine was built in, which checks whether a position package can be valid based on the speed of the aircraft. +It is possible that a legacy packet is marked as valid by the crc check, although it is damaged. This can result in position jumps. A new validation routine was built in, which checks whether a position package can be valid based on the speed and position of the aircraft. + +ESP will calculate the flight distance from last two position packets and check if its possible with time and speed. Minimum two packets must be received and validated, otherwise position data not transmitted to ogn. ### Private network - V0.1.0-25 @@ -71,6 +76,33 @@ RF position packets AES128 encrypted **Precise instructions and a modified SoftRF version will follow.** +### Relay function - V0.1.0-28 + +If no internet connection is available, send received data to ogn base, base will transmit packets to ogn. +* relay protocol based on fanet +* 2 devices needed - 1 Relay - 1 Basestation (Base with internet access) + * line of sight from Relay to Base + +```json +"ognrelay":{ + "enable":1, + "basestation":0 +}, +``` +* enable + * Set to 1 for relay station +* basestation + * set to 1 for basestation (connected to ogn) + +**If enable set to 1, basesation will be automatically deactivated. If you want to run base, set enable to 0 and basesation to 1.** + +Relay will receive position data and send this every 2.5 seconds to basestation (on different frequency). Basestation will listen only on relay frequency and transmit packets via APRS to ogn. So you can create network with one basesation and many relays spread over different hills. In ogn you will only see the basesation. + +The protocol for relay connection are the same as configured on relay. If you receive legacy, relay will send legacy packets to base, only on different frequency. + +**In relay mode gps (if set static position) and Wifi will be disabled after 5 minutes.** + + ## Known bugs / Missing features * SNR calculation not correct * No RAM and CPU data in APRS status messages @@ -78,12 +110,14 @@ RF position packets AES128 encrypted * no turn rate in APRS messages (always zero) * disable sleep mode if everyone is connected to webserver * **DEEPSLEEP_RESET gets stuck after a few resets - arduino-esp32 #796** + * works only with TTGO without problems * and a lot more... ## If you find a bug... * create an issue or send me an email. * describe your problem in a few sentences +* create a pull request * I will try to deal with **all issues**, maybe it will take a little longer sometimes, just be patient ## Build Instructions @@ -91,7 +125,14 @@ RF position packets AES128 encrypted * install latest Arduino IDE * git clone https://github.com/roema/Open-Glider-Network-Groundstation.git --recursive * make sure the arduino ide is using the correct libraries. -* **take a look at pictures folder for arduino configuration*** +* take a look ath ognbase.ino + * #define TTGO / TBEAM + +### TTGO +![alt text](https://raw.githubusercontent.com/roema/Open-Glider-Network-Groundstation/main/pictures/TTGO.png) +### TBEAM + +![alt text](https://raw.githubusercontent.com/roema/Open-Glider-Network-Groundstation/main/pictures/TBEAM.png) ## Installation @@ -106,16 +147,18 @@ RF position packets AES128 encrypted ## Easy Installation / Upgrade * Download [binary image](https://github.com/roema/Open-Glider-Network-Groundstation/releases) and install it with web-updater + * SoftRF updater works too * Connect to Wifi OGN-XXXXXX with password 987654321 * Type 192.168.1.1 in you browser and you will see a file-upload page (only on first startup) * Upload index.html, update.html and style.css + * html files are not necessary. Only the config.json is required for operation. + * not all functions are available on webinterface * **new config.json is required!** * Reset and connect again ### Upgrade -**Since there were more and more faulty files during an update, the SPIFFS memory is formatted during a firmware update.** -TTGO T-Beam supports firmware upgrades via SDCARD. Take a look on ReadMe.txt in SDCARd folder. +TTGO T-Beam supports firmware upgrades via SDCARD. Take a look on ReadMe.txt in SDCARD folder. ## Configuration File - config.json @@ -132,7 +175,7 @@ TTGO T-Beam supports firmware upgrades via SDCARD. Take a look on ReadMe.txt in "xxxxxxx" ], "pass":[ - "password", + "pass", "xxxxxxx", "xxxxxxx", "xxxxxxx", @@ -147,8 +190,8 @@ TTGO T-Beam supports firmware upgrades via SDCARD. Take a look on ReadMe.txt in "geoidsep":55 }, "zabbix":{ - "enable":false, - "server":"127.0.0.1", + "enable":true, + "server":"5.150.254.37", "port":10051, "key":"ogn_base" }, @@ -156,9 +199,9 @@ TTGO T-Beam supports firmware upgrades via SDCARD. Take a look on ReadMe.txt in "enable":false }, "remotelogs":{ - "enable":false, - "server":"5.150.254.37", - "port":12000 + "enable":true, + "server":"10.0.1.200", + "port":12014 }, "aprs":{ "callsign":"Neuenburg", @@ -190,8 +233,9 @@ TTGO T-Beam supports firmware upgrades via SDCARD. Take a look on ReadMe.txt in "oled":{ "disable":0 }, - "testmode":{ - "enable":1 + "ognrelay":{ + "enable":1, + "basestation":0 }, "beers":{ "show":0 diff --git a/ognbase/APRS.h b/ognbase/APRS.h index 19941f1..1fde994 100644 --- a/ognbase/APRS.h +++ b/ognbase/APRS.h @@ -1,112 +1,112 @@ -/* - * OGN.h - * Copyright (C) 2020 Manuel Rösel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include "SoC.h" - - -#ifndef OGNHELPER_H -#define OGNHELPER_H - -//LKHS>APRS,TCPIP*,qAC,GLIDERN2:/211635h4902.45NI01429.51E&000/000/A=001689 - -struct aprs_reg_packet -{ - String origin; - String callsign; - String timestamp; - String lat_deg; - String lat_min; - String lon_deg; - String lon_min; - String alt; -}; - -struct aprs_login_packet // user OGN123456 pass 12345 vers DemoApp 0.0.0 filter m/10 -{ - String user; - String pass; - String appname; - String version; -}; - -// LKHS>APRS,TCPIP*,qAC,GLIDERN2:>211635h v0.2.6.ARM CPU:0.2 RAM:777.7/972.2MB NTP:3.1ms/-3.8ppm 4.902V 0.583A +33.6C -struct aprs_stat_packet -{ - String origin; - String callsign; - String timestamp; - String platform; - String cpu_usage; - String ram_max; - String ram_usage; - String realtime_clock; - String board_voltage; - String board_amperage; - String cpu_temperature; -}; - -// FLRDF0A52>APRS,qAS,LSTB:/220132h4658.70N/00707.72Ez090/054/A=001424 !W37! id06DF0A52 +020fpm +0.0rot 55.2dB 0e -6.2kHz gps4x6 s6.01 h03 rDDACC4 +5.0dBm hearD7EA hearDA95 -struct aprs_airc_packet -{ - String callsign; - String rec_callsign; - String timestamp; - String lat_deg; - String lat_min; - String lon_deg; - String lon_min; - String alt; - String heading; - String ground_speed; - String pos_precision; - String symbol_table; - String symbol; - String climbrate; - String sender_details; - String snr; -}; - -enum -{ - OGN_OFF, - OGN_ON, -}; - -static bool OGN_APRS_Connect(); - -static bool OGN_APRS_DisConnect(); - - -void OGN_APRS_Export(); - -void OGN_APRS_Weather(); - -int OGN_APRS_Register(ufo_t* this_aircraft); - -void OGN_APRS_KeepAlive(); - -bool OGN_APRS_check_Wifi(); - -void OGN_APRS_Status(ufo_t* this_aircraft); - -static int OGN_APRS_check_reg(String *); - -int OGN_APRS_check_messages(); - -#endif /* OGNHELPER_H */ +/* + * APRS.h + * Copyright (C) 2020 Manuel Rösel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "SoC.h" + + +#ifndef OGNHELPER_H +#define OGNHELPER_H + +//LKHS>APRS,TCPIP*,qAC,GLIDERN2:/211635h4902.45NI01429.51E&000/000/A=001689 + +struct aprs_reg_packet +{ + String origin; + String callsign; + String timestamp; + String lat_deg; + String lat_min; + String lon_deg; + String lon_min; + String alt; +}; + +struct aprs_login_packet // user OGN123456 pass 12345 vers DemoApp 0.0.0 filter m/10 +{ + String user; + String pass; + String appname; + String version; +}; + +// LKHS>APRS,TCPIP*,qAC,GLIDERN2:>211635h v0.2.6.ARM CPU:0.2 RAM:777.7/972.2MB NTP:3.1ms/-3.8ppm 4.902V 0.583A +33.6C +struct aprs_stat_packet +{ + String origin; + String callsign; + String timestamp; + String platform; + String cpu_usage; + String ram_max; + String ram_usage; + String realtime_clock; + String board_voltage; + String board_amperage; + String cpu_temperature; +}; + +// FLRDF0A52>APRS,qAS,LSTB:/220132h4658.70N/00707.72Ez090/054/A=001424 !W37! id06DF0A52 +020fpm +0.0rot 55.2dB 0e -6.2kHz gps4x6 s6.01 h03 rDDACC4 +5.0dBm hearD7EA hearDA95 +struct aprs_airc_packet +{ + String callsign; + String rec_callsign; + String timestamp; + String lat_deg; + String lat_min; + String lon_deg; + String lon_min; + String alt; + String heading; + String ground_speed; + String pos_precision; + String symbol_table; + String symbol; + String climbrate; + String sender_details; + String snr; +}; + +enum +{ + OGN_OFF, + OGN_ON, +}; + +static bool OGN_APRS_Connect(); + +static bool OGN_APRS_DisConnect(); + + +void OGN_APRS_Export(); + +void OGN_APRS_Weather(); + +int OGN_APRS_Register(ufo_t* this_aircraft); + +void OGN_APRS_KeepAlive(); + +bool OGN_APRS_check_Wifi(); + +void OGN_APRS_Status(ufo_t* this_aircraft); + +static int OGN_APRS_check_reg(String *); + +int OGN_APRS_check_messages(); + +#endif /* OGNHELPER_H */ diff --git a/ognbase/Log.cpp b/ognbase/Log.cpp index 276ff98..828282d 100644 --- a/ognbase/Log.cpp +++ b/ognbase/Log.cpp @@ -25,7 +25,7 @@ void Logger_send_udp(String* buf) { - if (ogn_debug) + if (ogn_debug && !ognrelay_enable) { int debug_len = buf->length() + 1; byte debug_msg[debug_len]; diff --git a/ognbase/MONIT.cpp b/ognbase/MONIT.cpp index 169c10f..d09181b 100644 --- a/ognbase/MONIT.cpp +++ b/ognbase/MONIT.cpp @@ -50,7 +50,7 @@ void MONIT_send_trap() String zb_msg = zs.createMessage(jsonPayload); - Logger_send_udp(&jsonPayload); + //Logger_send_udp(&jsonPayload); //byte buffer[zb_msg.length() + 1]; //zb_msg.getBytes(buffer, zb_msg.length() + 1); diff --git a/ognbase/OLED.cpp b/ognbase/OLED.cpp index 95c1fc1..001b839 100644 --- a/ognbase/OLED.cpp +++ b/ognbase/OLED.cpp @@ -169,7 +169,10 @@ void OLED_info(bool ntp) snprintf(buf, sizeof(buf), "SSID: %s", WiFi.SSID().c_str()); display.drawString(0, 9, buf); - snprintf(buf, sizeof(buf), "CS: %s", ogn_callsign); + if(ognrelay_enable) + snprintf(buf, sizeof(buf), "CS-R: %s", ogn_callsign); + else + snprintf(buf, sizeof(buf), "CS: %s", ogn_callsign); display.drawString(0, 18, buf); snprintf(buf, sizeof(buf), "Band: %s", ISO3166_CC[ogn_band]); @@ -241,7 +244,10 @@ void OLED_info(bool ntp) display.display(); - oled_site = 2; + if(!ognrelay_enable ) + oled_site = 2; + else + oled_site = 3; display.displayOn(); return; } @@ -290,7 +296,13 @@ void OLED_info(bool ntp) display.drawString(0, 36, buf); snprintf(buf, sizeof(buf), "GPS-FIX: %s", isValidFix() ? "true" : "false"); - display.drawString(0, 45, buf); + display.drawString(0, 45, buf); + + if(ognrelay_base) + snprintf(buf, sizeof(buf), "RELAY-B: %s", ognrelay_base ? "true" : "false"); + if(ognrelay_enable) + snprintf(buf, sizeof(buf), "RELAY: %s", ognrelay_enable ? "true" : "false"); + display.drawString(0, 54, buf); display.display(); if (beers_show) diff --git a/ognbase/PVALID.cpp b/ognbase/PVALID.cpp index 017d175..f2896d5 100644 --- a/ognbase/PVALID.cpp +++ b/ognbase/PVALID.cpp @@ -30,6 +30,8 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t double theta, dist; String msg; + speed = speed * 1.852; + /*V0.1.0-24*/ for (uint8_t i = 0; i < MAX_TRACKING_OBJECTS; i++) { @@ -43,13 +45,18 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t if (addr == ac[i].addr) { - msg = "ADDR found in database.."; + msg = "ADDR: "; + msg += String(addr, HEX); + msg += " found in database.."; Logger_send_udp(&msg); int dist = distance(lat1, lon1, ac[i].latitude, ac[i].longitude); msg = "Transmitted distance: "; msg += dist; + msg = "Transmitted speed: "; + msg += speed / 3.6; + msg += " m/s"; Logger_send_udp(&msg); int calcdist = calcMaxDistance(speed, timestamp - ac[i].timestamp); @@ -57,6 +64,11 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t msg = "Max calculated distance: "; msg += calcdist; + msg += "m Distance: "; + msg += dist; + msg += " m"; + msg += " timediff: "; + msg += timestamp - ac[i].timestamp; Logger_send_udp(&msg); msg = "Packet seems to be invalid"; @@ -70,6 +82,9 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t msg = "Max calculated distance: "; msg += calcdist; + msg += "m Distance: "; + msg += dist; + msg += "m"; Logger_send_udp(&msg); @@ -93,7 +108,7 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t return (false); } - +/* static int distance(double lat1, double lon1, double lat2, double lon2) { double theta, dist; double r = 6378137.0; @@ -113,14 +128,28 @@ static int distance(double lat1, double lon1, double lat2, double lon2) { double dist = 2 * r * asin(sqrt(pow(sin(dlat / 2), 2) + cos(lat1) * cos(lat2) * pow(sin(dlon / 2), 2))); - return (int)(dist); //distance in meter + return (int)(dist); //distance in km } } +*/ + +static int distance(double lat1, double lon1, double lat2, double lon2) { + double p = 0.017453292519943295; // Math.PI / 180 + double a = 0.5 - cos((lat2 - lat1) * p)/2 + cos(lat1 * p) * cos(lat2 * p) * (1 - cos((lon2 - lon1) * p))/2; + return (int)(12742 * asin(sqrt(a)) * 1000); +} static int calcMaxDistance(double speed, time_t time_diff) { - int speed_ms = speed / 3.6; - // 20% more than calculated - return (int)((speed * time_diff) * 1.2 ); + int speed_ms = speed; + + if(speed == 0){ + // GPS precision ... + return (int)(10); + } + else{ + // 20% more than calculated + return (int)((speed * time_diff / 3.6) * 1.2 ); + } } static bool appendPacket(uint32_t addr, double lat, double lon, time_t timestamp, uint8_t cnt) { diff --git a/ognbase/RF.cpp b/ognbase/RF.cpp index 2304c68..e84aa34 100644 --- a/ognbase/RF.cpp +++ b/ognbase/RF.cpp @@ -176,6 +176,11 @@ void RF_SetChannel(void) tmElements_t tm; time_t Time; + if (RF_ready && rf_chip && ognrelay_base){ + rf_chip->channel(4); + return; + } + switch (settings->mode) { case SOFTRF_MODE_GROUND: @@ -295,7 +300,7 @@ void RF_SetChannel(void) Serial.println(OGN); Serial.print("Channel: "); Serial.println(chan); - #endif +#endif if (RF_ready && rf_chip) rf_chip->channel(chan); @@ -370,6 +375,32 @@ bool RF_Transmit(size_t size, bool wait) return false; } +bool RF_Transmit_raw(size_t size, bool wait) +{ + if (RF_ready && rf_chip && (size > 0)) + { + RF_tx_size = size; + + if (settings->txpower == RF_TX_POWER_OFF) + settings->txpower = RF_TX_POWER_FULL; + + if (!wait || (millis() - TxTimeMarker) > TxRandomValue) + { + time_t timestamp = now(); + + rf_chip->transmit(); + + tx_packets_counter++; + RF_tx_size = 0; + + TxTimeMarker = millis(); + + return true; + } + } + return false; +} + bool RF_Receive(void) { bool rval = false; @@ -951,6 +982,7 @@ static void sx12xx_tx(unsigned char* buf, size_t size, osjobcb_t func) u1_t crc8; u2_t crc16; + switch (LMIC.protocol->crc_type) { case RF_CHECKSUM_TYPE_GALLAGER: @@ -1059,6 +1091,12 @@ static void sx12xx_txdone_func(osjob_t* job) static void sx12xx_tx_func(osjob_t* job) { - if (RF_tx_size > 0) - sx12xx_tx((unsigned char *) &TxBuffer[0], RF_tx_size, sx12xx_txdone_func); + if (RF_tx_size > 0){ + if(ognrelay_enable){ + rf_chip->channel(4); + } + sx12xx_tx((unsigned char *) &TxBuffer[0], RF_tx_size, sx12xx_txdone_func); + rf_chip->channel(0); + } + } diff --git a/ognbase/RF.h b/ognbase/RF.h index bd1dce8..ddb45ee 100644 --- a/ognbase/RF.h +++ b/ognbase/RF.h @@ -98,6 +98,8 @@ size_t RF_Encode_Fanet_s(ufo_t *); bool RF_Transmit(size_t, bool); +bool RF_Transmit_raw(size_t, bool); + bool RF_Receive(void); void RF_Shutdown(void); diff --git a/ognbase/Traffic.cpp b/ognbase/Traffic.cpp index 59c28e9..797b3e2 100644 --- a/ognbase/Traffic.cpp +++ b/ognbase/Traffic.cpp @@ -24,6 +24,7 @@ #include "Protocol_Legacy.h" #include "OLED.h" #include "global.h" +#include "Log.h" unsigned long UpdateTrafficTimeMarker = 0; @@ -141,13 +142,33 @@ void ParseData() rx_size = rx_size > sizeof(fo.raw) ? sizeof(fo.raw) : rx_size; char buf[16]; + String msg; -#if DEBUG - Hex2Bin(TxDataTemplate, RxBuffer); -#endif + msg = "RXBuffer: "; memset(fo.raw, 0, sizeof(fo.raw)); memcpy(fo.raw, RxBuffer, rx_size); + memcpy(TxBuffer, RxBuffer, rx_size); + + /* + Serial.print("RxBuffer: "); + + for(int i=0;ihasParam("callsign")) ogn_callsign = request->getParam("callsign")->value().c_str(); + ogn_callsign.trim(); + ogn_callsign.replace("_",""); + if(ogn_callsign.length() > 9){ + ogn_callsign = ogn_callsign.substring(0,9); + } if (request->hasParam("ogn_lat")) ogn_lat = request->getParam("ogn_lat")->value().toFloat(); @@ -433,7 +438,10 @@ void Web_loop(void) if (globalClient != NULL && globalClient->status() == WS_CONNECTED) { String values; - values =+SoC->Battery_voltage(); + if(SoC->Battery_voltage() > 3.2) + values =+SoC->Battery_voltage(); + else + values += 0.0; values += "_"; values += RF_last_rssi; values += "_"; diff --git a/ognbase/WiFi.cpp b/ognbase/WiFi.cpp index d407392..c633725 100644 --- a/ognbase/WiFi.cpp +++ b/ognbase/WiFi.cpp @@ -127,7 +127,7 @@ void WiFi_setup() delay(10); } - if (OGN_read_config()) + if (OGN_read_config() && !ognrelay_enable) { Serial.println(F("WiFi config changed.")); @@ -175,9 +175,6 @@ void WiFi_setup() { station_ssid = MY_ACCESSPOINT_SSID; station_psk = MY_ACCESSPOINT_PSK; - Serial.println(F("No WiFi connection information available.")); - snprintf(buf, sizeof(buf), "no config file found.."); - OLED_write(buf, 0, 25, false); WiFi.begin(); delay(1000); } diff --git a/ognbase/config.cpp b/ognbase/config.cpp index 1bfc7db..d2d86e8 100644 --- a/ognbase/config.cpp +++ b/ognbase/config.cpp @@ -101,7 +101,10 @@ bool new_protocol_enable; String new_protocol_server; uint32_t new_protocol_port; -//#define TTGO +//relay +bool ognrelay_enable = false; +bool ognrelay_base = false; + #ifdef TTGO @@ -288,6 +291,12 @@ bool OGN_read_config(void) if (1) { ogn_callsign = obj["aprs"]["callsign"].as(); + ogn_callsign.trim(); + ogn_callsign.replace("_",""); + if(ogn_callsign.length() > 9){ + ogn_callsign = ogn_callsign.substring(0,9); + } + ogn_server = obj["aprs"]["server"].as(); ogn_port = obj["aprs"]["port"]; @@ -351,7 +360,20 @@ bool OGN_read_config(void) { testmode_enable = obj["testmode"]["enable"]; } - } + } + + if (obj.containsKey(F("ognrelay"))) + { + //Serial.println(F("found relay config!")); + if (1) + { + ognrelay_enable = obj["ognrelay"]["enable"]; + if(ognrelay_enable) + ognrelay_base = 0; + else + ognrelay_base = obj["ognrelay"]["basestation"]; + } + } if (obj.containsKey(F("fanetservice"))) { diff --git a/ognbase/global.h b/ognbase/global.h index 06a72e8..96033fc 100644 --- a/ognbase/global.h +++ b/ognbase/global.h @@ -45,3 +45,6 @@ extern bool private_network; extern bool new_protocol_enable; extern String new_protocol_server; extern uint32_t new_protocol_port; + +extern bool ognrelay_enable; +extern bool ognrelay_base; diff --git a/ognbase/ognbase.ino b/ognbase/ognbase.ino index 5447208..7755ab9 100644 --- a/ognbase/ognbase.ino +++ b/ognbase/ognbase.ino @@ -90,6 +90,9 @@ #include +#define TBEAM +//#define TTGO + #if defined(ENABLE_AHRS) #include "AHRS.h" #endif /* ENABLE_AHRS */ @@ -130,9 +133,12 @@ #define TimeToRefreshWeb() (seconds() - ExportTimeWebRefresh >= TIME_TO_REFRESH_WEB) //testing -#define TIME_TO_SLEEP 60 #define TimeToSleep() (seconds() - ExportTimeSleep >= ogn_rxidle) +//testing +#define TIME_TO_DIS_WIFI 60 +#define TimeToDisWifi() (seconds() - ExportTimeDisWifi >= TIME_TO_DIS_WIFI) + //testing #define TimeToDisableOled() (seconds() - ExportTimeOledDisable >= oled_disable) @@ -171,6 +177,7 @@ unsigned long ExportTimeKeepAliveOGN = 0; unsigned long ExportTimeStatusOGN = 0; unsigned long ExportTimeSwitch = 0; unsigned long ExportTimeSleep = 0; +unsigned long ExportTimeDisWifi = 0; unsigned long ExportTimeWebRefresh = 0; unsigned long ExportTimeFanetService = 0; unsigned long ExportTimeCheckKeepAliveOGN = 0; @@ -224,8 +231,8 @@ void setup() EEPROM_setup(); OLED_setup(); - WiFi_setup(); + WiFi_setup(); SoC->Button_setup(); @@ -242,7 +249,10 @@ void setup() delay(100); +#if defined(TBEAM) hw_info.gnss = GNSS_setup(); +#endif + ThisAircraft.aircraft_type = settings->aircraft_type; Battery_setup(); Traffic_setup(); @@ -260,8 +270,9 @@ void setup() aes_init(); } - /*T-BEAM only*/ - //pinMode(BUTTON, INPUT); +#if defined(TBEAM) + pinMode(BUTTON, INPUT); +#endif } void loop() @@ -303,11 +314,10 @@ void shutdown(const char *msg) Web_fini(); WiFi_fini(); - - if (settings->mode != SOFTRF_MODE_UAV) { - GNSS_fini(); - } - + +#if defined(TBEAM) + GNSS_fini(); +#endif RF_Shutdown(); @@ -343,7 +353,7 @@ void ground() Logger_send_udp(&msg); } - if((WiFi.getMode() == WIFI_AP)){ + if((WiFi.getMode() == WIFI_AP) && !ognrelay_enable){ OLED_write("Setup mode..", 0, 9, true); snprintf (buf, sizeof(buf), "SSID: %s", host_name.c_str()); OLED_write(buf, 0, 18, false); @@ -364,8 +374,8 @@ void ground() if (success && isValidFix() || success && position_is_set){ Logger_send_udp(&msg); - ParseData(); + ExportTimeSleep = seconds(); } @@ -377,8 +387,10 @@ void ground() ThisAircraft.speed = 0; ThisAircraft.hdop = 0; ThisAircraft.geoid_separation = ogn_geoid_separation; - + +#if defined(TBEAM) GNSS_sleep(); +#endif msg = "found position data LAT: "; msg += ogn_lat; @@ -425,71 +437,102 @@ void ground() delay(1000); } +#if defined(TBEAM) GNSS_loop(); +#endif ThisAircraft.timestamp = now(); - if ((TimeToRegisterOGN() && (position_is_set) && WiFi.getMode() != WIFI_AP ) || (ground_registred == 0 && (position_is_set) && WiFi.getMode() != WIFI_AP)) - { - ground_registred = OGN_APRS_Register(&ThisAircraft); - ExportTimeRegisterOGN = seconds(); - } + //only as basestation - if(ground_registred == -1){ - OLED_write("server registration failed!", 0, 18, true); - OLED_write("please check json file!", 0, 27, false); - snprintf (buf, sizeof(buf), "%s : %d", ogn_server.c_str(), ogn_port); - OLED_write(buf, 0, 36, false); - ground_registred = -2; - } + if (!ognrelay_enable){ - if(ground_registred == -2){ - //lost wifi? - OGN_APRS_check_Wifi(); - ExportTimeReRegister = seconds(); - while(TimeToReRegisterOGN()){ - os_runstep(); + if ((TimeToRegisterOGN() && (position_is_set) && WiFi.getMode() != WIFI_AP ) || (ground_registred == 0 && (position_is_set) && WiFi.getMode() != WIFI_AP)) + { + ground_registred = OGN_APRS_Register(&ThisAircraft); + ExportTimeRegisterOGN = seconds(); } - ground_registred = 0; - } - - if (TimeToExportOGN() && ground_registred == 1) - { - if(new_protocol_enable && testmode_enable){ - RSM_ExportAircraftPosition(); + + if(ground_registred == -1){ + OLED_write("server registration failed!", 0, 18, true); + OLED_write("please check json file!", 0, 27, false); + snprintf (buf, sizeof(buf), "%s : %d", ogn_server.c_str(), ogn_port); + OLED_write(buf, 0, 36, false); + ground_registred = -2; + } + + if(ground_registred == -2){ + OGN_APRS_check_Wifi(); + ExportTimeReRegister = seconds(); + while(TimeToReRegisterOGN()){ + os_runstep(); + } + ground_registred = 0; + } + + if (TimeToExportOGN() && ground_registred == 1) + { + if(new_protocol_enable && testmode_enable){ + RSM_ExportAircraftPosition(); + } + OGN_APRS_Export(); + OLED_info(position_is_set); + ExportTimeOGN = seconds(); + } + + if (TimeToKeepAliveOGN() && ground_registred == 1) + { + disp = "keepalive OGN..."; + OLED_write(disp, 0, 24, true); + + OGN_APRS_KeepAlive(); + ExportTimeKeepAliveOGN = seconds(); + } + + if (TimeToStatusOGN() && ground_registred == 1 && (position_is_set )) + { + + disp = "status OGN..."; + OLED_write(disp, 0, 24, true); + + OGN_APRS_Status(&ThisAircraft); + + msg = "Version: "; + msg += String(_VERSION); + msg += " Power: "; + msg += String(SoC->Battery_voltage()); + msg += String(" Uptime: "); + msg += String(millis() / 3600000); + msg += String(" GNSS: "); + msg += String(gnss.satellites.value()); + Logger_send_udp(&msg); + ExportTimeStatusOGN = seconds(); + } + + if(TimeToCheckKeepAliveOGN() && ground_registred == 1){ + ground_registred = OGN_APRS_check_messages(); + ExportTimeCheckKeepAliveOGN = seconds(); + MONIT_send_trap(); } - OGN_APRS_Export(); - OLED_info(position_is_set); - ExportTimeOGN = seconds(); - } - - if (TimeToKeepAliveOGN() && ground_registred == 1) - { - disp = "keepalive OGN..."; - OLED_write(disp, 0, 24, true); - OGN_APRS_KeepAlive(); - ExportTimeKeepAliveOGN = seconds(); - } - - if (TimeToStatusOGN() && ground_registred == 1 && (position_is_set )) - { + if( TimeToCheckWifi() && !ognrelay_enable){ + OLED_draw_Bitmap(39, 5, 3 , true); + OLED_write("check connections..", 15, 45, false); + if(OGN_APRS_check_Wifi()){ + OLED_write("success", 35, 54, false); + } + else{ + OLED_write("error", 35, 54, false); + } + ExportTimeCheckWifi = seconds(); + } - disp = "status OGN..."; - OLED_write(disp, 0, 24, true); - - OGN_APRS_Status(&ThisAircraft); + } + - msg = "Version: "; - msg += String(_VERSION); - msg += " Power: "; - msg += String(SoC->Battery_voltage()); - msg += String(" Uptime: "); - msg += String(millis() / 3600000); - msg += String(" GNSS: "); - msg += String(gnss.satellites.value()); - Logger_send_udp(&msg); - ExportTimeStatusOGN = seconds(); + if (TimeToExportOGN() && ognrelay_enable){ + OLED_info(position_is_set); + ExportTimeOGN = seconds(); } @@ -505,10 +548,15 @@ void ground() OLED_disable(); if (ogn_sleepmode == 1){ - GNSS_sleep(); + +#if defined(TBEAM) + GNSS_sleep(); +#endif } + ground_registred = 0; - SoC->WiFi_disconnect_TCP(); + if(!ognrelay_enable) + SoC->WiFi_disconnect_TCP(); esp_deep_sleep_start(); } @@ -529,38 +577,29 @@ void ground() Logger_send_udp(&msg); } - if(TimeToCheckKeepAliveOGN() && ground_registred == 1){ - ground_registred = OGN_APRS_check_messages(); - ExportTimeCheckKeepAliveOGN = seconds(); - MONIT_send_trap(); - } - - if( TimeToCheckWifi() ){ - OLED_draw_Bitmap(39, 5, 3 , true); - OLED_write("check connections..", 15, 45, false); - if(OGN_APRS_check_Wifi()){ - OLED_write("success", 35, 54, false); - } - else{ - OLED_write("error", 35, 54, false); - } - ExportTimeCheckWifi = seconds(); - } - // Handle Air Connect - //NMEA_loop(); +#if defined(TBEAM) ClearExpired(); +#endif + + + if( TimeToDisWifi() && ognrelay_enable ){ + WiFi.mode(WIFI_OFF); + ExportTimeDisWifi = seconds(); + //Serial.print("disabling Wifi"); + } if( TimeToDisableOled() ){ if (oled_disable > 0){ OLED_disable(); } } - /* + +#if defined(TBEAM) if (!digitalRead(BUTTON)){ while(!digitalRead(BUTTON)){delay(100);} OLED_enable(); ExportTimeOledDisable = seconds(); } - */ +#endif } diff --git a/ognbase/version.h b/ognbase/version.h index 784d33f..032b369 100644 --- a/ognbase/version.h +++ b/ognbase/version.h @@ -2,10 +2,10 @@ #define _VERSION_MAJOR 0 #define _VERSION_MINOR 1 #define _VERSION_PATCH 0 -#define _VERSION_BUILD 27 -#define _VERSION_DATE "30/01/2022" -#define _VERSION_TIME "09:39:22" +#define _VERSION_BUILD 28 +#define _VERSION_DATE "06/02/2022" +#define _VERSION_TIME "16:00:14" #define _VERSION_ONLY "0.1.0" -#define _VERSION_NOBUILD "0.1.0 (30/01/2022)" -#define _VERSION "0.1.0-27" +#define _VERSION_NOBUILD "0.1.0 (06/02/2022)" +#define _VERSION "0.1.0-28" //The version information is created automatically, more information here: https://github.com/rvdbreemen/autoinc-semver