diff --git a/data/igate_conf.json b/data/igate_conf.json index c36a8c9..b41a5d3 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -4,12 +4,16 @@ "wifi": { "active": true, "AP": [ - { "SSID": "Jimenicita", "password": "mg6wyMhqRnxk" }, - { "SSID": "Richon", "password": "k4fPnmg5qnyf" } - ], - "wifiPositions": [ - { "latitude": -33.0312173, "longitude": -71.5795816 }, - { "latitude": -33.0337121, "longitude": -71.5738217 } + { "SSID": "Jimenicita", + "Password": "mg6wyMhqRnxk", + "Latitude": -33.0312173, + "Longitude": -71.5795816 + }, + { "SSID": "Richon", + "Password": "k4fPnmg5qnyf", + "Latitude": -33.0337121, + "Longitude": -71.5738217 + } ] }, "aprs_is": { @@ -27,6 +31,6 @@ }, "display": { "always_on": true, - "timeout": 10 + "timeout": 5 } } diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index bc7ced3..1bd507c 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -2,19 +2,30 @@ #include #include #include -#include "iGate_config.h" -#include "pins_config.h" -#include #include #include -#include "display.h" +#include + +#include "pins_config.h" +#include "igate_config.h" +#include "display.h" +#include "iGate_config_OLD.h" + +WiFiClient espClient; +String ConfigurationFilePath = "/igate_conf.json"; +Configuration Config(ConfigurationFilePath); + -WiFiClient espClient; uint32_t lastTxTime = 0; static bool beacon_update = true; unsigned long previousWiFiMillis = 0; static uint32_t lastRxTxTime = millis(); static bool displayEcoMode = true; + +static int myWiFiAPIndex = 0; +int myWiFiAPSize = Config.wifiAPs.size(); +WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; + String firstLine, secondLine, thirdLine, fourthLine; void load_config() { @@ -118,6 +129,23 @@ String process_aprsisPacket(String aprsisMessage) { return newLoraPacket; } +void showConfig() { + Serial.println(myWiFiAPSize); + Serial.println(myWiFiAPIndex); + if(myWiFiAPIndex >= (myWiFiAPSize-1)) { + myWiFiAPIndex = 0; + } else { + myWiFiAPIndex++; + } + Serial.println(myWiFiAPIndex); + currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; + Serial.println(currentWiFi->ssid); + Serial.println(currentWiFi->password); + Serial.println(currentWiFi->latitude); + Serial.println(currentWiFi->longitude); + Serial.println(Config.callsign); +} + void setup() { Serial.begin(115200); Serial.println("Starting iGate: " + iGateCallsign + "\n"); @@ -129,7 +157,9 @@ void setup() { } void loop() { - String wifiState, aprsisState; + showConfig(); + delay(2000); + /*String wifiState, aprsisState; firstLine = "LoRa iGate: " + iGateCallsign; secondLine = " "; thirdLine = " "; @@ -216,4 +246,6 @@ void loop() { } } } + + */ } \ No newline at end of file diff --git a/src/iGate_config.h b/src/iGate_config.h index 9c4d042..a206a84 100644 --- a/src/iGate_config.h +++ b/src/iGate_config.h @@ -1,32 +1,166 @@ -#ifndef IGATE_CONFIG_H_ -#define IGATE_CONFIG_H_ +#ifndef GPS_CONFIG_H_ +#define GPS_CONFIG_H_ #include +#include +#include +#include +#include -#define VERSION "V.0.0.1" //MEGA BETA +class WiFi_AP { +public: + String ssid; + String password; + double latitude; + double longitude; +}; -#define WIFI_SSID "Richon" -#define WIFI_PASSWORD "k4fPnmg5qnyf" +class APRS_IS { +public: + bool active; + int passcode; + String server; + int port; -#define BeaconInterval 900000 // 15 minutes = 900000 seg -#define WifiCheckInterval 60000 // wificheck after one minute +}; -#define EcoModeDisplayTime 5000 // after 5 segs Display goes off +class LoRa { +public: + long frequency; + int spreadingFactor; + long signalBandwidth; + int codingRate4; + int power; +}; -const String iGateCallsign = "CD2RXU-11"; // use your own iGate Callsign -const String iGatePasscode = "23201"; // use your one iGate Callsign Passcode -const String AprsServer = "radioaficion.pro"; // write the address of the aprs server near you , like "brazil.aprs2.net"; -const int AprsServerPort = 14580; -const String AprsSoftwareName = "ESP32_LoRa_iGate"; -const String AprsSoftwareVersion = "0.0.9"; -const int AprsReportingDistance = 20; // kms -const String AprsFilter = "t/m/" + iGateCallsign + "/" + (String)AprsReportingDistance; +class Display { +public: + bool always_on; + int timeout; +}; -const String iGateComment = "LoRa_APRS_iGate https://github.com/richonguzman/LoRa_APRS_iGate"; +class Configuration { +public: -const String Latitude = "3302.02S"; // write your own iGate latitude and longitude -const String Longitude = "07134.42W"; + String callsign; + String comment; + std::vector wifiAPs; -String iGateBeaconPacket = iGateCallsign + ">APRS,TCPIP*,qAC,CHILE:=" + Latitude + "L" + Longitude+ "&" + iGateComment + "\n"; + Configuration(String &filePath) { + _filePath = filePath; + if (!SPIFFS.begin(false)) { + Serial.println("SPIFFS Mount Failed"); + return; + } + readFile(SPIFFS, _filePath.c_str()); + } -#endif \ No newline at end of file +private: + String _filePath; + + void readFile(fs::FS &fs, const char *fileName) { + StaticJsonDocument<1024> data; + File configFile = fs.open(fileName, "r"); + DeserializationError error = deserializeJson(data, configFile); + if (error) { + Serial.println("Failed to read file, using default configuration"); + } + + JsonArray WiFiArray = data["wifi"]["AP"]; + for (int i = 0; i < WiFiArray.size(); i++) { + WiFi_AP wifiap; + wifiap.ssid = WiFiArray[i]["SSID"].as(); + wifiap.password = WiFiArray[i]["Password"].as(); + wifiap.latitude = WiFiArray[i]["Latitude"].as(); + wifiap.longitude = WiFiArray[i]["Longitude"].as(); + + wifiAPs.push_back(wifiap); + } + + callsign = data["callsign"].as(); + comment = data["comment"].as(); + + + /*conf.aprs_is.active = data["aprs_is"]["active"]; + conf.aprs_is.passcode = data["aprs_is"]["passcode"]; + conf.aprs_is.server = data["aprs_is"]["server"]; + conf.aprs_is.port = data["aprs_is"]["port"]; + + conf.lora.port = data["lora"]["frequency"]; + conf.lora.port = data["lora"]["spreading_factor"]; + conf.lora.port = data["lora"]["signal_bandwidth"]; + conf.lora.port = data["lora"]["coding_rate4"]; + conf.lora.port = data["lora"]["power"]; + + conf.display.always_on = data["display"]["always_on"]; + conf.display.timeout = data["display"]["timeout"];*/ + + + configFile.close(); + } +}; +#endif + +/*class Configuration { +public: + /*class WiFiAccessPoint { + public: + class WiFiAP { + WiFiAP(): SSID(), Password(), Latitude(), Longitude() { + } + std::string SSID; + std::string Password; + long Latitude; + long Longitude; + } + + WiFiAccessPoint() : active() { + } + bool active; + };*/ + + /*class APRSIS { + public: + APRSIS() : active(), passcode(), server(), port() { + } + bool active; + int passcode; + String server; + int port; + + }; + + class LoRa { + public: + LoRa() : frequency(), power(), spreadingFactor(), signalBandwidth(), codingRate4() { + } + long frequency; + int spreadingFactor; + long signalBandwidth; + int codingRate4; + int power; + }; + + class Display { + public: + Display() : always_on(), timeout() { + } + bool always_on; + int timeout; + }; + + + Configuration() : callsign(), comment() { + } + + String callsign; + String comment; + /// WIFI + std::list beacons; + /// + WiFiAccessPioint wifiap; + APRSIS aprsis; + LoRa lora; + Display display; + +};*/ \ No newline at end of file diff --git a/src/iGate_config_OLD.h b/src/iGate_config_OLD.h new file mode 100644 index 0000000..9c4d042 --- /dev/null +++ b/src/iGate_config_OLD.h @@ -0,0 +1,32 @@ +#ifndef IGATE_CONFIG_H_ +#define IGATE_CONFIG_H_ + +#include + +#define VERSION "V.0.0.1" //MEGA BETA + +#define WIFI_SSID "Richon" +#define WIFI_PASSWORD "k4fPnmg5qnyf" + +#define BeaconInterval 900000 // 15 minutes = 900000 seg +#define WifiCheckInterval 60000 // wificheck after one minute + +#define EcoModeDisplayTime 5000 // after 5 segs Display goes off + +const String iGateCallsign = "CD2RXU-11"; // use your own iGate Callsign +const String iGatePasscode = "23201"; // use your one iGate Callsign Passcode +const String AprsServer = "radioaficion.pro"; // write the address of the aprs server near you , like "brazil.aprs2.net"; +const int AprsServerPort = 14580; +const String AprsSoftwareName = "ESP32_LoRa_iGate"; +const String AprsSoftwareVersion = "0.0.9"; +const int AprsReportingDistance = 20; // kms +const String AprsFilter = "t/m/" + iGateCallsign + "/" + (String)AprsReportingDistance; + +const String iGateComment = "LoRa_APRS_iGate https://github.com/richonguzman/LoRa_APRS_iGate"; + +const String Latitude = "3302.02S"; // write your own iGate latitude and longitude +const String Longitude = "07134.42W"; + +String iGateBeaconPacket = iGateCallsign + ">APRS,TCPIP*,qAC,CHILE:=" + Latitude + "L" + Longitude+ "&" + iGateComment + "\n"; + +#endif \ No newline at end of file diff --git a/src/igate_config.cpp b/src/igate_config.cpp new file mode 100644 index 0000000..5734167 --- /dev/null +++ b/src/igate_config.cpp @@ -0,0 +1,72 @@ +#include "igate_config.h" +/*#include "Arduino.h" +#include +#include +#include +#include + +/*class WiFi_AP { +public: + String ssid; + String password; + double latitude; + double longitude; +}; + +class Configuration { +public: + //std::vector wifiAPs; + + Configuration(String &filePath) { + _filePath = filePath; + if (!SPIFFS.begin(false)) { + Serial.println("SPIFFS Mount Failed"); + return; + } + readFile(SPIFFS, _filePath.c_str()); + } + +private: + String _filePath; + + void readFile(fs::FS &fs, const char *fileName) { + StaticJsonDocument<1024> data; + File configFile = fs.open(fileName, "r"); + DeserializationError error = deserializeJson(data, configFile); + if (error) { + Serial.println("Failed to read file, using default configuration"); + } + + Configuration conf; + + conf.callsign = data["callsign"]; + conf.comment = data["comment"]; + + JsonArray WiFiArray = doc["wifi"]["AP"]; + for (int i = 0; i < WiFiArray.size(); i++) { + WiFi_AP wifi; + wifi.ssid = WiFiArray[i]["wifi"]["AP"]["SSID"].as(); + wifi.password = WiFiArray[i]["wifi"]["AP"]["Password"].as(); + wifi.latitude = WiFiArray[i]["wifi"]["AP"]["Latitude"].as(); + wifi.longitude = WiFiArray[i]["wifi"]["AP"]["Longitude"].as(); + + conf.wifiAPs.push_back(wifi); + } + + conf.aprs_is.active = data["aprs_is"]["active"]; + conf.aprs_is.passcode = data["aprs_is"]["passcode"]; + conf.aprs_is.server = data["aprs_is"]["server"]; + conf.aprs_is.port = data["aprs_is"]["port"]; + + conf.lora.port = data["lora"]["frequency"]; + conf.lora.port = data["lora"]["spreading_factor"]; + conf.lora.port = data["lora"]["signal_bandwidth"]; + conf.lora.port = data["lora"]["coding_rate4"]; + conf.lora.port = data["lora"]["power"]; + + conf.display.always_on = data["display"]["always_on"]; + conf.display.timeout = data["display"]["timeout"]; + + configFile.close(); + } +}*/ \ No newline at end of file diff --git a/src/pins_config.h b/src/pins_config.h index eac6844..77d9c12 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -10,7 +10,10 @@ #define LORA_RST 23 // GPIO14 - SX1276 RST #define LORA_IRQ 26 // GPIO26 - SX1276 IRQ ---->DIO0 -/* +#define OLED_SDA 21 +#define OLED_SCL 22 + +/* (Same pins for LILYGO LoRa32 and ESP32 Wroom Dev ) SX1278-------------------> ESP32 TTGO LILYGO 2.1 or 1.6.1 GND GND DIO1 - @@ -25,8 +28,4 @@ DIO0 26 REST 14 GND - */ - -#define OLED_SDA 21 -#define OLED_SCL 22 - #endif