RadMon support

This commit is contained in:
Bartosz Mazurczak
2025-01-14 11:33:57 +01:00
parent 55578b5636
commit 962eddbd40
2 changed files with 52 additions and 37 deletions

View File

@@ -46,6 +46,7 @@ reload configuration and voilà!
### RadMon integration ### RadMon integration
- Create account on https://radmon.org/ - Create account on https://radmon.org/
- Login, go to **Control Panel** -> fill form to add sensor
### J3x5 Tube specification ### J3x5 Tube specification
| Property | J3x5 | | Property | J3x5 |

View File

@@ -241,6 +241,36 @@ void radmonUpload(int cpm) {
} }
} }
void gmcUpload() {
Serial.print("[HTTP] begin...\n");
GMCMap_Request = GMCMap_Request_payload + "?AID=" + gmcAccountID + "&GID=" + gmcDeviceID + "&CPM=" + buf + "&ACPM=" + buf + "&uSV=" + buf2;
Serial.println(GMCMap_Request);
HTTPClient http;
if (http.begin(espClient2, GMCMap_Request)) { // HTTP
Serial.print("[HTTP] GET...\n");
int httpCode = http.GET();
if (httpCode > 0) {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
if (payload.indexOf("ERR0") > 0) GMCMap = "OK";
if (payload.indexOf("ERR1") > 0) GMCMap = "Error! User is not found";
if (payload.indexOf("ERR2") > 0) GMCMap = "Error! Geiger Counter is not found";
if (payload.indexOf("Warning") > 0) GMCMap = "Warning! The Geiger Counter location changed, please confirm the location";
Serial.println(GMCMap);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
GMCMap = http.errorToString(httpCode).c_str();
}
http.end();
} else {
Serial.println("[HTTP] Unable to connect");
GMCMap = "Unable to connect";
}
}
void setup() { void setup() {
// WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP // WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// it is a good practice to make sure your code sets wifi mode how you want it. // it is a good practice to make sure your code sets wifi mode how you want it.
@@ -251,7 +281,7 @@ void setup() {
initLittleFS(); initLittleFS();
display.begin(i2c_Address, true); display.begin(i2c_Address, true);
display.setContrast (0);
lcdPrint("Geiger Interace"); lcdPrint("Geiger Interace");
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS); drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
@@ -334,6 +364,7 @@ void setup() {
} }
void loop() { void loop() {
// Double Reset Detection
drd->loop(); drd->loop();
// if MQTT server provided // if MQTT server provided
@@ -342,12 +373,6 @@ void loop() {
reconnect(); reconnect();
} }
if(millis() >= time_now + 5000){
time_now += 5000;
client.publish("esp32/heartbeat", "PING");
}
if (millis() >= mold + 60000) { if (millis() >= mold + 60000) {
ltoa(GeigerCounts, buf, 10); ltoa(GeigerCounts, buf, 10);
dtostrf(GeigerCounts*TUBE_FACTOR, -4, 2, buf2); dtostrf(GeigerCounts*TUBE_FACTOR, -4, 2, buf2);
@@ -358,45 +383,34 @@ void loop() {
lcdUpdate(); lcdUpdate();
} }
client.loop(); client.loop();
//if(millis() >= time_now + 5000){
// time_now += 5000;
// client.publish("esp32/heartbeat", "PING");
//}
} }
// Update time on LCD
getLocalTime(&timeinfo); getLocalTime(&timeinfo);
if (timeinfo.tm_sec == 0){ if (timeinfo.tm_sec == 0){
lcdUpdate(); lcdUpdate();
} }
// if GMC IDs provided // Sending HTTP requests in every 10 minutes
if (String(gmcAccountID) != "") {
currentMillis = millis(); currentMillis = millis();
if (currentMillis - previousMillis_10m >= interval_10m) { if (currentMillis - previousMillis_10m >= interval_10m) {
previousMillis_10m = currentMillis; previousMillis_10m = currentMillis;
Serial.print("[HTTP] begin...\n");
GMCMap_Request = GMCMap_Request_payload + "?AID=" + gmcAccountID + "&GID=" + gmcDeviceID + "&CPM=" + buf + "&ACPM=" + buf + "&uSV=" + buf2; // if RadMon username provided
Serial.println(GMCMap_Request); if (String(rmUser) != "") {
HTTPClient http; radmonUpload(atoi(buf));
if (http.begin(espClient2, GMCMap_Request)) { // HTTP
Serial.print("[HTTP] GET...\n");
int httpCode = http.GET();
if (httpCode > 0) {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
if (payload.indexOf("ERR0") > 0) GMCMap = "OK";
if (payload.indexOf("ERR1") > 0) GMCMap = "Error! User is not found";
if (payload.indexOf("ERR2") > 0) GMCMap = "Error! Geiger Counter is not found";
if (payload.indexOf("Warning") > 0) GMCMap = "Warning! The Geiger Counter location changed, please confirm the location";
Serial.println(GMCMap);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
GMCMap = http.errorToString(httpCode).c_str();
}
http.end();
} else {
Serial.println("[HTTP] Unable to connect");
GMCMap = "Unable to connect";
} }
// if GMC IDs provided
if (String(gmcAccountID) != "") {
gmcUpload();
} }
} }
} }