From 1390fc1ad0a9583b0045c2eee17631b1a1f32602 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 20 Sep 2021 07:43:43 +0200 Subject: [PATCH 001/125] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index bc8bd22..29e9c73 100644 --- a/README.md +++ b/README.md @@ -125,4 +125,3 @@ A direct mount of the [other display](pics/display-wrong.jpg) is not possible wi The 'wrong' display works too but you have to change VCC and GND by wire ! feel free to add hints! - From 6612e3da16542dd7908284ac79eb4b0ee1594c29 Mon Sep 17 00:00:00 2001 From: Jochen Date: Sat, 6 Nov 2021 22:00:27 +0100 Subject: [PATCH 002/125] Added an option to enable WiFi on (PoE) Ethernet boards as proposed in issue #116 Added an option to adjust LoRa receiver gain --- data/is-cfg.json | 2 ++ lib/LoRa_APRS/LoRa_APRS.cpp | 7 ++++++- lib/LoRa_APRS/LoRa_APRS.h | 3 +++ src/LoRa_APRS_iGate.cpp | 7 ++++--- src/TaskModem.cpp | 1 + src/project_configuration.cpp | 8 ++++++-- src/project_configuration.h | 4 +++- 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 736d44c..93808e2 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -11,6 +11,7 @@ "wifi": { "AP": [ { + "active": false, "SSID": "YOURSSID", "password": "YOURPASSWORD" } @@ -36,6 +37,7 @@ }, "lora": { "frequency_rx": 433775000, + "gain_rx": 6; "frequency_tx": 433775000, "power": 20, "spreading_factor": 12, diff --git a/lib/LoRa_APRS/LoRa_APRS.cpp b/lib/LoRa_APRS/LoRa_APRS.cpp index ea28f8b..668dc52 100644 --- a/lib/LoRa_APRS/LoRa_APRS.cpp +++ b/lib/LoRa_APRS/LoRa_APRS.cpp @@ -1,6 +1,6 @@ #include "LoRa_APRS.h" -LoRa_APRS::LoRa_APRS() : _RxFrequency(433775000), _TxFrequency(433775000) { +LoRa_APRS::LoRa_APRS() : _RxFrequency(433775000), _TxFrequency(433775000), _RxGain(6) { } bool LoRa_APRS::checkMessage() { @@ -50,6 +50,11 @@ void LoRa_APRS::setRxFrequency(long frequency) { setFrequency(_RxFrequency); } +void LoRa_APRS::setRxGain(uint8_t gain) { + _RxGain = gain; + setGain(_RxGain); +} + // cppcheck-suppress unusedFunction long LoRa_APRS::getRxFrequency() const { return _RxFrequency; diff --git a/lib/LoRa_APRS/LoRa_APRS.h b/lib/LoRa_APRS/LoRa_APRS.h index cacd0fe..748bfac 100644 --- a/lib/LoRa_APRS/LoRa_APRS.h +++ b/lib/LoRa_APRS/LoRa_APRS.h @@ -19,6 +19,8 @@ public: void setRxFrequency(long frequency); long getRxFrequency() const; + void setRxGain(uint8_t gain); + void setTxFrequency(long frequency); long getTxFrequency() const; @@ -26,6 +28,7 @@ private: std::shared_ptr _LastReceivedMsg; long _RxFrequency; long _TxFrequency; + uint8_t _RxGain; }; #endif diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 05739dd..6e4cf58 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -18,7 +18,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "21.35.0-dev" +#define VERSION "21.44.0-dev" String create_lat_aprs(double lat); String create_long_aprs(double lng); @@ -100,9 +100,10 @@ void setup() { LoRaSystem.getTaskManager().addTask(&routerTask); if (userConfig.aprs_is.active) { - if (boardConfig->Type == eETH_BOARD) { + if (boardConfig->Type == eETH_BOARD && !userConfig.wifi.active) { LoRaSystem.getTaskManager().addAlwaysRunTask(ðTask); - } else { + } + if (userConfig.wifi.active) { LoRaSystem.getTaskManager().addAlwaysRunTask(&wifiTask); } LoRaSystem.getTaskManager().addTask(&otaTask); diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 7dad353..d3908bc 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -24,6 +24,7 @@ bool ModemTask::setup(System &system) { ; } _lora_aprs.setRxFrequency(system.getUserConfig()->lora.frequencyRx); + _lora_aprs.setRxGain(system.getUserConfig()->lora.gainRx); _lora_aprs.setTxFrequency(system.getUserConfig()->lora.frequencyTx); _lora_aprs.setTxPower(system.getUserConfig()->lora.power); _lora_aprs.setSpreadingFactor(system.getUserConfig()->lora.spreadingFactor); diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 656d284..895f257 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -17,7 +17,8 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.network.dns2.fromString(data["network"]["dns2"].as()); } - JsonArray aps = data["wifi"]["AP"].as(); + conf.wifi.active = data["wifi"]["active"]; + JsonArray aps = data["wifi"]["AP"].as(); for (JsonVariant v : aps) { Configuration::Wifi::AP ap; ap.SSID = v["SSID"].as(); @@ -39,6 +40,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.digi.active = data["digi"]["active"] | false; conf.digi.beacon = data["digi"]["beacon"] | false; conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000; + conf.lora.gainRx = data["lora"]["gain_rx"] | 6; conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000; conf.lora.power = data["lora"]["power"] | 20; conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12; @@ -82,7 +84,8 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["network"]["dns2"] = conf.network.dns2.toString(); } - JsonArray aps = data["wifi"].createNestedArray("AP"); + data["wifi"]["active"] = conf.wifi.active; + JsonArray aps = data["wifi"].createNestedArray("AP"); for (Configuration::Wifi::AP ap : conf.wifi.APs) { JsonObject v = aps.createNestedObject(); v["SSID"] = ap.SSID; @@ -99,6 +102,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["digi"]["active"] = conf.digi.active; data["digi"]["beacon"] = conf.digi.beacon; data["lora"]["frequency_rx"] = conf.lora.frequencyRx; + data["lora"]["gain_rx"] = conf.lora.gainRx; data["lora"]["frequency_tx"] = conf.lora.frequencyTx; data["lora"]["power"] = conf.lora.power; data["lora"]["spreading_factor"] = conf.lora.spreadingFactor; diff --git a/src/project_configuration.h b/src/project_configuration.h index b2ba0bc..e013fe1 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -21,13 +21,14 @@ public: class Wifi { public: + bool active; class AP { public: String SSID; String password; }; - Wifi() { + Wifi() : active(true) { } std::list APs; @@ -70,6 +71,7 @@ public: } long frequencyRx; + uint8_t gainRx; long frequencyTx; int power; int spreadingFactor; From f518df43c6b25888432100c7b1eefc7f10a32184 Mon Sep 17 00:00:00 2001 From: df2jh <91030275+df2jh@users.noreply.github.com> Date: Sat, 6 Nov 2021 22:24:12 +0100 Subject: [PATCH 003/125] Update is-cfg.json --- data/is-cfg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 93808e2..91ad74f 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -37,7 +37,7 @@ }, "lora": { "frequency_rx": 433775000, - "gain_rx": 6; + "gain_rx": 6, "frequency_tx": 433775000, "power": 20, "spreading_factor": 12, From 36d73552ff5c55b048d296b10739886fc263196a Mon Sep 17 00:00:00 2001 From: Jochen Date: Sun, 7 Nov 2021 10:48:10 +0100 Subject: [PATCH 004/125] fixed is-cfg.json and project_configuration.h --- data/is-cfg.json | 4 ++-- src/project_configuration.h | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 93808e2..db2b2ba 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -9,9 +9,9 @@ "dns2": "192.0.2.2" }, "wifi": { + "active": true, "AP": [ { - "active": false, "SSID": "YOURSSID", "password": "YOURPASSWORD" } @@ -37,7 +37,7 @@ }, "lora": { "frequency_rx": 433775000, - "gain_rx": 6; + "gain_rx": 6, "frequency_tx": 433775000, "power": 20, "spreading_factor": 12, diff --git a/src/project_configuration.h b/src/project_configuration.h index e013fe1..c9d9ea9 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -21,6 +21,9 @@ public: class Wifi { public: + Wifi() : active(true) { + } + bool active; class AP { public: @@ -28,9 +31,6 @@ public: String password; }; - Wifi() : active(true) { - } - std::list APs; }; @@ -70,13 +70,13 @@ public: LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) { } - long frequencyRx; + long frequencyRx; uint8_t gainRx; - long frequencyTx; - int power; - int spreadingFactor; - long signalBandwidth; - int codingRate4; + long frequencyTx; + int power; + int spreadingFactor; + long signalBandwidth; + int codingRate4; }; class Display { From d6222b6cbeb63b018179c79d338a59bffcf8644a Mon Sep 17 00:00:00 2001 From: Jochen Date: Sun, 7 Nov 2021 19:54:22 +0100 Subject: [PATCH 005/125] minor changes in LoRa_APRS.h --- lib/LoRa_APRS/LoRa_APRS.cpp | 5 ++--- lib/LoRa_APRS/LoRa_APRS.h | 1 - src/project_configuration.cpp | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/LoRa_APRS/LoRa_APRS.cpp b/lib/LoRa_APRS/LoRa_APRS.cpp index 668dc52..48d2dfa 100644 --- a/lib/LoRa_APRS/LoRa_APRS.cpp +++ b/lib/LoRa_APRS/LoRa_APRS.cpp @@ -1,6 +1,6 @@ #include "LoRa_APRS.h" -LoRa_APRS::LoRa_APRS() : _RxFrequency(433775000), _TxFrequency(433775000), _RxGain(6) { +LoRa_APRS::LoRa_APRS() : _RxFrequency(433775000), _TxFrequency(433775000) { } bool LoRa_APRS::checkMessage() { @@ -51,8 +51,7 @@ void LoRa_APRS::setRxFrequency(long frequency) { } void LoRa_APRS::setRxGain(uint8_t gain) { - _RxGain = gain; - setGain(_RxGain); + setGain(gain); } // cppcheck-suppress unusedFunction diff --git a/lib/LoRa_APRS/LoRa_APRS.h b/lib/LoRa_APRS/LoRa_APRS.h index 748bfac..3d6eff4 100644 --- a/lib/LoRa_APRS/LoRa_APRS.h +++ b/lib/LoRa_APRS/LoRa_APRS.h @@ -28,7 +28,6 @@ private: std::shared_ptr _LastReceivedMsg; long _RxFrequency; long _TxFrequency; - uint8_t _RxGain; }; #endif diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 895f257..a416aa1 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -40,7 +40,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.digi.active = data["digi"]["active"] | false; conf.digi.beacon = data["digi"]["beacon"] | false; conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000; - conf.lora.gainRx = data["lora"]["gain_rx"] | 6; + conf.lora.gainRx = data["lora"]["gain_rx"] | 0; conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000; conf.lora.power = data["lora"]["power"] | 20; conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12; From c3a49b6c32115cf98bba9e74fc060c5b96047216 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 7 Nov 2021 20:59:44 +0100 Subject: [PATCH 006/125] set rx gain to 0 for agc usage --- data/is-cfg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index db2b2ba..02737a3 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -37,7 +37,7 @@ }, "lora": { "frequency_rx": 433775000, - "gain_rx": 6, + "gain_rx": 0, "frequency_tx": 433775000, "power": 20, "spreading_factor": 12, From 45f5bf9bb8857c448735529240c7e404fbcf67e3 Mon Sep 17 00:00:00 2001 From: Denis Apel <35398698+stardado@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:23:50 +0100 Subject: [PATCH 007/125] Add files via upload --- src/TaskEth.cpp | 15 +++++++++------ src/project_configuration.cpp | 2 ++ src/project_configuration.h | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index c25120e..ed59daa 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -36,13 +36,15 @@ void WiFiEvent(WiFiEvent_t event) { break; case SYSTEM_EVENT_ETH_START: logPrintlnI("ETH Started"); - ETH.setHostname("esp32-ethernet"); break; case SYSTEM_EVENT_ETH_CONNECTED: logPrintlnI("ETH Connected"); + ETH.setHostname("esp32-ethernet"); break; case SYSTEM_EVENT_ETH_GOT_IP: - logPrintI("ETH MAC: "); + logPrintI("Hostname: "); + logPrintI(ETH.getHostname()); + logPrintI(", ETH MAC: "); logPrintI(ETH.macAddress()); logPrintI(", IPv4: "); logPrintI(ETH.localIP().toString()); @@ -100,11 +102,12 @@ bool EthTask::setup(System &system) { delay(200); digitalWrite(ETH_NRST, 1); - if (!system.getUserConfig()->network.DHCP) { - ETH.config(system.getUserConfig()->network.staticIP, system.getUserConfig()->network.gateway, system.getUserConfig()->network.subnet, system.getUserConfig()->network.dns1, system.getUserConfig()->network.dns2); - } - ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK); + + if (!system.getUserConfig()->network.DHCP) { + ETH.config(system.getUserConfig()->network.staticIP, system.getUserConfig()->network.gateway, system.getUserConfig()->network.subnet, system.getUserConfig()->network.dns1, system.getUserConfig()->network.dns2); + } + ETH.setHostname(system.getUserConfig()->network.hostname.c_str()); return true; } diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 656d284..b81e706 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -9,6 +9,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.callsign = data["callsign"].as(); if (data.containsKey("network") && data["network"].containsKey("DHCP")) { + conf.network.hostname = data["network"]["hostname"].as(); conf.network.DHCP = data["network"]["DHCP"]; conf.network.staticIP.fromString(data["network"]["staticIP"].as()); conf.network.subnet.fromString(data["network"]["subnet"].as()); @@ -74,6 +75,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["callsign"] = conf.callsign; if (!conf.network.DHCP) { + data["network"]["hostname"] = conf.network.hostname; data["network"]["DHCP"] = conf.network.DHCP; data["network"]["staticIP"] = conf.network.staticIP.toString(); data["network"]["subnet"] = conf.network.subnet.toString(); diff --git a/src/project_configuration.h b/src/project_configuration.h index b2ba0bc..f3510b9 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -11,6 +11,7 @@ public: Network() : DHCP(true) { } + String hostname; bool DHCP; IPAddress staticIP; IPAddress subnet; From 75e85d8080e4511ad5e5464e958aec6f4f242e9b Mon Sep 17 00:00:00 2001 From: Denis Apel <35398698+stardado@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:24:08 +0100 Subject: [PATCH 008/125] Add files via upload From 6e10e0ce05c100f950f7487a92aa716f28369d92 Mon Sep 17 00:00:00 2001 From: Denis Apel <35398698+stardado@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:24:46 +0100 Subject: [PATCH 009/125] Add files via upload --- data/is-cfg.json | 1 + 1 file changed, 1 insertion(+) diff --git a/data/is-cfg.json b/data/is-cfg.json index 736d44c..029798b 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -1,6 +1,7 @@ { "callsign": "NOCALL-10", "network": { + "hostname": "lora-igate", "DHCP": true, "staticIP": "192.0.2.100", "subnet": "255.255.255.0", From fe860dad03b7474377cf64839b6875dbfd07b33f Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 18:05:14 +0100 Subject: [PATCH 010/125] Update project_configuration.h --- src/project_configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/project_configuration.h b/src/project_configuration.h index f3510b9..cdc0982 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -11,7 +11,7 @@ public: Network() : DHCP(true) { } - String hostname; + String hostname; bool DHCP; IPAddress staticIP; IPAddress subnet; From f28a551d1dd2d96eaeaa7a9d29bd673597eaca89 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 18:06:07 +0100 Subject: [PATCH 011/125] Update project_configuration.cpp --- src/project_configuration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index b81e706..c5e044f 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -10,7 +10,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen if (data.containsKey("network") && data["network"].containsKey("DHCP")) { conf.network.hostname = data["network"]["hostname"].as(); - conf.network.DHCP = data["network"]["DHCP"]; + conf.network.DHCP = data["network"]["DHCP"]; conf.network.staticIP.fromString(data["network"]["staticIP"].as()); conf.network.subnet.fromString(data["network"]["subnet"].as()); conf.network.gateway.fromString(data["network"]["gateway"].as()); From 87ce3b9800329c8c2cea42dd8f996d797973b795 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 18:07:37 +0100 Subject: [PATCH 012/125] Update TaskEth.cpp --- src/TaskEth.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index ed59daa..1d74eb5 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -104,8 +104,8 @@ bool EthTask::setup(System &system) { ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK); - if (!system.getUserConfig()->network.DHCP) { - ETH.config(system.getUserConfig()->network.staticIP, system.getUserConfig()->network.gateway, system.getUserConfig()->network.subnet, system.getUserConfig()->network.dns1, system.getUserConfig()->network.dns2); + if (!system.getUserConfig()->network.DHCP) { + ETH.config(system.getUserConfig()->network.staticIP, system.getUserConfig()->network.gateway, system.getUserConfig()->network.subnet, system.getUserConfig()->network.dns1, system.getUserConfig()->network.dns2); } ETH.setHostname(system.getUserConfig()->network.hostname.c_str()); return true; From 6869a22a6d928742690522802fe18530f3caf5c2 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 18:08:41 +0100 Subject: [PATCH 013/125] Update is-cfg.json --- data/is-cfg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 029798b..5018eb0 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -1,7 +1,7 @@ { "callsign": "NOCALL-10", "network": { - "hostname": "lora-igate", + "hostname": "NOCALL-10", "DHCP": true, "staticIP": "192.0.2.100", "subnet": "255.255.255.0", From 6897dd4856dbb210e5eb3eea2320d4147bc30801 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 18:13:33 +0100 Subject: [PATCH 014/125] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 29e9c73..bc8bd22 100644 --- a/README.md +++ b/README.md @@ -125,3 +125,4 @@ A direct mount of the [other display](pics/display-wrong.jpg) is not possible wi The 'wrong' display works too but you have to change VCC and GND by wire ! feel free to add hints! + From fb00628305b183efaef3bec367213c6a6ffe90e6 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 18:33:30 +0100 Subject: [PATCH 015/125] Update LoRa_APRS_iGate.cpp --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 6e4cf58..94b5cbf 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -18,7 +18,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "21.44.0-dev" +#define VERSION "21.50.0" String create_lat_aprs(double lat); String create_long_aprs(double lng); From f1e64a6acfa457e675083ec2e42be81d6105f202 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 22:33:35 +0100 Subject: [PATCH 016/125] fix hostname and static ip settings --- data/is-cfg.json | 17 +++++++++----- src/TaskEth.cpp | 9 +++++--- src/TaskOTA.cpp | 6 ++++- src/TaskWifi.cpp | 8 +++++-- src/project_configuration.cpp | 42 ++++++++++++++++++++++------------- src/project_configuration.h | 25 +++++++++++++++------ 6 files changed, 73 insertions(+), 34 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index cf49d82..bab9eae 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -1,13 +1,18 @@ { "callsign": "NOCALL-10", "network": { - "hostname": "NOCALL-10", "DHCP": true, - "staticIP": "192.0.2.100", - "subnet": "255.255.255.0", - "gateway": "192.0.2.1", - "dns1": "192.0.2.1", - "dns2": "192.0.2.2" + "static": { + "ip": "192.168.0.100", + "subnet": "255.255.255.0", + "gateway": "192.168.0.1", + "dns1": "192.168.0.1", + "dns2": "192.168.0.2" + }, + "hostname": { + "overwrite": false, + "name": "NOCALL-10" + } }, "wifi": { "active": true, diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index 1d74eb5..720856e 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -39,7 +39,6 @@ void WiFiEvent(WiFiEvent_t event) { break; case SYSTEM_EVENT_ETH_CONNECTED: logPrintlnI("ETH Connected"); - ETH.setHostname("esp32-ethernet"); break; case SYSTEM_EVENT_ETH_GOT_IP: logPrintI("Hostname: "); @@ -105,9 +104,13 @@ bool EthTask::setup(System &system) { ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK); if (!system.getUserConfig()->network.DHCP) { - ETH.config(system.getUserConfig()->network.staticIP, system.getUserConfig()->network.gateway, system.getUserConfig()->network.subnet, system.getUserConfig()->network.dns1, system.getUserConfig()->network.dns2); + ETH.config(system.getUserConfig()->network.static_.ip, system.getUserConfig()->network.static_.gateway, system.getUserConfig()->network.static_.subnet, system.getUserConfig()->network.static_.dns1, system.getUserConfig()->network.static_.dns2); + } + if (system.getUserConfig()->network.hostname.overwrite) { + ETH.setHostname(system.getUserConfig()->network.hostname.name.c_str()); + } else { + ETH.setHostname(system.getUserConfig()->callsign.c_str()); } - ETH.setHostname(system.getUserConfig()->network.hostname.c_str()); return true; } diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index 6b6348c..d3bd60c 100644 --- a/src/TaskOTA.cpp +++ b/src/TaskOTA.cpp @@ -43,7 +43,11 @@ bool OTATask::setup(System &system) { else if (error == OTA_END_ERROR) logPrintlnE("End Failed"); }); - _ota.setHostname(system.getUserConfig()->callsign.c_str()); + if (system.getUserConfig()->network.hostname.overwrite) { + _ota.setHostname(system.getUserConfig()->network.hostname.name.c_str()); + } else { + _ota.setHostname(system.getUserConfig()->callsign.c_str()); + } _stateInfo = ""; return true; } diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index 6a0b54e..aa02876 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -20,10 +20,14 @@ bool WifiTask::setup(System &system) { WiFi.mode(WIFI_STA); WiFi.onEvent(WiFiEvent); - WiFi.setHostname(system.getUserConfig()->callsign.c_str()); + if (system.getUserConfig()->network.hostname.overwrite) { + WiFi.setHostname(system.getUserConfig()->network.hostname.name.c_str()); + } else { + WiFi.setHostname(system.getUserConfig()->callsign.c_str()); + } if (!system.getUserConfig()->network.DHCP) { - WiFi.config(system.getUserConfig()->network.staticIP, system.getUserConfig()->network.gateway, system.getUserConfig()->network.subnet, system.getUserConfig()->network.dns1, system.getUserConfig()->network.dns2); + WiFi.config(system.getUserConfig()->network.static_.ip, system.getUserConfig()->network.static_.gateway, system.getUserConfig()->network.static_.subnet, system.getUserConfig()->network.static_.dns1, system.getUserConfig()->network.static_.dns2); } for (Configuration::Wifi::AP ap : system.getUserConfig()->wifi.APs) { diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index cd3702b..3ca11f2 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -8,14 +8,25 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen if (data.containsKey("callsign")) conf.callsign = data["callsign"].as(); - if (data.containsKey("network") && data["network"].containsKey("DHCP")) { - conf.network.hostname = data["network"]["hostname"].as(); - conf.network.DHCP = data["network"]["DHCP"]; - conf.network.staticIP.fromString(data["network"]["staticIP"].as()); - conf.network.subnet.fromString(data["network"]["subnet"].as()); - conf.network.gateway.fromString(data["network"]["gateway"].as()); - conf.network.dns1.fromString(data["network"]["dns1"].as()); - conf.network.dns2.fromString(data["network"]["dns2"].as()); + if (data.containsKey("network")) { + conf.network.DHCP = data["network"]["DHCP"] | false; + if (data["network"].containsKey("static")) { + if (data["network"]["static"].containsKey("ip")) + conf.network.static_.ip.fromString(data["network"]["static"]["ip"].as()); + if (data["network"]["static"].containsKey("subnet")) + conf.network.static_.subnet.fromString(data["network"]["static"]["subnet"].as()); + if (data["network"]["static"].containsKey("gateway")) + conf.network.static_.gateway.fromString(data["network"]["static"]["gateway"].as()); + if (data["network"]["static"].containsKey("dns1")) + conf.network.static_.dns1.fromString(data["network"]["static"]["dns1"].as()); + if (data["network"]["static"].containsKey("dns2")) + conf.network.static_.dns2.fromString(data["network"]["static"]["dns2"].as()); + } + if (data["network"].containsKey("hostname")) { + conf.network.hostname.overwrite = data["network"]["hostname"]["overwrite"] | false; + if (data["network"]["hostname"].containsKey("name")) + conf.network.hostname.name = data["network"]["hostname"]["name"].as(); + } } conf.wifi.active = data["wifi"]["active"]; @@ -77,13 +88,14 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["callsign"] = conf.callsign; if (!conf.network.DHCP) { - data["network"]["hostname"] = conf.network.hostname; - data["network"]["DHCP"] = conf.network.DHCP; - data["network"]["staticIP"] = conf.network.staticIP.toString(); - data["network"]["subnet"] = conf.network.subnet.toString(); - data["network"]["gateway"] = conf.network.gateway.toString(); - data["network"]["dns1"] = conf.network.dns1.toString(); - data["network"]["dns2"] = conf.network.dns2.toString(); + data["network"]["DHCP"] = conf.network.DHCP; + data["network"]["static"]["ip"] = conf.network.static_.ip.toString(); + data["network"]["static"]["subnet"] = conf.network.static_.subnet.toString(); + data["network"]["static"]["gateway"] = conf.network.static_.gateway.toString(); + data["network"]["static"]["dns1"] = conf.network.static_.dns1.toString(); + data["network"]["static"]["dns2"] = conf.network.static_.dns2.toString(); + data["network"]["hostname"]["overwrite"] = conf.network.hostname.overwrite; + data["network"]["hostname"]["name"] = conf.network.hostname.name; } data["wifi"]["active"] = conf.wifi.active; diff --git a/src/project_configuration.h b/src/project_configuration.h index 9ec3432..09745c4 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -6,18 +6,29 @@ class Configuration { public: + class Static { + public: + IPAddress ip; + IPAddress subnet; + IPAddress gateway; + IPAddress dns1; + IPAddress dns2; + }; + + class Hostname { + public: + bool overwrite; + String name; + }; + class Network { public: Network() : DHCP(true) { } - String hostname; - bool DHCP; - IPAddress staticIP; - IPAddress subnet; - IPAddress gateway; - IPAddress dns1; - IPAddress dns2; + bool DHCP; + Static static_; + Hostname hostname; }; class Wifi { From 348a9c63a0eb83e80176446730b5d89c7d4dd677 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 18 Dec 2021 22:50:00 +0100 Subject: [PATCH 017/125] Update README.md --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index bc8bd22..1adfc06 100644 --- a/README.md +++ b/README.md @@ -69,16 +69,6 @@ The best success is to use PlatformIO (and it is the only platform where I can s This firmware is developed in a rolling release system: everyday a new release could be created. But there are still rules where new pull requests has to go and and how the version system looks like. -### Branches - -There are 2 main branches: -* *master* and -* *develop* - -The *master* branch has all releases and is the most stable one. With the different tags you can jump to different versions or if you take the most current *master* branch you will just get the latest, stable version. There will be no side releases which are branched of from *master*. If there is a bugfix version it will be done directly on the *master* branch and a tag will be generated with a new version. - -The *develop* branch is used for new feature development. It will be also used to stabilize the current development to create a new stable version (pull request to *master* branch). **Again:** all new development (pull requests) has to go directly into the *develop* branch! - ### Version system If the *develop* branch is stable enough for a new release it will be merged with a pull request to the *master* branch and a new version will be generated. From a04e710291181d7dd4afd97c2b574a15548835a9 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 20 Dec 2021 11:27:45 +0100 Subject: [PATCH 018/125] set LNA to max --- lib/LoRa/LoRa.cpp | 234 +++++++++++++++++++--------------------------- 1 file changed, 96 insertions(+), 138 deletions(-) diff --git a/lib/LoRa/LoRa.cpp b/lib/LoRa/LoRa.cpp index 59142ec..35dfacd 100644 --- a/lib/LoRa/LoRa.cpp +++ b/lib/LoRa/LoRa.cpp @@ -41,47 +41,39 @@ #define REG_PA_DAC 0x4d // modes -#define MODE_LONG_RANGE_MODE 0x80 -#define MODE_SLEEP 0x00 -#define MODE_STDBY 0x01 -#define MODE_TX 0x03 -#define MODE_RX_CONTINUOUS 0x05 -#define MODE_RX_SINGLE 0x06 +#define MODE_LONG_RANGE_MODE 0x80 +#define MODE_SLEEP 0x00 +#define MODE_STDBY 0x01 +#define MODE_TX 0x03 +#define MODE_RX_CONTINUOUS 0x05 +#define MODE_RX_SINGLE 0x06 // PA config -#define PA_BOOST 0x80 +#define PA_BOOST 0x80 // IRQ masks #define IRQ_TX_DONE_MASK 0x08 #define IRQ_PAYLOAD_CRC_ERROR_MASK 0x20 #define IRQ_RX_DONE_MASK 0x40 -#define RF_MID_BAND_THRESHOLD 525E6 -#define RSSI_OFFSET_HF_PORT 157 -#define RSSI_OFFSET_LF_PORT 164 +#define RF_MID_BAND_THRESHOLD 525E6 +#define RSSI_OFFSET_HF_PORT 157 +#define RSSI_OFFSET_LF_PORT 164 -#define MAX_PKT_LENGTH 255 +#define MAX_PKT_LENGTH 255 #if (ESP8266 || ESP32) - #define ISR_PREFIX ICACHE_RAM_ATTR +#define ISR_PREFIX ICACHE_RAM_ATTR #else - #define ISR_PREFIX +#define ISR_PREFIX #endif -LoRaClass::LoRaClass() : - _spiSettings(LORA_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE0), - _spi(&LORA_DEFAULT_SPI), - _ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN), - _frequency(0), - _packetIndex(0), - _implicitHeaderMode(0) -{ +LoRaClass::LoRaClass() : _spiSettings(LORA_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE0), _spi(&LORA_DEFAULT_SPI), _ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN), _frequency(0), _packetIndex(0), _implicitHeaderMode(0) { // overide Stream timeout value setTimeout(0); } -int LoRaClass::begin(long frequency) -{ +int LoRaClass::begin(long frequency) { #if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) pinMode(LORA_IRQ_DUMB, OUTPUT); digitalWrite(LORA_IRQ_DUMB, LOW); @@ -134,7 +126,7 @@ int LoRaClass::begin(long frequency) writeRegister(REG_FIFO_RX_BASE_ADDR, 0); // set LNA boost - writeRegister(REG_LNA, readRegister(REG_LNA) | 0x03); + writeRegister(REG_LNA, readRegister(REG_LNA) | 0x01); // set auto AGC writeRegister(REG_MODEM_CONFIG_3, 0x04); @@ -148,8 +140,7 @@ int LoRaClass::begin(long frequency) return 1; } -void LoRaClass::end() -{ +void LoRaClass::end() { // put in sleep mode sleep(); @@ -157,8 +148,7 @@ void LoRaClass::end() _spi->end(); } -int LoRaClass::beginPacket(int implicitHeader) -{ +int LoRaClass::beginPacket(int implicitHeader) { if (isTransmitting()) { return 0; } @@ -179,8 +169,7 @@ int LoRaClass::beginPacket(int implicitHeader) return 1; } -int LoRaClass::endPacket(bool async) -{ +int LoRaClass::endPacket(bool async) { // put in TX mode writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_TX); @@ -197,8 +186,7 @@ int LoRaClass::endPacket(bool async) return 1; } -bool LoRaClass::isTransmitting() -{ +bool LoRaClass::isTransmitting() { if ((readRegister(REG_OP_MODE) & MODE_TX) == MODE_TX) { return true; } @@ -211,10 +199,9 @@ bool LoRaClass::isTransmitting() return false; } -int LoRaClass::parsePacket(int size) -{ +int LoRaClass::parsePacket(int size) { int packetLength = 0; - int irqFlags = readRegister(REG_IRQ_FLAGS); + int irqFlags = readRegister(REG_IRQ_FLAGS); if (size > 0) { implicitHeaderMode(); @@ -256,47 +243,41 @@ int LoRaClass::parsePacket(int size) return packetLength; } -int LoRaClass::packetRssi() -{ +int LoRaClass::packetRssi() { return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT)); } -float LoRaClass::packetSnr() -{ +float LoRaClass::packetSnr() { return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25; } -long LoRaClass::packetFrequencyError() -{ +long LoRaClass::packetFrequencyError() { int32_t freqError = 0; - freqError = static_cast(readRegister(REG_FREQ_ERROR_MSB) & B111); + freqError = static_cast(readRegister(REG_FREQ_ERROR_MSB) & B111); freqError <<= 8L; freqError += static_cast(readRegister(REG_FREQ_ERROR_MID)); freqError <<= 8L; freqError += static_cast(readRegister(REG_FREQ_ERROR_LSB)); if (readRegister(REG_FREQ_ERROR_MSB) & B1000) { // Sign bit is on - freqError -= 524288; // B1000'0000'0000'0000'0000 + freqError -= 524288; // B1000'0000'0000'0000'0000 } - const float fXtal = 32E6; // FXOSC: crystal oscillator (XTAL) frequency (2.5. Chip Specification, p. 14) + const float fXtal = 32E6; // FXOSC: crystal oscillator (XTAL) frequency (2.5. Chip Specification, p. 14) const float fError = ((static_cast(freqError) * (1L << 24)) / fXtal) * (getSignalBandwidth() / 500000.0f); // p. 37 return static_cast(fError); } -int LoRaClass::rssi() -{ +int LoRaClass::rssi() { return (readRegister(REG_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT)); } -size_t LoRaClass::write(uint8_t byte) -{ +size_t LoRaClass::write(uint8_t byte) { return write(&byte, sizeof(byte)); } -size_t LoRaClass::write(const uint8_t *buffer, size_t size) -{ +size_t LoRaClass::write(const uint8_t *buffer, size_t size) { int currentLength = readRegister(REG_PAYLOAD_LENGTH); // check size @@ -315,13 +296,11 @@ size_t LoRaClass::write(const uint8_t *buffer, size_t size) return size; } -int LoRaClass::available() -{ +int LoRaClass::available() { return (readRegister(REG_RX_NB_BYTES) - _packetIndex); } -int LoRaClass::read() -{ +int LoRaClass::read() { if (!available()) { return -1; } @@ -331,8 +310,7 @@ int LoRaClass::read() return readRegister(REG_FIFO); } -int LoRaClass::peek() -{ +int LoRaClass::peek() { if (!available()) { return -1; } @@ -349,12 +327,10 @@ int LoRaClass::peek() return b; } -void LoRaClass::flush() -{ +void LoRaClass::flush() { } -void LoRaClass::receive(int size) -{ +void LoRaClass::receive(int size) { writeRegister(REG_DIO_MAPPING_1, 0x00); // DIO0 => RXDONE @@ -369,18 +345,15 @@ void LoRaClass::receive(int size) writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS); } -void LoRaClass::idle() -{ +void LoRaClass::idle() { writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_STDBY); } -void LoRaClass::sleep() -{ +void LoRaClass::sleep() { writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_SLEEP); } -void LoRaClass::setTxPower(int level, int outputPin) -{ +void LoRaClass::setTxPower(int level, int outputPin) { if (PA_OUTPUT_RFO_PIN == outputPin) { // RFO if (level < 0) { @@ -407,7 +380,7 @@ void LoRaClass::setTxPower(int level, int outputPin) if (level < 2) { level = 2; } - //Default value PA_HF/LF or +17dBm + // Default value PA_HF/LF or +17dBm writeRegister(REG_PA_DAC, 0x84); setOCP(100); } @@ -416,8 +389,7 @@ void LoRaClass::setTxPower(int level, int outputPin) } } -void LoRaClass::setFrequency(long frequency) -{ +void LoRaClass::setFrequency(long frequency) { _frequency = frequency; uint64_t frf = ((uint64_t)frequency << 19) / 32000000; @@ -427,13 +399,11 @@ void LoRaClass::setFrequency(long frequency) writeRegister(REG_FRF_LSB, (uint8_t)(frf >> 0)); } -int LoRaClass::getSpreadingFactor() -{ +int LoRaClass::getSpreadingFactor() { return readRegister(REG_MODEM_CONFIG_2) >> 4; } -void LoRaClass::setSpreadingFactor(int sf) -{ +void LoRaClass::setSpreadingFactor(int sf) { if (sf < 6) { sf = 6; } else if (sf > 12) { @@ -452,28 +422,36 @@ void LoRaClass::setSpreadingFactor(int sf) setLdoFlag(); } -long LoRaClass::getSignalBandwidth() -{ +long LoRaClass::getSignalBandwidth() { byte bw = (readRegister(REG_MODEM_CONFIG_1) >> 4); switch (bw) { - case 0: return 7.8E3; - case 1: return 10.4E3; - case 2: return 15.6E3; - case 3: return 20.8E3; - case 4: return 31.25E3; - case 5: return 41.7E3; - case 6: return 62.5E3; - case 7: return 125E3; - case 8: return 250E3; - case 9: return 500E3; + case 0: + return 7.8E3; + case 1: + return 10.4E3; + case 2: + return 15.6E3; + case 3: + return 20.8E3; + case 4: + return 31.25E3; + case 5: + return 41.7E3; + case 6: + return 62.5E3; + case 7: + return 125E3; + case 8: + return 250E3; + case 9: + return 500E3; } return -1; } -void LoRaClass::setSignalBandwidth(long sbw) -{ +void LoRaClass::setSignalBandwidth(long sbw) { int bw; if (sbw <= 7.8E3) { @@ -502,10 +480,9 @@ void LoRaClass::setSignalBandwidth(long sbw) setLdoFlag(); } -void LoRaClass::setLdoFlag() -{ +void LoRaClass::setLdoFlag() { // Section 4.1.1.5 - long symbolDuration = 1000 / ( getSignalBandwidth() / (1L << getSpreadingFactor()) ) ; + long symbolDuration = 1000 / (getSignalBandwidth() / (1L << getSpreadingFactor())); // Section 4.1.1.6 boolean ldoOn = symbolDuration > 16; @@ -515,8 +492,7 @@ void LoRaClass::setLdoFlag() writeRegister(REG_MODEM_CONFIG_3, config3); } -void LoRaClass::setCodingRate4(int denominator) -{ +void LoRaClass::setCodingRate4(int denominator) { if (denominator < 5) { denominator = 5; } else if (denominator > 8) { @@ -528,62 +504,54 @@ void LoRaClass::setCodingRate4(int denominator) writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0xf1) | (cr << 1)); } -void LoRaClass::setPreambleLength(long length) -{ +void LoRaClass::setPreambleLength(long length) { writeRegister(REG_PREAMBLE_MSB, (uint8_t)(length >> 8)); writeRegister(REG_PREAMBLE_LSB, (uint8_t)(length >> 0)); } -void LoRaClass::setSyncWord(int sw) -{ +void LoRaClass::setSyncWord(int sw) { writeRegister(REG_SYNC_WORD, sw); } -void LoRaClass::enableCrc() -{ +void LoRaClass::enableCrc() { writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) | 0x04); } -void LoRaClass::disableCrc() -{ +void LoRaClass::disableCrc() { writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) & 0xfb); } -void LoRaClass::enableInvertIQ() -{ - writeRegister(REG_INVERTIQ, 0x66); +void LoRaClass::enableInvertIQ() { + writeRegister(REG_INVERTIQ, 0x66); writeRegister(REG_INVERTIQ2, 0x19); } -void LoRaClass::disableInvertIQ() -{ - writeRegister(REG_INVERTIQ, 0x27); +void LoRaClass::disableInvertIQ() { + writeRegister(REG_INVERTIQ, 0x27); writeRegister(REG_INVERTIQ2, 0x1d); } -void LoRaClass::setOCP(uint8_t mA) -{ +void LoRaClass::setOCP(uint8_t mA) { uint8_t ocpTrim = 27; if (mA <= 120) { ocpTrim = (mA - 45) / 5; - } else if (mA <=240) { + } else if (mA <= 240) { ocpTrim = (mA + 30) / 10; } writeRegister(REG_OCP, 0x20 | (0x1F & ocpTrim)); } -void LoRaClass::setGain(uint8_t gain) -{ +void LoRaClass::setGain(uint8_t gain) { // check allowed range if (gain > 6) { gain = 6; } - + // set to standby idle(); - + // set gain if (gain == 0) { // if gain = 0, enable AGC @@ -591,39 +559,34 @@ void LoRaClass::setGain(uint8_t gain) } else { // disable AGC writeRegister(REG_MODEM_CONFIG_3, 0x00); - + // clear Gain and set LNA boost - writeRegister(REG_LNA, 0x03); - + writeRegister(REG_LNA, 0x01); + // set gain writeRegister(REG_LNA, readRegister(REG_LNA) | (gain << 5)); } } -byte LoRaClass::random() -{ +byte LoRaClass::random() { return readRegister(REG_RSSI_WIDEBAND); } -void LoRaClass::setPins(int ss, int reset, int dio0) -{ - _ss = ss; +void LoRaClass::setPins(int ss, int reset, int dio0) { + _ss = ss; _reset = reset; - _dio0 = dio0; + _dio0 = dio0; } -void LoRaClass::setSPI(SPIClass& spi) -{ +void LoRaClass::setSPI(SPIClass &spi) { _spi = &spi; } -void LoRaClass::setSPIFrequency(uint32_t frequency) -{ +void LoRaClass::setSPIFrequency(uint32_t frequency) { _spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0); } -void LoRaClass::dumpRegisters(Stream& out) -{ +void LoRaClass::dumpRegisters(Stream &out) { for (int i = 0; i < 128; i++) { out.print("0x"); out.print(i, HEX); @@ -632,32 +595,27 @@ void LoRaClass::dumpRegisters(Stream& out) } } -void LoRaClass::explicitHeaderMode() -{ +void LoRaClass::explicitHeaderMode() { _implicitHeaderMode = 0; writeRegister(REG_MODEM_CONFIG_1, readRegister(REG_MODEM_CONFIG_1) & 0xfe); } -void LoRaClass::implicitHeaderMode() -{ +void LoRaClass::implicitHeaderMode() { _implicitHeaderMode = 1; writeRegister(REG_MODEM_CONFIG_1, readRegister(REG_MODEM_CONFIG_1) | 0x01); } -uint8_t LoRaClass::readRegister(uint8_t address) -{ +uint8_t LoRaClass::readRegister(uint8_t address) { return singleTransfer(address & 0x7f, 0x00); } -void LoRaClass::writeRegister(uint8_t address, uint8_t value) -{ +void LoRaClass::writeRegister(uint8_t address, uint8_t value) { singleTransfer(address | 0x80, value); } -uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value) -{ +uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value) { uint8_t response; digitalWrite(_ss, LOW); From d6388ccc32709a83d8837b27468f878d9e5d2b1b Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 17 Feb 2022 21:59:35 +0100 Subject: [PATCH 019/125] add version check --- .github/workflows/build_check.yml | 11 ++++++++++ scripts/check_version.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 scripts/check_version.py diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 542fe65..21e8860 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -3,6 +3,17 @@ name: Integreation Tests on: [push, pull_request] jobs: + version_check: + name: Version Check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + - name: check version + run: ./scripts/check_version.py + build: name: Compile Firmware runs-on: ubuntu-latest diff --git a/scripts/check_version.py b/scripts/check_version.py new file mode 100755 index 0000000..95e29c0 --- /dev/null +++ b/scripts/check_version.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +from datetime import date + +today = date.today() + +current_year = int(str(today.isocalendar()[0])[2:]) +current_week = int(today.isocalendar()[1]) + +version = None +with open("src/LoRa_APRS_iGate.cpp") as f: + for line in f: + if line.startswith("#define VERSION"): + version = line.strip().split(" ")[2].replace('"', "") + +version_split = version.split(".") +version_year = int(version_split[0]) +version_week = int(version_split[1]) + +print(f"firmware version year: {version_year}") +print(f"firmware version week: {version_week}") + +print(f"current year: {current_year}") +print(f"current week: {current_week}") + +error = False +if version_year != current_year: + print("firmware version is not current year!") + error = True + +if version_week != current_week: + print("firmware version is not current week!") + error = True + +exit(error) From 367ccd61ec2228628ad55ab2608b4ec6a7433574 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 17 Feb 2022 22:00:34 +0100 Subject: [PATCH 020/125] update version --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 94b5cbf..4f07a62 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -18,7 +18,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "21.50.0" +#define VERSION "22.7.0" String create_lat_aprs(double lat); String create_long_aprs(double lng); From 0b8e1363fb734207049f95cbbcc2931b02d4f3c9 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 17 Feb 2022 22:04:14 +0100 Subject: [PATCH 021/125] update clang-format-action --- .github/workflows/build_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 21e8860..3694829 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -52,7 +52,7 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Run clang-format style check for C/C++ programs. - uses: jidicula/clang-format-action@v3.2.0 + uses: jidicula/clang-format-action@v4.5.0 with: clang-format-version: '11' check-path: ${{ matrix.path }} From 6cc03c6a41b77d752bff2cb65afa97219b704077 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 17 Feb 2022 22:09:29 +0100 Subject: [PATCH 022/125] update q-path closing #145 --- src/TaskRouter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index f64f6b0..a1aa985 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -43,7 +43,7 @@ bool RouterTask::loop(System &system) { path += ","; } - aprsIsMsg->setPath(path + "qAR," + system.getUserConfig()->callsign); + aprsIsMsg->setPath(path + "qAO," + system.getUserConfig()->callsign); logPrintD("APRS-IS: "); logPrintlnD(aprsIsMsg->toString()); From b099a2ecf8140c494be823f5d01de1f9a679abeb Mon Sep 17 00:00:00 2001 From: Manuel Schrape Date: Wed, 23 Feb 2022 19:40:31 +0100 Subject: [PATCH 023/125] Adding MQTT for local APRS Packet storage. --- data/is-cfg.json | 8 ++++ platformio.ini | 1 + src/LoRa_APRS_iGate.cpp | 11 ++++- src/Task.h | 2 + src/TaskMQTT.cpp | 88 +++++++++++++++++++++++++++++++++++ src/TaskMQTT.h | 22 +++++++++ src/TaskRouter.cpp | 7 ++- src/TaskRouter.h | 5 +- src/project_configuration.cpp | 14 ++++++ src/project_configuration.h | 11 +++++ 10 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 src/TaskMQTT.cpp create mode 100644 src/TaskMQTT.h diff --git a/data/is-cfg.json b/data/is-cfg.json index bab9eae..190ad2c 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -65,5 +65,13 @@ } ] }, + "mqtt": { + "active": false, + "server": "", + "port": 1883, + "name": "", + "password": "", + "topic": "LoraAPRS/Data" + }, "ntp_server": "pool.ntp.org" } diff --git a/platformio.ini b/platformio.ini index c955992..ce8560b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,6 +13,7 @@ lib_deps = peterus/APRS-Decoder-Lib @ 0.0.6 peterus/esp-logger @ 0.0.1 peterus/ESP-FTP-Server-Lib @ 0.9.5 + knolleary/PubSubClient@^2.8 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 4f07a62..cdb7931 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -16,9 +16,10 @@ #include "TaskOTA.h" #include "TaskRouter.h" #include "TaskWifi.h" +#include "TaskMQTT.h" #include "project_configuration.h" -#define VERSION "22.7.0" +#define VERSION "22.7.0_zj" String create_lat_aprs(double lat); String create_long_aprs(double lng); @@ -26,6 +27,7 @@ String create_long_aprs(double lng); TaskQueue> toAprsIs; TaskQueue> fromModem; TaskQueue> toModem; +TaskQueue> toMQTT; System LoRaSystem; Configuration userConfig; @@ -37,8 +39,9 @@ WifiTask wifiTask; OTATask otaTask; NTPTask ntpTask; FTPTask ftpTask; +MQTTTask mqttTask(toMQTT); AprsIsTask aprsIsTask(toAprsIs); -RouterTask routerTask(fromModem, toModem, toAprsIs); +RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); void setup() { Serial.begin(115200); @@ -114,6 +117,10 @@ void setup() { LoRaSystem.getTaskManager().addTask(&aprsIsTask); } + if (userConfig.mqtt.active) { + LoRaSystem.getTaskManager().addTask(&mqttTask); + } + LoRaSystem.getTaskManager().setup(LoRaSystem); LoRaSystem.getDisplay().showSpashScreen("LoRa APRS iGate", VERSION); diff --git a/src/Task.h b/src/Task.h index 4c8163b..3a06ab8 100644 --- a/src/Task.h +++ b/src/Task.h @@ -12,6 +12,7 @@ enum TaskNames TaskWifi, TaskRouter, TaskSize, + TaskMQTT, }; #define TASK_APRS_IS "AprsIsTask" @@ -22,5 +23,6 @@ enum TaskNames #define TASK_OTA "OTATask" #define TASK_WIFI "WifiTask" #define TASK_ROUTER "RouterTask" +#define TASK_MQTT "MQTTTask" #endif diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp new file mode 100644 index 0000000..a808670 --- /dev/null +++ b/src/TaskMQTT.cpp @@ -0,0 +1,88 @@ +#include + +#include "Task.h" +#include "TaskMQTT.h" +#include "project_configuration.h" + +#include +#include + +#include + +WiFiClient wiFiClient; +PubSubClient _MQTT(wiFiClient); + + +MQTTTask::MQTTTask(TaskQueue> &toMQTT) : Task(TASK_MQTT, TaskMQTT), _beginCalled(false), _toMQTT(toMQTT) { +} + +MQTTTask::~MQTTTask() { +} + +bool MQTTTask::setup(System &system) { + _MQTT.setServer(system.getUserConfig()->mqtt.server.c_str(), system.getUserConfig()->mqtt.port); + + return true; +} + +bool MQTTTask::loop(System &system) { + if (!_beginCalled) { + _beginCalled = true; + } + + if (!system.isWifiEthConnected()) { + return false; + } + + if (!_MQTT.connected()) { + connect(system); + } + + if (!_toMQTT.empty()) { + std::shared_ptr msg = _toMQTT.getElement(); + + DynamicJsonDocument _Data(1024); + String _r; + + _Data["Source"] = msg->getSource(); + _Data["Destination"] = msg->getDestination(); + _Data["Path"] = msg->getPath(); + _Data["Type"] = msg->getType().toString(); + String _body = msg->getBody()->encode(); + _body.replace("\n", ""); + _Data["Data"] = _body; + + serializeJson(_Data, _r); + + logPrintD("Send MQTT: "); + logPrintlnD(_r); + + String _topic = String(system.getUserConfig()->mqtt.topic); + + if (!_topic.endsWith("/")) { + _topic = _topic + "/"; + } + _topic = _topic + system.getUserConfig()->callsign; + + _MQTT.publish(_topic.c_str(), _r.c_str()); + } + _MQTT.loop(); + return true; +} + +bool MQTTTask::connect(const System &system) { + logPrintI("Connecting to MQTT broker: "); + logPrintI(system.getUserConfig()->mqtt.server); + logPrintI(" on port "); + logPrintlnI(String(system.getUserConfig()->mqtt.port)); + + if (_MQTT.connect(system.getUserConfig()->callsign.c_str(),system.getUserConfig()->mqtt.name.c_str() ,system.getUserConfig()->mqtt.password.c_str() )) { + logPrintI("Connected to MQTT broker as: "); + logPrintlnI(system.getUserConfig()->callsign); + + return true; + } else { + logPrintlnI("Connecting to MQTT broker faild. Try again later."); + } + return false; +} diff --git a/src/TaskMQTT.h b/src/TaskMQTT.h new file mode 100644 index 0000000..ca3304c --- /dev/null +++ b/src/TaskMQTT.h @@ -0,0 +1,22 @@ +#ifndef TASK_MQTT_H_ +#define TASK_MQTT_H_ + +#include +#include +#include + +class MQTTTask : public Task { +public: + MQTTTask(TaskQueue> &toMQTT); + virtual ~MQTTTask(); + + virtual bool setup(System &system) override; + virtual bool loop(System &system) override; + +private: + bool _beginCalled; + TaskQueue> &_toMQTT; + bool connect(const System &system); +}; + +#endif diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index a1aa985..61d7c2c 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -9,7 +9,7 @@ String create_lat_aprs(double lat); String create_long_aprs(double lng); -RouterTask::RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs) : Task(TASK_ROUTER, TaskRouter), _fromModem(fromModem), _toModem(toModem), _toAprsIs(toAprsIs) { +RouterTask::RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs, TaskQueue> &toMQTT) : Task(TASK_ROUTER, TaskRouter), _fromModem(fromModem), _toModem(toModem), _toAprsIs(toAprsIs), _toMQTT(toMQTT) { } RouterTask::~RouterTask() { @@ -33,6 +33,11 @@ bool RouterTask::loop(System &system) { // do routing if (!_fromModem.empty()) { std::shared_ptr modemMsg = _fromModem.getElement(); + std::shared_ptr DataMQTT = modemMsg; + + if (system.getUserConfig()->mqtt.active) { + _toMQTT.addElement(DataMQTT); + } if (system.getUserConfig()->aprs_is.active && modemMsg->getSource() != system.getUserConfig()->callsign) { std::shared_ptr aprsIsMsg = std::make_shared(*modemMsg); diff --git a/src/TaskRouter.h b/src/TaskRouter.h index 8d8d1ac..617f476 100644 --- a/src/TaskRouter.h +++ b/src/TaskRouter.h @@ -3,10 +3,12 @@ #include #include +#include class RouterTask : public Task { public: - RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs); + RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs, TaskQueue> &toMQTT +); virtual ~RouterTask(); virtual bool setup(System &system) override; @@ -16,6 +18,7 @@ private: TaskQueue> &_fromModem; TaskQueue> &_toModem; TaskQueue> &_toAprsIs; + TaskQueue> &_toMQTT; std::shared_ptr _beaconMsg; Timer _beacon_timer; diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 3ca11f2..78a2510 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -77,6 +77,14 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen us.password = "ftp"; conf.ftp.users.push_back(us); } + if (data.containsKey("mqtt")) { + conf.mqtt.active = data["mqtt"]["active"] | false; + conf.mqtt.server = data["mqtt"]["server"].as(); + conf.mqtt.port = data["mqtt"]["port"].as(); + conf.mqtt.name = data["mqtt"]["name"].as(); + conf.mqtt.password = data["mqtt"]["password"].as(); + conf.mqtt.topic = data["mqtt"]["topic"].as(); + } if (data.containsKey("ntp_server")) conf.ntpServer = data["ntp_server"].as(); @@ -133,6 +141,12 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co v["name"] = u.name; v["password"] = u.password; } + data["mqtt"]["active"] = conf.mqtt.active; + data["mqtt"]["server"] = conf.mqtt.server; + data["mqtt"]["port"] = conf.mqtt.port; + data["mqtt"]["name"] = conf.mqtt.name; + data["mqtt"]["password"] = conf.mqtt.password; + data["mqtt"]["topic"] = conf.mqtt.topic; data["ntp_server"] = conf.ntpServer; data["board"] = conf.board; diff --git a/src/project_configuration.h b/src/project_configuration.h index 09745c4..12e94a7 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -117,6 +117,16 @@ public: std::list users; }; + class MQTT { + public: + bool active; + String server; + uint16_t port; + String name; + String password; + String topic; + }; + Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org"){}; String callsign; @@ -128,6 +138,7 @@ public: LoRa lora; Display display; Ftp ftp; + MQTT mqtt; String board; String ntpServer; }; From e9158a44fdfef464aea56c58d6940b4a0b5a42d3 Mon Sep 17 00:00:00 2001 From: Manuel Schrape Date: Thu, 24 Feb 2022 15:36:17 +0100 Subject: [PATCH 024/125] Removed unnecessary variable DataMQTT. --- src/TaskRouter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index 61d7c2c..2ab3cd5 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -33,10 +33,9 @@ bool RouterTask::loop(System &system) { // do routing if (!_fromModem.empty()) { std::shared_ptr modemMsg = _fromModem.getElement(); - std::shared_ptr DataMQTT = modemMsg; if (system.getUserConfig()->mqtt.active) { - _toMQTT.addElement(DataMQTT); + _toMQTT.addElement(modemMsg); } if (system.getUserConfig()->aprs_is.active && modemMsg->getSource() != system.getUserConfig()->callsign) { From c66d7d7d8f86c39db9df424b01b0ed45dc4140db Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 24 Feb 2022 16:02:02 +0100 Subject: [PATCH 025/125] refactor MQTT task --- src/TaskMQTT.cpp | 71 ++++++++++++++++++++---------------------------- src/TaskMQTT.h | 13 +++++---- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index a808670..a8115ac 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -9,31 +9,22 @@ #include -WiFiClient wiFiClient; -PubSubClient _MQTT(wiFiClient); - - -MQTTTask::MQTTTask(TaskQueue> &toMQTT) : Task(TASK_MQTT, TaskMQTT), _beginCalled(false), _toMQTT(toMQTT) { +MQTTTask::MQTTTask(TaskQueue> &toMQTT) : Task(TASK_MQTT, TaskMQTT), _toMQTT(toMQTT), _MQTT(_client) { } MQTTTask::~MQTTTask() { } -bool MQTTTask::setup(System &system) { +bool MQTTTask::setup(System &system) { _MQTT.setServer(system.getUserConfig()->mqtt.server.c_str(), system.getUserConfig()->mqtt.port); - return true; } bool MQTTTask::loop(System &system) { - if (!_beginCalled) { - _beginCalled = true; - } - if (!system.isWifiEthConnected()) { return false; } - + if (!_MQTT.connected()) { connect(system); } @@ -41,48 +32,46 @@ bool MQTTTask::loop(System &system) { if (!_toMQTT.empty()) { std::shared_ptr msg = _toMQTT.getElement(); - DynamicJsonDocument _Data(1024); - String _r; + DynamicJsonDocument data(1024); + data["Source"] = msg->getSource(); + data["Destination"] = msg->getDestination(); + data["Path"] = msg->getPath(); + data["Type"] = msg->getType().toString(); + String body = msg->getBody()->encode(); + body.replace("\n", ""); + data["Data"] = body; - _Data["Source"] = msg->getSource(); - _Data["Destination"] = msg->getDestination(); - _Data["Path"] = msg->getPath(); - _Data["Type"] = msg->getType().toString(); - String _body = msg->getBody()->encode(); - _body.replace("\n", ""); - _Data["Data"] = _body; + String r; + serializeJson(data, r); - serializeJson(_Data, _r); - - logPrintD("Send MQTT: "); - logPrintlnD(_r); - - String _topic = String(system.getUserConfig()->mqtt.topic); - - if (!_topic.endsWith("/")) { - _topic = _topic + "/"; + String topic = String(system.getUserConfig()->mqtt.topic); + if (!topic.endsWith("/")) { + topic = topic + "/"; } - _topic = _topic + system.getUserConfig()->callsign; + topic = topic + system.getUserConfig()->callsign; - _MQTT.publish(_topic.c_str(), _r.c_str()); + logPrintD("Send MQTT with topic: \""); + logPrintD(topic); + logPrintD("\", data: "); + logPrintlnD(r); + + _MQTT.publish(topic.c_str(), r.c_str()); } _MQTT.loop(); return true; } bool MQTTTask::connect(const System &system) { - logPrintI("Connecting to MQTT broker: "); + logPrintI("Connecting to MQTT broker: "); logPrintI(system.getUserConfig()->mqtt.server); - logPrintI(" on port "); + logPrintI(" on port "); logPrintlnI(String(system.getUserConfig()->mqtt.port)); - - if (_MQTT.connect(system.getUserConfig()->callsign.c_str(),system.getUserConfig()->mqtt.name.c_str() ,system.getUserConfig()->mqtt.password.c_str() )) { - logPrintI("Connected to MQTT broker as: "); - logPrintlnI(system.getUserConfig()->callsign); + if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) { + logPrintI("Connected to MQTT broker as: "); + logPrintlnI(system.getUserConfig()->callsign); return true; - } else { - logPrintlnI("Connecting to MQTT broker faild. Try again later."); - } + } + logPrintlnI("Connecting to MQTT broker faild. Try again later."); return false; } diff --git a/src/TaskMQTT.h b/src/TaskMQTT.h index ca3304c..0f0524f 100644 --- a/src/TaskMQTT.h +++ b/src/TaskMQTT.h @@ -2,8 +2,8 @@ #define TASK_MQTT_H_ #include -#include #include +#include class MQTTTask : public Task { public: @@ -12,11 +12,14 @@ public: virtual bool setup(System &system) override; virtual bool loop(System &system) override; - + private: - bool _beginCalled; - TaskQueue> &_toMQTT; - bool connect(const System &system); + TaskQueue> &_toMQTT; + + WiFiClient _client; + PubSubClient _MQTT; + + bool connect(const System &system); }; #endif From af6fd114bca5bc461bcf0fb00d3d494f874fcc5b Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 24 Feb 2022 16:02:28 +0100 Subject: [PATCH 026/125] fixing format check --- src/LoRa_APRS_iGate.cpp | 2 +- src/project_configuration.cpp | 24 ++++++++++++------------ src/project_configuration.h | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index cdb7931..074c8fa 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -11,12 +11,12 @@ #include "TaskDisplay.h" #include "TaskEth.h" #include "TaskFTP.h" +#include "TaskMQTT.h" #include "TaskModem.h" #include "TaskNTP.h" #include "TaskOTA.h" #include "TaskRouter.h" #include "TaskWifi.h" -#include "TaskMQTT.h" #include "project_configuration.h" #define VERSION "22.7.0_zj" diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 78a2510..061c531 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -78,12 +78,12 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.ftp.users.push_back(us); } if (data.containsKey("mqtt")) { - conf.mqtt.active = data["mqtt"]["active"] | false; - conf.mqtt.server = data["mqtt"]["server"].as(); - conf.mqtt.port = data["mqtt"]["port"].as(); - conf.mqtt.name = data["mqtt"]["name"].as(); + conf.mqtt.active = data["mqtt"]["active"] | false; + conf.mqtt.server = data["mqtt"]["server"].as(); + conf.mqtt.port = data["mqtt"]["port"].as(); + conf.mqtt.name = data["mqtt"]["name"].as(); conf.mqtt.password = data["mqtt"]["password"].as(); - conf.mqtt.topic = data["mqtt"]["topic"].as(); + conf.mqtt.topic = data["mqtt"]["topic"].as(); } if (data.containsKey("ntp_server")) conf.ntpServer = data["ntp_server"].as(); @@ -141,13 +141,13 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co v["name"] = u.name; v["password"] = u.password; } - data["mqtt"]["active"] = conf.mqtt.active; - data["mqtt"]["server"] = conf.mqtt.server; - data["mqtt"]["port"] = conf.mqtt.port; - data["mqtt"]["name"] = conf.mqtt.name; - data["mqtt"]["password"] = conf.mqtt.password; - data["mqtt"]["topic"] = conf.mqtt.topic; - data["ntp_server"] = conf.ntpServer; + data["mqtt"]["active"] = conf.mqtt.active; + data["mqtt"]["server"] = conf.mqtt.server; + data["mqtt"]["port"] = conf.mqtt.port; + data["mqtt"]["name"] = conf.mqtt.name; + data["mqtt"]["password"] = conf.mqtt.password; + data["mqtt"]["topic"] = conf.mqtt.topic; + data["ntp_server"] = conf.ntpServer; data["board"] = conf.board; } diff --git a/src/project_configuration.h b/src/project_configuration.h index 12e94a7..5fe2fb3 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -119,12 +119,12 @@ public: class MQTT { public: - bool active; - String server; + bool active; + String server; uint16_t port; - String name; - String password; - String topic; + String name; + String password; + String topic; }; Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org"){}; From 6534055ac5299bc6d7f6fa1d682dbf9f4b1aac65 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 24 Feb 2022 16:21:07 +0100 Subject: [PATCH 027/125] format check fix --- src/TaskRouter.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/TaskRouter.h b/src/TaskRouter.h index 617f476..348cdff 100644 --- a/src/TaskRouter.h +++ b/src/TaskRouter.h @@ -2,13 +2,12 @@ #define TASK_ROUTER_H_ #include -#include #include +#include class RouterTask : public Task { public: - RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs, TaskQueue> &toMQTT -); + RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs, TaskQueue> &toMQTT); virtual ~RouterTask(); virtual bool setup(System &system) override; From f5b10a03af1bde6c4f80e8fdea400c0c1478cada Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 24 Feb 2022 16:24:02 +0100 Subject: [PATCH 028/125] include cleanup --- src/TaskMQTT.cpp | 3 --- src/TaskMQTT.h | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index a8115ac..1b7d6ee 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -4,9 +4,6 @@ #include "TaskMQTT.h" #include "project_configuration.h" -#include -#include - #include MQTTTask::MQTTTask(TaskQueue> &toMQTT) : Task(TASK_MQTT, TaskMQTT), _toMQTT(toMQTT), _MQTT(_client) { diff --git a/src/TaskMQTT.h b/src/TaskMQTT.h index 0f0524f..88fa35e 100644 --- a/src/TaskMQTT.h +++ b/src/TaskMQTT.h @@ -4,6 +4,7 @@ #include #include #include +#include class MQTTTask : public Task { public: From e1b3342e1251d987d64dee333ca7868c8728e252 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 24 Feb 2022 16:26:23 +0100 Subject: [PATCH 029/125] version update --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 074c8fa..0352a6b 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.7.0_zj" +#define VERSION "22.8.0" String create_lat_aprs(double lat); String create_long_aprs(double lng); From fb806206acdc4220c601ff44234cb726e50b56c1 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 24 Feb 2022 16:52:52 +0100 Subject: [PATCH 030/125] Update TaskMQTT.cpp --- src/TaskMQTT.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index 1b7d6ee..a4d0aa4 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -30,13 +30,13 @@ bool MQTTTask::loop(System &system) { std::shared_ptr msg = _toMQTT.getElement(); DynamicJsonDocument data(1024); - data["Source"] = msg->getSource(); - data["Destination"] = msg->getDestination(); - data["Path"] = msg->getPath(); - data["Type"] = msg->getType().toString(); + data["source"] = msg->getSource(); + data["destination"] = msg->getDestination(); + data["path"] = msg->getPath(); + data["type"] = msg->getType().toString(); String body = msg->getBody()->encode(); body.replace("\n", ""); - data["Data"] = body; + data["data"] = body; String r; serializeJson(data, r); From 71f11d8d00e8c1b269a9c319a9330e2d5f32d84c Mon Sep 17 00:00:00 2001 From: Daniel Caujolle-Bert Date: Thu, 24 Feb 2022 20:09:41 +0100 Subject: [PATCH 031/125] Fix task order enum. --- src/Task.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task.h b/src/Task.h index 3a06ab8..7dd4e6d 100644 --- a/src/Task.h +++ b/src/Task.h @@ -11,8 +11,8 @@ enum TaskNames TaskOta, TaskWifi, TaskRouter, - TaskSize, TaskMQTT, + TaskSize }; #define TASK_APRS_IS "AprsIsTask" From 9d1465e3ded1a0ddf341ba2c365304ae92b8f39e Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Fri, 18 Mar 2022 22:33:36 +0900 Subject: [PATCH 032/125] Add is-cfg.json to lora.txok for SWL station. --- data/is-cfg.json | 3 ++- src/TaskModem.cpp | 9 ++++++++- src/project_configuration.cpp | 1 + src/project_configuration.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 190ad2c..04aae81 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -48,7 +48,8 @@ "power": 20, "spreading_factor": 12, "signal_bandwidth": 125000, - "coding_rate4": 5 + "coding_rate4": 5, + "txok": true }, "display": { "always_on": true, diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index d3908bc..111617f 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -54,7 +54,14 @@ bool ModemTask::loop(System &system) { if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); - _lora_aprs.sendMessage(msg); + logPrintlnD(msg->toString()); + if (system.getUserConfig()->lora.txok) { + logPrintD(String("-- TXOK")); + _lora_aprs.sendMessage(msg); + logPrintlnD(String(" -- TXDone")); + } else { + logPrintlnD(String("-- TXNG")); + } } return true; diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 061c531..c7eac3a 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -58,6 +58,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12; conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000; conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5; + conf.lora.txok = data["lora"]["txok"] | false; conf.display.alwaysOn = data["display"]["always_on"] | true; conf.display.timeout = data["display"]["timeout"] | 10; conf.display.overwritePin = data["display"]["overwrite_pin"] | 0; diff --git a/src/project_configuration.h b/src/project_configuration.h index 5fe2fb3..91743c8 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -89,6 +89,7 @@ public: int spreadingFactor; long signalBandwidth; int codingRate4; + bool txok; }; class Display { From 2b5f45b2025d0816f4dd6c64009fdc015a0f9c5a Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Fri, 18 Mar 2022 22:50:09 +0900 Subject: [PATCH 033/125] Message changes which is same as Received packet. --- src/TaskModem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 111617f..93dc533 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -54,13 +54,15 @@ bool ModemTask::loop(System &system) { if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); - logPrintlnD(msg->toString()); if (system.getUserConfig()->lora.txok) { - logPrintD(String("-- TXOK")); + logPrintD("Transmitting packet '"); + logPrintD(msg->toString()); _lora_aprs.sendMessage(msg); - logPrintlnD(String(" -- TXDone")); + logPrintlnD(String(" TXDone")); } else { - logPrintlnD(String("-- TXNG")); + logPrintD("NOT Transmitting packet '"); + logPrintD(msg->toString()); + logPrintlnD(String(" TXNG")); } } From 824e84ec6cfebd07773712e7b3772a549f994f20 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Fri, 18 Mar 2022 23:29:19 +0900 Subject: [PATCH 034/125] version update. --- .vscode/extensions.json | 19 +++++++++++-------- platformio.ini | 1 + src/LoRa_APRS_iGate.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 27bdd05..9a91518 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,11 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide", - "xaver.clang-format" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide", + "xaver.clang-format" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/platformio.ini b/platformio.ini index ce8560b..96bb0e1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,6 +22,7 @@ check_skip_packages = yes # activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port: #upload_protocol = espota #upload_port = .local +upload_port = COM19 [env:lora_board] board = esp32doit-devkit-v1 diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 0352a6b..afaa3f0 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.8.0" +#define VERSION "22.11.0" String create_lat_aprs(double lat); String create_long_aprs(double lng); From 518ac7f3f2cc6cc237066b384e3cb4eb0e5190d8 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 19 Mar 2022 06:56:55 +0900 Subject: [PATCH 035/125] Revert local changes. --- .vscode/extensions.json | 19 ++++++++----------- platformio.ini | 1 - 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9a91518..27bdd05 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,11 +1,8 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide", - "xaver.clang-format" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide", + "xaver.clang-format" + ] +} diff --git a/platformio.ini b/platformio.ini index 96bb0e1..ce8560b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,7 +22,6 @@ check_skip_packages = yes # activate for OTA Update, use the CALLSIGN from is-cfg.json as upload_port: #upload_protocol = espota #upload_port = .local -upload_port = COM19 [env:lora_board] board = esp32doit-devkit-v1 From f6951e7ccb472b858b63f8fb4ce343adaeb5ac6c Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 19 Mar 2022 15:24:10 +0900 Subject: [PATCH 036/125] Add setting for LoRa.txok. --- src/project_configuration.cpp | 1 + src/project_configuration.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index c7eac3a..eaf27dd 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -131,6 +131,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["lora"]["spreading_factor"] = conf.lora.spreadingFactor; data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth; data["lora"]["coding_rate4"] = conf.lora.codingRate4; + data["lora"]["txok"] = conf.lora.txok; data["display"]["always_on"] = conf.display.alwaysOn; data["display"]["timeout"] = conf.display.timeout; data["display"]["overwrite_pin"] = conf.display.overwritePin; diff --git a/src/project_configuration.h b/src/project_configuration.h index 91743c8..854d450 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -79,7 +79,7 @@ public: class LoRa { public: - LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) { + LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5), txok(false) { } long frequencyRx; From 85746dfd3fd6c4750abe2e4fe9d52483ba8bf46b Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 19 Mar 2022 16:37:23 +0900 Subject: [PATCH 037/125] Add timestamp. --- src/TaskModem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 93dc533..50b9035 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -54,6 +54,7 @@ bool ModemTask::loop(System &system) { if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); + logPrintD("[" + timeString() + "] "); if (system.getUserConfig()->lora.txok) { logPrintD("Transmitting packet '"); logPrintD(msg->toString()); From 96fc8ea0b75f29505133c26a64cec270095fa850 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 18:43:48 +0100 Subject: [PATCH 038/125] update esp logger --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index ce8560b..e9d1555 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,7 +11,7 @@ lib_deps = bblanchon/ArduinoJson @ 6.17.0 lewisxhe/AXP202X_Library @ 1.1.2 peterus/APRS-Decoder-Lib @ 0.0.6 - peterus/esp-logger @ 0.0.1 + peterus/esp-logger @ 1.0.0 peterus/ESP-FTP-Server-Lib @ 0.9.5 knolleary/PubSubClient@^2.8 check_tool = cppcheck From 9cde910d5d3188ca521f7d74245c7d3d6239299b Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 18:44:03 +0100 Subject: [PATCH 039/125] add logger to system --- lib/System/System.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/System/System.h b/lib/System/System.h index 376741b..6c7e9d4 100644 --- a/lib/System/System.h +++ b/lib/System/System.h @@ -1,6 +1,7 @@ #ifndef SYSTEM_H_ #define SYSTEM_H_ +#include #include #include "TaskManager.h" @@ -22,6 +23,7 @@ public: Display & getDisplay(); bool isWifiEthConnected() const; void connectedViaWifiEth(bool status); + logging::Logger & getLogger(); private: BoardConfig const * _boardConfig; @@ -29,6 +31,7 @@ private: TaskManager _taskManager; Display _display; bool _isWifiEthConnected; + logging::Logger _logger; }; #endif From 1da93bb60e3af8282a73be73fa6fc87e1f846b8d Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 18:44:10 +0100 Subject: [PATCH 040/125] task manager update --- lib/System/TaskManager.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/System/TaskManager.cpp b/lib/System/TaskManager.cpp index d524ad0..d149e2f 100644 --- a/lib/System/TaskManager.cpp +++ b/lib/System/TaskManager.cpp @@ -2,6 +2,8 @@ #include #include +#define MODULE_NAME "TaskManager" + TaskManager::TaskManager() { } @@ -20,15 +22,13 @@ std::list TaskManager::getTasks() { } bool TaskManager::setup(System &system) { - logPrintlnV("will setup all tasks..."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will setup all tasks..."); for (Task *elem : _alwaysRunTasks) { - logPrintD("call setup from "); - logPrintlnD(elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); elem->setup(system); } for (Task *elem : _tasks) { - logPrintD("call setup from "); - logPrintlnD(elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); elem->setup(system); } _nextTask = _tasks.begin(); @@ -36,10 +36,7 @@ bool TaskManager::setup(System &system) { } bool TaskManager::loop(System &system) { - // logPrintlnD("will loop all tasks..."); for (Task *elem : _alwaysRunTasks) { - // logPrintD("call loop from "); - // logPrintlnD(elem->getName()); elem->loop(system); } From 692a2a6f35ba7f9309bd40220467e8e2549779b7 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 20:53:38 +0100 Subject: [PATCH 041/125] convert txok to tx_enable --- data/is-cfg.json | 2 +- src/TaskModem.cpp | 9 +++++---- src/project_configuration.cpp | 4 ++-- src/project_configuration.h | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 04aae81..f278166 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -49,7 +49,7 @@ "spreading_factor": 12, "signal_bandwidth": 125000, "coding_rate4": 5, - "txok": true + "tx_enable": true }, "display": { "always_on": true, diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 50b9035..e6c5ca6 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -55,15 +55,16 @@ bool ModemTask::loop(System &system) { if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); logPrintD("[" + timeString() + "] "); - if (system.getUserConfig()->lora.txok) { + if (system.getUserConfig()->lora.tx_enable) { logPrintD("Transmitting packet '"); logPrintD(msg->toString()); + logPrintlnD("'"); _lora_aprs.sendMessage(msg); - logPrintlnD(String(" TXDone")); + logPrintlnD("TX done"); } else { - logPrintD("NOT Transmitting packet '"); + logPrintD("NOT transmitting packet as TX is not enabled '"); logPrintD(msg->toString()); - logPrintlnD(String(" TXNG")); + logPrintlnD("'"); } } diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index eaf27dd..a462c5b 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -58,7 +58,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12; conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000; conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5; - conf.lora.txok = data["lora"]["txok"] | false; + conf.lora.tx_enable = data["lora"]["tx_enable"] | true; conf.display.alwaysOn = data["display"]["always_on"] | true; conf.display.timeout = data["display"]["timeout"] | 10; conf.display.overwritePin = data["display"]["overwrite_pin"] | 0; @@ -131,7 +131,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["lora"]["spreading_factor"] = conf.lora.spreadingFactor; data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth; data["lora"]["coding_rate4"] = conf.lora.codingRate4; - data["lora"]["txok"] = conf.lora.txok; + data["lora"]["tx_enable"] = conf.lora.tx_enable; data["display"]["always_on"] = conf.display.alwaysOn; data["display"]["timeout"] = conf.display.timeout; data["display"]["overwrite_pin"] = conf.display.overwritePin; diff --git a/src/project_configuration.h b/src/project_configuration.h index 854d450..df83acb 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -79,7 +79,7 @@ public: class LoRa { public: - LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5), txok(false) { + LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5), tx_enable(true) { } long frequencyRx; @@ -89,7 +89,7 @@ public: int spreadingFactor; long signalBandwidth; int codingRate4; - bool txok; + bool tx_enable; }; class Display { From 21b1ab0e2e7a1a094be16a64a82a9955db22825a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 20:54:27 +0100 Subject: [PATCH 042/125] version push --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index afaa3f0..205e00d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.0" +#define VERSION "22.11.1" String create_lat_aprs(double lat); String create_long_aprs(double lng); From 798d5b20410b81a7caa8b8f6735e18487664d63a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 21:57:09 +0100 Subject: [PATCH 043/125] log update in AprsIsTask --- src/TaskAprsIs.cpp | 11 ++++------- src/TaskAprsIs.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index b96b06e..8aa80c4 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -40,15 +40,12 @@ bool AprsIsTask::loop(System &system) { return true; } -bool AprsIsTask::connect(const System &system) { - logPrintI("connecting to APRS-IS server: "); - logPrintI(system.getUserConfig()->aprs_is.server); - logPrintI(" on port: "); - logPrintlnI(String(system.getUserConfig()->aprs_is.port)); +bool AprsIsTask::connect(System &system) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); if (!_aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port)) { - logPrintlnE("Connection failed."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); return false; } - logPrintlnI("Connected to APRS-IS server!"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to APRS-IS server!"); return true; } diff --git a/src/TaskAprsIs.h b/src/TaskAprsIs.h index de75fec..30679db 100644 --- a/src/TaskAprsIs.h +++ b/src/TaskAprsIs.h @@ -19,7 +19,7 @@ private: TaskQueue> &_toAprsIs; - bool connect(const System &system); + bool connect(System &system); }; #endif From 49c61d1845d4621183f51767df4cc0693bafefcb Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:03:28 +0100 Subject: [PATCH 044/125] fixing ftp task --- src/TaskFTP.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/TaskFTP.cpp b/src/TaskFTP.cpp index d9615cf..e4a6037 100644 --- a/src/TaskFTP.cpp +++ b/src/TaskFTP.cpp @@ -14,8 +14,7 @@ FTPTask::~FTPTask() { bool FTPTask::setup(System &system) { for (Configuration::Ftp::User user : system.getUserConfig()->ftp.users) { - logPrintD("Adding user to FTP Server: "); - logPrintlnD(user.name); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Adding user to FTP Server: %s", user.name); _ftpServer.addUser(user.name, user.password); } _ftpServer.addFilesystem("SPIFFS", &SPIFFS); @@ -31,8 +30,7 @@ bool FTPTask::loop(System &system) { _ftpServer.handle(); static bool configWasOpen = false; if (configWasOpen && _ftpServer.countConnections() == 0) { - logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config..."); - logPrintlnW(""); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_WARN, getName(), "Maybe the config has been changed via FTP, lets restart now to get the new config..."); ESP.restart(); } if (_ftpServer.countConnections() > 0) { From 3fbed7b963b2fb9aaccec475e9fd064f6b10b909 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:08:54 +0100 Subject: [PATCH 045/125] modem fixed --- src/TaskModem.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index e6c5ca6..645626b 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -17,7 +17,7 @@ bool ModemTask::setup(System &system) { SPI.begin(system.getBoardConfig()->LoraSck, system.getBoardConfig()->LoraMiso, system.getBoardConfig()->LoraMosi, system.getBoardConfig()->LoraCS); _lora_aprs.setPins(system.getBoardConfig()->LoraCS, system.getBoardConfig()->LoraReset, system.getBoardConfig()->LoraIRQ); if (!_lora_aprs.begin(system.getUserConfig()->lora.frequencyRx)) { - logPrintlnE("Starting LoRa failed!"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Starting LoRa failed!"); _stateInfo = "LoRa-Modem failed"; _state = Error; while (true) @@ -39,32 +39,19 @@ bool ModemTask::setup(System &system) { bool ModemTask::loop(System &system) { if (_lora_aprs.checkMessage()) { std::shared_ptr msg = _lora_aprs.getMessage(); - // msg->getAPRSBody()->setData(msg->getAPRSBody()->getData() + " 123"); - logPrintD("[" + timeString() + "] "); - logPrintD("Received packet '"); - logPrintD(msg->toString()); - logPrintD("' with RSSI "); - logPrintD(String(_lora_aprs.packetRssi())); - logPrintD(" and SNR "); - logPrintlnD(String(_lora_aprs.packetSnr())); - + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString(), msg->toString(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); _fromModem.addElement(msg); system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString()))); } if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); - logPrintD("[" + timeString() + "] "); if (system.getUserConfig()->lora.tx_enable) { - logPrintD("Transmitting packet '"); - logPrintD(msg->toString()); - logPrintlnD("'"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString(), msg->toString()); _lora_aprs.sendMessage(msg); - logPrintlnD("TX done"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString()); } else { - logPrintD("NOT transmitting packet as TX is not enabled '"); - logPrintD(msg->toString()); - logPrintlnD("'"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString(), msg->toString()); } } From 8d494c0832305cd535bc3987d19c9e52fb8b500e Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:18:07 +0100 Subject: [PATCH 046/125] fixing mqtt task --- src/TaskMQTT.cpp | 20 +++++--------------- src/TaskMQTT.h | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index a4d0aa4..aa0a7a0 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -46,29 +46,19 @@ bool MQTTTask::loop(System &system) { topic = topic + "/"; } topic = topic + system.getUserConfig()->callsign; - - logPrintD("Send MQTT with topic: \""); - logPrintD(topic); - logPrintD("\", data: "); - logPrintlnD(r); - + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic, r); _MQTT.publish(topic.c_str(), r.c_str()); } _MQTT.loop(); return true; } -bool MQTTTask::connect(const System &system) { - logPrintI("Connecting to MQTT broker: "); - logPrintI(system.getUserConfig()->mqtt.server); - logPrintI(" on port "); - logPrintlnI(String(system.getUserConfig()->mqtt.port)); - +bool MQTTTask::connect(System &system) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server, system.getUserConfig()->mqtt.port); if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) { - logPrintI("Connected to MQTT broker as: "); - logPrintlnI(system.getUserConfig()->callsign); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign); return true; } - logPrintlnI("Connecting to MQTT broker faild. Try again later."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker failed. Try again later."); return false; } diff --git a/src/TaskMQTT.h b/src/TaskMQTT.h index 88fa35e..d388075 100644 --- a/src/TaskMQTT.h +++ b/src/TaskMQTT.h @@ -20,7 +20,7 @@ private: WiFiClient _client; PubSubClient _MQTT; - bool connect(const System &system); + bool connect(System &system); }; #endif From ee25e0194f8dae015eda90693ee5961f8f2c867f Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:19:59 +0100 Subject: [PATCH 047/125] fixing ntp task --- src/TaskNTP.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TaskNTP.cpp b/src/TaskNTP.cpp index 14b3808..c012ae8 100644 --- a/src/TaskNTP.cpp +++ b/src/TaskNTP.cpp @@ -27,8 +27,7 @@ bool NTPTask::loop(System &system) { } if (_ntpClient.update()) { setTime(_ntpClient.getEpochTime()); - logPrintI("Current time: "); - logPrintlnI(_ntpClient.getFormattedTime()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Current time: %s", _ntpClient.getFormattedTime()); } _stateInfo = _ntpClient.getFormattedTime(); _state = Okay; From 9c2fb18d1b35dcb3b3686379b75624cc5bbfd579 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:29:38 +0100 Subject: [PATCH 048/125] fixing ota --- src/TaskOTA.cpp | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index d3bd60c..28dcb85 100644 --- a/src/TaskOTA.cpp +++ b/src/TaskOTA.cpp @@ -13,35 +13,33 @@ OTATask::~OTATask() { bool OTATask::setup(System &system) { _ota.onStart([&]() { String type; - if (_ota.getCommand() == U_FLASH) + if (_ota.getCommand() == U_FLASH) { type = "sketch"; - else // U_SPIFFS + } else { // U_SPIFFS type = "filesystem"; - logPrintlnI("Start updating " + type); + } + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type); }) - .onEnd([]() { - logPrintlnI(""); - logPrintlnI("OTA End"); + .onEnd([&]() { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "OTA End"); }) - .onProgress([](unsigned int progress, unsigned int total) { - logPrintI("Progress: "); - logPrintI(String(progress / (total / 100))); - logPrintlnI("%"); + .onProgress([&](unsigned int progress, unsigned int total) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Progress: %f", (progress / (total / 100))); }) - .onError([](ota_error_t error) { - logPrintE("Error["); - logPrintE(String(error)); - logPrintE("]: "); - if (error == OTA_AUTH_ERROR) - logPrintlnE("Auth Failed"); - else if (error == OTA_BEGIN_ERROR) - logPrintlnE("Begin Failed"); - else if (error == OTA_CONNECT_ERROR) - logPrintlnE("Connect Failed"); - else if (error == OTA_RECEIVE_ERROR) - logPrintlnE("Receive Failed"); - else if (error == OTA_END_ERROR) - logPrintlnE("End Failed"); + .onError([&](ota_error_t error) { + String error_str; + if (error == OTA_AUTH_ERROR) { + error_str = "Auth Failed"; + } else if (error == OTA_BEGIN_ERROR) { + error_str = "Begin Failed"; + } else if (error == OTA_CONNECT_ERROR) { + error_str = "Connect Failed"; + } else if (error == OTA_RECEIVE_ERROR) { + error_str = "Receive Failed"; + } else if (error == OTA_END_ERROR) { + error_str = "End Failed"; + } + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str); }); if (system.getUserConfig()->network.hostname.overwrite) { _ota.setHostname(system.getUserConfig()->network.hostname.name.c_str()); From 00603fe2c38e5364c06999b822fee79b1a4849e3 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:36:33 +0100 Subject: [PATCH 049/125] fixing router task --- src/TaskRouter.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index 2ab3cd5..25cf38d 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -16,7 +16,6 @@ RouterTask::~RouterTask() { } bool RouterTask::setup(System &system) { - // setup beacon _beacon_timer.setTimeout(system.getUserConfig()->beacon.timeout * 60 * 1000); _beaconMsg = std::shared_ptr(new APRSMessage()); @@ -30,7 +29,6 @@ bool RouterTask::setup(System &system) { } bool RouterTask::loop(System &system) { - // do routing if (!_fromModem.empty()) { std::shared_ptr modemMsg = _fromModem.getElement(); @@ -49,18 +47,19 @@ bool RouterTask::loop(System &system) { aprsIsMsg->setPath(path + "qAO," + system.getUserConfig()->callsign); - logPrintD("APRS-IS: "); - logPrintlnD(aprsIsMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString()); _toAprsIs.addElement(aprsIsMsg); } else { - logPrintlnD("APRS-IS: no forward => RFonly"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => RFonly"); } } else { - if (!system.getUserConfig()->aprs_is.active) - logPrintlnD("APRS-IS: disabled"); + if (!system.getUserConfig()->aprs_is.active) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: disabled"); + } - if (modemMsg->getSource() == system.getUserConfig()->callsign) - logPrintlnD("APRS-IS: no forward => own packet received"); + if (modemMsg->getSource() == system.getUserConfig()->callsign) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => own packet received"); + } } if (system.getUserConfig()->digi.active && modemMsg->getSource() != system.getUserConfig()->callsign) { @@ -72,8 +71,7 @@ bool RouterTask::loop(System &system) { // fixme digiMsg->setPath(system.getUserConfig()->callsign + "*"); - logPrintD("DIGI: "); - logPrintlnD(digiMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString()); _toModem.addElement(digiMsg); } @@ -82,8 +80,7 @@ bool RouterTask::loop(System &system) { // check for beacon if (_beacon_timer.check()) { - logPrintD("[" + timeString() + "] "); - logPrintlnD(_beaconMsg->encode()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString(), _beaconMsg->encode()); if (system.getUserConfig()->aprs_is.active) _toAprsIs.addElement(_beaconMsg); @@ -93,7 +90,6 @@ bool RouterTask::loop(System &system) { } system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); - _beacon_timer.start(); } From 4a39c5e2f2e65a670718fcf479a1b01a23cbc3ff Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 23:51:18 +0100 Subject: [PATCH 050/125] fixing APRS-IS lib --- lib/APRS-IS/APRS-IS.cpp | 17 +++++++---------- lib/APRS-IS/APRS-IS.h | 15 +++++++++++---- src/TaskAprsIs.cpp | 8 +++++++- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/APRS-IS/APRS-IS.cpp b/lib/APRS-IS/APRS-IS.cpp index 6988ac9..7863bbf 100644 --- a/lib/APRS-IS/APRS-IS.cpp +++ b/lib/APRS-IS/APRS-IS.cpp @@ -8,34 +8,32 @@ void APRS_IS::setup(const String &user, const String &passcode, const String &to _version = version; } -bool APRS_IS::connect(const String &server, const int port) { +APRS_IS::ConnectionStatus APRS_IS::connect(const String &server, const int port) { const String login = "user " + _user + " pass " + _passcode + " vers " + _tool_name + " " + _version + "\n\r"; return _connect(server, port, login); } -bool APRS_IS::connect(const String &server, const int port, const String &filter) { +APRS_IS::ConnectionStatus APRS_IS::connect(const String &server, const int port, const String &filter) { const String login = "user " + _user + " pass " + _passcode + " vers " + _tool_name + " " + _version + " filter " + filter + "\n\r"; return _connect(server, port, login); } -bool APRS_IS::_connect(const String &server, const int port, const String &login_line) { +APRS_IS::ConnectionStatus APRS_IS::_connect(const String &server, const int port, const String &login_line) { if (!_client.connect(server.c_str(), port)) { - logPrintlnE("Something went wrong on connecting! Is the server reachable?"); - return false; + return ERROR_CONNECTION; } sendMessage(login_line); while (true) { String line = _client.readStringUntil('\n'); if (line.indexOf("logresp") != -1) { if (line.indexOf("unverified") == -1) { - return true; + return SUCCESS; } else { - logPrintlnE("User can not be verified with passcode!"); - return false; + return ERROR_PASSCODE; } } } - return true; + return SUCCESS; } bool APRS_IS::connected() { @@ -76,7 +74,6 @@ std::shared_ptr APRS_IS::getAPRSMessage() { line = _client.readStringUntil('\n'); } if (line.startsWith("#")) { - logPrintlnD(line); return 0; } if (line.length() == 0) { diff --git a/lib/APRS-IS/APRS-IS.h b/lib/APRS-IS/APRS-IS.h index 00d27ca..0aa0691 100644 --- a/lib/APRS-IS/APRS-IS.h +++ b/lib/APRS-IS/APRS-IS.h @@ -9,9 +9,16 @@ class APRS_IS { public: void setup(const String &user, const String &passcode, const String &tool_name, const String &version); - bool connect(const String &server, const int port); - bool connect(const String &server, const int port, const String &filter); - bool connected(); + enum ConnectionStatus + { + SUCCESS, + ERROR_CONNECTION, + ERROR_PASSCODE, + }; + + ConnectionStatus connect(const String &server, const int port); + ConnectionStatus connect(const String &server, const int port, const String &filter); + bool connected(); bool sendMessage(const String &message); bool sendMessage(const std::shared_ptr message); @@ -28,7 +35,7 @@ private: String _version; WiFiClient _client; - bool _connect(const String &server, const int port, const String &login_line); + ConnectionStatus _connect(const String &server, const int port, const String &login_line); }; #endif diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 8aa80c4..86ef766 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -42,7 +42,13 @@ bool AprsIsTask::loop(System &system) { bool AprsIsTask::connect(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); - if (!_aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port)) { + APRS_IS::ConnectionStatus status = _aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); + if (status == APRS_IS::ERROR_CONNECTION) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Something went wrong on connecting! Is the server reachable?"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); + return false; + } else if (status == APRS_IS::ERROR_PASSCODE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "User can not be verified with passcode!"); system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); return false; } From c1fc1c5cbff552a8fbf0c3b26b691e271cdd4cc4 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:03:43 +0100 Subject: [PATCH 051/125] fixing main --- src/LoRa_APRS_iGate.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 205e00d..15c71fc 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,8 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.1" +#define VERSION "22.11.1" +#define MODULE_NAME "Main" String create_lat_aprs(double lat); String create_long_aprs(double lng); @@ -45,10 +46,10 @@ RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); void setup() { Serial.begin(115200); - Logger::instance().setSerial(&Serial); + LoRaSystem.getLogger().setSerial(&Serial); delay(500); - logPrintlnI("LoRa APRS iGate by OE5BPA (Peter Buchegger)"); - logPrintlnI("Version: " VERSION); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "LoRa APRS iGate by OE5BPA (Peter Buchegger)"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Version: %s", VERSION); std::list boardConfigs; boardConfigs.push_back(&TTGO_LORA32_V1); @@ -68,28 +69,26 @@ void setup() { if (!boardConfig) { boardConfig = finder.searchBoardConfig(); if (!boardConfig) { - logPrintlnE("Board config not set and search failed!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!"); while (true) ; } else { userConfig.board = boardConfig->Name; confmg.writeConfiguration(userConfig); - logPrintlnI("will restart board now!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will restart board now!"); ESP.restart(); } } - logPrintI("Board "); - logPrintI(boardConfig->Name); - logPrintlnI(" loaded."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Board %s loaded.", boardConfig->Name); if (boardConfig->Type == eTTGO_T_Beam_V1_0) { Wire.begin(boardConfig->OledSda, boardConfig->OledScl); PowerManagement powerManagement; if (!powerManagement.begin(Wire)) { - logPrintlnI("AXP192 init done!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "AXP192 init done!"); } else { - logPrintlnE("AXP192 init failed!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "AXP192 init failed!"); } powerManagement.activateLoRa(); powerManagement.activateOLED(); @@ -126,13 +125,13 @@ void setup() { LoRaSystem.getDisplay().showSpashScreen("LoRa APRS iGate", VERSION); if (userConfig.callsign == "NOCALL-10") { - logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "You have to change your settings in 'data/is-cfg.json' and upload it via 'Upload File System image'!"); LoRaSystem.getDisplay().showStatusScreen("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); while (true) ; } if ((!userConfig.aprs_is.active) && !(userConfig.digi.active)) { - logPrintlnE("No mode selected (iGate or Digi)! You have to activate one of iGate or Digi."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "No mode selected (iGate or Digi)! You have to activate one of iGate or Digi."); LoRaSystem.getDisplay().showStatusScreen("ERROR", "No mode selected (iGate or Digi)! You have to activate one of iGate or Digi."); while (true) ; @@ -144,7 +143,7 @@ void setup() { } delay(5000); - logPrintlnI("setup done..."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "setup done..."); } void loop() { From 121f90b59cc1500bb50b6f87712cb90948053bab Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:22:19 +0100 Subject: [PATCH 052/125] board finder fixed --- lib/BoardFinder/BoardFinder.cpp | 38 ++++++++++++++++----------------- lib/BoardFinder/BoardFinder.h | 8 ++++--- src/LoRa_APRS_iGate.cpp | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 0e076e0..00cfc57 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -2,6 +2,8 @@ #include #include +#define MODULE_NAME "BoardFinder" + BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip, bool powercheckstatus) : Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { } @@ -9,12 +11,12 @@ BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t o BoardFinder::BoardFinder(const std::list &boardConfigs) : _boardConfigs(boardConfigs) { } -BoardConfig const *BoardFinder::searchBoardConfig() { - logPrintlnI("looking for a board config."); - logPrintlnI("searching for OLED..."); +BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "looking for a board config."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "searching for OLED..."); for (BoardConfig const *boardconf : _boardConfigs) { - if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) { + if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) { PowerManagement powerManagement; Wire.begin(boardconf->OledSda, boardconf->OledScl); powerManagement.begin(Wire); @@ -22,30 +24,28 @@ BoardConfig const *BoardFinder::searchBoardConfig() { } else if (boardconf->needCheckPowerChip) { continue; } - if (checkOledConfig(boardconf)) { - logPrintI("found a board config: "); - logPrintlnI(boardconf->Name); + if (checkOledConfig(boardconf, logger)) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); return boardconf; } } - logPrintlnI("could not find OLED, will search for the modem now..."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "could not find OLED, will search for the modem now..."); for (BoardConfig const *boardconf : _boardConfigs) { - if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) { + if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) { PowerManagement powerManagement; Wire.begin(boardconf->OledSda, boardconf->OledScl); powerManagement.begin(Wire); powerManagement.activateLoRa(); } if (checkModemConfig(boardconf)) { - logPrintI("found a board config: "); - logPrintlnI(boardconf->Name); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); return boardconf; } } - logPrintlnE("could not find a board config!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "could not find a board config!"); return 0; } @@ -60,7 +60,7 @@ BoardConfig const *BoardFinder::getBoardConfig(String name) { return *elem; } -bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) { +bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger) { if (boardConfig->OledReset > 0) { pinMode(boardConfig->OledReset, OUTPUT); digitalWrite(boardConfig->OledReset, HIGH); @@ -70,7 +70,7 @@ bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) { digitalWrite(boardConfig->OledReset, HIGH); } if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) { - logPrintlnW("issue with wire"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "issue with wire"); return false; } Wire.beginTransmission(boardConfig->OledAddr); @@ -107,9 +107,9 @@ bool BoardFinder::checkModemConfig(BoardConfig const *boardConfig) { return false; } -bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) { +bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger) { if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) { - logPrintlnW("issue with wire"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "issue with wire"); return false; } Wire.beginTransmission(0x34); @@ -120,12 +120,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) { int response = Wire.read(); Wire.endTransmission(); - logPrintlnD(String(response)); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "wire response: %d", response); if (response == 0x03) { - logPrintlnD("power chip found!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip found!"); return true; } - logPrintlnD("power chip NOT found"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip NOT found"); return false; } diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index 142de6d..ef65881 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -8,6 +8,8 @@ #include #include +#include + enum BoardType { eHELTEC_WIFI_LORA_32_V1, @@ -47,16 +49,16 @@ class BoardFinder { public: explicit BoardFinder(const std::list &boardConfigs); - BoardConfig const *searchBoardConfig(); + BoardConfig const *searchBoardConfig(logging::Logger &logger); BoardConfig const *getBoardConfig(String name); private: const std::list &_boardConfigs; - bool checkOledConfig(BoardConfig const *boardConfig); + bool checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger); bool checkModemConfig(BoardConfig const *boardConfig); - bool checkPowerConfig(BoardConfig const *boardConfig); + bool checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger); }; extern BoardConfig TTGO_LORA32_V1; diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 15c71fc..2f5dfd1 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -67,7 +67,7 @@ void setup() { BoardFinder finder(boardConfigs); BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board); if (!boardConfig) { - boardConfig = finder.searchBoardConfig(); + boardConfig = finder.searchBoardConfig(LoRaSystem.getLogger()); if (!boardConfig) { LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!"); while (true) From fd1034a3a000e0ac8417622d96c4c6ca37f8ec19 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:37:29 +0100 Subject: [PATCH 053/125] fixing configuration management --- lib/ConfigurationManagement/configuration.cpp | 20 ++++++++++--------- lib/ConfigurationManagement/configuration.h | 8 +++++--- src/LoRa_APRS_iGate.cpp | 6 +++--- src/project_configuration.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/ConfigurationManagement/configuration.cpp b/lib/ConfigurationManagement/configuration.cpp index 5f50550..6734608 100644 --- a/lib/ConfigurationManagement/configuration.cpp +++ b/lib/ConfigurationManagement/configuration.cpp @@ -2,12 +2,14 @@ #include #include -ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) { +#define MODULE_NAME "ConfigurationManagement" + +ConfigurationManagement::ConfigurationManagement(logging::Logger &logger, String FilePath) : mFilePath(FilePath) { if (!SPIFFS.begin(true)) { - logPrintlnI("Mounting SPIFFS was not possible. Trying to format SPIFFS..."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Mounting SPIFFS was not possible. Trying to format SPIFFS..."); SPIFFS.format(); if (!SPIFFS.begin()) { - logPrintlnE("Formating SPIFFS was not okay!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Formating SPIFFS was not okay!"); } } } @@ -15,16 +17,16 @@ ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(Fi ConfigurationManagement::~ConfigurationManagement() { } -void ConfigurationManagement::readConfiguration(Configuration &conf) { +void ConfigurationManagement::readConfiguration(logging::Logger &logger, Configuration &conf) { File file = SPIFFS.open(mFilePath); if (!file) { - logPrintlnE("Failed to open file for reading, using default configuration."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Failed to open file for reading, using default configuration."); return; } DynamicJsonDocument data(2048); DeserializationError error = deserializeJson(data, file); if (error) { - logPrintlnW("Failed to read file, using default configuration."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "Failed to read file, using default configuration."); } // serializeJson(data, Serial); // Serial.println(); @@ -33,13 +35,13 @@ void ConfigurationManagement::readConfiguration(Configuration &conf) { readProjectConfiguration(data, conf); // update config in memory to get the new fields: - writeConfiguration(conf); + writeConfiguration(logger, conf); } -void ConfigurationManagement::writeConfiguration(Configuration &conf) { +void ConfigurationManagement::writeConfiguration(logging::Logger &logger, Configuration &conf) { File file = SPIFFS.open(mFilePath, "w"); if (!file) { - logPrintlnE("Failed to open file for writing..."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Failed to open file for writing..."); return; } DynamicJsonDocument data(2048); diff --git a/lib/ConfigurationManagement/configuration.h b/lib/ConfigurationManagement/configuration.h index 6ebcf75..4d988cb 100644 --- a/lib/ConfigurationManagement/configuration.h +++ b/lib/ConfigurationManagement/configuration.h @@ -9,15 +9,17 @@ #include #endif +#include + class Configuration; class ConfigurationManagement { public: - explicit ConfigurationManagement(String FilePath); + explicit ConfigurationManagement(logging::Logger &logger, String FilePath); virtual ~ConfigurationManagement(); - void readConfiguration(Configuration &conf); - void writeConfiguration(Configuration &conf); + void readConfiguration(logging::Logger &logger, Configuration &conf); + void writeConfiguration(logging::Logger &logger, Configuration &conf); private: virtual void readProjectConfiguration(DynamicJsonDocument &data, Configuration &conf) = 0; diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 2f5dfd1..4171138 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -61,8 +61,8 @@ void setup() { boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V1); boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V2); - ProjectConfigurationManagement confmg; - confmg.readConfiguration(userConfig); + ProjectConfigurationManagement confmg(LoRaSystem.getLogger()); + confmg.readConfiguration(LoRaSystem.getLogger(), userConfig); BoardFinder finder(boardConfigs); BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board); @@ -74,7 +74,7 @@ void setup() { ; } else { userConfig.board = boardConfig->Name; - confmg.writeConfiguration(userConfig); + confmg.writeConfiguration(LoRaSystem.getLogger(), userConfig); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will restart board now!"); ESP.restart(); } diff --git a/src/project_configuration.h b/src/project_configuration.h index df83acb..4fe78bd 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -146,7 +146,7 @@ public: class ProjectConfigurationManagement : public ConfigurationManagement { public: - explicit ProjectConfigurationManagement() : ConfigurationManagement("/is-cfg.json") { + explicit ProjectConfigurationManagement(logging::Logger &logger) : ConfigurationManagement(logger, "/is-cfg.json") { } virtual ~ProjectConfigurationManagement() { } From 11b392b3098fa2cf5ef1ce544559a1e399e9ece8 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:45:30 +0100 Subject: [PATCH 054/125] wifi task fixed --- src/TaskWifi.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index aa02876..fb01baf 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -31,8 +31,7 @@ bool WifiTask::setup(System &system) { } for (Configuration::Wifi::AP ap : system.getUserConfig()->wifi.APs) { - logPrintD("Looking for AP: "); - logPrintlnD(ap.SSID); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Looking for AP: %s", ap.SSID); _wiFiMulti.addAP(ap.SSID.c_str(), ap.password.c_str()); } return true; @@ -42,14 +41,13 @@ bool WifiTask::loop(System &system) { const uint8_t wifi_status = _wiFiMulti.run(); if (wifi_status != WL_CONNECTED) { system.connectedViaWifiEth(false); - logPrintlnE("WiFi not connected!"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "WiFi not connected!"); _oldWifiStatus = wifi_status; _stateInfo = "WiFi not connected"; _state = Error; return false; } else if (wifi_status != _oldWifiStatus) { - logPrintD("IP address: "); - logPrintlnD(WiFi.localIP().toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString()); _oldWifiStatus = wifi_status; return false; } From 4aa8a3197d2354c3a471ea846698d1e9d0c5be1a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 01:03:26 +0100 Subject: [PATCH 055/125] fixing WifiEvent function --- src/TaskEth.cpp | 65 +++++++++++++++++++++++-------------------------- src/TaskEth.h | 1 + 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index 720856e..d5a15ee 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -6,67 +6,62 @@ #include "TaskEth.h" #include "project_configuration.h" -volatile bool eth_connected = false; +#define WIFI_EVENT "WiFiEvent" + +volatile bool eth_connected = false; +logging::Logger *_logger; + +void setWiFiLogger(logging::Logger *logger) { + _logger = logger; +} void WiFiEvent(WiFiEvent_t event) { switch (event) { case SYSTEM_EVENT_STA_START: - logPrintlnI("WiFi Started"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Started"); break; case SYSTEM_EVENT_STA_CONNECTED: - logPrintlnI("WiFi Connected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Connected"); break; case SYSTEM_EVENT_STA_GOT_IP: - logPrintI("WiFi MAC: "); - logPrintI(WiFi.macAddress()); - logPrintI(", IPv4: "); - logPrintI(WiFi.localIP().toString()); - logPrintI(", Gateway: "); - logPrintI(WiFi.gatewayIP().toString()); - logPrintI(", DNS1: "); - logPrintI(WiFi.dnsIP().toString()); - logPrintI(", DNS2: "); - logPrintlnI(WiFi.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString()); break; case SYSTEM_EVENT_STA_DISCONNECTED: - logPrintlnW("WiFi Disconnected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Disconnected"); break; case SYSTEM_EVENT_STA_STOP: - logPrintlnW("WiFi Stopped"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Stopped"); break; case SYSTEM_EVENT_ETH_START: - logPrintlnI("ETH Started"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Started"); break; case SYSTEM_EVENT_ETH_CONNECTED: - logPrintlnI("ETH Connected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Connected"); break; case SYSTEM_EVENT_ETH_GOT_IP: - logPrintI("Hostname: "); - logPrintI(ETH.getHostname()); - logPrintI(", ETH MAC: "); - logPrintI(ETH.macAddress()); - logPrintI(", IPv4: "); - logPrintI(ETH.localIP().toString()); - logPrintI(", Gateway: "); - logPrintI(ETH.gatewayIP().toString()); - logPrintI(", DNS1: "); - logPrintI(ETH.dnsIP().toString()); - logPrintI(", DNS2: "); - logPrintI(ETH.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); if (ETH.fullDuplex()) { - logPrintI(", FULL_DUPLEX"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "FULL_DUPLEX"); } - logPrintI(", "); - logPrintI(String(ETH.linkSpeed())); - logPrintlnI("Mbps"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "%dMbps", ETH.linkSpeed()); eth_connected = true; break; case SYSTEM_EVENT_ETH_DISCONNECTED: - logPrintlnW("ETH Disconnected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_WARN, WIFI_EVENT, "ETH Disconnected"); eth_connected = false; break; case SYSTEM_EVENT_ETH_STOP: - logPrintlnW("ETH Stopped"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_WARN, WIFI_EVENT, "ETH Stopped"); eth_connected = false; break; default: diff --git a/src/TaskEth.h b/src/TaskEth.h index 4a63d3f..50f1d63 100644 --- a/src/TaskEth.h +++ b/src/TaskEth.h @@ -3,6 +3,7 @@ #include +void setWiFiLogger(logging::Logger *logger); void WiFiEvent(WiFiEvent_t event); class EthTask : public Task { From 006b29d17791c411477d943630fe4b3702d1f19e Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 01:03:42 +0100 Subject: [PATCH 056/125] fixing missing function --- lib/System/System.cpp | 4 ++++ src/LoRa_APRS_iGate.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/System/System.cpp b/lib/System/System.cpp index e074745..18b89d4 100644 --- a/lib/System/System.cpp +++ b/lib/System/System.cpp @@ -38,3 +38,7 @@ bool System::isWifiEthConnected() const { void System::connectedViaWifiEth(bool status) { _isWifiEthConnected = status; } + +logging::Logger &System::getLogger() { + return _logger; +} diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 4171138..d795da2 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -47,6 +47,7 @@ RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); void setup() { Serial.begin(115200); LoRaSystem.getLogger().setSerial(&Serial); + setWiFiLogger(&LoRaSystem.getLogger()); delay(500); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "LoRa APRS iGate by OE5BPA (Peter Buchegger)"); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Version: %s", VERSION); From 6839db20ca061362936e815fb896fbfb66dca17f Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 01:16:47 +0100 Subject: [PATCH 057/125] fix version check script --- scripts/check_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_version.py b/scripts/check_version.py index 95e29c0..df9914f 100755 --- a/scripts/check_version.py +++ b/scripts/check_version.py @@ -11,7 +11,7 @@ version = None with open("src/LoRa_APRS_iGate.cpp") as f: for line in f: if line.startswith("#define VERSION"): - version = line.strip().split(" ")[2].replace('"', "") + version = line.strip().split(" ")[-1].replace('"', "") version_split = version.split(".") version_year = int(version_split[0]) From 4bd1c46335d8b75e09435d62535ae44dc60b76e8 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 10:56:06 +0100 Subject: [PATCH 058/125] fixing String in fstring --- lib/BoardFinder/BoardFinder.cpp | 4 ++-- lib/System/TaskManager.cpp | 4 ++-- src/LoRa_APRS_iGate.cpp | 2 +- src/TaskAprsIs.cpp | 2 +- src/TaskEth.cpp | 20 ++++++++++---------- src/TaskFTP.cpp | 2 +- src/TaskMQTT.cpp | 6 +++--- src/TaskModem.cpp | 10 +++++----- src/TaskNTP.cpp | 2 +- src/TaskOTA.cpp | 4 ++-- src/TaskRouter.cpp | 6 +++--- src/TaskWifi.cpp | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 00cfc57..2276da5 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -25,7 +25,7 @@ BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) { continue; } if (checkOledConfig(boardconf, logger)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name.c_str()); return boardconf; } } @@ -40,7 +40,7 @@ BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) { powerManagement.activateLoRa(); } if (checkModemConfig(boardconf)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name.c_str()); return boardconf; } } diff --git a/lib/System/TaskManager.cpp b/lib/System/TaskManager.cpp index d149e2f..b643c1e 100644 --- a/lib/System/TaskManager.cpp +++ b/lib/System/TaskManager.cpp @@ -24,11 +24,11 @@ std::list TaskManager::getTasks() { bool TaskManager::setup(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will setup all tasks..."); for (Task *elem : _alwaysRunTasks) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName().c_str()); elem->setup(system); } for (Task *elem : _tasks) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName().c_str()); elem->setup(system); } _nextTask = _tasks.begin(); diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index d795da2..74a313d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -81,7 +81,7 @@ void setup() { } } - LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Board %s loaded.", boardConfig->Name); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Board %s loaded.", boardConfig->Name.c_str()); if (boardConfig->Type == eTTGO_T_Beam_V1_0) { Wire.begin(boardConfig->OledSda, boardConfig->OledScl); diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 86ef766..680a2c4 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -41,7 +41,7 @@ bool AprsIsTask::loop(System &system) { } bool AprsIsTask::connect(System &system) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server.c_str(), system.getUserConfig()->aprs_is.port); APRS_IS::ConnectionStatus status = _aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); if (status == APRS_IS::ERROR_CONNECTION) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Something went wrong on connecting! Is the server reachable?"); diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index d5a15ee..03f211f 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -24,11 +24,11 @@ void WiFiEvent(WiFiEvent_t event) { _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Connected"); break; case SYSTEM_EVENT_STA_GOT_IP: - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString().c_str()); break; case SYSTEM_EVENT_STA_DISCONNECTED: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Disconnected"); @@ -44,11 +44,11 @@ void WiFiEvent(WiFiEvent_t event) { break; case SYSTEM_EVENT_ETH_GOT_IP: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString().c_str()); _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); if (ETH.fullDuplex()) { _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "FULL_DUPLEX"); diff --git a/src/TaskFTP.cpp b/src/TaskFTP.cpp index e4a6037..86e0bef 100644 --- a/src/TaskFTP.cpp +++ b/src/TaskFTP.cpp @@ -14,7 +14,7 @@ FTPTask::~FTPTask() { bool FTPTask::setup(System &system) { for (Configuration::Ftp::User user : system.getUserConfig()->ftp.users) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Adding user to FTP Server: %s", user.name); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Adding user to FTP Server: %s", user.name.c_str()); _ftpServer.addUser(user.name, user.password); } _ftpServer.addFilesystem("SPIFFS", &SPIFFS); diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index aa0a7a0..fe6ee3f 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -46,7 +46,7 @@ bool MQTTTask::loop(System &system) { topic = topic + "/"; } topic = topic + system.getUserConfig()->callsign; - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic, r); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic.c_str(), r.c_str()); _MQTT.publish(topic.c_str(), r.c_str()); } _MQTT.loop(); @@ -54,9 +54,9 @@ bool MQTTTask::loop(System &system) { } bool MQTTTask::connect(System &system) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server, system.getUserConfig()->mqtt.port); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server.c_str(), system.getUserConfig()->mqtt.port); if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign.c_str()); return true; } system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker failed. Try again later."); diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 645626b..ca0784d 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -39,19 +39,19 @@ bool ModemTask::setup(System &system) { bool ModemTask::loop(System &system) { if (_lora_aprs.checkMessage()) { std::shared_ptr msg = _lora_aprs.getMessage(); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString(), msg->toString(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString().c_str(), msg->toString().c_str(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); _fromModem.addElement(msg); - system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString()))); + system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString().c_str()))); } if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); if (system.getUserConfig()->lora.tx_enable) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString(), msg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); _lora_aprs.sendMessage(msg); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); } else { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString(), msg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString().c_str(), msg->toString().c_str()); } } diff --git a/src/TaskNTP.cpp b/src/TaskNTP.cpp index c012ae8..569eecc 100644 --- a/src/TaskNTP.cpp +++ b/src/TaskNTP.cpp @@ -27,7 +27,7 @@ bool NTPTask::loop(System &system) { } if (_ntpClient.update()) { setTime(_ntpClient.getEpochTime()); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Current time: %s", _ntpClient.getFormattedTime()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Current time: %s", _ntpClient.getFormattedTime().c_str()); } _stateInfo = _ntpClient.getFormattedTime(); _state = Okay; diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index 28dcb85..89cbf7f 100644 --- a/src/TaskOTA.cpp +++ b/src/TaskOTA.cpp @@ -18,7 +18,7 @@ bool OTATask::setup(System &system) { } else { // U_SPIFFS type = "filesystem"; } - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type.c_str()); }) .onEnd([&]() { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "OTA End"); @@ -39,7 +39,7 @@ bool OTATask::setup(System &system) { } else if (error == OTA_END_ERROR) { error_str = "End Failed"; } - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str.c_str()); }); if (system.getUserConfig()->network.hostname.overwrite) { _ota.setHostname(system.getUserConfig()->network.hostname.name.c_str()); diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index 25cf38d..96b13dc 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -47,7 +47,7 @@ bool RouterTask::loop(System &system) { aprsIsMsg->setPath(path + "qAO," + system.getUserConfig()->callsign); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString().c_str()); _toAprsIs.addElement(aprsIsMsg); } else { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => RFonly"); @@ -71,7 +71,7 @@ bool RouterTask::loop(System &system) { // fixme digiMsg->setPath(system.getUserConfig()->callsign + "*"); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString().c_str()); _toModem.addElement(digiMsg); } @@ -80,7 +80,7 @@ bool RouterTask::loop(System &system) { // check for beacon if (_beacon_timer.check()) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString(), _beaconMsg->encode()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString().c_str(), _beaconMsg->encode().c_str()); if (system.getUserConfig()->aprs_is.active) _toAprsIs.addElement(_beaconMsg); diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index fb01baf..d7e1868 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -31,7 +31,7 @@ bool WifiTask::setup(System &system) { } for (Configuration::Wifi::AP ap : system.getUserConfig()->wifi.APs) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Looking for AP: %s", ap.SSID); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Looking for AP: %s", ap.SSID.c_str()); _wiFiMulti.addAP(ap.SSID.c_str(), ap.password.c_str()); } return true; @@ -47,7 +47,7 @@ bool WifiTask::loop(System &system) { _state = Error; return false; } else if (wifi_status != _oldWifiStatus) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString().c_str()); _oldWifiStatus = wifi_status; return false; } From d6bc7e9788c556f4e2bceb1594c61d96d7a81f76 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 12:16:37 +0100 Subject: [PATCH 059/125] add syslog config --- data/is-cfg.json | 7 ++++++- src/LoRa_APRS_iGate.cpp | 5 +++++ src/project_configuration.cpp | 8 ++++++++ src/project_configuration.h | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index f278166..942f750 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -49,7 +49,7 @@ "spreading_factor": 12, "signal_bandwidth": 125000, "coding_rate4": 5, - "tx_enable": true + "tx_enable": false }, "display": { "always_on": true, @@ -74,5 +74,10 @@ "password": "", "topic": "LoraAPRS/Data" }, + "syslog": { + "active": true, + "server": "syslog.lora-aprs.info", + "port": 514 + }, "ntp_server": "pool.ntp.org" } diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 74a313d..8f7b8c9 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -149,6 +149,11 @@ void setup() { void loop() { LoRaSystem.getTaskManager().loop(LoRaSystem); + if (LoRaSystem.isWifiEthConnected()) { + if (LoRaSystem.getUserConfig()->syslog.active) { + LoRaSystem.getLogger().setSyslogServer(LoRaSystem.getUserConfig()->syslog.server, LoRaSystem.getUserConfig()->syslog.port, LoRaSystem.getUserConfig()->callsign); + } + } } String create_lat_aprs(double lat) { diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index a462c5b..6deebf5 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -86,6 +86,11 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.mqtt.password = data["mqtt"]["password"].as(); conf.mqtt.topic = data["mqtt"]["topic"].as(); } + if (data.containsKey("syslog")) { + conf.syslog.active = data["syslog"]["active"] | true; + conf.syslog.server = data["syslog"]["server"].as(); + conf.syslog.port = data["syslog"]["port"] | 514; + } if (data.containsKey("ntp_server")) conf.ntpServer = data["ntp_server"].as(); @@ -149,6 +154,9 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["mqtt"]["name"] = conf.mqtt.name; data["mqtt"]["password"] = conf.mqtt.password; data["mqtt"]["topic"] = conf.mqtt.topic; + data["syslog"]["active"] = conf.syslog.active; + data["syslog"]["server"] = conf.syslog.server; + data["syslog"]["port"] = conf.syslog.port; data["ntp_server"] = conf.ntpServer; data["board"] = conf.board; diff --git a/src/project_configuration.h b/src/project_configuration.h index 4fe78bd..234a83a 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -120,6 +120,9 @@ public: class MQTT { public: + MQTT() : active(false), server(""), port(1883), name(""), password(""), topic("LoraAPRS/Data") { + } + bool active; String server; uint16_t port; @@ -128,7 +131,18 @@ public: String topic; }; - Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org"){}; + class Syslog { + public: + Syslog() : active(true), server("syslog.lora-aprs.info"), port(514) { + } + + bool active; + String server; + int port; + }; + + Configuration() : callsign("NOCALL-10"), ntpServer("pool.ntp.org"), board("") { + } String callsign; Network network; @@ -140,8 +154,9 @@ public: Display display; Ftp ftp; MQTT mqtt; - String board; + Syslog syslog; String ntpServer; + String board; }; class ProjectConfigurationManagement : public ConfigurationManagement { From 7d240680b930709cc7fd26853def370ed4f71da9 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 12:18:21 +0100 Subject: [PATCH 060/125] version push --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 8f7b8c9..163146d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.1" +#define VERSION "22.11.2" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 66a72fa0822aa15507b55b966abbad36ab26fd1a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 13:38:24 +0100 Subject: [PATCH 061/125] send syslog message on connect --- src/LoRa_APRS_iGate.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 163146d..58a6b65 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -147,12 +147,14 @@ void setup() { LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "setup done..."); } +volatile bool syslogSet = false; + void loop() { LoRaSystem.getTaskManager().loop(LoRaSystem); - if (LoRaSystem.isWifiEthConnected()) { - if (LoRaSystem.getUserConfig()->syslog.active) { - LoRaSystem.getLogger().setSyslogServer(LoRaSystem.getUserConfig()->syslog.server, LoRaSystem.getUserConfig()->syslog.port, LoRaSystem.getUserConfig()->callsign); - } + if (LoRaSystem.isWifiEthConnected() && LoRaSystem.getUserConfig()->syslog.active && !syslogSet) { + LoRaSystem.getLogger().setSyslogServer(LoRaSystem.getUserConfig()->syslog.server, LoRaSystem.getUserConfig()->syslog.port, LoRaSystem.getUserConfig()->callsign); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "System connected after a restart to the network, syslog server set"); + syslogSet = true; } } From 5ea6a8f0084476574be5a6237235d5608f4f7753 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 20 Mar 2022 21:39:45 +0900 Subject: [PATCH 062/125] Add GPS function for setting beacon position. --- data/is-cfg.json | 1 + lib/BoardFinder/BoardFinder.cpp | 20 +++--- lib/BoardFinder/BoardFinder.h | 4 +- src/LoRa_APRS_iGate.cpp | 33 +++------- src/Task.h | 2 + src/TaskBeacon.cpp | 113 ++++++++++++++++++++++++++++++++ src/TaskBeacon.h | 31 +++++++++ src/TaskRouter.cpp | 33 +--------- src/TaskRouter.h | 3 - src/project_configuration.cpp | 2 + src/project_configuration.h | 3 +- 11 files changed, 173 insertions(+), 72 deletions(-) create mode 100644 src/TaskBeacon.cpp create mode 100644 src/TaskBeacon.h diff --git a/data/is-cfg.json b/data/is-cfg.json index 04aae81..e9c5f7e 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -29,6 +29,7 @@ "latitude": 0.000000, "longitude": 0.000000 }, + "gps": true, "timeout": 15 }, "aprs_is": { diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 0e076e0..0990d86 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -2,8 +2,8 @@ #include #include -BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip, bool powercheckstatus) - : Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { +BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, bool needcheckpowerchip, bool powercheckstatus) + : Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), GpsRx(gpsrx), GpsTx(gpstx), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { } BoardFinder::BoardFinder(const std::list &boardConfigs) : _boardConfigs(boardConfigs) { @@ -130,12 +130,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) { } // clang-format off -BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26); -BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true); -BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true); -BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true, true); -BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36); -BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26); -BoardConfig HELTEC_WIFI_LORA_32_V1("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26); -BoardConfig HELTEC_WIFI_LORA_32_V2("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26); +BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0); +BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, true); +BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 15, 12, true); +BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 12, 34, true, true); +BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36, 0, 0); +BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26, 0, 0); +BoardConfig HELTEC_WIFI_LORA_32_V1("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26, 0, 0); +BoardConfig HELTEC_WIFI_LORA_32_V2("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26, 0, 0); // clang-format on diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index 142de6d..fa68451 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -22,7 +22,7 @@ enum BoardType class BoardConfig { public: - explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip = false, bool powercheckstatus = false); + explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, bool needcheckpowerchip = false, bool powercheckstatus = false); String Name; BoardType Type; @@ -38,6 +38,8 @@ public: uint8_t LoraCS; uint8_t LoraReset; uint8_t LoraIRQ; + uint8_t GpsRx; + uint8_t GpsTx; bool needCheckPowerChip; bool powerCheckStatus; diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index afaa3f0..1996af2 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -8,6 +8,7 @@ #include #include "TaskAprsIs.h" +#include "TaskBeacon.h" #include "TaskDisplay.h" #include "TaskEth.h" #include "TaskFTP.h" @@ -42,6 +43,7 @@ FTPTask ftpTask; MQTTTask mqttTask(toMQTT); AprsIsTask aprsIsTask(toAprsIs); RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); +BeaconTask beaconTask(toModem, toAprsIs); void setup() { Serial.begin(115200); @@ -93,7 +95,11 @@ void setup() { } powerManagement.activateLoRa(); powerManagement.activateOLED(); - powerManagement.deactivateGPS(); + if (userConfig.beacon.gps) { + powerManagement.activateGPS(); + } else { + powerManagement.deactivateGPS(); + } } LoRaSystem.setBoardConfig(boardConfig); @@ -101,6 +107,7 @@ void setup() { LoRaSystem.getTaskManager().addTask(&displayTask); LoRaSystem.getTaskManager().addTask(&modemTask); LoRaSystem.getTaskManager().addTask(&routerTask); + LoRaSystem.getTaskManager().addTask(&beaconTask); if (userConfig.aprs_is.active) { if (boardConfig->Type == eETH_BOARD && !userConfig.wifi.active) { @@ -150,27 +157,3 @@ void setup() { void loop() { LoRaSystem.getTaskManager().loop(LoRaSystem); } - -String create_lat_aprs(double lat) { - char str[20]; - char n_s = 'N'; - if (lat < 0) { - n_s = 'S'; - } - lat = std::abs(lat); - sprintf(str, "%02d%05.2f%c", (int)lat, (lat - (double)((int)lat)) * 60.0, n_s); - String lat_str(str); - return lat_str; -} - -String create_long_aprs(double lng) { - char str[20]; - char e_w = 'E'; - if (lng < 0) { - e_w = 'W'; - } - lng = std::abs(lng); - sprintf(str, "%03d%05.2f%c", (int)lng, (lng - (double)((int)lng)) * 60.0, e_w); - String lng_str(str); - return lng_str; -} diff --git a/src/Task.h b/src/Task.h index 7dd4e6d..cd4b3da 100644 --- a/src/Task.h +++ b/src/Task.h @@ -12,6 +12,7 @@ enum TaskNames TaskWifi, TaskRouter, TaskMQTT, + TaskBeacon, TaskSize }; @@ -24,5 +25,6 @@ enum TaskNames #define TASK_WIFI "WifiTask" #define TASK_ROUTER "RouterTask" #define TASK_MQTT "MQTTTask" +#define TASK_BEACON "BeaconTask" #endif diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp new file mode 100644 index 0000000..43ab41c --- /dev/null +++ b/src/TaskBeacon.cpp @@ -0,0 +1,113 @@ +#include + +#include + +#include "Task.h" +#include "TaskBeacon.h" +#include "project_configuration.h" + +BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQueue> &toAprsIs) : Task(TASK_BEACON, TaskBeacon), _toModem(toModem), _toAprsIs(toAprsIs), ss(1), gpsok(false) { +} + +BeaconTask::~BeaconTask() { +} + +bool BeaconTask::setup(System &system) { + gpsok = system.getUserConfig()->beacon.gps; + + // Setup GPS + if (gpsok) { + if (system.getBoardConfig()->GpsRx != 0) { + ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); + } else { + logPrintlnD("NO GPS found."); + gpsok = false; + } + } + // setup beacon + _beacon_timer.setTimeout(system.getUserConfig()->beacon.timeout * 60 * 1000); + + _beaconMsg = std::shared_ptr(new APRSMessage()); + _beaconMsg->setSource(system.getUserConfig()->callsign); + _beaconMsg->setDestination("APLG01"); + + return true; +} + +bool BeaconTask::loop(System &system) { + + if (gpsok) { + while (ss.available() > 0) { + char c = ss.read(); + gps.encode(c); + } + } + + setBeacon(system); +} + +uint32_t diff = _beacon_timer.getTriggerTimeInSec(); +_stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10)); + +return true; +} + +String create_lat_aprs(double lat) { + char str[20]; + char n_s = 'N'; + if (lat < 0) { + n_s = 'S'; + } + lat = std::abs(lat); + sprintf(str, "%02d%05.2f%c", (int)lat, (lat - (double)((int)lat)) * 60.0, n_s); + String lat_str(str); + return lat_str; +} + +String create_long_aprs(double lng) { + char str[20]; + char e_w = 'E'; + if (lng < 0) { + e_w = 'W'; + } + lng = std::abs(lng); + sprintf(str, "%03d%05.2f%c", (int)lng, (lng - (double)((int)lng)) * 60.0, e_w); + String lng_str(str); + return lng_str; +} + +void BeaconTask::setBeacon(System &system) { + // check for beacon + if (_beacon_timer.check()) { + double lat, lng; + + if (gpsok) { + // bool gps_time_update = gps.time.isUpdated(); + bool gps_loc_update = gps.location.isUpdated(); + + if (!gps_loc_update) { + return; + } + lat = gps.location.lat(); + lng = gps.location.lng(); + } else { + lat = system.getUserConfig()->beacon.positionLatitude; + lng = system.getUserConfig()->beacon.positionLongitude; + } + _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); + + logPrintD("[" + timeString() + "] "); + logPrintlnD(_beaconMsg->encode()); + + if (system.getUserConfig()->aprs_is.active) + _toAprsIs.addElement(_beaconMsg); + + if (system.getUserConfig()->digi.beacon) { + _toModem.addElement(_beaconMsg); + } + + system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); + + _beacon_timer.start(); + } +} diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h new file mode 100644 index 0000000..dfa5e9a --- /dev/null +++ b/src/TaskBeacon.h @@ -0,0 +1,31 @@ +#ifndef TASK_BEACON_H_ +#define TASK_BEACON_H_ + +#include + +#include +#include +#include + +class BeaconTask : public Task { +public: + BeaconTask(TaskQueue> &toModem, TaskQueue> &toAprsIs); + virtual ~BeaconTask(); + + virtual bool setup(System &system) override; + virtual bool loop(System &system) override; + void setBeacon(System &system); + +private: + TaskQueue> &_toModem; + TaskQueue> &_toAprsIs; + + std::shared_ptr _beaconMsg; + Timer _beacon_timer; + + HardwareSerial ss; + TinyGPSPlus gps; + bool gpsok; +}; + +#endif diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index 2ab3cd5..26d23ab 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -6,9 +6,6 @@ #include "TaskRouter.h" #include "project_configuration.h" -String create_lat_aprs(double lat); -String create_long_aprs(double lng); - RouterTask::RouterTask(TaskQueue> &fromModem, TaskQueue> &toModem, TaskQueue> &toAprsIs, TaskQueue> &toMQTT) : Task(TASK_ROUTER, TaskRouter), _fromModem(fromModem), _toModem(toModem), _toAprsIs(toAprsIs), _toMQTT(toMQTT) { } @@ -16,16 +13,6 @@ RouterTask::~RouterTask() { } bool RouterTask::setup(System &system) { - // setup beacon - _beacon_timer.setTimeout(system.getUserConfig()->beacon.timeout * 60 * 1000); - - _beaconMsg = std::shared_ptr(new APRSMessage()); - _beaconMsg->setSource(system.getUserConfig()->callsign); - _beaconMsg->setDestination("APLG01"); - String lat = create_lat_aprs(system.getUserConfig()->beacon.positionLatitude); - String lng = create_long_aprs(system.getUserConfig()->beacon.positionLongitude); - _beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "&" + system.getUserConfig()->beacon.message); - return true; } @@ -80,25 +67,7 @@ bool RouterTask::loop(System &system) { } } - // check for beacon - if (_beacon_timer.check()) { - logPrintD("[" + timeString() + "] "); - logPrintlnD(_beaconMsg->encode()); - - if (system.getUserConfig()->aprs_is.active) - _toAprsIs.addElement(_beaconMsg); - - if (system.getUserConfig()->digi.beacon) { - _toModem.addElement(_beaconMsg); - } - - system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); - - _beacon_timer.start(); - } - - uint32_t diff = _beacon_timer.getTriggerTimeInSec(); - _stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10)); + _stateInfo = "Router done "; return true; } diff --git a/src/TaskRouter.h b/src/TaskRouter.h index 348cdff..a2e1bbe 100644 --- a/src/TaskRouter.h +++ b/src/TaskRouter.h @@ -18,9 +18,6 @@ private: TaskQueue> &_toModem; TaskQueue> &_toAprsIs; TaskQueue> &_toMQTT; - - std::shared_ptr _beaconMsg; - Timer _beacon_timer; }; #endif diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index eaf27dd..829fdc0 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -41,6 +41,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.beacon.message = data["beacon"]["message"].as(); conf.beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0; conf.beacon.positionLongitude = data["beacon"]["position"]["longitude"] | 0.0; + conf.beacon.gps = data["beacon"]["gps"] | false; conf.beacon.timeout = data["beacon"]["timeout"] | 15; conf.aprs_is.active = data["aprs_is"]["active"] | true; if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("passcode")) @@ -117,6 +118,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["beacon"]["message"] = conf.beacon.message; data["beacon"]["position"]["latitude"] = conf.beacon.positionLatitude; data["beacon"]["position"]["longitude"] = conf.beacon.positionLongitude; + data["beacon"]["gps"] = conf.beacon.gps; data["beacon"]["timeout"] = conf.beacon.timeout; data["aprs_is"]["active"] = conf.aprs_is.active; data["aprs_is"]["passcode"] = conf.aprs_is.passcode; diff --git a/src/project_configuration.h b/src/project_configuration.h index 854d450..d7c5f28 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -48,12 +48,13 @@ public: class Beacon { public: - Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), timeout(15) { + Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), gps(false), timeout(15) { } String message; double positionLatitude; double positionLongitude; + bool gps; int timeout; }; From 804a0afe05e213018c4962cabba79e3c0d352183 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 20 Mar 2022 22:00:29 +0900 Subject: [PATCH 063/125] Add TynyGPSPlus library. --- platformio.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio.ini b/platformio.ini index e9d1555..81ddad3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,7 @@ lib_deps = peterus/esp-logger @ 1.0.0 peterus/ESP-FTP-Server-Lib @ 0.9.5 knolleary/PubSubClient@^2.8 + mikalhart/TinyGPSPlus @ 1.0.2 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient From d0deb99668e917117fd5642e8a4dff1db85ab46b Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 20 Mar 2022 22:08:20 +0900 Subject: [PATCH 064/125] Change logger and correct corrupt source. --- src/TaskBeacon.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 43ab41c..5e48d72 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -20,7 +20,7 @@ bool BeaconTask::setup(System &system) { if (system.getBoardConfig()->GpsRx != 0) { ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); } else { - logPrintlnD("NO GPS found."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "NO GPS found."); gpsok = false; } } @@ -44,12 +44,11 @@ bool BeaconTask::loop(System &system) { } setBeacon(system); -} -uint32_t diff = _beacon_timer.getTriggerTimeInSec(); -_stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10)); + uint32_t diff = _beacon_timer.getTriggerTimeInSec(); + _stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10)); -return true; + return true; } String create_lat_aprs(double lat) { @@ -96,8 +95,7 @@ void BeaconTask::setBeacon(System &system) { } _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); - logPrintD("[" + timeString() + "] "); - logPrintlnD(_beaconMsg->encode()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString(), _beaconMsg->encode()); if (system.getUserConfig()->aprs_is.active) _toAprsIs.addElement(_beaconMsg); From 2ce81ed3f2fabc490ce662b0f48113b14abd6e98 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 21 Mar 2022 08:28:06 +0900 Subject: [PATCH 065/125] Debug for using logger. --- src/TaskBeacon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 5e48d72..6f187e9 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -95,7 +95,7 @@ void BeaconTask::setBeacon(System &system) { } _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString(), _beaconMsg->encode()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString().c_str(), _beaconMsg->encode().c_str()); if (system.getUserConfig()->aprs_is.active) _toAprsIs.addElement(_beaconMsg); From bef3062c658a16e95f79c829547ad2e4a661e905 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 21 Mar 2022 08:39:40 +0900 Subject: [PATCH 066/125] Clean source. --- src/TaskBeacon.cpp | 55 +++++++++++++++++++++++----------------------- src/TaskBeacon.h | 2 +- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 6f187e9..8f9d3a9 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -43,7 +43,12 @@ bool BeaconTask::loop(System &system) { } } - setBeacon(system); + // check for beacon + if (_beacon_timer.check()) { + if setBeacon (system) { + _beacon_timer.start(); + } + } uint32_t diff = _beacon_timer.getTriggerTimeInSec(); _stateInfo = "beacon " + String(uint32_t(diff / 600)) + String(uint32_t(diff / 60) % 10) + ":" + String(uint32_t(diff / 10) % 6) + String(uint32_t(diff % 10)); @@ -75,37 +80,33 @@ String create_long_aprs(double lng) { return lng_str; } -void BeaconTask::setBeacon(System &system) { - // check for beacon - if (_beacon_timer.check()) { - double lat, lng; +bool BeaconTask::setBeacon(System &system) { - if (gpsok) { - // bool gps_time_update = gps.time.isUpdated(); - bool gps_loc_update = gps.location.isUpdated(); + double lat, lng; - if (!gps_loc_update) { - return; - } + if (gpsok) { + if (gps.location.isUpdated()) { lat = gps.location.lat(); lng = gps.location.lng(); } else { - lat = system.getUserConfig()->beacon.positionLatitude; - lng = system.getUserConfig()->beacon.positionLongitude; + return false; } - _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); - - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString().c_str(), _beaconMsg->encode().c_str()); - - if (system.getUserConfig()->aprs_is.active) - _toAprsIs.addElement(_beaconMsg); - - if (system.getUserConfig()->digi.beacon) { - _toModem.addElement(_beaconMsg); - } - - system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); - - _beacon_timer.start(); + } else { + lat = system.getUserConfig()->beacon.positionLatitude; + lng = system.getUserConfig()->beacon.positionLongitude; } + _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); + + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString().c_str(), _beaconMsg->encode().c_str()); + + if (system.getUserConfig()->aprs_is.active) + _toAprsIs.addElement(_beaconMsg); + + if (system.getUserConfig()->digi.beacon) { + _toModem.addElement(_beaconMsg); + } + + system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); + + return true; } diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h index dfa5e9a..c23ca07 100644 --- a/src/TaskBeacon.h +++ b/src/TaskBeacon.h @@ -14,7 +14,7 @@ public: virtual bool setup(System &system) override; virtual bool loop(System &system) override; - void setBeacon(System &system); + bool setBeacon(System &system); private: TaskQueue> &_toModem; From 2758b2c4be5e2fd679646c7c2a6ebe273310b7a5 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 21 Mar 2022 14:20:29 +0900 Subject: [PATCH 067/125] Wrong syntax. --- src/TaskBeacon.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 8f9d3a9..574b299 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -44,8 +44,7 @@ bool BeaconTask::loop(System &system) { } // check for beacon - if (_beacon_timer.check()) { - if setBeacon (system) { + if (setBeacon(system)) { _beacon_timer.start(); } } From c4496274e726518604b9f88bedb24b3513545d2a Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 21 Mar 2022 14:22:43 +0900 Subject: [PATCH 068/125] Correct if block. --- src/TaskBeacon.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 574b299..7fdf265 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -44,6 +44,7 @@ bool BeaconTask::loop(System &system) { } // check for beacon + if (_beacon_timer.check()) { if (setBeacon(system)) { _beacon_timer.start(); } From fb83b79081c22015c269f9ea62fc022f4a155e12 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 21 Mar 2022 14:26:46 +0900 Subject: [PATCH 069/125] Change version. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 92bd27a..48a7e73 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.2" +#define VERSION "22.12.0" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From b9ae54de45860829639c6747e5f75b19a3e393d5 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 26 Mar 2022 22:27:43 +0100 Subject: [PATCH 070/125] update gps function --- data/is-cfg.json | 2 +- src/LoRa_APRS_iGate.cpp | 2 +- src/TaskBeacon.cpp | 44 ++++++++++++++++------------------- src/TaskBeacon.h | 8 +++---- src/project_configuration.cpp | 4 ++-- src/project_configuration.h | 4 ++-- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index 37e449b..47d6f65 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -29,7 +29,7 @@ "latitude": 0.000000, "longitude": 0.000000 }, - "gps": true, + "use_gps": false, "timeout": 15 }, "aprs_is": { diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 48a7e73..2043e7d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -95,7 +95,7 @@ void setup() { } powerManagement.activateLoRa(); powerManagement.activateOLED(); - if (userConfig.beacon.gps) { + if (userConfig.beacon.use_gps) { powerManagement.activateGPS(); } else { powerManagement.deactivateGPS(); diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 7fdf265..50025e2 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -6,22 +6,21 @@ #include "TaskBeacon.h" #include "project_configuration.h" -BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQueue> &toAprsIs) : Task(TASK_BEACON, TaskBeacon), _toModem(toModem), _toAprsIs(toAprsIs), ss(1), gpsok(false) { +BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQueue> &toAprsIs) : Task(TASK_BEACON, TaskBeacon), _toModem(toModem), _toAprsIs(toAprsIs), _ss(1), _useGps(false) { } BeaconTask::~BeaconTask() { } bool BeaconTask::setup(System &system) { - gpsok = system.getUserConfig()->beacon.gps; + _useGps = system.getUserConfig()->beacon.use_gps; - // Setup GPS - if (gpsok) { + if (_useGps) { if (system.getBoardConfig()->GpsRx != 0) { - ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); + _ss.begin(9600, SERIAL_8N1, system.getBoardConfig()->GpsTx, system.getBoardConfig()->GpsRx); } else { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "NO GPS found."); - gpsok = false; + _useGps = false; } } // setup beacon @@ -35,17 +34,16 @@ bool BeaconTask::setup(System &system) { } bool BeaconTask::loop(System &system) { - - if (gpsok) { - while (ss.available() > 0) { - char c = ss.read(); - gps.encode(c); + if (_useGps) { + while (_ss.available() > 0) { + char c = _ss.read(); + _gps.encode(c); } } // check for beacon if (_beacon_timer.check()) { - if (setBeacon(system)) { + if (sendBeacon(system)) { _beacon_timer.start(); } } @@ -80,27 +78,25 @@ String create_long_aprs(double lng) { return lng_str; } -bool BeaconTask::setBeacon(System &system) { +bool BeaconTask::sendBeacon(System &system) { + double lat = system.getUserConfig()->beacon.positionLatitude; + double lng = system.getUserConfig()->beacon.positionLongitude; - double lat, lng; - - if (gpsok) { - if (gps.location.isUpdated()) { - lat = gps.location.lat(); - lng = gps.location.lng(); + if (_useGps) { + if (_gps.location.isUpdated()) { + lat = _gps.location.lat(); + lng = _gps.location.lng(); } else { return false; } - } else { - lat = system.getUserConfig()->beacon.positionLatitude; - lng = system.getUserConfig()->beacon.positionLongitude; } _beaconMsg->getBody()->setData(String("=") + create_lat_aprs(lat) + "L" + create_long_aprs(lng) + "&" + system.getUserConfig()->beacon.message); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s]%s", timeString().c_str(), _beaconMsg->encode().c_str()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString().c_str(), _beaconMsg->encode().c_str()); - if (system.getUserConfig()->aprs_is.active) + if (system.getUserConfig()->aprs_is.active) { _toAprsIs.addElement(_beaconMsg); + } if (system.getUserConfig()->digi.beacon) { _toModem.addElement(_beaconMsg); diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h index c23ca07..9927dd6 100644 --- a/src/TaskBeacon.h +++ b/src/TaskBeacon.h @@ -14,7 +14,7 @@ public: virtual bool setup(System &system) override; virtual bool loop(System &system) override; - bool setBeacon(System &system); + bool sendBeacon(System &system); private: TaskQueue> &_toModem; @@ -23,9 +23,9 @@ private: std::shared_ptr _beaconMsg; Timer _beacon_timer; - HardwareSerial ss; - TinyGPSPlus gps; - bool gpsok; + HardwareSerial _ss; + TinyGPSPlus _gps; + bool _useGps; }; #endif diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 231fe03..680f2c0 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -41,7 +41,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.beacon.message = data["beacon"]["message"].as(); conf.beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0; conf.beacon.positionLongitude = data["beacon"]["position"]["longitude"] | 0.0; - conf.beacon.gps = data["beacon"]["gps"] | false; + conf.beacon.use_gps = data["beacon"]["use_gps"] | false; conf.beacon.timeout = data["beacon"]["timeout"] | 15; conf.aprs_is.active = data["aprs_is"]["active"] | true; if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("passcode")) @@ -123,7 +123,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["beacon"]["message"] = conf.beacon.message; data["beacon"]["position"]["latitude"] = conf.beacon.positionLatitude; data["beacon"]["position"]["longitude"] = conf.beacon.positionLongitude; - data["beacon"]["gps"] = conf.beacon.gps; + data["beacon"]["use_gps"] = conf.beacon.use_gps; data["beacon"]["timeout"] = conf.beacon.timeout; data["aprs_is"]["active"] = conf.aprs_is.active; data["aprs_is"]["passcode"] = conf.aprs_is.passcode; diff --git a/src/project_configuration.h b/src/project_configuration.h index f38974e..8a626c6 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -48,13 +48,13 @@ public: class Beacon { public: - Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), gps(false), timeout(15) { + Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), use_gps(false), timeout(15) { } String message; double positionLatitude; double positionLongitude; - bool gps; + bool use_gps; int timeout; }; From bcbd174512ec45acd0b7708862415be24ce1b26b Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 26 Mar 2022 23:26:42 +0100 Subject: [PATCH 071/125] update build action --- .github/workflows/build_check.yml | 6 ++++- .github/workflows/release.yml | 45 +++++++++---------------------- scripts/create_version_tag.py | 21 +++++++++++++++ 3 files changed, 38 insertions(+), 34 deletions(-) create mode 100755 scripts/create_version_tag.py diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 3694829..efa3945 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -1,6 +1,10 @@ name: Integreation Tests -on: [push, pull_request] +on: + push: + branches: + - '*' + - '!master' jobs: version_check: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ccc28a..a1e50e4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,46 +1,25 @@ +name: Upload Release Assets + on: push: - tags: - - 'v*' - -name: Upload Release Assets + branches: + - 'master' jobs: build: name: Upload Release Assets runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - run: sudo apt-get install python3-setuptools python3-wheel - run: pip3 install platformio - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - - uses: actions/checkout@v2 - with: - submodules: 'recursive' - run: platformio run - - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: echo "VERSION=$(echo ./scripts/create_version_tag.py)" >> $GITHUB_ENV + - uses: ncipollo/release-action@v1 with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: false - prerelease: false - # upload firmware bin - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: .pio/build/lora_board/firmware.bin - asset_name: lora_board.bin - asset_content_type: application/bin - # upload json file - - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: data/is-cfg.json - asset_name: is-cfg.json - asset_content_type: application/json \ No newline at end of file + tag: ${{ env.VERSION }} + commit: Release ${{ env.VERSION }} + generateReleaseNotes: true + artifacts: ".pio/build/lora_board/firmware.bin,data/is-cfg.json" + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/create_version_tag.py b/scripts/create_version_tag.py new file mode 100755 index 0000000..5b37c82 --- /dev/null +++ b/scripts/create_version_tag.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +from datetime import date + +today = date.today() + +current_year = int(str(today.isocalendar()[0])[2:]) +current_week = int(today.isocalendar()[1]) + +version = None +with open("src/LoRa_APRS_iGate.cpp") as f: + for line in f: + if line.startswith("#define VERSION"): + version = line.strip().split(" ")[-1].replace('"', "") + +version_split = version.split(".") +version_year = int(version_split[0]) +version_week = int(version_split[1]) +version_vers = int(version_split[2]) + +print(f"v{version_year}.{version_week}.{version_vers}") From bf4055339806431044f020a10ce7a8486d53a3df Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 26 Mar 2022 23:34:01 +0100 Subject: [PATCH 072/125] update relase script --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1e50e4..6521fcb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Upload Release Assets +name: Create new release on: push: @@ -7,7 +7,7 @@ on: jobs: build: - name: Upload Release Assets + name: Create new release runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -15,7 +15,7 @@ jobs: - run: pip3 install platformio - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - run: platformio run - - run: echo "VERSION=$(echo ./scripts/create_version_tag.py)" >> $GITHUB_ENV + - run: echo "VERSION=$(./scripts/create_version_tag.py)" >> $GITHUB_ENV - uses: ncipollo/release-action@v1 with: tag: ${{ env.VERSION }} From 296a6f1c2cc64bff540a77167211a2f665042b58 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 26 Mar 2022 23:55:35 +0100 Subject: [PATCH 073/125] set commit to master --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6521fcb..5ba6a87 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: - uses: ncipollo/release-action@v1 with: tag: ${{ env.VERSION }} - commit: Release ${{ env.VERSION }} + commit: master generateReleaseNotes: true artifacts: ".pio/build/lora_board/firmware.bin,data/is-cfg.json" token: ${{ secrets.GITHUB_TOKEN }} From fba322a0d53993be71ee27e3ba9567753e3304c7 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 27 Mar 2022 09:02:14 +0900 Subject: [PATCH 074/125] Push button to send beacon immediately. --- lib/BoardFinder/BoardFinder.cpp | 20 ++++++++++---------- lib/BoardFinder/BoardFinder.h | 3 ++- platformio.ini | 1 + src/TaskBeacon.cpp | 20 +++++++++++++++++++- src/TaskBeacon.h | 6 ++++++ 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 8a39ae6..833008e 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -4,8 +4,8 @@ #define MODULE_NAME "BoardFinder" -BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, bool needcheckpowerchip, bool powercheckstatus) - : Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), GpsRx(gpsrx), GpsTx(gpstx), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { +BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, uint8_t button, bool needcheckpowerchip, bool powercheckstatus) + : Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), GpsRx(gpsrx), GpsTx(gpstx), Button(button), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { } BoardFinder::BoardFinder(const std::list &boardConfigs) : _boardConfigs(boardConfigs) { @@ -130,12 +130,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logg } // clang-format off -BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0); -BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, true); -BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 15, 12, true); -BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 12, 34, true, true); -BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36, 0, 0); -BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26, 0, 0); -BoardConfig HELTEC_WIFI_LORA_32_V1("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26, 0, 0); -BoardConfig HELTEC_WIFI_LORA_32_V2("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26, 0, 0); +BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, 0); +BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, 0, true); +BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 15, 12, 38, true); +BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 12, 34, 38, true, true); +BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36, 0, 0, 0); +BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26, 0, 0, 0); +BoardConfig HELTEC_WIFI_LORA_32_V1("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26, 0, 0, 0); +BoardConfig HELTEC_WIFI_LORA_32_V2("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26, 0, 0, 0); // clang-format on diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index c833fab..73b5ff9 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -24,7 +24,7 @@ enum BoardType class BoardConfig { public: - explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, bool needcheckpowerchip = false, bool powercheckstatus = false); + explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, uint8_t button, bool needcheckpowerchip = false, bool powercheckstatus = false); String Name; BoardType Type; @@ -42,6 +42,7 @@ public: uint8_t LoraIRQ; uint8_t GpsRx; uint8_t GpsTx; + uint8_t Button; bool needCheckPowerChip; bool powerCheckStatus; diff --git a/platformio.ini b/platformio.ini index 81ddad3..a2f5cb3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,6 +15,7 @@ lib_deps = peterus/ESP-FTP-Server-Lib @ 0.9.5 knolleary/PubSubClient@^2.8 mikalhart/TinyGPSPlus @ 1.0.2 + shaggydog/OneButton @ 1.5.0 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 50025e2..e356920 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -1,5 +1,6 @@ #include +#include #include #include "Task.h" @@ -12,7 +13,21 @@ BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQue BeaconTask::~BeaconTask() { } +OneButton BeaconTask::_userButton; +bool BeaconTask::_send_update; +uint BeaconTask::_instances; + +void BeaconTask::pushButton() { + _send_update = true; +} + bool BeaconTask::setup(System &system) { + if (_instances++ == 0 && system.getBoardConfig()->Button > 0) { + _userButton = OneButton(system.getBoardConfig()->Button, true, true); + _userButton.attachClick(pushButton); + _send_update = false; + } + _useGps = system.getUserConfig()->beacon.use_gps; if (_useGps) { @@ -41,9 +56,12 @@ bool BeaconTask::loop(System &system) { } } + _userButton.tick(); + // check for beacon - if (_beacon_timer.check()) { + if (_beacon_timer.check() || _send_update) { if (sendBeacon(system)) { + _send_update = false; _beacon_timer.start(); } } diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h index 9927dd6..ba0ff22 100644 --- a/src/TaskBeacon.h +++ b/src/TaskBeacon.h @@ -1,6 +1,7 @@ #ifndef TASK_BEACON_H_ #define TASK_BEACON_H_ +#include #include #include @@ -26,6 +27,11 @@ private: HardwareSerial _ss; TinyGPSPlus _gps; bool _useGps; + + static uint _instances; + static OneButton _userButton; + static bool _send_update; + static void pushButton(); }; #endif From 21d3ba67e4a1d2c76aba777017c390cdc04bd466 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 27 Mar 2022 01:14:22 +0100 Subject: [PATCH 075/125] version check update --- .github/workflows/build_check.yml | 1 + scripts/check_version.py | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index efa3945..1c8b2b6 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -15,6 +15,7 @@ jobs: uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 + - run: pip install GitPython - name: check version run: ./scripts/check_version.py diff --git a/scripts/check_version.py b/scripts/check_version.py index df9914f..5fc3f93 100755 --- a/scripts/check_version.py +++ b/scripts/check_version.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import git from datetime import date today = date.today() @@ -16,20 +17,32 @@ with open("src/LoRa_APRS_iGate.cpp") as f: version_split = version.split(".") version_year = int(version_split[0]) version_week = int(version_split[1]) +version_vers = int(version_split[2]) -print(f"firmware version year: {version_year}") -print(f"firmware version week: {version_week}") +print(f"[INFO] firmware version year: {version_year}") +print(f"[INFO] firmware version week: {version_week}") +print(f"[INFO] firmware version version: {version_vers}") +print(f"[INFO] -> {version}") -print(f"current year: {current_year}") -print(f"current week: {current_week}") +print(f"[INFO] current year: {current_year}") +print(f"[INFO] current week: {current_week}") +print(f"[INFO] -> {current_year}.{current_week}.x") error = False if version_year != current_year: - print("firmware version is not current year!") + print("[ERROR] firmware version is not current year!") error = True if version_week != current_week: - print("firmware version is not current week!") + print("[ERROR] firmware version is not current week!") error = True +repo = git.Repo('.') +if f"v{version}" in repo.tags: + print("[ERROR] tag with this version is already existing") + error = True + +if error: + print("[ERROR] check/update VERSION define in src/LoRa_APRS_iGate.cpp to fix this issue") + exit(error) From 30f69bd0392e052f98b37f8e9a97dd0ac4f5a3cb Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 27 Mar 2022 01:20:04 +0100 Subject: [PATCH 076/125] version check update --- scripts/check_version.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_version.py b/scripts/check_version.py index 5fc3f93..57f87ea 100755 --- a/scripts/check_version.py +++ b/scripts/check_version.py @@ -38,6 +38,7 @@ if version_week != current_week: error = True repo = git.Repo('.') +print(f"[INFO] found {len(repo.tags)} tags in repo") if f"v{version}" in repo.tags: print("[ERROR] tag with this version is already existing") error = True From 6c052d71363da52038aefead780139fdacc5943d Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 27 Mar 2022 01:24:28 +0100 Subject: [PATCH 077/125] get all tags --- .github/workflows/build_check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 1c8b2b6..65b055c 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v2 - run: pip install GitPython From 44e4f8ec4119c3c0cef85c268362d12eb961c724 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 27 Mar 2022 01:28:33 +0100 Subject: [PATCH 078/125] version bump --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 2043e7d..de4cc71 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.12.0" +#define VERSION "22.12.1" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 593703b57aeb1e6d7320aa825adbae8a407af357 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 27 Mar 2022 01:47:54 +0100 Subject: [PATCH 079/125] fix github action (jobs not running) --- .github/workflows/build_check.yml | 3 +++ src/LoRa_APRS_iGate.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 65b055c..7686833 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -5,6 +5,9 @@ on: branches: - '*' - '!master' + pull_request: + branches: + - master jobs: version_check: diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index de4cc71..62355c9 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.12.1" +#define VERSION "22.12.2" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From d8d0a0a2827b908d5ea72ccb35a13f437f171d20 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 27 Mar 2022 10:02:37 +0900 Subject: [PATCH 080/125] syslog doesn't work properly if aprs_is is false. --- src/LoRa_APRS_iGate.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 62355c9..b3cbeef 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -109,23 +109,30 @@ void setup() { LoRaSystem.getTaskManager().addTask(&routerTask); LoRaSystem.getTaskManager().addTask(&beaconTask); - if (userConfig.aprs_is.active) { - if (boardConfig->Type == eETH_BOARD && !userConfig.wifi.active) { - LoRaSystem.getTaskManager().addAlwaysRunTask(ðTask); - } - if (userConfig.wifi.active) { - LoRaSystem.getTaskManager().addAlwaysRunTask(&wifiTask); - } + bool tcpip = false; + + if (userConfig.wifi.active) { + LoRaSystem.getTaskManager().addAlwaysRunTask(&wifiTask); LoRaSystem.getTaskManager().addTask(&otaTask); + tcpip = true; + } else if (boardConfig->Type == eETH_BOARD) { + LoRaSystem.getTaskManager().addAlwaysRunTask(ðTask); + tcpip = true; + } + + if (tcpip) { LoRaSystem.getTaskManager().addTask(&ntpTask); if (userConfig.ftp.active) { LoRaSystem.getTaskManager().addTask(&ftpTask); } - LoRaSystem.getTaskManager().addTask(&aprsIsTask); - } - if (userConfig.mqtt.active) { - LoRaSystem.getTaskManager().addTask(&mqttTask); + if (userConfig.aprs_is.active) { + LoRaSystem.getTaskManager().addTask(&aprsIsTask); + } + + if (userConfig.mqtt.active) { + LoRaSystem.getTaskManager().addTask(&mqttTask); + } } LoRaSystem.getTaskManager().setup(LoRaSystem); From 8277fd228e2bd12a22ddc6e9ee7172ad09979537 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 27 Mar 2022 10:05:25 +0900 Subject: [PATCH 081/125] Change VERSION. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index b3cbeef..b839e47 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.12.2" +#define VERSION "22.12.3" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 8652ecc0dec6a4188c44058374723e43e2544631 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 27 Mar 2022 12:56:51 +0200 Subject: [PATCH 082/125] tweet release --- .github/workflows/tweet_release.yml | 19 +++++++++++++++++++ src/LoRa_APRS_iGate.cpp | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tweet_release.yml diff --git a/.github/workflows/tweet_release.yml b/.github/workflows/tweet_release.yml new file mode 100644 index 0000000..462b2bc --- /dev/null +++ b/.github/workflows/tweet_release.yml @@ -0,0 +1,19 @@ +name: tweet-release + +on: + release: + types: [published] + +jobs: + tweet: + runs-on: ubuntu-latest + steps: + - uses: Eomm/why-don-t-you-tweet@v1 + if: ${{ !github.event.repository.private }} + with: + tweet-message: "New ${{ github.event.repository.name }} release ${{ github.event.release.tag_name }}! ${{ github.event.release.html_url }} #LoRa #APRS #HAM #hamradio #iGate" + env: + TWITTER_CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }} + TWITTER_CONSUMER_API_SECRET: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index b839e47..14637e2 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.12.3" +#define VERSION "22.12.4" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From f31781cf751d2fb075b36f39aa319e8d0a73adf7 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 28 Mar 2022 10:15:37 +0900 Subject: [PATCH 083/125] Collision avoidance. --- lib/LoRa/LoRa.cpp | 5 +++++ lib/LoRa/LoRa.h | 1 + src/TaskModem.cpp | 17 +++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/LoRa/LoRa.cpp b/lib/LoRa/LoRa.cpp index 35dfacd..2422ca8 100644 --- a/lib/LoRa/LoRa.cpp +++ b/lib/LoRa/LoRa.cpp @@ -18,6 +18,7 @@ #define REG_FIFO_RX_CURRENT_ADDR 0x10 #define REG_IRQ_FLAGS 0x12 #define REG_RX_NB_BYTES 0x13 +#define REG_MODEM_STAT 0x18 #define REG_PKT_SNR_VALUE 0x19 #define REG_PKT_RSSI_VALUE 0x1a #define REG_RSSI_VALUE 0x1b @@ -251,6 +252,10 @@ float LoRaClass::packetSnr() { return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25; } +bool LoRaClass::rxSignalDetected() { + return (readRegister(REG_MODEM_STAT) & 0x01) == 0x01; +} + long LoRaClass::packetFrequencyError() { int32_t freqError = 0; freqError = static_cast(readRegister(REG_FREQ_ERROR_MSB) & B111); diff --git a/lib/LoRa/LoRa.h b/lib/LoRa/LoRa.h index 51e089a..45c92bd 100644 --- a/lib/LoRa/LoRa.h +++ b/lib/LoRa/LoRa.h @@ -44,6 +44,7 @@ public: int packetRssi(); float packetSnr(); long packetFrequencyError(); + bool rxSignalDetected(); int rssi(); diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index ca0784d..017b2b2 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -45,13 +45,18 @@ bool ModemTask::loop(System &system) { } if (!_toModem.empty()) { - std::shared_ptr msg = _toModem.getElement(); - if (system.getUserConfig()->lora.tx_enable) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); - _lora_aprs.sendMessage(msg); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); + if (_lora_aprs.rxSignalDetected()) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str()); + delay(1000); } else { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString().c_str(), msg->toString().c_str()); + std::shared_ptr msg = _toModem.getElement(); + if (system.getUserConfig()->lora.tx_enable) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); + _lora_aprs.sendMessage(msg); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); + } else { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString().c_str(), msg->toString().c_str()); + } } } From c48636757f22a17f8d8f74f1618e56d63ec3e9ab Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 28 Mar 2022 11:09:19 +0900 Subject: [PATCH 084/125] Update version. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 14637e2..30040e6 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.12.4" +#define VERSION "22.12.5" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 6c43f70c4e691434cb70f06fc67a5c1327a1a6aa Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Mon, 28 Mar 2022 11:21:00 +0900 Subject: [PATCH 085/125] Change next week version. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 30040e6..77f0dcc 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.12.5" +#define VERSION "22.13.0" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From aeef66a3388f87a4541317aee195040bad4d6808 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 28 Mar 2022 20:16:06 +0200 Subject: [PATCH 086/125] fixing missing string in config --- src/project_configuration.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 680f2c0..80aaa11 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -89,8 +89,10 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen } if (data.containsKey("syslog")) { conf.syslog.active = data["syslog"]["active"] | true; - conf.syslog.server = data["syslog"]["server"].as(); - conf.syslog.port = data["syslog"]["port"] | 514; + if (data["syslog"].containsKey("server")) { + conf.syslog.server = data["syslog"]["server"].as(); + } + conf.syslog.port = data["syslog"]["port"] | 514; } if (data.containsKey("ntp_server")) conf.ntpServer = data["ntp_server"].as(); From 8e86f868cd737c21d5d7e933e053d677463b7c3a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 28 Mar 2022 20:26:42 +0200 Subject: [PATCH 087/125] release update --- .github/workflows/release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5ba6a87..fd4ec4e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,4 +22,5 @@ jobs: commit: master generateReleaseNotes: true artifacts: ".pio/build/lora_board/firmware.bin,data/is-cfg.json" - token: ${{ secrets.GITHUB_TOKEN }} + owner: ${{ secrets.OWNER }} + token: ${{ secrets.PAT }} From 58400bd38bcc114599562d577bb7e4a38d063fef Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 28 Mar 2022 20:30:10 +0200 Subject: [PATCH 088/125] version bump --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 77f0dcc..b90f582 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.13.0" +#define VERSION "22.13.1" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 414b85d47f79efc3a8117bdaab2f16761183b63a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 28 Mar 2022 22:21:50 +0200 Subject: [PATCH 089/125] update project config --- src/project_configuration.cpp | 49 +++++++++++++++++++++-------------- src/project_configuration.h | 12 ++++----- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 80aaa11..02e5acb 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -33,8 +33,10 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen JsonArray aps = data["wifi"]["AP"].as(); for (JsonVariant v : aps) { Configuration::Wifi::AP ap; - ap.SSID = v["SSID"].as(); - ap.password = v["password"].as(); + if (v.containsKey("SSID")) + ap.SSID = v["SSID"].as(); + if (v.containsKey("password")) + ap.password = v["password"].as(); conf.wifi.APs.push_back(ap); } if (data.containsKey("beacon") && data["beacon"].containsKey("message")) @@ -44,14 +46,16 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.beacon.use_gps = data["beacon"]["use_gps"] | false; conf.beacon.timeout = data["beacon"]["timeout"] | 15; conf.aprs_is.active = data["aprs_is"]["active"] | true; + if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("passcode")) conf.aprs_is.passcode = data["aprs_is"]["passcode"].as(); if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("server")) conf.aprs_is.server = data["aprs_is"]["server"].as(); conf.aprs_is.port = data["aprs_is"]["port"] | 14580; - conf.digi.active = data["digi"]["active"] | false; - conf.digi.beacon = data["digi"]["beacon"] | false; + conf.digi.active = data["digi"]["active"] | false; + conf.digi.beacon = data["digi"]["beacon"] | false; + conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000; conf.lora.gainRx = data["lora"]["gain_rx"] | 0; conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000; @@ -60,6 +64,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000; conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5; conf.lora.tx_enable = data["lora"]["tx_enable"] | true; + conf.display.alwaysOn = data["display"]["always_on"] | true; conf.display.timeout = data["display"]["timeout"] | 10; conf.display.overwritePin = data["display"]["overwrite_pin"] | 0; @@ -69,8 +74,10 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen JsonArray users = data["ftp"]["user"].as(); for (JsonVariant u : users) { Configuration::Ftp::User us; - us.name = u["name"].as(); - us.password = u["password"].as(); + if (u.containsKey("name")) + us.name = u["name"].as(); + if (u.containsKey("password")) + us.password = u["password"].as(); conf.ftp.users.push_back(us); } if (conf.ftp.users.empty()) { @@ -79,21 +86,23 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen us.password = "ftp"; conf.ftp.users.push_back(us); } - if (data.containsKey("mqtt")) { - conf.mqtt.active = data["mqtt"]["active"] | false; - conf.mqtt.server = data["mqtt"]["server"].as(); - conf.mqtt.port = data["mqtt"]["port"].as(); - conf.mqtt.name = data["mqtt"]["name"].as(); + + conf.mqtt.active = data["mqtt"]["active"] | false; + if (data["mqtt"].containsKey("server")) + conf.mqtt.server = data["mqtt"]["server"].as(); + conf.mqtt.port = data["mqtt"]["port"] | 1883; + if (data["mqtt"].containsKey("name")) + conf.mqtt.name = data["mqtt"]["name"].as(); + if (data["mqtt"].containsKey("password")) conf.mqtt.password = data["mqtt"]["password"].as(); - conf.mqtt.topic = data["mqtt"]["topic"].as(); - } - if (data.containsKey("syslog")) { - conf.syslog.active = data["syslog"]["active"] | true; - if (data["syslog"].containsKey("server")) { - conf.syslog.server = data["syslog"]["server"].as(); - } - conf.syslog.port = data["syslog"]["port"] | 514; - } + if (data["mqtt"].containsKey("topic")) + conf.mqtt.topic = data["mqtt"]["topic"].as(); + + conf.syslog.active = data["syslog"]["active"] | true; + if (data["syslog"].containsKey("server")) + conf.syslog.server = data["syslog"]["server"].as(); + conf.syslog.port = data["syslog"]["port"] | 514; + if (data.containsKey("ntp_server")) conf.ntpServer = data["ntp_server"].as(); diff --git a/src/project_configuration.h b/src/project_configuration.h index 8a626c6..e32a17a 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -124,12 +124,12 @@ public: MQTT() : active(false), server(""), port(1883), name(""), password(""), topic("LoraAPRS/Data") { } - bool active; - String server; - uint16_t port; - String name; - String password; - String topic; + bool active; + String server; + int port; + String name; + String password; + String topic; }; class Syslog { From 8029c7f51fa76ab7b5bacef054701d38ed9b8b7e Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 28 Mar 2022 22:22:36 +0200 Subject: [PATCH 090/125] version bump --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index b90f582..4dbc9cd 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.13.1" +#define VERSION "22.13.2" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From e26023302dcad9220f5551219692ea2ce8860046 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Thu, 31 Mar 2022 10:34:34 +0900 Subject: [PATCH 091/125] Add log to RX Frequency error. --- src/TaskModem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 017b2b2..05e4fcd 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -39,7 +39,7 @@ bool ModemTask::setup(System &system) { bool ModemTask::loop(System &system) { if (_lora_aprs.checkMessage()) { std::shared_ptr msg = _lora_aprs.getMessage(); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString().c_str(), msg->toString().c_str(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %ddBm, SNR %.2fdB and FreqErr %dHz", timeString().c_str(), msg->toString().c_str(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr(), -_lora_aprs.packetFrequencyError()); _fromModem.addElement(msg); system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString().c_str()))); } From 61c27b838d61ccd1b9e591cef7daab31a8d133f2 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Thu, 31 Mar 2022 10:36:34 +0900 Subject: [PATCH 092/125] version number update. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 4dbc9cd..f2a2e35 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.13.2" +#define VERSION "22.13.3" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 3516fbeeb5841e5bcbd10ea678aaeba7f320c9c9 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 2 Apr 2022 10:20:16 +0900 Subject: [PATCH 093/125] Add TaskRadiolib. --- platformio.ini | 1 + src/LoRa_APRS_iGate.cpp | 24 ++--- src/Task.h | 22 +++-- src/TaskRadiolib.cpp | 201 ++++++++++++++++++++++++++++++++++++++++ src/TaskRadiolib.h | 38 ++++++++ 5 files changed, 265 insertions(+), 21 deletions(-) create mode 100644 src/TaskRadiolib.cpp create mode 100644 src/TaskRadiolib.h diff --git a/platformio.ini b/platformio.ini index a2f5cb3..750984e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,6 +16,7 @@ lib_deps = knolleary/PubSubClient@^2.8 mikalhart/TinyGPSPlus @ 1.0.2 shaggydog/OneButton @ 1.5.0 + jgromes/RadioLib@^5.1.2 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index f2a2e35..179372e 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -13,9 +13,10 @@ #include "TaskEth.h" #include "TaskFTP.h" #include "TaskMQTT.h" -#include "TaskModem.h" +//#include "TaskModem.h" #include "TaskNTP.h" #include "TaskOTA.h" +#include "TaskRadioLib.h" #include "TaskRouter.h" #include "TaskWifi.h" #include "project_configuration.h" @@ -35,16 +36,17 @@ System LoRaSystem; Configuration userConfig; DisplayTask displayTask; -ModemTask modemTask(fromModem, toModem); -EthTask ethTask; -WifiTask wifiTask; -OTATask otaTask; -NTPTask ntpTask; -FTPTask ftpTask; -MQTTTask mqttTask(toMQTT); -AprsIsTask aprsIsTask(toAprsIs); -RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); -BeaconTask beaconTask(toModem, toAprsIs); +// ModemTask modemTask(fromModem, toModem); +RadiolibTask modemTask(fromModem, toModem); +EthTask ethTask; +WifiTask wifiTask; +OTATask otaTask; +NTPTask ntpTask; +FTPTask ftpTask; +MQTTTask mqttTask(toMQTT); +AprsIsTask aprsIsTask(toAprsIs); +RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); +BeaconTask beaconTask(toModem, toAprsIs); void setup() { Serial.begin(115200); diff --git a/src/Task.h b/src/Task.h index cd4b3da..a3b3fb9 100644 --- a/src/Task.h +++ b/src/Task.h @@ -7,6 +7,7 @@ enum TaskNames TaskEth, TaskFtp, TaskModem, + TaskRadiolib, TaskNtp, TaskOta, TaskWifi, @@ -16,15 +17,16 @@ enum TaskNames TaskSize }; -#define TASK_APRS_IS "AprsIsTask" -#define TASK_ETH "EthTask" -#define TASK_FTP "FTPTask" -#define TASK_MODEM "ModemTask" -#define TASK_NTP "NTPTask" -#define TASK_OTA "OTATask" -#define TASK_WIFI "WifiTask" -#define TASK_ROUTER "RouterTask" -#define TASK_MQTT "MQTTTask" -#define TASK_BEACON "BeaconTask" +#define TASK_APRS_IS "AprsIsTask" +#define TASK_ETH "EthTask" +#define TASK_FTP "FTPTask" +#define TASK_MODEM "ModemTask" +#define TASK_RADIOLIB "RadiolibTask" +#define TASK_NTP "NTPTask" +#define TASK_OTA "OTATask" +#define TASK_WIFI "WifiTask" +#define TASK_ROUTER "RouterTask" +#define TASK_MQTT "MQTTTask" +#define TASK_BEACON "BeaconTask" #endif diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp new file mode 100644 index 0000000..1a032f8 --- /dev/null +++ b/src/TaskRadiolib.cpp @@ -0,0 +1,201 @@ +#include + +#include +#include + +#include "Task.h" +#include "TaskAprsIs.h" +#include "TaskRadioLib.h" + +RadiolibTask::RadiolibTask(TaskQueue> &fromModem, TaskQueue> &toModem) : Task(TASK_RADIOLIB, TaskModem), _fromModem(fromModem), _toModem(toModem) { +} + +RadiolibTask::~RadiolibTask() { +} + +volatile bool RadiolibTask::enableInterrupt = true; // Need to catch interrupt or not. +volatile bool RadiolibTask::operationDone = false; // Caught IRQ or not. + +void RadiolibTask::setFlag(void) { + if (!enableInterrupt) { + return; + } + + operationDone = true; +} + +bool RadiolibTask::setup(System &system) { + SPI.begin(system.getBoardConfig()->LoraSck, system.getBoardConfig()->LoraMiso, system.getBoardConfig()->LoraMosi, system.getBoardConfig()->LoraCS); + module = new Module(system.getBoardConfig()->LoraCS, system.getBoardConfig()->LoraIRQ, system.getBoardConfig()->LoraReset); + radio = new SX1278(module); + + config = system.getUserConfig()->lora; + + rxEnable = true; + txEnable = config.tx_enable; + + float freqMHz = (float)config.frequencyRx / 1000000; + float BWkHz = (float)config.signalBandwidth / 1000; + + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); + + int state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power /* 2-17 */, 8, config.gainRx); + if (state != RADIOLIB_ERR_NONE) { + switch (state) { + case RADIOLIB_ERR_INVALID_FREQUENCY: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied frequency value (%fMHz) is invalid for this module.", timeString().c_str(), freqMHz); + rxEnable = false; + txEnable = false; + break; + case RADIOLIB_ERR_INVALID_BANDWIDTH: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied bandwidth value (%fkHz) is invalid for this module. Should be 7800, 10400, 15600, 20800, 31250, 41700 ,62500, 125000, 250000, 500000.", timeString().c_str(), BWkHz); + rxEnable = false; + txEnable = false; + break; + case RADIOLIB_ERR_INVALID_SPREADING_FACTOR: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied spreading factor value (%d) is invalid for this module.", timeString().c_str(), config.spreadingFactor); + rxEnable = false; + txEnable = false; + break; + case RADIOLIB_ERR_INVALID_CODING_RATE: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied coding rate value (%d) is invalid for this module.", timeString().c_str(), config.codingRate4); + rxEnable = false; + txEnable = false; + break; + case RADIOLIB_ERR_INVALID_OUTPUT_POWER: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied output power value (%d) is invalid for this module.", timeString().c_str(), config.power); + txEnable = false; + break; + case RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied preamble length is invalid.", timeString().c_str()); + txEnable = false; + break; + case RADIOLIB_ERR_INVALID_GAIN: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, The supplied gain value (%d) is invalid.", timeString().c_str(), config.gainRx); + rxEnable = false; + break; + default: + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] SX1278 init failed, code %d", timeString().c_str(), state); + rxEnable = false; + txEnable = false; + } + } + + state = radio->setCRC(true); + if (state != RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] setCRC failed, code %d", timeString().c_str(), state); + while (true) + ; + } + + radio->setDio0Action(setFlag); + + if (rxEnable) { + int state = startRX(RADIOLIB_SX127X_RXCONTINUOUS); + if (state != RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, code %d", timeString().c_str(), state); + rxEnable = false; + } + } + + return true; +} + +int transmissionState = RADIOLIB_ERR_NONE; +bool transmitFlag = false; // Transmitting or not. + +bool RadiolibTask::loop(System &system) { + if (operationDone) { // occurs interrupt. + enableInterrupt = false; + + if (transmitFlag) { // transmitted. + if (transmissionState == RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); + + } else { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] transmitFlag failed, code %d", timeString().c_str(), transmissionState); + } + operationDone = false; + transmitFlag = false; + + } else { // received. + String str; + int state = radio->readData(str); + + if (state != RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] readData failed, code %d", timeString().c_str(), state); + } else { + if (str.substring(0, 3) != "<\xff\x01") { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %dHz", timeString().c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError()); + } else { + std::shared_ptr msg = std::shared_ptr(new APRSMessage()); + msg->decode(str.substring(3)); + _fromModem.addElement(msg); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), msg->toString().c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError()); + system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString().c_str()))); + } + } + operationDone = false; + } + + if (rxEnable) { + int state = startRX(RADIOLIB_SX127X_RXCONTINUOUS); + if (state != RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, code %d", timeString().c_str(), state); + rxEnable = false; + } + } + + enableInterrupt = true; + } else { // not interrupt. + if (!txEnable) { + // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str()); + } else { + if (transmitFlag) { + // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str()); + } else { + if (!_toModem.empty()) { + if (config.frequencyRx == config.frequencyTx && (radio->getModemStatus() & 0x01) == 0x01) { + // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str()); + } else { + std::shared_ptr msg = _toModem.getElement(); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); + + int16_t state = startTX("<\xff\x01" + msg->encode()); + if (state != RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state); + txEnable = false; + return true; + } + } + } + } + } + } + + return true; +} + +int16_t RadiolibTask::startRX(uint8_t mode) { + if (config.frequencyTx != config.frequencyRx) { + int16_t state = radio->setFrequency((float)config.frequencyRx / 1000000); + if (state != RADIOLIB_ERR_NONE) { + return state; + } + } + + return radio->startReceive(0, mode); +} + +int16_t RadiolibTask::startTX(String &str) { + if (config.frequencyTx != config.frequencyRx) { + int16_t state = radio->setFrequency((float)config.frequencyTx / 1000000); + if (state != RADIOLIB_ERR_NONE) { + return state; + } + } + + transmissionState = radio->startTransmit(str); + transmitFlag = true; + return RADIOLIB_ERR_NONE; +} diff --git a/src/TaskRadiolib.h b/src/TaskRadiolib.h new file mode 100644 index 0000000..a53cb6d --- /dev/null +++ b/src/TaskRadiolib.h @@ -0,0 +1,38 @@ +#ifndef TASK_LORA_H_ +#define TASK_LORA_H_ + +#include "project_configuration.h" +#include +#include +#include +#include + +class RadiolibTask : public Task { +public: + explicit RadiolibTask(TaskQueue> &fromModem, TaskQueue> &_toModem); + virtual ~RadiolibTask(); + + virtual bool setup(System &system) override; + virtual bool loop(System &system) override; + +private: + Module *module; + SX1278 *radio; + + Configuration::LoRa config; + + bool rxEnable, txEnable; + + TaskQueue> &_fromModem; + TaskQueue> &_toModem; + + static volatile bool enableInterrupt; // Need to catch interrupt or not. + static volatile bool operationDone; // Caught IRQ or not. + + static void setFlag(void); + + int16_t startRX(uint8_t mode); + int16_t startTX(String &str); +}; + +#endif From 3b7f0ffc6c0048fb10cd88432ee9ad0fe3c91ba5 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 2 Apr 2022 10:27:27 +0900 Subject: [PATCH 094/125] Bump up. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 179372e..237af8f 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -21,7 +21,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.13.3" +#define VERSION "22.13.4" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 6cb20361d608ee3b15b075d0363137dd8aa7e560 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 2 Apr 2022 10:36:06 +0900 Subject: [PATCH 095/125] typo --- src/TaskRadiolib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index 1a032f8..fb9f6b4 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -5,7 +5,7 @@ #include "Task.h" #include "TaskAprsIs.h" -#include "TaskRadioLib.h" +#include "TaskRadiolib.h" RadiolibTask::RadiolibTask(TaskQueue> &fromModem, TaskQueue> &toModem) : Task(TASK_RADIOLIB, TaskModem), _fromModem(fromModem), _toModem(toModem) { } From ba45d3e5518ec5284980a5c5030bedfcfcf18148 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 2 Apr 2022 10:38:51 +0900 Subject: [PATCH 096/125] sorry more typo. --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 237af8f..49abcf4 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -16,7 +16,7 @@ //#include "TaskModem.h" #include "TaskNTP.h" #include "TaskOTA.h" -#include "TaskRadioLib.h" +#include "TaskRadiolib.h" #include "TaskRouter.h" #include "TaskWifi.h" #include "project_configuration.h" From 2a1475ec723c750e26bb8329d90082a27a93a788 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 2 Apr 2022 13:16:24 +0900 Subject: [PATCH 097/125] clear intr func when deconstuctor called, and delete no need definition. --- src/TaskRadiolib.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index fb9f6b4..964f23f 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -11,6 +11,7 @@ RadiolibTask::RadiolibTask(TaskQueue> &fromModem, T } RadiolibTask::~RadiolibTask() { + radio->clearDio0Action(); } volatile bool RadiolibTask::enableInterrupt = true; // Need to catch interrupt or not. @@ -37,9 +38,7 @@ bool RadiolibTask::setup(System &system) { float freqMHz = (float)config.frequencyRx / 1000000; float BWkHz = (float)config.signalBandwidth / 1000; - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - - int state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power /* 2-17 */, 8, config.gainRx); + int16_t state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power /* 2-17 */, 8, config.gainRx); if (state != RADIOLIB_ERR_NONE) { switch (state) { case RADIOLIB_ERR_INVALID_FREQUENCY: From ebe78ceaadda189d9abcbec4e5bf800808747abb Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sat, 2 Apr 2022 18:50:54 +0900 Subject: [PATCH 098/125] Avoid collision after TX is done. --- src/TaskRadiolib.cpp | 42 ++++++++++++++++++++++++++---------------- src/TaskRadiolib.h | 3 +++ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index 964f23f..a35ffbd 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -38,7 +38,9 @@ bool RadiolibTask::setup(System &system) { float freqMHz = (float)config.frequencyRx / 1000000; float BWkHz = (float)config.signalBandwidth / 1000; - int16_t state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power /* 2-17 */, 8, config.gainRx); + const uint16_t preambleLength = 8; + + int16_t state = radio->begin(freqMHz, BWkHz, config.spreadingFactor, config.codingRate4, RADIOLIB_SX127X_SYNC_WORD, config.power, preambleLength, config.gainRx); if (state != RADIOLIB_ERR_NONE) { switch (state) { case RADIOLIB_ERR_INVALID_FREQUENCY: @@ -97,6 +99,8 @@ bool RadiolibTask::setup(System &system) { } } + preambleDurationMilliSec = ((uint64_t)(preambleLength + 4) << (config.spreadingFactor + 10 /* to milli-sec */)) / config.signalBandwidth; + return true; } @@ -117,6 +121,9 @@ bool RadiolibTask::loop(System &system) { operationDone = false; transmitFlag = false; + txWaitTimer.setTimeout(preambleDurationMilliSec * 2); + txWaitTimer.start(); + } else { // received. String str; int state = radio->readData(str); @@ -147,24 +154,27 @@ bool RadiolibTask::loop(System &system) { enableInterrupt = true; } else { // not interrupt. - if (!txEnable) { - // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str()); + if (!txWaitTimer.check()) { } else { - if (transmitFlag) { - // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str()); + if (!txEnable) { + // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX is not enabled", timeString().c_str()); } else { - if (!_toModem.empty()) { - if (config.frequencyRx == config.frequencyTx && (radio->getModemStatus() & 0x01) == 0x01) { - // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str()); - } else { - std::shared_ptr msg = _toModem.getElement(); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); + if (transmitFlag) { + // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX signal detected. Waiting TX", timeString().c_str()); + } else { + if (!_toModem.empty()) { + if (config.frequencyRx == config.frequencyTx && (radio->getModemStatus() & 0x01) == 0x01) { + // system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str()); + } else { + std::shared_ptr msg = _toModem.getElement(); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); - int16_t state = startTX("<\xff\x01" + msg->encode()); - if (state != RADIOLIB_ERR_NONE) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state); - txEnable = false; - return true; + int16_t state = startTX("<\xff\x01" + msg->encode()); + if (state != RADIOLIB_ERR_NONE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startTX failed, code %d", timeString().c_str(), state); + txEnable = false; + return true; + } } } } diff --git a/src/TaskRadiolib.h b/src/TaskRadiolib.h index a53cb6d..2f9cc85 100644 --- a/src/TaskRadiolib.h +++ b/src/TaskRadiolib.h @@ -33,6 +33,9 @@ private: int16_t startRX(uint8_t mode); int16_t startTX(String &str); + + uint32_t preambleDurationMilliSec; + Timer txWaitTimer; }; #endif From 3f7d972958782f3f0b049d99672809dedc09e662 Mon Sep 17 00:00:00 2001 From: FUJIURA Toyonori Date: Sun, 3 Apr 2022 08:39:56 +0900 Subject: [PATCH 099/125] debug. --- src/TaskRadiolib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index a35ffbd..34f05b9 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -7,7 +7,7 @@ #include "TaskAprsIs.h" #include "TaskRadiolib.h" -RadiolibTask::RadiolibTask(TaskQueue> &fromModem, TaskQueue> &toModem) : Task(TASK_RADIOLIB, TaskModem), _fromModem(fromModem), _toModem(toModem) { +RadiolibTask::RadiolibTask(TaskQueue> &fromModem, TaskQueue> &toModem) : Task(TASK_RADIOLIB, TaskRadiolib), _fromModem(fromModem), _toModem(toModem) { } RadiolibTask::~RadiolibTask() { From 1257d9dca0f41dff99d676914830a049a1cec42f Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Wed, 6 Apr 2022 23:50:55 +0200 Subject: [PATCH 100/125] do kot creare a new version with every push request --- .github/workflows/release.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fd4ec4e..076e9f9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,7 @@ name: Create new release on: - push: - branches: - - 'master' + workflow_dispatch: jobs: build: From b28d6ea3f45dee17c76d210482f99949a1d745a7 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 7 Apr 2022 11:01:15 +0200 Subject: [PATCH 101/125] remove version check from build --- .github/workflows/build_check.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 7686833..a5655db 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -10,20 +10,6 @@ on: - master jobs: - version_check: - name: Version Check - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v2 - - run: pip install GitPython - - name: check version - run: ./scripts/check_version.py - build: name: Compile Firmware runs-on: ubuntu-latest From b31709bf27931b882066e4e34871422765823188 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 7 Apr 2022 11:01:31 +0200 Subject: [PATCH 102/125] add version check on relaese --- .github/workflows/release.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 076e9f9..71a9939 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,22 @@ on: workflow_dispatch: jobs: - build: + version_check: + name: Version Check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v2 + - run: pip install GitPython + - name: check version + run: ./scripts/check_version.py + + create_release: + needs: version_check name: Create new release runs-on: ubuntu-latest steps: From 7ddaf8f23c87f00adc71c15dc13ceb69cc6bd40b Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 7 Apr 2022 11:12:45 +0200 Subject: [PATCH 103/125] fix ota and wifi bug with ethernet --- src/LoRa_APRS_iGate.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index f2a2e35..554aad7 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -113,14 +113,15 @@ void setup() { if (userConfig.wifi.active) { LoRaSystem.getTaskManager().addAlwaysRunTask(&wifiTask); - LoRaSystem.getTaskManager().addTask(&otaTask); tcpip = true; - } else if (boardConfig->Type == eETH_BOARD) { + } + if (boardConfig->Type == eETH_BOARD) { LoRaSystem.getTaskManager().addAlwaysRunTask(ðTask); tcpip = true; } if (tcpip) { + LoRaSystem.getTaskManager().addTask(&otaTask); LoRaSystem.getTaskManager().addTask(&ntpTask); if (userConfig.ftp.active) { LoRaSystem.getTaskManager().addTask(&ftpTask); From bf6951c850f39b60a95745840a04c2d9904d32fe Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 7 Apr 2022 11:13:24 +0200 Subject: [PATCH 104/125] version bump --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 554aad7..3793970 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.13.3" +#define VERSION "22.14.1" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From 42cd9a34f3cb83bdfc2d3d2f311a0531d115a893 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 7 Apr 2022 11:15:46 +0200 Subject: [PATCH 105/125] use correct version --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 3793970..9ec796b 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.14.1" +#define VERSION "22.14.0" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From b5623a58706265627d1da8dd0f5437389ad549d0 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 20 May 2022 22:45:58 +0200 Subject: [PATCH 106/125] delete not needed files --- lib/LoRa/LoRa.cpp | 636 ------------------------------------ lib/LoRa/LoRa.h | 120 ------- lib/LoRa_APRS/LoRa_APRS.cpp | 69 ---- lib/LoRa_APRS/LoRa_APRS.h | 33 -- src/TaskModem.cpp | 64 ---- src/TaskModem.h | 23 -- 6 files changed, 945 deletions(-) delete mode 100644 lib/LoRa/LoRa.cpp delete mode 100644 lib/LoRa/LoRa.h delete mode 100644 lib/LoRa_APRS/LoRa_APRS.cpp delete mode 100644 lib/LoRa_APRS/LoRa_APRS.h delete mode 100644 src/TaskModem.cpp delete mode 100644 src/TaskModem.h diff --git a/lib/LoRa/LoRa.cpp b/lib/LoRa/LoRa.cpp deleted file mode 100644 index 2422ca8..0000000 --- a/lib/LoRa/LoRa.cpp +++ /dev/null @@ -1,636 +0,0 @@ -// Copyright (c) Sandeep Mistry. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -#include - -// registers -#define REG_FIFO 0x00 -#define REG_OP_MODE 0x01 -#define REG_FRF_MSB 0x06 -#define REG_FRF_MID 0x07 -#define REG_FRF_LSB 0x08 -#define REG_PA_CONFIG 0x09 -#define REG_OCP 0x0b -#define REG_LNA 0x0c -#define REG_FIFO_ADDR_PTR 0x0d -#define REG_FIFO_TX_BASE_ADDR 0x0e -#define REG_FIFO_RX_BASE_ADDR 0x0f -#define REG_FIFO_RX_CURRENT_ADDR 0x10 -#define REG_IRQ_FLAGS 0x12 -#define REG_RX_NB_BYTES 0x13 -#define REG_MODEM_STAT 0x18 -#define REG_PKT_SNR_VALUE 0x19 -#define REG_PKT_RSSI_VALUE 0x1a -#define REG_RSSI_VALUE 0x1b -#define REG_MODEM_CONFIG_1 0x1d -#define REG_MODEM_CONFIG_2 0x1e -#define REG_PREAMBLE_MSB 0x20 -#define REG_PREAMBLE_LSB 0x21 -#define REG_PAYLOAD_LENGTH 0x22 -#define REG_MODEM_CONFIG_3 0x26 -#define REG_FREQ_ERROR_MSB 0x28 -#define REG_FREQ_ERROR_MID 0x29 -#define REG_FREQ_ERROR_LSB 0x2a -#define REG_RSSI_WIDEBAND 0x2c -#define REG_DETECTION_OPTIMIZE 0x31 -#define REG_INVERTIQ 0x33 -#define REG_DETECTION_THRESHOLD 0x37 -#define REG_SYNC_WORD 0x39 -#define REG_INVERTIQ2 0x3b -#define REG_DIO_MAPPING_1 0x40 -#define REG_VERSION 0x42 -#define REG_PA_DAC 0x4d - -// modes -#define MODE_LONG_RANGE_MODE 0x80 -#define MODE_SLEEP 0x00 -#define MODE_STDBY 0x01 -#define MODE_TX 0x03 -#define MODE_RX_CONTINUOUS 0x05 -#define MODE_RX_SINGLE 0x06 - -// PA config -#define PA_BOOST 0x80 - -// IRQ masks -#define IRQ_TX_DONE_MASK 0x08 -#define IRQ_PAYLOAD_CRC_ERROR_MASK 0x20 -#define IRQ_RX_DONE_MASK 0x40 - -#define RF_MID_BAND_THRESHOLD 525E6 -#define RSSI_OFFSET_HF_PORT 157 -#define RSSI_OFFSET_LF_PORT 164 - -#define MAX_PKT_LENGTH 255 - -#if (ESP8266 || ESP32) -#define ISR_PREFIX ICACHE_RAM_ATTR -#else -#define ISR_PREFIX -#endif - -LoRaClass::LoRaClass() : _spiSettings(LORA_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE0), _spi(&LORA_DEFAULT_SPI), _ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN), _frequency(0), _packetIndex(0), _implicitHeaderMode(0) { - // overide Stream timeout value - setTimeout(0); -} - -int LoRaClass::begin(long frequency) { -#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) - pinMode(LORA_IRQ_DUMB, OUTPUT); - digitalWrite(LORA_IRQ_DUMB, LOW); - - // Hardware reset - pinMode(LORA_BOOT0, OUTPUT); - digitalWrite(LORA_BOOT0, LOW); - - pinMode(LORA_RESET, OUTPUT); - digitalWrite(LORA_RESET, HIGH); - delay(200); - digitalWrite(LORA_RESET, LOW); - delay(200); - digitalWrite(LORA_RESET, HIGH); - delay(50); -#endif - - // setup pins - pinMode(_ss, OUTPUT); - // set SS high - digitalWrite(_ss, HIGH); - - if (_reset != -1) { - pinMode(_reset, OUTPUT); - - // perform reset - digitalWrite(_reset, LOW); - delay(10); - digitalWrite(_reset, HIGH); - delay(10); - } - - // start SPI - _spi->begin(); - - // check version - uint8_t version = readRegister(REG_VERSION); - if (version != 0x12) { - return 0; - } - - // put in sleep mode - sleep(); - - // set frequency - setFrequency(frequency); - - // set base addresses - writeRegister(REG_FIFO_TX_BASE_ADDR, 0); - writeRegister(REG_FIFO_RX_BASE_ADDR, 0); - - // set LNA boost - writeRegister(REG_LNA, readRegister(REG_LNA) | 0x01); - - // set auto AGC - writeRegister(REG_MODEM_CONFIG_3, 0x04); - - // set output power to 17 dBm - setTxPower(17); - - // put in standby mode - idle(); - - return 1; -} - -void LoRaClass::end() { - // put in sleep mode - sleep(); - - // stop SPI - _spi->end(); -} - -int LoRaClass::beginPacket(int implicitHeader) { - if (isTransmitting()) { - return 0; - } - - // put in standby mode - idle(); - - if (implicitHeader) { - implicitHeaderMode(); - } else { - explicitHeaderMode(); - } - - // reset FIFO address and paload length - writeRegister(REG_FIFO_ADDR_PTR, 0); - writeRegister(REG_PAYLOAD_LENGTH, 0); - - return 1; -} - -int LoRaClass::endPacket(bool async) { - - // put in TX mode - writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_TX); - - if (!async) { - // wait for TX done - while ((readRegister(REG_IRQ_FLAGS) & IRQ_TX_DONE_MASK) == 0) { - yield(); - } - // clear IRQ's - writeRegister(REG_IRQ_FLAGS, IRQ_TX_DONE_MASK); - } - - return 1; -} - -bool LoRaClass::isTransmitting() { - if ((readRegister(REG_OP_MODE) & MODE_TX) == MODE_TX) { - return true; - } - - if (readRegister(REG_IRQ_FLAGS) & IRQ_TX_DONE_MASK) { - // clear IRQ's - writeRegister(REG_IRQ_FLAGS, IRQ_TX_DONE_MASK); - } - - return false; -} - -int LoRaClass::parsePacket(int size) { - int packetLength = 0; - int irqFlags = readRegister(REG_IRQ_FLAGS); - - if (size > 0) { - implicitHeaderMode(); - - writeRegister(REG_PAYLOAD_LENGTH, size & 0xff); - } else { - explicitHeaderMode(); - } - - // clear IRQ's - writeRegister(REG_IRQ_FLAGS, irqFlags); - - if ((irqFlags & IRQ_RX_DONE_MASK) && (irqFlags & IRQ_PAYLOAD_CRC_ERROR_MASK) == 0) { - // received a packet - _packetIndex = 0; - - // read packet length - if (_implicitHeaderMode) { - packetLength = readRegister(REG_PAYLOAD_LENGTH); - } else { - packetLength = readRegister(REG_RX_NB_BYTES); - } - - // set FIFO address to current RX address - writeRegister(REG_FIFO_ADDR_PTR, readRegister(REG_FIFO_RX_CURRENT_ADDR)); - - // put in standby mode - idle(); - } else if (readRegister(REG_OP_MODE) != (MODE_LONG_RANGE_MODE | MODE_RX_SINGLE)) { - // not currently in RX mode - - // reset FIFO address - writeRegister(REG_FIFO_ADDR_PTR, 0); - - // put in single RX mode - writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_SINGLE); - } - - return packetLength; -} - -int LoRaClass::packetRssi() { - return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT)); -} - -float LoRaClass::packetSnr() { - return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25; -} - -bool LoRaClass::rxSignalDetected() { - return (readRegister(REG_MODEM_STAT) & 0x01) == 0x01; -} - -long LoRaClass::packetFrequencyError() { - int32_t freqError = 0; - freqError = static_cast(readRegister(REG_FREQ_ERROR_MSB) & B111); - freqError <<= 8L; - freqError += static_cast(readRegister(REG_FREQ_ERROR_MID)); - freqError <<= 8L; - freqError += static_cast(readRegister(REG_FREQ_ERROR_LSB)); - - if (readRegister(REG_FREQ_ERROR_MSB) & B1000) { // Sign bit is on - freqError -= 524288; // B1000'0000'0000'0000'0000 - } - - const float fXtal = 32E6; // FXOSC: crystal oscillator (XTAL) frequency (2.5. Chip Specification, p. 14) - const float fError = ((static_cast(freqError) * (1L << 24)) / fXtal) * (getSignalBandwidth() / 500000.0f); // p. 37 - - return static_cast(fError); -} - -int LoRaClass::rssi() { - return (readRegister(REG_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT)); -} - -size_t LoRaClass::write(uint8_t byte) { - return write(&byte, sizeof(byte)); -} - -size_t LoRaClass::write(const uint8_t *buffer, size_t size) { - int currentLength = readRegister(REG_PAYLOAD_LENGTH); - - // check size - if ((currentLength + size) > MAX_PKT_LENGTH) { - size = MAX_PKT_LENGTH - currentLength; - } - - // write data - for (size_t i = 0; i < size; i++) { - writeRegister(REG_FIFO, buffer[i]); - } - - // update length - writeRegister(REG_PAYLOAD_LENGTH, currentLength + size); - - return size; -} - -int LoRaClass::available() { - return (readRegister(REG_RX_NB_BYTES) - _packetIndex); -} - -int LoRaClass::read() { - if (!available()) { - return -1; - } - - _packetIndex++; - - return readRegister(REG_FIFO); -} - -int LoRaClass::peek() { - if (!available()) { - return -1; - } - - // store current FIFO address - int currentAddress = readRegister(REG_FIFO_ADDR_PTR); - - // read - uint8_t b = readRegister(REG_FIFO); - - // restore FIFO address - writeRegister(REG_FIFO_ADDR_PTR, currentAddress); - - return b; -} - -void LoRaClass::flush() { -} - -void LoRaClass::receive(int size) { - - writeRegister(REG_DIO_MAPPING_1, 0x00); // DIO0 => RXDONE - - if (size > 0) { - implicitHeaderMode(); - - writeRegister(REG_PAYLOAD_LENGTH, size & 0xff); - } else { - explicitHeaderMode(); - } - - writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS); -} - -void LoRaClass::idle() { - writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_STDBY); -} - -void LoRaClass::sleep() { - writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_SLEEP); -} - -void LoRaClass::setTxPower(int level, int outputPin) { - if (PA_OUTPUT_RFO_PIN == outputPin) { - // RFO - if (level < 0) { - level = 0; - } else if (level > 14) { - level = 14; - } - - writeRegister(REG_PA_CONFIG, 0x70 | level); - } else { - // PA BOOST - if (level > 17) { - if (level > 20) { - level = 20; - } - - // subtract 3 from level, so 18 - 20 maps to 15 - 17 - level -= 3; - - // High Power +20 dBm Operation (Semtech SX1276/77/78/79 5.4.3.) - writeRegister(REG_PA_DAC, 0x87); - setOCP(140); - } else { - if (level < 2) { - level = 2; - } - // Default value PA_HF/LF or +17dBm - writeRegister(REG_PA_DAC, 0x84); - setOCP(100); - } - - writeRegister(REG_PA_CONFIG, PA_BOOST | (level - 2)); - } -} - -void LoRaClass::setFrequency(long frequency) { - _frequency = frequency; - - uint64_t frf = ((uint64_t)frequency << 19) / 32000000; - - writeRegister(REG_FRF_MSB, (uint8_t)(frf >> 16)); - writeRegister(REG_FRF_MID, (uint8_t)(frf >> 8)); - writeRegister(REG_FRF_LSB, (uint8_t)(frf >> 0)); -} - -int LoRaClass::getSpreadingFactor() { - return readRegister(REG_MODEM_CONFIG_2) >> 4; -} - -void LoRaClass::setSpreadingFactor(int sf) { - if (sf < 6) { - sf = 6; - } else if (sf > 12) { - sf = 12; - } - - if (sf == 6) { - writeRegister(REG_DETECTION_OPTIMIZE, 0xc5); - writeRegister(REG_DETECTION_THRESHOLD, 0x0c); - } else { - writeRegister(REG_DETECTION_OPTIMIZE, 0xc3); - writeRegister(REG_DETECTION_THRESHOLD, 0x0a); - } - - writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0)); - setLdoFlag(); -} - -long LoRaClass::getSignalBandwidth() { - byte bw = (readRegister(REG_MODEM_CONFIG_1) >> 4); - - switch (bw) { - case 0: - return 7.8E3; - case 1: - return 10.4E3; - case 2: - return 15.6E3; - case 3: - return 20.8E3; - case 4: - return 31.25E3; - case 5: - return 41.7E3; - case 6: - return 62.5E3; - case 7: - return 125E3; - case 8: - return 250E3; - case 9: - return 500E3; - } - - return -1; -} - -void LoRaClass::setSignalBandwidth(long sbw) { - int bw; - - if (sbw <= 7.8E3) { - bw = 0; - } else if (sbw <= 10.4E3) { - bw = 1; - } else if (sbw <= 15.6E3) { - bw = 2; - } else if (sbw <= 20.8E3) { - bw = 3; - } else if (sbw <= 31.25E3) { - bw = 4; - } else if (sbw <= 41.7E3) { - bw = 5; - } else if (sbw <= 62.5E3) { - bw = 6; - } else if (sbw <= 125E3) { - bw = 7; - } else if (sbw <= 250E3) { - bw = 8; - } else /*if (sbw <= 250E3)*/ { - bw = 9; - } - - writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4)); - setLdoFlag(); -} - -void LoRaClass::setLdoFlag() { - // Section 4.1.1.5 - long symbolDuration = 1000 / (getSignalBandwidth() / (1L << getSpreadingFactor())); - - // Section 4.1.1.6 - boolean ldoOn = symbolDuration > 16; - - uint8_t config3 = readRegister(REG_MODEM_CONFIG_3); - bitWrite(config3, 3, ldoOn); - writeRegister(REG_MODEM_CONFIG_3, config3); -} - -void LoRaClass::setCodingRate4(int denominator) { - if (denominator < 5) { - denominator = 5; - } else if (denominator > 8) { - denominator = 8; - } - - int cr = denominator - 4; - - writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0xf1) | (cr << 1)); -} - -void LoRaClass::setPreambleLength(long length) { - writeRegister(REG_PREAMBLE_MSB, (uint8_t)(length >> 8)); - writeRegister(REG_PREAMBLE_LSB, (uint8_t)(length >> 0)); -} - -void LoRaClass::setSyncWord(int sw) { - writeRegister(REG_SYNC_WORD, sw); -} - -void LoRaClass::enableCrc() { - writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) | 0x04); -} - -void LoRaClass::disableCrc() { - writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) & 0xfb); -} - -void LoRaClass::enableInvertIQ() { - writeRegister(REG_INVERTIQ, 0x66); - writeRegister(REG_INVERTIQ2, 0x19); -} - -void LoRaClass::disableInvertIQ() { - writeRegister(REG_INVERTIQ, 0x27); - writeRegister(REG_INVERTIQ2, 0x1d); -} - -void LoRaClass::setOCP(uint8_t mA) { - uint8_t ocpTrim = 27; - - if (mA <= 120) { - ocpTrim = (mA - 45) / 5; - } else if (mA <= 240) { - ocpTrim = (mA + 30) / 10; - } - - writeRegister(REG_OCP, 0x20 | (0x1F & ocpTrim)); -} - -void LoRaClass::setGain(uint8_t gain) { - // check allowed range - if (gain > 6) { - gain = 6; - } - - // set to standby - idle(); - - // set gain - if (gain == 0) { - // if gain = 0, enable AGC - writeRegister(REG_MODEM_CONFIG_3, 0x04); - } else { - // disable AGC - writeRegister(REG_MODEM_CONFIG_3, 0x00); - - // clear Gain and set LNA boost - writeRegister(REG_LNA, 0x01); - - // set gain - writeRegister(REG_LNA, readRegister(REG_LNA) | (gain << 5)); - } -} - -byte LoRaClass::random() { - return readRegister(REG_RSSI_WIDEBAND); -} - -void LoRaClass::setPins(int ss, int reset, int dio0) { - _ss = ss; - _reset = reset; - _dio0 = dio0; -} - -void LoRaClass::setSPI(SPIClass &spi) { - _spi = &spi; -} - -void LoRaClass::setSPIFrequency(uint32_t frequency) { - _spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0); -} - -void LoRaClass::dumpRegisters(Stream &out) { - for (int i = 0; i < 128; i++) { - out.print("0x"); - out.print(i, HEX); - out.print(": 0x"); - out.println(readRegister(i), HEX); - } -} - -void LoRaClass::explicitHeaderMode() { - _implicitHeaderMode = 0; - - writeRegister(REG_MODEM_CONFIG_1, readRegister(REG_MODEM_CONFIG_1) & 0xfe); -} - -void LoRaClass::implicitHeaderMode() { - _implicitHeaderMode = 1; - - writeRegister(REG_MODEM_CONFIG_1, readRegister(REG_MODEM_CONFIG_1) | 0x01); -} - -uint8_t LoRaClass::readRegister(uint8_t address) { - return singleTransfer(address & 0x7f, 0x00); -} - -void LoRaClass::writeRegister(uint8_t address, uint8_t value) { - singleTransfer(address | 0x80, value); -} - -uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value) { - uint8_t response; - - digitalWrite(_ss, LOW); - - _spi->beginTransaction(_spiSettings); - _spi->transfer(address); - response = _spi->transfer(value); - _spi->endTransaction(); - - digitalWrite(_ss, HIGH); - - return response; -} diff --git a/lib/LoRa/LoRa.h b/lib/LoRa/LoRa.h deleted file mode 100644 index 45c92bd..0000000 --- a/lib/LoRa/LoRa.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) Sandeep Mistry. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -#ifndef LORA_H -#define LORA_H - -#include -#include - -#if defined(ARDUINO_SAMD_MKRWAN1300) -#define LORA_DEFAULT_SPI SPI1 -#define LORA_DEFAULT_SPI_FREQUENCY 200000 -#define LORA_DEFAULT_SS_PIN LORA_IRQ_DUMB -#define LORA_DEFAULT_RESET_PIN -1 -#define LORA_DEFAULT_DIO0_PIN -1 -#elif defined(ARDUINO_SAMD_MKRWAN1310) -#define LORA_DEFAULT_SPI SPI1 -#define LORA_DEFAULT_SPI_FREQUENCY 200000 -#define LORA_DEFAULT_SS_PIN LORA_IRQ_DUMB -#define LORA_DEFAULT_RESET_PIN -1 -#define LORA_DEFAULT_DIO0_PIN LORA_IRQ -#else -#define LORA_DEFAULT_SPI SPI -#define LORA_DEFAULT_SPI_FREQUENCY 8E6 -#define LORA_DEFAULT_SS_PIN 10 -#define LORA_DEFAULT_RESET_PIN 9 -#define LORA_DEFAULT_DIO0_PIN 2 -#endif - -#define PA_OUTPUT_RFO_PIN 0 -#define PA_OUTPUT_PA_BOOST_PIN 1 - -class LoRaClass : public Stream { -public: - LoRaClass(); - - int begin(long frequency); - void end(); - - int beginPacket(int implicitHeader = false); - int endPacket(bool async = false); - - int parsePacket(int size = 0); - int packetRssi(); - float packetSnr(); - long packetFrequencyError(); - bool rxSignalDetected(); - - int rssi(); - - // from Print - virtual size_t write(uint8_t byte); - virtual size_t write(const uint8_t *buffer, size_t size); - - // from Stream - virtual int available(); - virtual int read(); - virtual int peek(); - virtual void flush(); - - void receive(int size = 0); - - void idle(); - void sleep(); - - void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN); - void setFrequency(long frequency); - void setSpreadingFactor(int sf); - void setSignalBandwidth(long sbw); - void setCodingRate4(int denominator); - void setPreambleLength(long length); - void setSyncWord(int sw); - void enableCrc(); - void disableCrc(); - void enableInvertIQ(); - void disableInvertIQ(); - - void setOCP(uint8_t mA); // Over Current Protection control - - void setGain(uint8_t gain); // Set LNA gain - - // deprecated - void crc() { enableCrc(); } - void noCrc() { disableCrc(); } - - byte random(); - - void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN); - void setSPI(SPIClass& spi); - void setSPIFrequency(uint32_t frequency); - - void dumpRegisters(Stream& out); - -private: - void explicitHeaderMode(); - void implicitHeaderMode(); - - bool isTransmitting(); - - int getSpreadingFactor(); - long getSignalBandwidth(); - - void setLdoFlag(); - - uint8_t readRegister(uint8_t address); - void writeRegister(uint8_t address, uint8_t value); - uint8_t singleTransfer(uint8_t address, uint8_t value); - -private: - SPISettings _spiSettings; - SPIClass* _spi; - int _ss; - int _reset; - int _dio0; - long _frequency; - int _packetIndex; - int _implicitHeaderMode; -}; - -#endif diff --git a/lib/LoRa_APRS/LoRa_APRS.cpp b/lib/LoRa_APRS/LoRa_APRS.cpp deleted file mode 100644 index 48d2dfa..0000000 --- a/lib/LoRa_APRS/LoRa_APRS.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "LoRa_APRS.h" - -LoRa_APRS::LoRa_APRS() : _RxFrequency(433775000), _TxFrequency(433775000) { -} - -bool LoRa_APRS::checkMessage() { - if (!parsePacket()) { - return false; - } - // read header: - char dummy[4]; - readBytes(dummy, 3); - if (dummy[0] != '<') { - // is no APRS message, ignore message - while (available()) { - read(); - } - return false; - } - // read APRS data: - String str; - while (available()) { - str += (char)read(); - } - _LastReceivedMsg = std::shared_ptr(new APRSMessage()); - _LastReceivedMsg->decode(str); - return true; -} - -std::shared_ptr LoRa_APRS::getMessage() { - return _LastReceivedMsg; -} - -void LoRa_APRS::sendMessage(const std::shared_ptr msg) { - setFrequency(_TxFrequency); - String data = msg->encode(); - beginPacket(); - // Header: - write('<'); - write(0xFF); - write(0x01); - // APRS Data: - write((const uint8_t *)data.c_str(), data.length()); - endPacket(); - setFrequency(_RxFrequency); -} - -void LoRa_APRS::setRxFrequency(long frequency) { - _RxFrequency = frequency; - setFrequency(_RxFrequency); -} - -void LoRa_APRS::setRxGain(uint8_t gain) { - setGain(gain); -} - -// cppcheck-suppress unusedFunction -long LoRa_APRS::getRxFrequency() const { - return _RxFrequency; -} - -void LoRa_APRS::setTxFrequency(long frequency) { - _TxFrequency = frequency; -} - -// cppcheck-suppress unusedFunction -long LoRa_APRS::getTxFrequency() const { - return _TxFrequency; -} diff --git a/lib/LoRa_APRS/LoRa_APRS.h b/lib/LoRa_APRS/LoRa_APRS.h deleted file mode 100644 index 3d6eff4..0000000 --- a/lib/LoRa_APRS/LoRa_APRS.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef LORA_H_ -#define LORA_H_ - -#include - -#include -#include -#include - -class LoRa_APRS : public LoRaClass { -public: - LoRa_APRS(); - - bool checkMessage(); - std::shared_ptr getMessage(); - - void sendMessage(const std::shared_ptr msg); - - void setRxFrequency(long frequency); - long getRxFrequency() const; - - void setRxGain(uint8_t gain); - - void setTxFrequency(long frequency); - long getTxFrequency() const; - -private: - std::shared_ptr _LastReceivedMsg; - long _RxFrequency; - long _TxFrequency; -}; - -#endif diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp deleted file mode 100644 index 05e4fcd..0000000 --- a/src/TaskModem.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include - -#include - -#include "Task.h" -#include "TaskAprsIs.h" -#include "TaskModem.h" -#include "project_configuration.h" - -ModemTask::ModemTask(TaskQueue> &fromModem, TaskQueue> &toModem) : Task(TASK_MODEM, TaskModem), _lora_aprs(), _fromModem(fromModem), _toModem(toModem) { -} - -ModemTask::~ModemTask() { -} - -bool ModemTask::setup(System &system) { - SPI.begin(system.getBoardConfig()->LoraSck, system.getBoardConfig()->LoraMiso, system.getBoardConfig()->LoraMosi, system.getBoardConfig()->LoraCS); - _lora_aprs.setPins(system.getBoardConfig()->LoraCS, system.getBoardConfig()->LoraReset, system.getBoardConfig()->LoraIRQ); - if (!_lora_aprs.begin(system.getUserConfig()->lora.frequencyRx)) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Starting LoRa failed!"); - _stateInfo = "LoRa-Modem failed"; - _state = Error; - while (true) - ; - } - _lora_aprs.setRxFrequency(system.getUserConfig()->lora.frequencyRx); - _lora_aprs.setRxGain(system.getUserConfig()->lora.gainRx); - _lora_aprs.setTxFrequency(system.getUserConfig()->lora.frequencyTx); - _lora_aprs.setTxPower(system.getUserConfig()->lora.power); - _lora_aprs.setSpreadingFactor(system.getUserConfig()->lora.spreadingFactor); - _lora_aprs.setSignalBandwidth(system.getUserConfig()->lora.signalBandwidth); - _lora_aprs.setCodingRate4(system.getUserConfig()->lora.codingRate4); - _lora_aprs.enableCrc(); - - _stateInfo = ""; - return true; -} - -bool ModemTask::loop(System &system) { - if (_lora_aprs.checkMessage()) { - std::shared_ptr msg = _lora_aprs.getMessage(); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %ddBm, SNR %.2fdB and FreqErr %dHz", timeString().c_str(), msg->toString().c_str(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr(), -_lora_aprs.packetFrequencyError()); - _fromModem.addElement(msg); - system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString().c_str()))); - } - - if (!_toModem.empty()) { - if (_lora_aprs.rxSignalDetected()) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] RX signal detected. Waiting TX", timeString().c_str()); - delay(1000); - } else { - std::shared_ptr msg = _toModem.getElement(); - if (system.getUserConfig()->lora.tx_enable) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); - _lora_aprs.sendMessage(msg); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); - } else { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString().c_str(), msg->toString().c_str()); - } - } - } - - return true; -} diff --git a/src/TaskModem.h b/src/TaskModem.h deleted file mode 100644 index 6087b67..0000000 --- a/src/TaskModem.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef TASK_LORA_H_ -#define TASK_LORA_H_ - -#include -#include -#include - -class ModemTask : public Task { -public: - explicit ModemTask(TaskQueue> &fromModem, TaskQueue> &_toModem); - virtual ~ModemTask(); - - virtual bool setup(System &system) override; - virtual bool loop(System &system) override; - -private: - LoRa_APRS _lora_aprs; - - TaskQueue> &_fromModem; - TaskQueue> &_toModem; -}; - -#endif From 6ec0ea292e99e328efd782e6cab2484fc0eaa801 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 20 May 2022 22:46:27 +0200 Subject: [PATCH 107/125] adjust header and some status variables --- src/LoRa_APRS_iGate.cpp | 1 - src/TaskRadiolib.cpp | 18 ++++++++++-------- src/TaskRadiolib.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index af97d49..1dfea9a 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -13,7 +13,6 @@ #include "TaskEth.h" #include "TaskFTP.h" #include "TaskMQTT.h" -//#include "TaskModem.h" #include "TaskNTP.h" #include "TaskOTA.h" #include "TaskRadiolib.h" diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index 34f05b9..afc7ac2 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -1,10 +1,7 @@ +#include +#include #include -#include -#include - -#include "Task.h" -#include "TaskAprsIs.h" #include "TaskRadiolib.h" RadiolibTask::RadiolibTask(TaskQueue> &fromModem, TaskQueue> &toModem) : Task(TASK_RADIOLIB, TaskRadiolib), _fromModem(fromModem), _toModem(toModem) { @@ -80,13 +77,15 @@ bool RadiolibTask::setup(System &system) { rxEnable = false; txEnable = false; } + _stateInfo = "LoRa-Modem failed"; + _state = Error; } state = radio->setCRC(true); if (state != RADIOLIB_ERR_NONE) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] setCRC failed, code %d", timeString().c_str(), state); - while (true) - ; + _stateInfo = "LoRa-Modem failed"; + _state = Error; } radio->setDio0Action(setFlag); @@ -95,12 +94,15 @@ bool RadiolibTask::setup(System &system) { int state = startRX(RADIOLIB_SX127X_RXCONTINUOUS); if (state != RADIOLIB_ERR_NONE) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] startRX failed, code %d", timeString().c_str(), state); - rxEnable = false; + rxEnable = false; + _stateInfo = "LoRa-Modem failed"; + _state = Error; } } preambleDurationMilliSec = ((uint64_t)(preambleLength + 4) << (config.spreadingFactor + 10 /* to milli-sec */)) / config.signalBandwidth; + _stateInfo = ""; return true; } diff --git a/src/TaskRadiolib.h b/src/TaskRadiolib.h index 2f9cc85..11e59da 100644 --- a/src/TaskRadiolib.h +++ b/src/TaskRadiolib.h @@ -2,8 +2,8 @@ #define TASK_LORA_H_ #include "project_configuration.h" +#include #include -#include #include #include From 2f748621dc2ef5db441097e8ea9e3e31b020e1a3 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 20 May 2022 22:46:44 +0200 Subject: [PATCH 108/125] update version in platformio --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 750984e..7c1aa1c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,7 +16,7 @@ lib_deps = knolleary/PubSubClient@^2.8 mikalhart/TinyGPSPlus @ 1.0.2 shaggydog/OneButton @ 1.5.0 - jgromes/RadioLib@^5.1.2 + jgromes/RadioLib @ 5.1.2 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient From 312c1ab70a776abd208609246e5c967bcb2b05c1 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 20 May 2022 22:47:29 +0200 Subject: [PATCH 109/125] version bump --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 1dfea9a..11adfdf 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.14.0" +#define VERSION "22.20.0" #define MODULE_NAME "Main" String create_lat_aprs(double lat); From faa22606618ddd1c0e860bff88de48ad2a4d3faf Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 20 May 2022 22:50:24 +0200 Subject: [PATCH 110/125] remove old check --- .github/workflows/build_check.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index a5655db..ef7e68f 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -38,8 +38,6 @@ jobs: - 'lib/BoardFinder' - 'lib/ConfigurationManagement' #- 'lib/Display' - #- 'lib/LoRa' - - 'lib/LoRa_APRS' #- 'lib/NTPClient' - 'lib/PowerManagement' - 'lib/System' From e8aec31c1790b0ef16c22a7a9cbdac76fd385d5e Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Fri, 20 May 2022 23:09:26 +0200 Subject: [PATCH 111/125] comment write on read --- lib/ConfigurationManagement/configuration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ConfigurationManagement/configuration.cpp b/lib/ConfigurationManagement/configuration.cpp index 6734608..451fee4 100644 --- a/lib/ConfigurationManagement/configuration.cpp +++ b/lib/ConfigurationManagement/configuration.cpp @@ -35,7 +35,7 @@ void ConfigurationManagement::readConfiguration(logging::Logger &logger, Configu readProjectConfiguration(data, conf); // update config in memory to get the new fields: - writeConfiguration(logger, conf); + // writeConfiguration(logger, conf); } void ConfigurationManagement::writeConfiguration(logging::Logger &logger, Configuration &conf) { From e2a544f1c0b7eb0e45bcd440529a951f192b18cf Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 23 May 2022 21:12:30 +0000 Subject: [PATCH 112/125] add devcontainer --- .devcontainer/Dockerfile | 4 ++++ .devcontainer/devcontainer.json | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..b129666 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,4 @@ +ARG VARIANT="3.10-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} + +RUN pip3 --disable-pip-version-check --no-cache-dir install platformio diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..d4b6ff2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +{ + "name": "Python 3", + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + "VARIANT": "3.10-bullseye" + } + }, + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" + }, + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "platformio.platformio-ide" + ], + "postCreateCommand": "pip3 install --user platformio", + "remoteUser": "vscode" +} From 0835d45f3c1eae4becae5ec892b7250aaeadd4ad Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 23 May 2022 21:16:57 +0000 Subject: [PATCH 113/125] update --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d4b6ff2..4ce1cec 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -27,5 +27,5 @@ "platformio.platformio-ide" ], "postCreateCommand": "pip3 install --user platformio", - "remoteUser": "vscode" + //"remoteUser": "vscode" } From fc053ebf97d6f29dad9328eb8d59cb6162c62f30 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Thu, 26 May 2022 06:08:47 +0000 Subject: [PATCH 114/125] add clang-format-11 support --- .devcontainer/Dockerfile | 2 ++ .devcontainer/devcontainer.json | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b129666..eb3135b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,6 @@ ARG VARIANT="3.10-bullseye" FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} +RUN apt-get update && apt-get install -y clang-format-11 + RUN pip3 --disable-pip-version-check --no-cache-dir install platformio diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4ce1cec..dc7411a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,12 +19,14 @@ "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", - "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", + "clang-format.executable": "clang-format-11" }, "extensions": [ "ms-python.python", "ms-python.vscode-pylance", - "platformio.platformio-ide" + "platformio.platformio-ide", + "xaver.clang-format" ], "postCreateCommand": "pip3 install --user platformio", //"remoteUser": "vscode" From 7d91f0ec8c113966761f7a7ee664ccd7d3bf2906 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 6 Jun 2022 23:53:36 +0200 Subject: [PATCH 115/125] change ntp sync to 1h --- lib/NTPClient/NTPClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/NTPClient/NTPClient.h b/lib/NTPClient/NTPClient.h index b528023..1c6c9c2 100644 --- a/lib/NTPClient/NTPClient.h +++ b/lib/NTPClient/NTPClient.h @@ -17,7 +17,7 @@ class NTPClient { unsigned int _port = NTP_DEFAULT_LOCAL_PORT; long _timeOffset = 0; - unsigned long _updateInterval = 60000; // In ms + unsigned long _updateInterval = 3600000; // In ms unsigned long _currentEpoc = 0; // In s unsigned long _lastUpdate = 0; // In ms From 468cda5d57dad9d44f20c8e2f098ad248eb9a5e9 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Mon, 6 Jun 2022 23:56:26 +0200 Subject: [PATCH 116/125] Update TaskOTA.cpp --- src/TaskOTA.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index 89cbf7f..08f90fa 100644 --- a/src/TaskOTA.cpp +++ b/src/TaskOTA.cpp @@ -18,14 +18,11 @@ bool OTATask::setup(System &system) { } else { // U_SPIFFS type = "filesystem"; } - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type.c_str()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s. please wait, this prozess is taking some time!", type.c_str()); }) .onEnd([&]() { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "OTA End"); }) - .onProgress([&](unsigned int progress, unsigned int total) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Progress: %f", (progress / (total / 100))); - }) .onError([&](ota_error_t error) { String error_str; if (error == OTA_AUTH_ERROR) { From 0d0f0d922fdfcf11c458429e6103ab61c8d5559e Mon Sep 17 00:00:00 2001 From: dahuafschmied <3955019+dahuafschmied@users.noreply.github.com> Date: Tue, 28 Jun 2022 21:26:53 +0200 Subject: [PATCH 117/125] fix for NTP booting on ETH Board eht and wifi status has been mutually overwritten --- lib/System/System.cpp | 14 +++++++++----- lib/System/System.h | 7 ++++--- src/LoRa_APRS_iGate.cpp | 2 +- src/TaskAprsIs.cpp | 2 +- src/TaskEth.cpp | 4 ++-- src/TaskMQTT.cpp | 2 +- src/TaskNTP.cpp | 2 +- src/TaskWifi.cpp | 4 ++-- 8 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/System/System.cpp b/lib/System/System.cpp index 18b89d4..008e3a4 100644 --- a/lib/System/System.cpp +++ b/lib/System/System.cpp @@ -1,7 +1,7 @@ #include "System.h" -System::System() : _boardConfig(0), _userConfig(0), _isWifiEthConnected(false) { +System::System() : _boardConfig(0), _userConfig(0), _isEthConnected(false), _isWifiConnected(false) { } System::~System() { @@ -31,12 +31,16 @@ Display &System::getDisplay() { return _display; } -bool System::isWifiEthConnected() const { - return _isWifiEthConnected; +bool System::isWifiOrEthConnected() const { + return _isEthConnected || _isWifiConnected; } -void System::connectedViaWifiEth(bool status) { - _isWifiEthConnected = status; +void System::connectedViaEth(bool status) { + _isEthConnected = status; +} + +void System::connectedViaWifi(bool status) { + _isWifiConnected = status; } logging::Logger &System::getLogger() { diff --git a/lib/System/System.h b/lib/System/System.h index 6c7e9d4..6e7daa2 100644 --- a/lib/System/System.h +++ b/lib/System/System.h @@ -21,8 +21,9 @@ public: Configuration const *const getUserConfig() const; TaskManager & getTaskManager(); Display & getDisplay(); - bool isWifiEthConnected() const; - void connectedViaWifiEth(bool status); + bool isWifiOrEthConnected() const; + void connectedViaEth(bool status); + void connectedViaWifi(bool status); logging::Logger & getLogger(); private: @@ -30,7 +31,7 @@ private: Configuration const *_userConfig; TaskManager _taskManager; Display _display; - bool _isWifiEthConnected; + bool _isEthConnected, _isWifiConnected; logging::Logger _logger; }; diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 11adfdf..da05b99 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -167,7 +167,7 @@ volatile bool syslogSet = false; void loop() { LoRaSystem.getTaskManager().loop(LoRaSystem); - if (LoRaSystem.isWifiEthConnected() && LoRaSystem.getUserConfig()->syslog.active && !syslogSet) { + if (LoRaSystem.isWifiOrEthConnected() && LoRaSystem.getUserConfig()->syslog.active && !syslogSet) { LoRaSystem.getLogger().setSyslogServer(LoRaSystem.getUserConfig()->syslog.server, LoRaSystem.getUserConfig()->syslog.port, LoRaSystem.getUserConfig()->callsign); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "System connected after a restart to the network, syslog server set"); syslogSet = true; diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 680a2c4..3fa3da6 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -16,7 +16,7 @@ bool AprsIsTask::setup(System &system) { } bool AprsIsTask::loop(System &system) { - if (!system.isWifiEthConnected()) { + if (!system.isWifiOrEthConnected()) { return false; } if (!_aprs_is.connected()) { diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index 03f211f..1efdad9 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -111,12 +111,12 @@ bool EthTask::setup(System &system) { bool EthTask::loop(System &system) { if (!eth_connected) { - system.connectedViaWifiEth(false); + system.connectedViaEth(false); _stateInfo = "Ethernet not connected"; _state = Error; return false; } - system.connectedViaWifiEth(true); + system.connectedViaEth(true); _stateInfo = ETH.localIP().toString(); _state = Okay; return true; diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index fe6ee3f..e065a1d 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -18,7 +18,7 @@ bool MQTTTask::setup(System &system) { } bool MQTTTask::loop(System &system) { - if (!system.isWifiEthConnected()) { + if (!system.isWifiOrEthConnected()) { return false; } diff --git a/src/TaskNTP.cpp b/src/TaskNTP.cpp index 569eecc..7622032 100644 --- a/src/TaskNTP.cpp +++ b/src/TaskNTP.cpp @@ -18,7 +18,7 @@ bool NTPTask::setup(System &system) { } bool NTPTask::loop(System &system) { - if (!system.isWifiEthConnected()) { + if (!system.isWifiOrEthConnected()) { return false; } if (!_beginCalled) { diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index d7e1868..2756cd7 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -40,7 +40,7 @@ bool WifiTask::setup(System &system) { bool WifiTask::loop(System &system) { const uint8_t wifi_status = _wiFiMulti.run(); if (wifi_status != WL_CONNECTED) { - system.connectedViaWifiEth(false); + system.connectedViaWifi(false); system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "WiFi not connected!"); _oldWifiStatus = wifi_status; _stateInfo = "WiFi not connected"; @@ -51,7 +51,7 @@ bool WifiTask::loop(System &system) { _oldWifiStatus = wifi_status; return false; } - system.connectedViaWifiEth(true); + system.connectedViaWifi(true); _stateInfo = WiFi.localIP().toString(); _state = Okay; return true; From f093167bf7ba2db7481795e2dfc44ad467a35d08 Mon Sep 17 00:00:00 2001 From: dahuafschmied <3955019+dahuafschmied@users.noreply.github.com> Date: Tue, 28 Jun 2022 22:00:48 +0200 Subject: [PATCH 118/125] one line for one variable --- lib/System/System.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/System/System.h b/lib/System/System.h index 6e7daa2..a2788e9 100644 --- a/lib/System/System.h +++ b/lib/System/System.h @@ -31,7 +31,8 @@ private: Configuration const *_userConfig; TaskManager _taskManager; Display _display; - bool _isEthConnected, _isWifiConnected; + bool _isEthConnected; + bool _isWifiConnected; logging::Logger _logger; }; From 2f53d44a09f717ae0cf2e9b248fe0752624fd65c Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Tue, 28 Jun 2022 22:41:11 +0200 Subject: [PATCH 119/125] remove whitespace --- lib/System/System.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/System/System.h b/lib/System/System.h index a2788e9..a6a0d97 100644 --- a/lib/System/System.h +++ b/lib/System/System.h @@ -31,7 +31,7 @@ private: Configuration const *_userConfig; TaskManager _taskManager; Display _display; - bool _isEthConnected; + bool _isEthConnected; bool _isWifiConnected; logging::Logger _logger; }; From 183b23af584aa39bc2e8cffbe98370ccee114c8e Mon Sep 17 00:00:00 2001 From: dahuafschmied <3955019+dahuafschmied@users.noreply.github.com> Date: Wed, 29 Jun 2022 08:28:16 +0200 Subject: [PATCH 120/125] Copy Paste Typo Fix --- src/TaskEth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index 1efdad9..e1843c9 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -37,7 +37,7 @@ void WiFiEvent(WiFiEvent_t event) { _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Stopped"); break; case SYSTEM_EVENT_ETH_START: - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Started"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Started"); break; case SYSTEM_EVENT_ETH_CONNECTED: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Connected"); From 8ca68d492da7c817a4ab3325c88eec162dde6f45 Mon Sep 17 00:00:00 2001 From: dahuafschmied <3955019+dahuafschmied@users.noreply.github.com> Date: Wed, 29 Jun 2022 08:56:55 +0200 Subject: [PATCH 121/125] better differentiation in debug output ETH/WiFi --- src/TaskEth.cpp | 25 +++++++++++++------------ src/TaskWifi.cpp | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index e1843c9..59d4149 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -25,10 +25,11 @@ void WiFiEvent(WiFiEvent_t event) { break; case SYSTEM_EVENT_STA_GOT_IP: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi IPv4: %s", WiFi.localIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Gateway: %s", WiFi.gatewayIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi DNS1: %s", WiFi.dnsIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi DNS2: %s", WiFi.dnsIP(1).toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Hostname: %s", WiFi.getHostname()); break; case SYSTEM_EVENT_STA_DISCONNECTED: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Disconnected"); @@ -43,17 +44,16 @@ void WiFiEvent(WiFiEvent_t event) { _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Connected"); break; case SYSTEM_EVENT_ETH_GOT_IP: - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString().c_str()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH IPv4: %s", ETH.localIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Gateway: %s", ETH.gatewayIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH DNS1: %s", ETH.dnsIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH DNS2: %s", ETH.dnsIP(1).toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Hostname: %s", ETH.getHostname()); if (ETH.fullDuplex()) { - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "FULL_DUPLEX"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH FULL_DUPLEX"); } - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "%dMbps", ETH.linkSpeed()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Speed: %dMbps", ETH.linkSpeed()); eth_connected = true; break; case SYSTEM_EVENT_ETH_DISCONNECTED: @@ -106,6 +106,7 @@ bool EthTask::setup(System &system) { } else { ETH.setHostname(system.getUserConfig()->callsign.c_str()); } + return true; } diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index 2756cd7..03cf95d 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -47,7 +47,7 @@ bool WifiTask::loop(System &system) { _state = Error; return false; } else if (wifi_status != _oldWifiStatus) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString().c_str()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "WiFi IP address: %s", WiFi.localIP().toString().c_str()); _oldWifiStatus = wifi_status; return false; } From 3fdac573257569783dca424d51c4d7175132e20a Mon Sep 17 00:00:00 2001 From: dahuafschmied <3955019+dahuafschmied@users.noreply.github.com> Date: Thu, 30 Jun 2022 14:00:24 +0200 Subject: [PATCH 122/125] last octet of ip address and signal stength for WiFi status --- src/TaskWifi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index 03cf95d..1377ba7 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -52,7 +52,7 @@ bool WifiTask::loop(System &system) { return false; } system.connectedViaWifi(true); - _stateInfo = WiFi.localIP().toString(); + _stateInfo = String("IP .") + String(WiFi.localIP()[3]) + String(" @ ") + String(WiFi.RSSI()) + String("dBm"); _state = Okay; return true; } From be8a006394876f4a25656158e4a9b03fa9d3bc03 Mon Sep 17 00:00:00 2001 From: Konrad Roeder Date: Sun, 14 Aug 2022 01:55:58 +0000 Subject: [PATCH 123/125] Update README.md Spelling corrections, added link to LoRa APRS Traker WiKi - Displays --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1adfc06..6766f7e 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,11 @@ Try it out and be part of the APRS network. * [Manuel Lausmann - Tracker](https://www.youtube.com/watch?v=clIlTEFbWLk) (youtube - german - OLD) 02.11.2020 * [OE1ROT](https://www.aronaut.at/2019/12/lora-aprs-tracker-mit-ttgo-t-beam-433mhz/) (blog post - german) 09.12.2019 -feel free to add yours or create a ticket if you want to be added. +Feel free to add yours or create a ticket if you want to be added. ## Supported boards -You can use one of the Lora32 boards without changings: +You can use one of the Lora32 boards without changes: * Heltec WiFi LoRa 32 V1 (433MHz SX1278) * Heltec WiFi LoRa 32 V2 (433MHz SX1278) @@ -42,7 +42,7 @@ Here are some amazon-de links for some example boards: * [T-Beam V1.0](https://www.amazon.de/dp/B07RT9FKPL) This boards cost around 20 Euros, they are very cheap and perfect for an LoRa iGate. -Keep in minde: you need a 433MHz version! +Keep in mind: you need a 433MHz version! ## Compiling and configuration @@ -63,7 +63,7 @@ The best success is to use PlatformIO (and it is the only platform where I can s * You can find all nessesary settings to change for your configuration in **data/is-cfg.json**. * To upload it to your board you have to do this via **Upload File System image** in PlatformIO! -* To find the 'Upload File System image' click the PlatformIO symbol (the little alien) on the left side, choos your configuration, click on 'Platform' and search for 'Upload File System image'. +* To find the 'Upload File System image' click the PlatformIO symbol (the little alien) on the left side, choose your configuration, click on 'Platform' and search for 'Upload File System image'. ## Branches in this repository and version system @@ -106,13 +106,15 @@ Look at my other project: a [LoRa Tracker](https://github.com/peterus/LoRa_APRS_ ### Here are some peculiarities of the different boards -* TTGO T-Beam V1 +* TTGO T-Beam V1.0 and V1.1 and SSD1306 OLED display -When adding a 0,96" OLED display direct to the board you have to be careful, there are two different pinout +When adding an SSD1306 0,96" OLED display direct to the board you have to be careful, there are two different pinout versions on the market. For direct mount you need a display with this Pinout -> [VCC - GND - SCL - SDA](pics/display-right.jpg). A direct mount of the [other display](pics/display-wrong.jpg) is not possible without damage the display! The 'wrong' display works too but you have to change VCC and GND by wire ! -feel free to add hints! +The [LoRa APRS WiKi Displays](https://github.com/lora-aprs/LoRa_APRS_Tracker/wiki/Displays) page has more details. + +Feel free to add hints! From 31d807fac766a09a7e7807d6d8f9259d67889776 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 21 Aug 2022 09:34:04 +0200 Subject: [PATCH 124/125] Fix for incorrect formatting string --- src/TaskRadiolib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index afc7ac2..435c18a 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -134,7 +134,7 @@ bool RadiolibTask::loop(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] readData failed, code %d", timeString().c_str(), state); } else { if (str.substring(0, 3) != "<\xff\x01") { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %dHz", timeString().c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError()); } else { std::shared_ptr msg = std::shared_ptr(new APRSMessage()); msg->decode(str.substring(3)); From 7f2155336afcf8e86a089d1e791d1441158c7949 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 21 Aug 2022 10:16:07 +0200 Subject: [PATCH 125/125] An other "unknown packet"-fix --- src/TaskRadiolib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskRadiolib.cpp b/src/TaskRadiolib.cpp index 435c18a..295753a 100644 --- a/src/TaskRadiolib.cpp +++ b/src/TaskRadiolib.cpp @@ -134,7 +134,7 @@ bool RadiolibTask::loop(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "[%s] readData failed, code %d", timeString().c_str(), state); } else { if (str.substring(0, 3) != "<\xff\x01") { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz", timeString().c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Unknown packet '%s' with RSSI %.0fdBm, SNR %.2fdB and FreqErr %fHz%s", timeString().c_str(), str.c_str(), radio->getRSSI(), radio->getSNR(), -radio->getFrequencyError()); } else { std::shared_ptr msg = std::shared_ptr(new APRSMessage()); msg->decode(str.substring(3));