Skip to content

Commit

Permalink
first edit
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed May 23, 2024
1 parent 6090b83 commit 7c17cd2
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 43 deletions.
12 changes: 9 additions & 3 deletions data/igate_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@
"username": "",
"password": ""
},
"battery": {
"sendInternalVoltage": false,
"sendExternalVoltage": false,
"externalVoltagePin": 34,
"internalMonitor": false,
"internalSleepVoltage": 0.0,
"externalMonitor": false,
"externalSleepVoltage": 0.0
},
"other": {
"rememberStationTime": 30,
"sendBatteryVoltage": false,
"externalVoltageMeasurement": false,
"externalVoltagePin": 34,
"lowPowerMode": false,
"lowVoltageCutOff": 0,
"backupDigiMode": false,
Expand Down
2 changes: 2 additions & 0 deletions src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ String firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seven
void setup() {
Serial.begin(115200);
POWER_Utils::setup();
BATTERY_Utils::checkBatteryHealth();
Utils::setupDisplay();
Config.check();
LoRa_Utils::setup();
Expand Down Expand Up @@ -111,6 +112,7 @@ void setup() {
Config.loramodule.rxActive = false;
}
#endif

WIFI_Utils::setup();
SYSLOG_Utils::setup();
BME_Utils::setup();
Expand Down
10 changes: 9 additions & 1 deletion src/battery_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace BATTERY_Utils {
int sample;
int sampleSum = 0;
for (int i = 0; i < 100; i++) {
sample = analogRead(Config.externalVoltagePin);
sample = analogRead(Config.battery.externalVoltagePin);
sampleSum += sample;
delayMicroseconds(50);
}
Expand All @@ -88,4 +88,12 @@ namespace BATTERY_Utils {
}
}

void checkBatteryHealth() {
if (Config.battery.internalMonitor) {
//medir interna y ver si dormir
}
if (Config.battery.externalMonitor) {
//medir externa y ver si dormir
}
}
}
1 change: 1 addition & 0 deletions src/battery_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace BATTERY_Utils {
float checkBattery();
float checkExternalVoltage();
void checkIfShouldSleep();
void checkBatteryHealth();

}

Expand Down
45 changes: 30 additions & 15 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ void Configuration::writeFile() {
// data["other"]["igateSendsLoRaBeacons"] = igateSendsLoRaBeacons;
// data["other"]["igateRepeatsLoRaPackets"] = igateRepeatsLoRaPackets;
data["other"]["rememberStationTime"] = rememberStationTime;
data["other"]["sendBatteryVoltage"] = sendBatteryVoltage;
data["other"]["externalVoltageMeasurement"] = externalVoltageMeasurement;
data["other"]["externalVoltagePin"] = externalVoltagePin;

data["digi"]["mode"] = digi.mode;
// data["digi"]["comment"] = digi.comment;
Expand Down Expand Up @@ -110,6 +107,14 @@ void Configuration::writeFile() {
data["other"]["rebootMode"] = rebootMode;
data["other"]["rebootModeTime"] = rebootModeTime;

data["battery"]["sendInternalVoltage"] = battery.sendInternalVoltage;
data["battery"]["sendExternalVoltage"] = battery.sendExternalVoltage;
data["battery"]["externalVoltagePin"] = battery.externalVoltagePin;
data["battery"]["internalMonitor"] = battery.internalMonitor;
data["battery"]["internalSleepVoltage"] = battery.internalSleepVoltage;
data["battery"]["externalMonitor"] = battery.externalMonitor;
data["battery"]["externalSleepVoltage"] = battery.externalSleepVoltage;

serializeJson(data, configFile);

configFile.close();
Expand Down Expand Up @@ -144,9 +149,6 @@ bool Configuration::readFile() {

callsign = data["callsign"].as<String>();
rememberStationTime = data["other"]["rememberStationTime"].as<int>();
sendBatteryVoltage = data["other"]["sendBatteryVoltage"].as<bool>();
externalVoltageMeasurement = data["other"]["externalVoltageMeasurement"].as<bool>();
externalVoltagePin = data["other"]["externalVoltagePin"].as<int>();

aprs_is.passcode = data["aprs_is"]["passcode"].as<String>();
aprs_is.server = data["aprs_is"]["server"].as<String>();
Expand Down Expand Up @@ -184,6 +186,14 @@ bool Configuration::readFile() {
rebootMode = data["other"]["rebootMode"].as<bool>();
rebootModeTime = data["other"]["rebootModeTime"].as<int>();

battery.sendInternalVoltage = data["battery"]["sendInternalVoltage"].as<bool>();
battery.sendExternalVoltage = data["battery"]["sendExternalVoltage"].as<bool>();
battery.externalVoltagePin = data["battery"]["externalVoltagePin"].as<int>();
battery.internalMonitor = data["battery"]["internalMonitor"].as<bool>();
battery.internalSleepVoltage = data["battery"]["internalSleepVoltage"].as<float>();
battery.externalMonitor = data["battery"]["externalMonitor"].as<bool>();
battery.externalSleepVoltage = data["battery"]["externalSleepVoltage"].as<float>();

int stationMode = data["stationMode"].as<int>(); // deprecated but need to specify config version

if (stationMode == 0) {
Expand Down Expand Up @@ -356,18 +366,23 @@ void Configuration::init() {
// beaconInterval = 15; // deprecated
// igateSendsLoRaBeacons = false; // deprecated
// igateRepeatsLoRaPackets = false; // deprecated
rememberStationTime = 30;
sendBatteryVoltage = false;
externalVoltageMeasurement = false;
externalVoltagePin = 34;
rememberStationTime = 30;

lowPowerMode = false;
lowVoltageCutOff = 0;

lowPowerMode = false;
lowVoltageCutOff = 0;
backupDigiMode = false;

backupDigiMode = false;
rebootMode = false;
rebootModeTime = 0;

rebootMode = false;
rebootModeTime = 0;
battery.sendInternalVoltage = false;
battery.sendExternalVoltage = false;
battery.externalVoltagePin = 34;
battery.internalMonitor = false;
battery.internalSleepVoltage = 0.0;
battery.externalMonitor = false;
battery.externalSleepVoltage = 0.0;

Serial.println("All is Written!");
}
Expand Down
27 changes: 17 additions & 10 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ class OTA {
String password;
};


class BATTERY {
public:
bool sendInternalVoltage;
bool sendExternalVoltage;
int externalVoltagePin;
bool internalMonitor;
float internalSleepVoltage;
bool externalMonitor;
float externalSleepVoltage;
};


class Configuration {
Expand All @@ -115,26 +124,24 @@ class Configuration {
// bool igateSendsLoRaBeacons; // deprecated
// bool igateRepeatsLoRaPackets; // deprecated
int rememberStationTime;
bool sendBatteryVoltage;
bool externalVoltageMeasurement;
int externalVoltagePin;
bool lowPowerMode;
double lowVoltageCutOff;
bool backupDigiMode;
bool rebootMode;
int rebootModeTime;
bool backupDigiMode; // new
bool rebootMode; // new
int rebootModeTime; // new
std::vector<WiFi_AP> wifiAPs;
WiFi_Auto_AP wifiAutoAP;
Beacon beacon; // new
Beacon beacon; // new
DIGI digi;
TNC tnc; // new
TNC tnc; // new
APRS_IS aprs_is;
LoraModule loramodule;
Display display;
SYSLOG syslog;
BME bme;
OTA ota;

BATTERY battery; // new

void init();
void writeFile();
void check();
Expand Down
12 changes: 6 additions & 6 deletions src/power_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ namespace POWER_Utils {
PMU.setSysPowerDownVoltage(2600);
#endif

#ifdef BATTERY_PIN
pinMode(BATTERY_PIN, INPUT);
#endif

#ifdef INTERNAL_LED_PIN
pinMode(INTERNAL_LED_PIN, OUTPUT);
#endif

if (Config.externalVoltageMeasurement) {
pinMode(Config.externalVoltagePin, INPUT);
#ifdef BATTERY_PIN
pinMode(BATTERY_PIN, INPUT);
#endif

if (Config.battery.sendExternalVoltage) {
pinMode(Config.battery.externalVoltagePin, INPUT);
}

#ifdef VEXT_CTRL
Expand Down
4 changes: 2 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ namespace Utils {
secondaryBeaconPacket += Config.beacon.comment;

#ifdef BATTERY_PIN
if (Config.sendBatteryVoltage) {
if (Config.battery.sendInternalVoltage) {
String batteryInfo = "Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V";
beaconPacket += " " + batteryInfo;
secondaryBeaconPacket += " " + batteryInfo;
sixthLine = " ( " + batteryInfo + ")";
}
#endif

if (Config.externalVoltageMeasurement) {
if (Config.battery.sendExternalVoltage) {
String externalVoltage = String(BATTERY_Utils::checkExternalVoltage(),2) + "V";
beaconPacket += " Ext=" + externalVoltage;
secondaryBeaconPacket += " Ext=" + externalVoltage;
Expand Down
13 changes: 7 additions & 6 deletions src/web_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ namespace WEB_Utils {
// Config.igateSendsLoRaBeacons = request->hasParam("other.igateSendsLoRaBeacons", true);
// Config.igateRepeatsLoRaPackets = request->hasParam("other.igateRepeatsLoRaPackets", true);
Config.rememberStationTime = request->getParam("other.rememberStationTime", true)->value().toInt();
Config.sendBatteryVoltage = request->hasParam("other.sendBatteryVoltage", true);
Config.externalVoltageMeasurement = request->hasParam("other.externalVoltageMeasurement", true);

if (Config.externalVoltageMeasurement) {
Config.externalVoltagePin = request->getParam("other.externalVoltagePin", true)->value().toInt();
}

Config.rebootMode = request->hasParam("other.rebootMode", true);
Config.rebootModeTime = request->getParam("other.rebootModeTime", true)->value().toInt();
Expand All @@ -187,6 +181,13 @@ namespace WEB_Utils {

Config.backupDigiMode = request->hasParam("other.backupDigiMode", true);

Config.battery.sendInternalVoltage = request->hasParam("battery.sendInternalVoltage", true);
Config.battery.sendExternalVoltage = request->hasParam("battery.sendExternalVoltage", true);

if (Config.battery.sendExternalVoltage) {
Config.battery.externalVoltagePin = request->getParam("battery.externalVoltagePin", true)->value().toInt();
}

if (Config.bme.active) {
Config.beacon.symbol = "_";
}
Expand Down

0 comments on commit 7c17cd2

Please sign in to comment.