diff --git a/data/igate_conf.json b/data/igate_conf.json index e1c72bd..60e8b62 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -48,5 +48,8 @@ "other": { "beaconInterval": 5, "rememberStationTime": 30 + }, + "bme": { + "active": true } } \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 3f38ed4..650e163 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,4 +21,6 @@ lib_deps = ayushsharma82/AsyncElegantOTA@^2.2.7 ottowinter/ESPAsyncWebServer-esphome@^3.0.0 esphome/AsyncTCP-esphome@^2.0.0 - mikalhart/TinyGPSPlus @ 1.0.3 \ No newline at end of file + mikalhart/TinyGPSPlus @ 1.0.3 + adafruit/Adafruit Unified Sensor@^1.1.9 + adafruit/Adafruit BME280 Library@^2.2.2 \ No newline at end of file diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 7bde097..85ed9d7 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -12,6 +12,7 @@ #include "wifi_utils.h" #include "digi_utils.h" #include "gps_utils.h" +#include "bme_utils.h" #include "display.h" #include "utils.h" @@ -47,6 +48,7 @@ void setup() { iGateBeaconPacket = GPS_Utils::generateBeacon(); Utils::startOTAServer(); SYSLOG_Utils::setup(); + BME_Utils::setup(); } void loop() { diff --git a/src/bme_utils.cpp b/src/bme_utils.cpp new file mode 100644 index 0000000..cf1a3d1 --- /dev/null +++ b/src/bme_utils.cpp @@ -0,0 +1,113 @@ +#include "bme_utils.h" +#include "configuration.h" +#include "gps_utils.h" +#include "display.h" + +extern Configuration Config; + +namespace BME_Utils { + +Adafruit_BME280 bme; + +void setup() { + if (Config.bme.active) { + bool status; + status = bme.begin(0x76); // Don't forget to join pins for righ direction on BME280! + if (!status) { + Serial.println("Could not find a valid BME280 sensor, check wiring!"); + show_display("ERROR", "", "BME sensor active", "but no sensor found..."); + while (1); // sacar esto para que quede pegado si no encuentra BME280 + } else { + Serial.println("init : BME280 Module ... done!"); + } + } else { + Serial.println("(BME not 'active' in 'igate_config.json')"); + } +} + +String generateTempString(float bmeTemp) { + String strTemp; + strTemp = String((int)bmeTemp); + switch (strTemp.length()) { + case 1: + return "00" + strTemp; + break; + case 2: + return "0" + strTemp; + break; + case 3: + return strTemp; + break; + default: + return "-999"; + } +} + +String generateHumString(float bmeHum) { + String strHum; + strHum = String((int)bmeHum); + switch (strHum.length()) { + case 1: + return "0" + strHum; + break; + case 2: + return strHum; + break; + case 3: + if ((int)bmeHum == 100) { + return "00"; + } else { + return "-99"; + } + break; + default: + return "-99"; + } +} + +String generatePresString(float bmePress) { + String strPress; + strPress = String((int)bmePress); + switch (strPress.length()) { + case 1: + return "000" + strPress + "0"; + break; + case 2: + return "00" + strPress + "0"; + break; + case 3: + return "0" + strPress + "0"; + break; + case 4: + return strPress + "0"; + break; + case 5: + return strPress; + break; + default: + return "-99999"; + } +} + +String readDataSensor() { + String wx, tempStr, humStr, presStr; + float newTemp = bme.readTemperature(); + float newHum = bme.readHumidity(); + float newPress = (bme.readPressure() / 100.0F); + //float bat = analogRead(battery); + //bme.readAltitude(SEALEVELPRESSURE_HPA) + + if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) { + Serial.println("BME280 Module data failed"); + wx = ".../...g...t...r...p...P...h..b....."; + return wx; + } else { + tempStr = generateTempString((newTemp * 1.8) + 32); + humStr = generateHumString(newHum); + presStr = generatePresString(newPress); + wx = ".../...g...t" + tempStr + "r...p...P...h" + humStr + "b" + presStr; + return wx; + } +} + +} \ No newline at end of file diff --git a/src/bme_utils.h b/src/bme_utils.h new file mode 100644 index 0000000..2ce7884 --- /dev/null +++ b/src/bme_utils.h @@ -0,0 +1,18 @@ +#ifndef BME_UTILS_H_ +#define BME_UTILS_H_ + +#include +#include +#include + +namespace BME_Utils { + +void setup(); +String generateTempString(float bmeTemp); +String generateHumString(float bmeHum); +String generatePresString(float bmePress); +String readDataSensor(); + +} + +#endif \ No newline at end of file diff --git a/src/configuration.cpp b/src/configuration.cpp index 7557151..499257a 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -60,6 +60,8 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) { syslog.active = data["syslog"]["active"].as(); syslog.server = data["syslog"]["server"].as(); syslog.port = data["syslog"]["port"].as(); + + bme.active = data["bme"]["active"].as(); configFile.close(); } diff --git a/src/configuration.h b/src/configuration.h index 9f709a0..ec90351 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -52,6 +52,11 @@ public: int port; }; +class BME { +public: + bool active; +}; + class Configuration { public: @@ -66,6 +71,7 @@ public: LoraModule loramodule; Display display; SYSLOG syslog; + BME bme; Configuration(); diff --git a/src/lora_utils.cpp b/src/lora_utils.cpp index 68a78fe..523970c 100644 --- a/src/lora_utils.cpp +++ b/src/lora_utils.cpp @@ -30,7 +30,7 @@ void setup() { LoRa.setCodingRate4(Config.loramodule.codingRate4); LoRa.enableCrc(); LoRa.setTxPower(Config.loramodule.power); - Serial.println("LoRa init done!"); + Serial.println("init : LoRa Module ... done!"); } void sendNewPacket(const String &typeOfMessage, const String &newPacket) { diff --git a/src/syslog_utils.cpp b/src/syslog_utils.cpp index c3adf2c..9874937 100644 --- a/src/syslog_utils.cpp +++ b/src/syslog_utils.cpp @@ -52,7 +52,7 @@ void log(String type, String packet, int rssi, float snr, int freqError) { void setup() { if (Config.syslog.active && (stationMode==1 || stationMode==2)) { udpClient.begin(WiFi.localIP(), 0); - Serial.println("Syslog Server (" + Config.syslog.server + ") connected!\n"); + Serial.println("init : Syslog Server ... done! (at " + Config.syslog.server + ")"); } } diff --git a/src/utils.cpp b/src/utils.cpp index 45c5459..f7fd6ac 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -4,10 +4,12 @@ #include #include #include "configuration.h" +#include "station_utils.h" #include "syslog_utils.h" #include "pins_config.h" #include "wifi_utils.h" #include "lora_utils.h" +#include "bme_utils.h" #include "display.h" #include "utils.h" @@ -86,17 +88,21 @@ void checkBeaconInterval() { Serial.println("---- Sending iGate Beacon ----"); if (stationMode==1 || stationMode==2) { thirdLine = getLocalIP(); + STATION_Utils::deleteNotHeard(); if (lastHeardStation.size() < 10) { fifthLine = "Stations (30min) = " + String(lastHeardStation.size()); } else { fifthLine = "Stations (30min) = " + String(lastHeardStation.size()); } - //fifthLine = ""; sixthLine = ""; seventhLine = ""; show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, "SENDING iGate BEACON", 1000); eigthLine = " listening..."; - espClient.write((iGateBeaconPacket + "\n").c_str()); + if (Config.bme.active) { + espClient.write((iGateBeaconPacket.substring(0,iGateBeaconPacket.indexOf(":=")+20) + "_" + BME_Utils::readDataSensor() + iGateBeaconPacket.substring(iGateBeaconPacket.indexOf(":=")+21) + " + WX" + "\n").c_str()); + } else { + espClient.write((iGateBeaconPacket + "\n").c_str()); + } show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, eigthLine, 0); } else if (stationMode==3 || stationMode==4) { fifthLine = ""; @@ -115,10 +121,11 @@ void checkBeaconInterval() { lastBeaconTx = millis(); lastScreenOn = millis(); beacon_update = false; + } - if (statusAfterBoot) { + /*if (statusAfterBoot) { processStatus(); - } + }*/ } void checkDisplayInterval() { @@ -186,7 +193,7 @@ void startOTAServer() { }); AsyncElegantOTA.begin(&server); server.begin(); - Serial.println("HTTP server started (OTA Firmware Updates)!\n"); + Serial.println("init : OTA Server ... done!"); } }