diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b940d07..2374e3a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,5 @@ -name: PlatformIO CI + +name: check and build on: [push, pull_request] @@ -6,20 +7,50 @@ jobs: PlatformIO-Check: runs-on: ubuntu-latest steps: - - run: sudo apt-get install python3-setuptools python3-wheel - - run: pip3 install platformio - - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - uses: actions/checkout@v2 - - run: platformio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high --skip-packages --flags "--suppress=*:*.pio\* --inline-suppr" -v + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip- + - name: Cache PlatformIO + uses: actions/cache@v2 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Set up Python + uses: actions/setup-python@v2 + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - name: Run PlatformIO Check + run: platformio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high PlatformIO-Build: runs-on: ubuntu-latest steps: - - run: sudo apt-get install python3-setuptools python3-wheel - - run: pip3 install platformio - - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - uses: actions/checkout@v2 - - run: platformio run + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: ${{ runner.os }}-pip- + - name: Cache PlatformIO + uses: actions/cache@v2 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + - name: Set up Python + uses: actions/setup-python@v2 + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + - name: Run PlatformIO CI + run: platformio run - uses: actions/upload-artifact@v2 with: name: firmware diff --git a/data/is-cfg.json b/data/tracker.json similarity index 63% rename from data/is-cfg.json rename to data/tracker.json index 5f540c4..a81fa8c 100644 --- a/data/is-cfg.json +++ b/data/tracker.json @@ -3,7 +3,7 @@ "debug": false, "beacon": { - "message":"TTGO LoRA-APRS Tracker", + "message":"LoRa Tracker, Info: github.com/lora-aprs/LoRa_APRS_Tracker", "timeout": 1, "symbol": "[", "overlay": "/" @@ -19,20 +19,13 @@ "min_tx_dist":100, "min_bcn":5 }, - "wifi": - { - "active":false, - "AP": [ - { "SSID":"yourssid", "password":"yoursecrets" } - ] - }, "lora": { - "frequency_rx":433775E3, - "frequency_tx":433775E3, + "frequency_rx":433775000, + "frequency_tx":433775000, "power":20, "spreading_factor":12, - "signal_bandwidth":125E3, + "signal_bandwidth":125000, "coding_rate4":5 } } diff --git a/platformio.ini b/platformio.ini index ac04725..8fae8e8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,6 +7,7 @@ monitor_speed = 115200 lib_deps = adafruit/Adafruit GFX Library @ 1.7.5 adafruit/Adafruit SSD1306 @ 2.4.0 + bblanchon/ArduinoJson @ 6.17.0 lewisxhe/AXP202X_Library @ 1.1.2 sandeepmistry/LoRa @ 0.7.2 peterus/APRS-Decoder-Lib @ 0.0.5 @@ -14,7 +15,8 @@ lib_deps = paulstoffregen/Time @ 1.6 check_tool = cppcheck check_flags = - cppcheck: --suppress=*:*.pio\* --inline-suppr + cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK +check_skip_packages = yes [env:ttgo-t-beam-v1] board = ttgo-t-beam diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 011eae8..fcde5a0 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -18,9 +18,9 @@ PowerManagement powerManagement; HardwareSerial ss(1); TinyGPSPlus gps; +void load_config(); void setup_lora(); void setup_gps(); -void load_config(); String create_lat_aprs(RawDegrees lat); String create_long_aprs(RawDegrees lng); @@ -28,31 +28,20 @@ String createDateString(time_t t); String createTimeString(time_t t); String getSmartBeaconState(); -static bool send_update = true; - -// Initial lat/lng pos, change to your base station coordnates -float lastTxLat = 0; -float lastTxLng = 0; -float lastTxdistance; -unsigned long txInterval = 60000L; // Initial 60 secs internal -int previousHeading, currentHeading, headingDelta, headingTresh = 0; -int lastTxTime = millis(); - // cppcheck-suppress unusedFunction void setup() { Serial.begin(115200); - #ifdef TTGO_T_Beam_V1_0 Wire.begin(SDA, SCL); if (!powerManagement.begin(Wire)) { - Serial.println("[INFO] AXP192 init done!"); + logPrintlnI("AXP192 init done!"); } else { - Serial.println("[ERROR] AXP192 init failed!"); + logPrintlnE("AXP192 init failed!"); } powerManagement.activateLoRa(); powerManagement.activateOLED(); @@ -61,11 +50,11 @@ void setup() #endif delay(500); - Serial.println("[INFO] LoRa APRS Tracker by OE5BPA (Peter Buchegger)"); + logPrintlnI("LoRa APRS Tracker by OE5BPA (Peter Buchegger)"); setup_display(); - show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "[INFO] Smart Beacon is " + getSmartBeaconState(), 2000); - load_config(); + show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", 2000); + load_config(); setup_gps(); setup_lora(); @@ -74,106 +63,96 @@ void setup() WiFi.mode(WIFI_OFF); btStop(); - Serial.println("[INFO] Smart Beacon is " + getSmartBeaconState()); - Serial.println("[INFO] setup done..."); + logPrintlnI("Smart Beacon is " + getSmartBeaconState()); + show_display("INFO", "Smart Beacon is " + getSmartBeaconState(), 1000); + logPrintlnI("setup done..."); delay(500); - } // cppcheck-suppress unusedFunction void loop() { -if (Config.debug == false) - while (ss.available() > 0) + if(Config.debug == false) { - char c = ss.read(); - //Serial.print(c); - gps.encode(c); + while(ss.available() > 0) + { + char c = ss.read(); + //Serial.print(c); + gps.encode(c); + } } -else -{ - while (Serial.available() > 0) + else { - char c = Serial.read(); - //Serial.print(c); - gps.encode(c); + while(Serial.available() > 0) + { + char c = Serial.read(); + //Serial.print(c); + gps.encode(c); + } } -} bool gps_time_update = gps.time.isUpdated(); bool gps_loc_update = gps.location.isUpdated(); static time_t nextBeaconTimeStamp = -1; + static bool send_update = true; if(gps.time.isValid()) { - setTime(gps.time.hour(),gps.time.minute(),gps.time.second(),gps.date.day(),gps.date.month(),gps.date.year()); + setTime(gps.time.hour(), gps.time.minute(), gps.time.second(), gps.date.day(), gps.date.month(), gps.date.year()); - if (nextBeaconTimeStamp <= now() || nextBeaconTimeStamp == -1) + if(nextBeaconTimeStamp <= now()) { send_update = true; } - } - if (Config.smart_beacon.active) - { - send_update = false; - if ( gps_loc_update ) + static double lastTxLat = 0.0; + static double lastTxLng = 0.0; + static double lastTxdistance = 0.0; + static unsigned long txInterval = 60000L; // Initial 60 secs internal + + static double currentHeading = 0; + static double previousHeading = 0; + + static int lastTxTime = millis(); + + if(Config.smart_beacon.active) { - lastTxdistance = TinyGPSPlus::distanceBetween( - gps.location.lat(), - gps.location.lng(), - lastTxLat, - lastTxLng - ); - - // Get headings and heading delta - currentHeading = (int) gps.course.deg(); - if ( currentHeading >= 180 ) + if(gps_loc_update) { - currentHeading = currentHeading-180; - } - headingDelta = (int) ( previousHeading - currentHeading ) % 360; - int turn_slope = 100; - headingTresh = (float) Config.smart_beacon.turn_min + turn_slope / gps.speed.kmph(); + lastTxdistance = TinyGPSPlus::distanceBetween(gps.location.lat(), gps.location.lng(), lastTxLat, lastTxLng); + + // Get headings and heading delta + currentHeading = gps.course.deg(); + double headingDelta = abs(previousHeading - currentHeading); - int lastTx = millis() - lastTxTime; - - if ( lastTx > Config.smart_beacon.min_bcn * 1000) - { - //send_update = true; - // Check for heading more than 25 degrees - if ( (headingDelta < -Config.smart_beacon.turn_min || headingDelta > Config.smart_beacon.turn_min) && lastTxdistance > Config.smart_beacon.min_tx_dist ) + int lastTx = millis() - lastTxTime; + + if(lastTx > Config.smart_beacon.min_bcn * 1000) { - send_update = true; + // Check for heading more than 25 degrees + if(headingDelta > Config.smart_beacon.turn_min && lastTxdistance > Config.smart_beacon.min_tx_dist) + { + send_update = true; + } } - } - if ( lastTx >= txInterval ) - { - // Trigger Tx Tracker when Tx interval is reach - // Will not Tx if stationary bcos speed < 5 and lastTxDistance < 20 - if ( lastTxdistance > 20 ) + if(lastTx >= txInterval) { - send_update = true; + // Trigger Tx Tracker when Tx interval is reach + // Will not Tx if stationary bcos speed < 5 and lastTxDistance < 20 + if (lastTxdistance > 20) + { + send_update = true; + } } } } - } - if(send_update && gps.location.isValid() && gps_loc_update) + if(send_update && gps_loc_update) { - #ifdef TTGO_T_Beam_V1_0 - String volts = "Bat.: " + powerManagement.getBatteryVoltageStr() + " V"; - String amps = "Cur.:" + powerManagement.getBatteryChargeDischargeCurrentStr() + " mA"; - String sats = String("Sats: ") + gps.satellites.value(); - - #endif - powerManagement.deactivateMeasurement(); - - nextBeaconTimeStamp = now() + (Config.beacon.timeout * SECS_PER_MIN); - String nextbcnStr = String("Nxt Bcn: ") + createTimeString(nextBeaconTimeStamp); send_update = false; + nextBeaconTimeStamp = now() + (Config.beacon.timeout * SECS_PER_MIN); APRSMessage msg; msg.setSource(Config.callsign); @@ -181,9 +160,15 @@ else String lat = create_lat_aprs(gps.location.rawLat()); String lng = create_long_aprs(gps.location.rawLng()); - msg.getAPRSBody()->setData(String("=") + lat + Config.beacon.overlay + lng + Config.beacon.symbol + Config.beacon.message + " - " + volts + " - " + amps + " - " + sats); +#ifdef TTGO_T_Beam_V1_0 + String batteryVoltage(powerManagement.getBatteryVoltage(), 2); + String batteryChargeCurrent(powerManagement.getBatteryChargeDischargeCurrent(), 0); + msg.getAPRSBody()->setData(String("=") + lat + Config.beacon.overlay + lng + Config.beacon.symbol + Config.beacon.message + " - Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA"); +#else + msg.getAPRSBody()->setData(String("=") + lat + Config.beacon.overlay + lng + Config.beacon.symbol + Config.beacon.message); +#endif String data = msg.encode(); - Serial.println(data); + logPrintlnD(data); show_display("<< TX >>", data); LoRa.beginPacket(); // Header: @@ -193,16 +178,15 @@ else // APRS Data: LoRa.write((const uint8_t *)data.c_str(), data.length()); LoRa.endPacket(); - powerManagement.activateMeasurement(); if (Config.smart_beacon.active) - { + { lastTxLat = gps.location.lat(); lastTxLng = gps.location.lng(); previousHeading = currentHeading; - lastTxdistance = 0; + lastTxdistance = 0.0; lastTxTime = millis(); - } + } } if(gps_time_update) @@ -222,62 +206,71 @@ else , String("Smart Beacon is " + getSmartBeaconState()) ); -if (Config.smart_beacon.active) - { + if(Config.smart_beacon.active) + { // Change the Tx internal based on the current speed - if ( gps.speed.kmph() < 5 ) + if(gps.speed.kmph() < 5) { - txInterval = 300000; // Change Tx internal to 5 mins - } - else if ( gps.speed.kmph() < Config.smart_beacon.slow_speed ) + txInterval = 300000; // Change Tx internal to 5 mins + } + else if(gps.speed.kmph() < Config.smart_beacon.slow_speed) { - txInterval = Config.smart_beacon.slow_rate * 1000; // Change Tx interval - } - else if ( gps.speed.kmph() > Config.smart_beacon.fast_speed) + txInterval = Config.smart_beacon.slow_rate * 1000; + } + else if(gps.speed.kmph() > Config.smart_beacon.fast_speed) { - txInterval = Config.smart_beacon.fast_rate * 1000; // Change Tx interval - } + txInterval = Config.smart_beacon.fast_rate * 1000; + } else { - // Interval inbetween low and high speed - txInterval = (Config.smart_beacon.fast_speed / gps.speed.kmph()) * Config.smart_beacon.fast_rate * 1000; - } + // Interval inbetween low and high speed + txInterval = (Config.smart_beacon.fast_speed / gps.speed.kmph()) * Config.smart_beacon.fast_rate * 1000; + } } - } - if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) { - Serial.println("No GPS detected!"); + logPrintlnE("No GPS frames detected! Try to reset the GPS Chip with this firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset"); } +} - - +void load_config() +{ + ConfigurationManagement confmg("/tracker.json"); + Config = confmg.readConfiguration(); + if(Config.callsign == "NOCALL-10") + { + logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); + show_display("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); + while(true) + {} + } } void setup_lora() { - Serial.println("[INFO] Set SPI pins!"); + logPrintlnI("Set SPI pins!"); SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); + logPrintlnI("Set LoRa pins!"); LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); - Serial.println("[INFO] Set LoRa pins!"); long freq = Config.lora.frequencyTx; - Serial.print("[INFO] frequency: "); - Serial.println(freq); + logPrintI("frequency: "); + logPrintlnI(String(freq)); if (!LoRa.begin(freq)) { - Serial.println("[ERROR] Starting LoRa failed!"); + logPrintlnE("Starting LoRa failed!"); show_display("ERROR", "Starting LoRa failed!"); - while (1); + while(true) + {} } LoRa.setSpreadingFactor(Config.lora.spreadingFactor); LoRa.setSignalBandwidth(Config.lora.signalBandwidth); LoRa.setCodingRate4(Config.lora.codingRate4); LoRa.enableCrc(); - LoRa.setTxPower(20); - Serial.println("[INFO] LoRa init done!"); + LoRa.setTxPower(Config.lora.power); + logPrintlnI("LoRa init done!"); show_display("INFO", "LoRa init done!", 2000); } @@ -286,28 +279,6 @@ void setup_gps() ss.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX); } -void load_config() -{ - ConfigurationManagement confmg("/is-cfg.json"); - Config = confmg.readConfiguration(); - if(Config.callsign == "NOCALL-10") - { - logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); - show_display("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); - while (true) - {} - } - -#ifndef ETH_BOARD - if(Config.aprs_is.active && !Config.wifi.active) - { - logPrintlnE("You have to activate Wifi for APRS IS to work, please check your settings!"); - show_display("ERROR", "You have to activate Wifi for APRS IS to work, please check your settings!"); - while (true) - {} - } -#endif -} String create_lat_aprs(RawDegrees lat) { char str[20]; @@ -354,14 +325,9 @@ String createTimeString(time_t t) String getSmartBeaconState() { - String sm_beaconstate = ""; - if (Config.smart_beacon.active == true) + if (Config.smart_beacon.active) { - sm_beaconstate = "On"; + return "On"; } - else - { - sm_beaconstate = "Off"; - } - return sm_beaconstate; + return "Off"; } diff --git a/src/configuration.cpp b/src/configuration.cpp index ad45cb3..4f7fc2f 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -22,95 +22,51 @@ Configuration ConfigurationManagement::readConfiguration() File file = SPIFFS.open(mFilePath); if(!file) { - Serial.println("Failed to open file for reading..."); + logPrintlnE("Failed to open file for reading..."); return Configuration(); } DynamicJsonDocument data(2048); - DeserializationError error = deserializeJson(data, file); // update config in memory to get the new fields: - // writeConfiguration(conf); + DeserializationError error = deserializeJson(data, file); if(error) { - Serial.println("Failed to read file, using default configuration."); + logPrintlnE("Failed to read file, using default configuration."); } - serializeJson(data, Serial); - Serial.println(); file.close(); Configuration conf; - if(data.containsKey("debug")) - conf.debug = data["debug"] | false; if(data.containsKey("callsign")) conf.callsign = data["callsign"].as(); + conf.debug = data["debug"] | false; - conf.wifi.active = data["wifi"]["active"] | false; - JsonArray aps = data["wifi"]["AP"].as(); - for(JsonVariant v : aps) - { - Configuration::Wifi::AP ap; - ap.SSID = v["SSID"].as(); - ap.password = v["password"].as(); - conf.wifi.APs.push_back(ap); - } if(data.containsKey("beacon") && data["beacon"].containsKey("message")) conf.beacon.message = data["beacon"]["message"].as(); + conf.beacon.timeout = data["beacon"]["timeout"] | 1; + if(data.containsKey("beacon") && data["beacon"].containsKey("symbol")) + conf.beacon.symbol = data["beacon"]["symbol"].as(); + if(data.containsKey("beacon") && data["beacon"].containsKey("overlay")) + conf.beacon.overlay = data["beacon"]["overlay"].as() ; - conf.beacon.timeout = data["beacon"]["timeout"] | 1; - conf.beacon.symbol = data["beacon"]["symbol"].as(); - conf.beacon.overlay = data["beacon"]["overlay"].as() ; + conf.smart_beacon.active = data["smart_beacon"]["active"] | false; + conf.smart_beacon.turn_min = data["smart_beacon"]["turn_min"] | 25; + conf.smart_beacon.slow_rate = data["smart_beacon"]["slow_rate"] | 300; + conf.smart_beacon.slow_speed = data["smart_beacon"]["slow_speed"] | 10; + conf.smart_beacon.fast_rate = data["smart_beacon"]["fast_rate"] | 60; + conf.smart_beacon.fast_speed = data["smart_beacon"]["fast_speed"] | 100; + conf.smart_beacon.min_tx_dist = data["smart_beacon"]["min_tx_dist"] | 100; + conf.smart_beacon.min_bcn = data["smart_beacon"]["min_bcn"] | 5; - - conf.smart_beacon.active = data["smart_beacon"]["active"]; - conf.smart_beacon.turn_min = data["smart_beacon"]["turn_min"]; - conf.smart_beacon.slow_rate = data["smart_beacon"]["slow_rate"]; - conf.smart_beacon.slow_speed = data["smart_beacon"]["slow_speed"]; - conf.smart_beacon.fast_rate = data["smart_beacon"]["fast_rate"]; - conf.smart_beacon.fast_speed = data["smart_beacon"]["fast_speed"]; - conf.smart_beacon.min_tx_dist = data["smart_beacon"]["min_tx_dist"]; - conf.smart_beacon.min_bcn = data["smart_beacon"]["min_bcn"]; - - conf.aprs_is.active = data["aprs_is"]["active"] | false; - if(data.containsKey("aprs_is") && data["aprs_is"].containsKey("password")) - conf.aprs_is.password = data["aprs_is"]["password"].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.aprs_is.beacon = data["aprs_is"]["beacon"] | true; - conf.aprs_is.beaconTimeout = data["aprs_is"]["beacon_timeout"] | 15; - conf.digi.active = data["digi"]["active"] | false; - conf.digi.forwardTimeout = data["digi"]["forward_timeout"] | 5; - conf.digi.beacon = data["digi"]["beacon"] | true; - conf.digi.beaconTimeout = data["digi"]["beacon_timeout"] | 30; - conf.lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000; conf.lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000; conf.lora.power = data["lora"]["power"] | 20; 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.display.alwaysOn = data["display"]["always_on"] | true; - conf.display.timeout = data["display"]["timeout"] | 10; - conf.display.overwritePin = data["display"]["overwrite_pin"] | 0; - conf.ftp.active = data["ftp"]["active"] | false; - JsonArray users = data["ftp"]["user"].as(); - for(JsonVariant u : users) - { - Configuration::Ftp::User us; - us.name = u["name"].as(); - us.password = u["password"].as(); - conf.ftp.users.push_back(us); - } - if(conf.ftp.users.empty()) - { - Configuration::Ftp::User us; - us.name = "ftp"; - us.password = "ftp"; - conf.ftp.users.push_back(us); - } return conf; } +// cppcheck-suppress unusedFunction void ConfigurationManagement::writeConfiguration(Configuration conf) { File file = SPIFFS.open(mFilePath, "w"); @@ -122,54 +78,27 @@ void ConfigurationManagement::writeConfiguration(Configuration conf) DynamicJsonDocument data(2048); data["callsign"] = conf.callsign; - 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; - v["password"] = ap.password; - } + data["debug"] = conf.debug; data["beacon"]["message"] = conf.beacon.message; - data["smart_beacon"]["active"] = conf.smart_beacon.active; - data["smart_beacon"]["turn_min"] = conf.smart_beacon.turn_min; - data["smart_beacon"]["slow_rate"] = conf.smart_beacon.slow_rate; - data["smart_beacon"]["slow_speed"] = conf.smart_beacon.slow_speed; - data["smart_beacon"]["fast_rate"] = conf.smart_beacon.fast_rate; - data["smart_beacon"]["fast_speed"] = conf.smart_beacon.fast_speed; - data["smart_beacon"]["min_tx_dist"] = conf.smart_beacon.min_tx_dist; - data["smart_beacon"]["min_bcn"] = conf.smart_beacon.min_bcn ; + data["beacon"]["timeout"] = conf.beacon.timeout; + data["beacon"]["symbol"] = conf.beacon.symbol; + data["beacon"]["overlay"] = conf.beacon.overlay; + data["smart_beacon"]["active"] = conf.smart_beacon.active; + data["smart_beacon"]["turn_min"] = conf.smart_beacon.turn_min; + data["smart_beacon"]["slow_rate"] = conf.smart_beacon.slow_rate; + data["smart_beacon"]["slow_speed"] = conf.smart_beacon.slow_speed; + data["smart_beacon"]["fast_rate"] = conf.smart_beacon.fast_rate; + data["smart_beacon"]["fast_speed"] = conf.smart_beacon.fast_speed; + data["smart_beacon"]["min_tx_dist"] = conf.smart_beacon.min_tx_dist; + data["smart_beacon"]["min_bcn"] = conf.smart_beacon.min_bcn ; - data["aprs_is"]["active"] = conf.aprs_is.active; - data["aprs_is"]["password"] = conf.aprs_is.password; - data["aprs_is"]["server"] = conf.aprs_is.server; - data["aprs_is"]["port"] = conf.aprs_is.port; - data["aprs_is"]["beacon"] = conf.aprs_is.beacon; - data["aprs_is"]["beacon_timeout"] = conf.aprs_is.beaconTimeout; - data["digi"]["active"] = conf.digi.active; - data["digi"]["forward_timeout"] = conf.digi.forwardTimeout; - data["digi"]["beacon"] = conf.digi.beacon; - data["digi"]["beacon_timeout"] = conf.digi.beaconTimeout; data["lora"]["frequency_rx"] = conf.lora.frequencyRx; data["lora"]["frequency_tx"] = conf.lora.frequencyTx; data["lora"]["power"] = conf.lora.power; data["lora"]["spreading_factor"] = conf.lora.spreadingFactor; data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth; data["lora"]["coding_rate4"] = conf.lora.codingRate4; - data["display"]["always_on"] = conf.display.alwaysOn; - data["display"]["timeout"] = conf.display.timeout; - data["display"]["overwrite_pin"] = conf.display.overwritePin; - data["ftp"]["active"] = conf.ftp.active; - JsonArray users = data["ftp"].createNestedArray("user"); - for(Configuration::Ftp::User u : conf.ftp.users) - { - JsonObject v = users.createNestedObject(); - v["name"] = u.name; - v["password"] = u.password; - } - + serializeJson(data, file); - //serializeJson(data, Serial); - //Serial.println(); file.close(); } diff --git a/src/configuration.h b/src/configuration.h index 73b8034..6caa710 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -11,41 +11,24 @@ class Configuration { public: - class Wifi - { - public: - class AP - { - public: - String SSID; - String password; - }; - - Wifi() : active(false) {} - - bool active; - std::list APs; - }; - class Beacon { public: - Beacon() : message("LoRa Tracker, Info: github.com/peterus/LoRa_APRS_Tracker") {} + Beacon() : message("LoRa Tracker, Info: github.com/lora-aprs/LoRa_APRS_Tracker"), timeout(1), symbol("["), overlay("/") {} String message; - int timeout = 1; - String symbol; - String overlay; - + int timeout; + String symbol; + String overlay; }; class Smart_Beacon { public: - Smart_Beacon() : active(true), turn_min(25), slow_rate(300), slow_speed(10), fast_rate(60), fast_speed(100), min_tx_dist(100), min_bcn(5) {} - + Smart_Beacon() : active(false), turn_min(25), slow_rate(300), slow_speed(10), fast_rate(60), fast_speed(100), min_tx_dist(100), min_bcn(5) {} + bool active; - int turn_min; + int turn_min; int slow_rate; int slow_speed; int fast_rate; @@ -54,34 +37,10 @@ public: int min_bcn; }; - class APRS_IS - { - public: - APRS_IS() : active(false), server("euro.aprs2.net"), port(14580), beacon(true), beaconTimeout(15) {} - - bool active; - String password; - String server; - int port; - bool beacon; - int beaconTimeout; - }; - - class Digi - { - public: - Digi() : active(false), forwardTimeout(5), beacon(true), beaconTimeout(30) {} - - bool active; - int forwardTimeout; - bool beacon; - int beaconTimeout; - }; - class LoRa { public: - LoRa() : frequencyRx(433775E3), frequencyTx(433775E3), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {} + LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {} long frequencyRx; long frequencyTx; @@ -91,44 +50,13 @@ public: int codingRate4; }; - class Display - { - public: - Display() : alwaysOn(true), timeout(10), overwritePin(0) {} - - bool alwaysOn; - int timeout; - int overwritePin; - }; - - class Ftp - { - public: - class User - { - public: - String name; - String password; - }; - - Ftp() : active(false) {} - - bool active; - std::list users; - }; - - Configuration() : callsign("NOCALL-10") {}; + Configuration() : callsign("NOCALL-10"), debug(false) {}; String callsign; - Wifi wifi; + bool debug; Beacon beacon; Smart_Beacon smart_beacon; - APRS_IS aprs_is; - Digi digi; LoRa lora; - Display display; - Ftp ftp; - bool debug; }; class ConfigurationManagement diff --git a/src/display.cpp b/src/display.cpp index a399f18..c705427 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -5,6 +5,7 @@ #include "display.h" #include "pins.h" +#include "logger.h" Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST); @@ -18,8 +19,9 @@ void setup_display() Wire.begin(OLED_SDA, OLED_SCL); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { - Serial.println("SSD1306 allocation failed"); - while (1); + logPrintlnE("SSD1306 allocation failed"); + while(true) + {} } display.clearDisplay(); diff --git a/src/logger.h b/src/logger.h index 51ddedb..8d7242b 100644 --- a/src/logger.h +++ b/src/logger.h @@ -17,10 +17,10 @@ public: }; static Logger & instance() - { - static Logger _instance; - return _instance; - } + { + static Logger _instance; + return _instance; + } ~Logger() {} diff --git a/src/power_management.cpp b/src/power_management.cpp index e8d14c3..678651a 100644 --- a/src/power_management.cpp +++ b/src/power_management.cpp @@ -75,38 +75,12 @@ double PowerManagement::getBatteryVoltage() return axp.getBattVoltage() / 1000.0; } -// cppcheck-suppress unusedFunction -String PowerManagement::getBatteryVoltageStr() -{ - double volts = axp.getBattVoltage() / 1000.0; - return String(volts); - -} - // cppcheck-suppress unusedFunction double PowerManagement::getBatteryChargeDischargeCurrent() { - if(axp.isChargeing()) { return axp.getBattChargeCurrent(); } return -1.0 * axp.getBattDischargeCurrent(); - } - - -// cppcheck-suppress unusedFunction -String PowerManagement::getBatteryChargeDischargeCurrentStr() -{ - double amps = 0.0; - if(axp.isChargeing()) - { - amps = axp.getBattChargeCurrent(); - } - else - { - amps = -1.0 * axp.getBattDischargeCurrent(); - }; - return String(amps,'\000'); } - diff --git a/src/power_management.h b/src/power_management.h index 2d5fd2e..7ac590a 100644 --- a/src/power_management.h +++ b/src/power_management.h @@ -25,9 +25,6 @@ public: double getBatteryVoltage(); double getBatteryChargeDischargeCurrent(); - String getBatteryVoltageStr(); - String getBatteryChargeDischargeCurrentStr(); - private: AXP20X_Class axp; };