diff --git a/README.md b/README.md index 2c67104..63f732a 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,13 @@ 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*** ## Installation * git clone --recursive https://github.com/roema/Open-Glider-Network-Groundstation.git * Install arduino ide - make sure you are using the correct librarys -* ~~Install ESP32 Filesystem Uploader~~ * Compile and upload Sketch and files (.css and .html) * Connect to OGN Wifi AP and configure * You can update you installation http://you-ogn-ground-ip/update diff --git a/ognbase/APRS.cpp b/ognbase/APRS.cpp index 5cd12ae..29ffeb5 100644 --- a/ognbase/APRS.cpp +++ b/ognbase/APRS.cpp @@ -95,34 +95,6 @@ static short AprsPasscode(const char* theCall) return hash & 0x7fff; } -static long double toRadians(const long double degree) -{ - long double one_deg = (M_PI) / 180; - return one_deg * degree; -} - -static long double distance(long double lat1, long double long1, long double lat2, long double long2) -{ - lat1 = toRadians(lat1); - long1 = toRadians(long1); - lat2 = toRadians(lat2); - long2 = toRadians(long2); - - long double dlong = long2 - long1; - long double dlat = lat2 - lat1; - - long double ans = pow(sin(dlat / 2), 2) + - cos(lat1) * cos(lat2) * - pow(sin(dlong / 2), 2); - - ans = 2 * asin(sqrt(ans)); - - long double R = 6371; - ans = ans * R; - - return ans * 1000; -} - static bool OGN_APRS_Connect() { if (SoC->WiFi_connect_TCP(ogn_server.c_str(), ogn_port)) @@ -221,7 +193,7 @@ void OGN_APRS_Export() if (Container[i].addr && (this_moment - Container[i].timestamp) <= EXPORT_EXPIRATION_TIME && Container[i].distance < ogn_range * 1000) { - if(!isPacketValid(Container[i].addr, Container[i].latitude, Container[i].longitude, Container[i].speed, Container[i].timestamp) && testmode_enable){ + if(!isPacketValid(Container[i].addr, Container[i].latitude, Container[i].longitude, Container[i].speed, Container[i].timestamp)){ break; } @@ -429,7 +401,7 @@ int OGN_APRS_Register(ufo_t* this_aircraft) void OGN_APRS_KeepAlive() { - String KeepAlivePacket = "#keepalive\n\n"; + String KeepAlivePacket = "#keepalive\n"; Logger_send_udp(&KeepAlivePacket); SoC->WiFi_transmit_TCP(KeepAlivePacket); } diff --git a/ognbase/Log.cpp b/ognbase/Log.cpp index 1ab6d1a..276ff98 100644 --- a/ognbase/Log.cpp +++ b/ognbase/Log.cpp @@ -19,6 +19,7 @@ #include "SoC.h" #include "Log.h" #include "EEPROM.h" +#include "PNET.h" #include "global.h" @@ -30,6 +31,14 @@ void Logger_send_udp(String* buf) byte debug_msg[debug_len]; buf->getBytes(debug_msg, debug_len); SoC->WiFi_transmit_UDP_debug(ogn_debugport, debug_msg, debug_len); + + if(remotelogs_enable){ + char *encrypted; + size_t encrypted_len; + //PNETencrypt(debug_msg, debug_len, &encrypted, &encrypted_len); + //SoC->WiFi_transmit_UDP(remotelogs_server.c_str(), remotelogs_port, (byte*)encrypted, encrypted_len); + //free(encrypted); + } } } diff --git a/ognbase/Log.h b/ognbase/Log.h index 4d592c0..aacaf9b 100644 --- a/ognbase/Log.h +++ b/ognbase/Log.h @@ -1,39 +1,40 @@ -/* - * Log.h - * Copyright (C) 2019-2020 Linar Yusupov - * - * 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 . - */ - -#ifndef LOGHELPER_H -#define LOGHELPER_H - -#include "SoftRF.h" - -void Logger_send_udp(String *); - -#if LOGGER_IS_ENABLED - -#include - -extern File LogFile; -void Logger_setup(void); - -void Logger_loop(void); - -void Logger_fini(void); - -#endif /* LOGGER_IS_ENABLED */ - -#endif /* LOGHELPER_H */ +/* + * Log.h + * Copyright (C) 2019-2020 Linar Yusupov + * + * 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 . + */ + +#ifndef LOGHELPER_H +#define LOGHELPER_H + +#include "SoftRF.h" + +void Logger_send_udp(String *); +void Logger_send_enc_udp(String *); + +#if LOGGER_IS_ENABLED + +#include + +extern File LogFile; +void Logger_setup(void); + +void Logger_loop(void); + +void Logger_fini(void); + +#endif /* LOGGER_IS_ENABLED */ + +#endif /* LOGHELPER_H */ diff --git a/ognbase/OLED.cpp b/ognbase/OLED.cpp index a277063..599a438 100644 --- a/ognbase/OLED.cpp +++ b/ognbase/OLED.cpp @@ -75,18 +75,19 @@ byte OLED_setup() void OLED_write(char* text, short x, short y, bool clear) { - if (display_init) - { - display.displayOn(); - if (clear) - display.clear(); - display.drawString(x, y, text); - display.display(); - } + if (!display_enabled){return;} + + display.displayOn(); + if (clear) + display.clear(); + display.drawString(x, y, text); + display.display(); } void OLED_disable() { + if (!display_enabled){return;} + display.clear(); display.displayOff(); display_enabled = false; @@ -322,6 +323,3 @@ void OLED_info(bool ntp) } } } - -void OLED_status() -{} diff --git a/ognbase/PVALID.cpp b/ognbase/PVALID.cpp index ebef921..017d175 100644 --- a/ognbase/PVALID.cpp +++ b/ognbase/PVALID.cpp @@ -32,38 +32,33 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t /*V0.1.0-24*/ - if (!testmode_enable){ - return true; - } - - - for(uint8_t i=0;i calcdist){ + if (dist > calcdist) { msg = "Max calculated distance: "; msg += calcdist; - Logger_send_udp(&msg); - + Logger_send_udp(&msg); + msg = "Packet seems to be invalid"; Logger_send_udp(&msg); @@ -71,19 +66,19 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t shiftPackets(); return false; } - else{ + else { msg = "Max calculated distance: "; msg += calcdist; - Logger_send_udp(&msg); - + Logger_send_udp(&msg); + uint8_t cnt = ac[i].pkt_counter + 1; msg = "Packet seems to be valid - counter: "; msg += cnt; - Logger_send_udp(&msg); - + Logger_send_udp(&msg); + cleanUpPacket(i); shiftPackets(); appendPacket(addr, lat1, lon1, timestamp, cnt); @@ -95,53 +90,65 @@ bool isPacketValid(uint32_t addr, double lat1, double lon1, double speed, time_t Logger_send_udp(&msg); shiftPackets(); appendPacket(addr, lat1, lon1, timestamp, 0); - return(false); + return (false); } static int distance(double lat1, double lon1, double lat2, double lon2) { double theta, dist; + double r = 6378137.0; + if ((lat1 == lat2) && (lon1 == lon2)) { return 0; } else { - theta = lon1 - lon2; - dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta)); - dist = acos(dist); - dist = rad2deg(dist); - dist = dist * 60 * 1.1515; - dist = dist * 1.609344; - } - return (int)(dist); + lat1 = deg2rad(lat1); + lon1 = deg2rad(lon1); + lat2 = deg2rad(lat2); + lon2 = deg2rad(lon2); + + double dlat = lat2 - lat1; + double dlon = lon2 - lon1; + + 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 } +} static int calcMaxDistance(double speed, time_t time_diff) { - return (int)((speed / 3.6 * time_diff) * 2 ); - } - -static bool appendPacket(uint32_t addr, double lat, double lon, time_t timestamp, uint8_t cnt){ - ac[MAX_TRACKING_OBJECTS-1].timestamp = timestamp; - ac[MAX_TRACKING_OBJECTS-1].addr = addr; - ac[MAX_TRACKING_OBJECTS-1].latitude = lat; - ac[MAX_TRACKING_OBJECTS-1].longitude = lon; - ac[MAX_TRACKING_OBJECTS-1].pkt_counter = cnt; + int speed_ms = speed / 3.6; + // 20% more than calculated + return (int)((speed * time_diff) * 1.2 ); +} + +static bool appendPacket(uint32_t addr, double lat, double lon, time_t timestamp, uint8_t cnt) { + ac[MAX_TRACKING_OBJECTS - 1].timestamp = timestamp; + ac[MAX_TRACKING_OBJECTS - 1].addr = addr; + ac[MAX_TRACKING_OBJECTS - 1].latitude = lat; + ac[MAX_TRACKING_OBJECTS - 1].longitude = lon; + ac[MAX_TRACKING_OBJECTS - 1].pkt_counter = cnt; } -static void shiftPackets(void){ - for(uint8_t i=0; iaddr << 8) & 0xffffff); btea((uint32_t *) pkt + 1, -5, key); + for (ndx = 0; ndx < sizeof (legacy_packet_t); ndx++) pkt_parity += parity(*(((unsigned char *) pkt) + ndx)); if (pkt_parity % 2) { - if (settings->nmea_p) - { - msg = "bad parity of decoded legacy packet"; - Logger_send_udp(&msg); - msg = "decoding failed"; - Logger_send_udp(&msg); - } + msg = "bad parity of decoded legacy packet"; + Logger_send_udp(&msg); + msg = "decoding failed"; + Logger_send_udp(&msg); return false; } diff --git a/ognbase/Protocol_Legacy.h b/ognbase/Protocol_Legacy.h index 6b5b977..22f35f7 100644 --- a/ognbase/Protocol_Legacy.h +++ b/ognbase/Protocol_Legacy.h @@ -1,142 +1,143 @@ -/* - * Protocol_Legacy.h - * Copyright (C) 2014-2015 Stanislaw Pusep - * Copyright (C) 2019-2020 Linar Yusupov - * - * 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 . - */ - -#ifndef PROTOCOL_LEGACY_H -#define PROTOCOL_LEGACY_H - -/* IEEE Manchester(F531FAB6) = 55 99 A5 A9 55 66 65 96 */ -#define LEGACY_PREAMBLE_TYPE RF_PREAMBLE_TYPE_55 -#define LEGACY_PREAMBLE_SIZE 1 -#define LEGACY_SYNCWORD {0x99, 0xA5, 0xA9, 0x55, 0x66, 0x65, 0x96} -#define LEGACY_SYNCWORD_SIZE 7 -#define LEGACY_PAYLOAD_SIZE 24 -#define LEGACY_CRC_TYPE RF_CHECKSUM_TYPE_CCITT_FFFF -#define LEGACY_CRC_SIZE 2 - -#define LEGACY_TX_INTERVAL_MIN 600 /* in ms */ -#define LEGACY_TX_INTERVAL_MAX 1400 - -#define LEGACY_KEY1 { 0xe43276df, 0xdca83759, 0x9802b8ac, 0x4675a56b, \ - 0xfc78ea65, 0x804b90ea, 0xb76542cd, 0x329dfa32 } -#define LEGACY_KEY2 0x045d9f3b -#define LEGACY_KEY3 0x87b562f4 - -/* FTD-12 Version: 7.00 */ -enum -{ - ADDR_TYPE_RANDOM, - ADDR_TYPE_ICAO, - ADDR_TYPE_FLARM, - ADDR_TYPE_ANONYMOUS, /* FLARM stealth, OGN */ - ADDR_TYPE_P3I, - ADDR_TYPE_FANET -}; - -enum -{ - AIRCRAFT_TYPE_UNKNOWN, - AIRCRAFT_TYPE_GLIDER, - AIRCRAFT_TYPE_TOWPLANE, - AIRCRAFT_TYPE_HELICOPTER, - AIRCRAFT_TYPE_PARACHUTE, - AIRCRAFT_TYPE_DROPPLANE, - AIRCRAFT_TYPE_HANGGLIDER, - AIRCRAFT_TYPE_PARAGLIDER, - AIRCRAFT_TYPE_POWERED, - AIRCRAFT_TYPE_JET, - AIRCRAFT_TYPE_UFO, - AIRCRAFT_TYPE_BALLOON, - AIRCRAFT_TYPE_ZEPPELIN, - AIRCRAFT_TYPE_UAV, - AIRCRAFT_TYPE_RESERVED, - AIRCRAFT_TYPE_STATIC -}; - -enum -{ - ALARM_LEVEL_NONE, - ALARM_LEVEL_LOW, /* 13-18 seconds to impact */ - ALARM_LEVEL_IMPORTANT, /* 9-12 seconds to impact */ - ALARM_LEVEL_URGENT /* 0-8 seconds to impact */ -}; - -enum -{ - ALARM_TYPE_TRAFFIC, - ALARM_TYPE_SILENT, - ALARM_TYPE_AIRCRAFT, - ALARM_TYPE_OBSTACLE -}; - -enum -{ - GNSS_STATUS_NONE, - GNSS_STATUS_3D_GROUND, - GNSS_STATUS_3D_MOVING -}; - -enum -{ - POWER_STATUS_BAD, - POWER_STATUS_GOOD -}; - -enum -{ - TX_STATUS_OFF, - TX_STATUS_ON -}; - -typedef struct -{ - /********************/ - unsigned int addr : 24; - unsigned int _unk0 : 4; - unsigned int addr_type : 3; - unsigned int _unk1 : 1; - // unsigned int magic:8; - /********************/ - int vs : 10; - unsigned int _unk2 : 2; - unsigned int airborne : 1; - unsigned int stealth : 1; - unsigned int no_track : 1; - unsigned int parity : 1; - unsigned int gps : 12; - unsigned int aircraft_type : 4; - /********************/ - unsigned int lat : 19; - unsigned int alt : 13; - /********************/ - unsigned int lon : 20; - unsigned int _unk3 : 10; - unsigned int smult : 2; - /********************/ - int8_t ns[4]; - int8_t ew[4]; - /********************/ -} legacy_packet_t; - -bool legacy_decode(void *, ufo_t *, ufo_t *); - -size_t legacy_encode(void *, ufo_t *); - -extern const rf_proto_desc_t legacy_proto_desc; - -#endif /* PROTOCOL_LEGACY_H */ +/* + * Protocol_Legacy.h + * Copyright (C) 2014-2015 Stanislaw Pusep + * Copyright (C) 2019-2020 Linar Yusupov + * + * 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 . + */ + +#ifndef PROTOCOL_LEGACY_H +#define PROTOCOL_LEGACY_H + +/* IEEE Manchester(F531FAB6) = 55 99 A5 A9 55 66 65 96 */ +#define LEGACY_PREAMBLE_TYPE RF_PREAMBLE_TYPE_55 +#define LEGACY_PREAMBLE_SIZE 1 +#define LEGACY_SYNCWORD {0x99, 0xA5, 0xA9, 0x55, 0x66, 0x65, 0x96} +#define LEGACY_SYNCWORD_SIZE 7 +#define LEGACY_PAYLOAD_SIZE 24 +#define LEGACY_CRC_TYPE RF_CHECKSUM_TYPE_CCITT_FFFF +#define LEGACY_CRC_SIZE 2 + +#define LEGACY_TX_INTERVAL_MIN 600 /* in ms */ +#define LEGACY_TX_INTERVAL_MAX 1400 + +#define LEGACY_KEY1 { 0xe43276df, 0xdca83759, 0x9802b8ac, 0x4675a56b, \ + 0xfc78ea65, 0x804b90ea, 0xb76542cd, 0x329dfa32 } +#define LEGACY_KEY2 0x045d9f3b +#define LEGACY_KEY3 0x87b562f4 + + +/* FTD-12 Version: 7.00 */ +enum +{ + ADDR_TYPE_RANDOM, + ADDR_TYPE_ICAO, + ADDR_TYPE_FLARM, + ADDR_TYPE_ANONYMOUS, /* FLARM stealth, OGN */ + ADDR_TYPE_P3I, + ADDR_TYPE_FANET +}; + +enum +{ + AIRCRAFT_TYPE_UNKNOWN, + AIRCRAFT_TYPE_GLIDER, + AIRCRAFT_TYPE_TOWPLANE, + AIRCRAFT_TYPE_HELICOPTER, + AIRCRAFT_TYPE_PARACHUTE, + AIRCRAFT_TYPE_DROPPLANE, + AIRCRAFT_TYPE_HANGGLIDER, + AIRCRAFT_TYPE_PARAGLIDER, + AIRCRAFT_TYPE_POWERED, + AIRCRAFT_TYPE_JET, + AIRCRAFT_TYPE_UFO, + AIRCRAFT_TYPE_BALLOON, + AIRCRAFT_TYPE_ZEPPELIN, + AIRCRAFT_TYPE_UAV, + AIRCRAFT_TYPE_RESERVED, + AIRCRAFT_TYPE_STATIC +}; + +enum +{ + ALARM_LEVEL_NONE, + ALARM_LEVEL_LOW, /* 13-18 seconds to impact */ + ALARM_LEVEL_IMPORTANT, /* 9-12 seconds to impact */ + ALARM_LEVEL_URGENT /* 0-8 seconds to impact */ +}; + +enum +{ + ALARM_TYPE_TRAFFIC, + ALARM_TYPE_SILENT, + ALARM_TYPE_AIRCRAFT, + ALARM_TYPE_OBSTACLE +}; + +enum +{ + GNSS_STATUS_NONE, + GNSS_STATUS_3D_GROUND, + GNSS_STATUS_3D_MOVING +}; + +enum +{ + POWER_STATUS_BAD, + POWER_STATUS_GOOD +}; + +enum +{ + TX_STATUS_OFF, + TX_STATUS_ON +}; + +typedef struct +{ + /********************/ + unsigned int addr : 24; + unsigned int _unk0 : 4; + unsigned int addr_type : 3; + unsigned int _unk1 : 1; + // unsigned int magic:8; + /********************/ + int vs : 10; + unsigned int _unk2 : 2; + unsigned int airborne : 1; + unsigned int stealth : 1; + unsigned int no_track : 1; + unsigned int parity : 1; + unsigned int gps : 12; + unsigned int aircraft_type : 4; + /********************/ + unsigned int lat : 19; + unsigned int alt : 13; + /********************/ + unsigned int lon : 20; + unsigned int _unk3 : 10; + unsigned int smult : 2; + /********************/ + int8_t ns[4]; + int8_t ew[4]; + /********************/ +} legacy_packet_t; + +bool legacy_decode(void *, ufo_t *, ufo_t *); + +size_t legacy_encode(void *, ufo_t *); + +extern const rf_proto_desc_t legacy_proto_desc; + +#endif /* PROTOCOL_LEGACY_H */ diff --git a/ognbase/config.cpp b/ognbase/config.cpp index 38d869f..1bfc7db 100644 --- a/ognbase/config.cpp +++ b/ognbase/config.cpp @@ -56,10 +56,12 @@ bool ogn_debug = false; uint16_t ogn_debugport = 12000; bool ogn_itrackbit = false; bool ogn_istealthbit = false; +uint16_t ogn_range = 100; + +//sleep mode bool ogn_sleepmode = false; uint16_t ogn_rxidle = 3600; uint16_t ogn_wakeuptimer = 3600; -uint8_t ogn_range = 100; //position float ogn_lat = 0; @@ -303,6 +305,19 @@ bool OGN_read_config(void) } } + if (obj.containsKey(F("sleepmode"))) + { + //Serial.println(F("found aprs config!")); + if (1) + { + ogn_sleepmode = obj["aprs"]["sleepmode"]; + ogn_rxidle = obj["aprs"]["rxidle"]; + if(ogn_rxidle < 600){ogn_rxidle = 600;} + ogn_wakeuptimer = obj["aprs"]["wakeuptimer"]; + if(ogn_wakeuptimer < 600){ogn_wakeuptimer = 600;} + } + } + if (obj.containsKey(F("zabbix"))) { diff --git a/ognbase/data/config.json b/ognbase/data/config.json index dd24d8e..da3fd57 100644 --- a/ognbase/data/config.json +++ b/ognbase/data/config.json @@ -1,14 +1,14 @@ { "wifi":{ "ssid":[ - "ssid", + "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx" ], "pass":[ - "password", + "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", @@ -32,9 +32,9 @@ "enable":false }, "remotelogs":{ - "enable":false, - "server":"5.150.254.37", - "port":12000 + "enable":true, + "server":"10.0.1.200", + "port":12014 }, "aprs":{ "callsign":"Neuenburg", diff --git a/ognbase/global.h b/ognbase/global.h index 226e621..06a72e8 100644 --- a/ognbase/global.h +++ b/ognbase/global.h @@ -24,12 +24,12 @@ extern bool ogn_istealthbit; extern bool ogn_sleepmode; extern uint16_t ogn_rxidle; extern uint16_t ogn_wakeuptimer; -extern uint8_t ogn_range; +extern uint16_t ogn_range; -extern bool fanet_enable; -extern bool zabbix_enable; -extern String zabbix_server; -extern uint16_t zabbix_port; +extern bool fanet_enable; +extern bool zabbix_enable; +extern String zabbix_server; +extern uint16_t zabbix_port; extern String zabbix_key; extern bool beers_show; diff --git a/ognbase/ognbase.ino b/ognbase/ognbase.ino index dabfd24..5447208 100644 --- a/ognbase/ognbase.ino +++ b/ognbase/ognbase.ino @@ -136,6 +136,10 @@ //testing #define TimeToDisableOled() (seconds() - ExportTimeOledDisable >= oled_disable) +//time reregister if failed +#define TIME_TO_REREG 30 +#define TimeToReRegisterOGN() (seconds() - ExportTimeReRegister >= TIME_TO_REREG) + /*Testing FANET service messages*/ #define TIME_TO_EXPORT_FANET_SERVICE 40 /*every 40 sec 10 for testing*/ #define TimeToExportFanetService() (seconds() - ExportTimeFanetService >= TIME_TO_EXPORT_FANET_SERVICE) @@ -172,6 +176,7 @@ unsigned long ExportTimeFanetService = 0; unsigned long ExportTimeCheckKeepAliveOGN = 0; unsigned long ExportTimeCheckWifi = 0; unsigned long ExportTimeOledDisable = 0; +unsigned long ExportTimeReRegister = 0; /*set ground position only once*/ bool position_is_set = false; @@ -251,7 +256,7 @@ void setup() Time_setup(); SoC->WDT_setup(); - if(private_network){ + if(private_network || remotelogs_enable){ aes_init(); } @@ -439,7 +444,13 @@ void ground() } if(ground_registred == -2){ - // + //lost wifi? + OGN_APRS_check_Wifi(); + ExportTimeReRegister = seconds(); + while(TimeToReRegisterOGN()){ + os_runstep(); + } + ground_registred = 0; } if (TimeToExportOGN() && ground_registred == 1) @@ -491,6 +502,8 @@ void ground() esp_sleep_enable_timer_wakeup(ogn_wakeuptimer*1000000LL); esp_sleep_enable_ext0_wakeup(GPIO_NUM_26,1); + OLED_disable(); + if (ogn_sleepmode == 1){ GNSS_sleep(); } diff --git a/ognbase/sdcard/config.json b/ognbase/sdcard/config.json index 71851ba..dd32d24 100644 --- a/ognbase/sdcard/config.json +++ b/ognbase/sdcard/config.json @@ -32,9 +32,9 @@ "enable":false }, "remotelogs":{ - "enable":false, - "server":"5.150.254.37", - "port":12000 + "enable":true, + "server":"10.0.1.200", + "port":12014 }, "aprs":{ "callsign":"Neuenburg", @@ -47,11 +47,13 @@ "debugport":12000, "itrackbit":false, "istealthbit":false, - "sleepmode":false, - "rxidle":3600, - "wakeuptimer":3600, "range":100 }, + "sleepmode":{ + "enable":false, + "rxidle":3600, + "wakeuptimer":3600, + }, "fanetservice":{ "enable":1 }, @@ -61,7 +63,7 @@ "port":12012 }, "private":{ - "enable":1 + "enable":0 }, "oled":{ "disable":0 diff --git a/ognbase/version.h b/ognbase/version.h index e4d6d61..0027328 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 24 -#define _VERSION_DATE "17/10/2021" -#define _VERSION_TIME "11:41:09" +#define _VERSION_BUILD 25 +#define _VERSION_DATE "24/10/2021" +#define _VERSION_TIME "11:41:12" #define _VERSION_ONLY "0.1.0" -#define _VERSION_NOBUILD "0.1.0 (17/10/2021)" -#define _VERSION "0.1.0-24" +#define _VERSION_NOBUILD "0.1.0 (24/10/2021)" +#define _VERSION "0.1.0-25" //The version information is created automatically, more information here: https://github.com/rvdbreemen/autoinc-semver diff --git a/pictures/TBEAM.png b/pictures/TBEAM.png new file mode 100644 index 0000000..81ad3c5 Binary files /dev/null and b/pictures/TBEAM.png differ diff --git a/pictures/TTGO.png b/pictures/TTGO.png new file mode 100644 index 0000000..ac826e7 Binary files /dev/null and b/pictures/TTGO.png differ diff --git a/tools/aprs_decode/client.py b/tools/aprs_decode/client.py new file mode 100644 index 0000000..d172046 --- /dev/null +++ b/tools/aprs_decode/client.py @@ -0,0 +1,141 @@ +import socket +import logging +from time import time, sleep + +from ogn.client import settings + + +def create_aprs_login(user_name, pass_code, app_name, app_version, aprs_filter=None): + if not aprs_filter: + return "user {} pass {} vers {} {}\n".format(user_name, pass_code, app_name, app_version) + else: + return "user {} pass {} vers {} {} filter {}\n".format(user_name, pass_code, app_name, app_version, aprs_filter) + + +class AprsClient: + def __init__(self, aprs_user, aprs_filter='', settings=settings): + self.logger = logging.getLogger(__name__) + self.logger.addHandler(logging.NullHandler()) + + self.aprs_user = aprs_user + self.aprs_filter = aprs_filter + self.settings = settings + + self._sock_peer_ip = None + self._kill = False + + def connect(self, retries=1, wait_period=15): + # create socket, connect to server, login and make a file object associated with the socket + while retries > 0: + retries -= 1 + try: + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) + self.sock.settimeout(5) + + if self.aprs_filter: + port = self.settings.APRS_SERVER_PORT_CLIENT_DEFINED_FILTERS + else: + port = self.settings.APRS_SERVER_PORT_FULL_FEED + + self.sock.connect((self.settings.APRS_SERVER_HOST, port)) + self._sock_peer_ip = self.sock.getpeername()[0] + + login = create_aprs_login(self.aprs_user, -1, self.settings.APRS_APP_NAME, self.settings.APRS_APP_VER, self.aprs_filter) + self.sock.send(login.encode()) + self.sock_file = self.sock.makefile('rb') + + self._kill = False + self.logger.info("Connect to OGN ({}/{}:{}) as {} with filter: {}". + format(self.settings.APRS_SERVER_HOST, self._sock_peer_ip, port, self.aprs_user, + "'" + self.aprs_filter + "'" if self.aprs_filter else 'none (full-feed)')) + break + except (socket.error, ConnectionError) as e: + self.logger.error('Connect error: {}'.format(e)) + if retries > 0: + self.logger.info('Waiting {}s before next connection try ({} attempts left).'.format(wait_period, retries)) + sleep(wait_period) + else: + self._kill = True + self.logger.critical('Could not connect to OGN.') + + def disconnect(self): + self.logger.info('Disconnect from {}'.format(self._sock_peer_ip)) + try: + # close everything + self.sock.shutdown(0) + self.sock.close() + except OSError: + self.logger.error('Socket close error') + + self._kill = True + + def run(self, callback, timed_callback=lambda client: None, autoreconnect=False, ignore_decoding_error=True, + **kwargs): + while not self._kill: + try: + keepalive_time = time() + while not self._kill: + if time() - keepalive_time > self.settings.APRS_KEEPALIVE_TIME: + self.logger.info('Send keepalive to {}'.format(self._sock_peer_ip)) + self.sock.send('#keepalive\n'.encode()) + timed_callback(self) + keepalive_time = time() + + # Read packet string from socket + packet_b = self.sock_file.readline().strip() + packet_str = packet_b.decode(errors="replace") if ignore_decoding_error else packet_b.decode() + + # A zero length line should not be return if keepalives are being sent + # A zero length line will only be returned after ~30m if keepalives are not sent + if len(packet_str) == 0: + self.logger.warning('Read returns zero length string. Failure. Orderly closeout from {}'. + format(self._sock_peer_ip)) + break + + callback(packet_str, **kwargs) + except socket.error: + self.logger.error('socket.error') + except OSError: + self.logger.error('OSError') + except UnicodeDecodeError: + self.logger.error('UnicodeDecodeError') + self.logger.debug(packet_b) + + if autoreconnect and not self._kill: + self.connect(retries=100) + else: + return + + +class TelnetClient: + def __init__(self, settings=settings): + self.logger = logging.getLogger(__name__) + self.logger.info("Connect to local telnet server") + self.settings = settings + + def connect(self): + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.connect((self.settings.TELNET_SERVER_HOST, self.settings.TELNET_SERVER_PORT)) + + def run(self, callback, autoreconnect=False): + while True: + try: + self.sock_file = self.sock.makefile(mode='rw', encoding='iso-8859-1') + while True: + packet_str = self.sock_file.readline().strip() + callback(packet_str) + + except ConnectionRefusedError: + self.logger.error('Telnet server not running', exc_info=True) + + if autoreconnect: + sleep(1) + self.connect() + else: + return + + def disconnect(self): + self.logger.info('Disconnect') + self.sock.shutdown(0) + self.sock.close() diff --git a/tools/aprs_decode/main.py b/tools/aprs_decode/main.py new file mode 100644 index 0000000..87597c2 --- /dev/null +++ b/tools/aprs_decode/main.py @@ -0,0 +1,28 @@ + + +from ogn.client import AprsClient +from ogn.parser import parse, ParseError +import re + + +pattern_table = re.compile(r'[N][ ]{1}') + +def process_beacon(raw_message): + try: + beacon = parse(raw_message) + messages = re.findall(pattern_table, beacon['raw_message']) + if messages: + print(messages) + print(beacon['raw_message']) + + except ParseError as e: + print('Error, {}'.format(e.message)) + +client = AprsClient(aprs_user='N0CALL') +client.connect() + +try: + client.run(callback=process_beacon, autoreconnect=True) +except KeyboardInterrupt: + print('\nStop ogn gateway') + client.disconnect() diff --git a/tools/aprs_decode/settings.py b/tools/aprs_decode/settings.py new file mode 100644 index 0000000..7b1747a --- /dev/null +++ b/tools/aprs_decode/settings.py @@ -0,0 +1,13 @@ +APRS_SERVER_HOST = 'aprs.glidernet.org' +APRS_SERVER_PORT_FULL_FEED = 10152 +APRS_SERVER_PORT_CLIENT_DEFINED_FILTERS = 14580 + +APRS_APP_NAME = 'python-ogn-client' + +PACKAGE_VERSION = '1.2.1' +APRS_APP_VER = PACKAGE_VERSION[:3] + +APRS_KEEPALIVE_TIME = 240 + +TELNET_SERVER_HOST = 'localhost' +TELNET_SERVER_PORT = 50001 diff --git a/tools/iv.bin b/tools/iv.bin new file mode 100644 index 0000000..cf4a739 --- /dev/null +++ b/tools/iv.bin @@ -0,0 +1 @@ +yP=}o \ No newline at end of file diff --git a/tools/key.bin b/tools/key.bin new file mode 100644 index 0000000..daae022 --- /dev/null +++ b/tools/key.bin @@ -0,0 +1 @@ + ct_u]3 \ No newline at end of file diff --git a/tools/ogn/__pycache__/AircraftPos.cpython-39.pyc b/tools/ogn/__pycache__/AircraftPos.cpython-39.pyc deleted file mode 100644 index 0b4034a..0000000 Binary files a/tools/ogn/__pycache__/AircraftPos.cpython-39.pyc and /dev/null differ diff --git a/tools/ogn/__pycache__/OneMessage.cpython-39.pyc b/tools/ogn/__pycache__/OneMessage.cpython-39.pyc deleted file mode 100644 index 066e060..0000000 Binary files a/tools/ogn/__pycache__/OneMessage.cpython-39.pyc and /dev/null differ diff --git a/tools/ogn/__pycache__/__init__.cpython-39.pyc b/tools/ogn/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 01281e4..0000000 Binary files a/tools/ogn/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/tools/udp_server.py b/tools/udp_log_server.py similarity index 100% rename from tools/udp_server.py rename to tools/udp_log_server.py