first beta test

This commit is contained in:
richonguzman
2023-06-17 18:28:40 -04:00
parent 08191ebb04
commit 89176a8842
10 changed files with 161 additions and 8 deletions
+3
View File
@@ -48,5 +48,8 @@
"other": {
"beaconInterval": 5,
"rememberStationTime": 30
},
"bme": {
"active": true
}
}
+3 -1
View File
@@ -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
mikalhart/TinyGPSPlus @ 1.0.3
adafruit/Adafruit Unified Sensor@^1.1.9
adafruit/Adafruit BME280 Library@^2.2.2
+2
View File
@@ -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() {
+113
View File
@@ -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;
}
}
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef BME_UTILS_H_
#define BME_UTILS_H_
#include <Arduino.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
namespace BME_Utils {
void setup();
String generateTempString(float bmeTemp);
String generateHumString(float bmeHum);
String generatePresString(float bmePress);
String readDataSensor();
}
#endif
+2
View File
@@ -60,6 +60,8 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) {
syslog.active = data["syslog"]["active"].as<bool>();
syslog.server = data["syslog"]["server"].as<String>();
syslog.port = data["syslog"]["port"].as<int>();
bme.active = data["bme"]["active"].as<bool>();
configFile.close();
}
+6
View File
@@ -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();
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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 + ")");
}
}
+12 -5
View File
@@ -4,10 +4,12 @@
#include <SPIFFS.h>
#include <WiFi.h>
#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!");
}
}