add radmon support

This commit is contained in:
Bartosz Mazurczak
2025-01-12 19:46:34 +01:00
parent 9dbc2dec58
commit ebd10751fa
2 changed files with 52 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
# Geiger-interface - WIP
#### TODO:
- RadMon integration
- ~~RadMon integration~~
- Clean code
- check MQTT reliability
- ~~OLED display support~~
@@ -10,6 +10,7 @@
- Wifi connection
- MQTT server address
- GMC accound and geiger ID
- RadMon Username and Password
After **save** interface should connect to Wifi and send data :) If you provide wrong data you can enable captive portal by double reset of ESP.
@@ -43,7 +44,7 @@ reload configuration and voilà!
<img src="assets/ha2.png" width="600">
### RadMon integration
**TBD**
- Create account on https://radmon.org/
### J3x5 Tube specification
| Property | J3x5 |

View File

@@ -43,6 +43,8 @@ char mqttUser[50] = "";
char mqttPass[50] = "";
char gmcAccountID[50] = "";
char gmcDeviceID[50] = "";
char rmUser[50] = "";
char rmPass[50] = "";
bool shouldSaveConfig = false;
char buf[10];
@@ -84,6 +86,8 @@ void saveConfigFile()
json["mqttPass"] = mqttPass;
json["gmcAccountID"] = gmcAccountID;
json["gmcDeviceID"] = gmcDeviceID;
json["rmUser"] = rmUser;
json["rmPass"] = rmPass;
File configFile = FileFS.open(JSON_CONFIG_FILE, "w");
if (!configFile)
@@ -127,7 +131,8 @@ bool loadConfigFile()
strcpy(mqttPass, json["mqttPass"]);
strcpy(gmcAccountID, json["gmcAccountID"]);
strcpy(gmcDeviceID, json["gmcDeviceID"]);
strcpy(rmUser, json["rmUser"]);
strcpy(rmPass, json["rmPass"]);
return true;
}
@@ -201,6 +206,41 @@ String printLocalTime()
return String(buffer);
}
void radmonUpload(int cpm) {
const char *cmdFormat = "http://radmon.org/radmon.php?function=submit&user=%s&password=%s&value=%d&unit=CPM";
char url[256];
HTTPClient http2;
// create the request URL
sprintf(url, cmdFormat, rmUser, rmPass, cpm);
Serial.print("[HTTP] begin: ");
Serial.println(url);
if (http2.begin(espClient2, url)) {
Serial.print("[HTTP] GET...");
// start connection and send HTTP header
int httpCode = http2.GET();
// HTTP header has been sent and server response header has been handled
Serial.printf(" code: %d\n", httpCode);
// httpCode will be negative on error
if (httpCode > 0) {
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http2.getString();
Serial.println(payload);
}
}
else {
Serial.printf("[HTTP] GET failed, error: %s\n", http2.errorToString(httpCode).c_str());
}
http2.end();
}
}
void setup() {
// 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.
@@ -228,6 +268,8 @@ void setup() {
WiFiManagerParameter custom_mqttPass("mqttPass", "MQTT Password", mqttPass, 50);
WiFiManagerParameter custom_gmcAccountID("gmcAccountID", "GMC MAP Account ID", gmcAccountID, 50);
WiFiManagerParameter custom_gmcDeviceID("gmcDeviceID", "GMC MAP Device ID", gmcDeviceID, 50);
WiFiManagerParameter custom_rmUser("rmUser", "RadMon User", rmUser, 50);
WiFiManagerParameter custom_rmPass("rmPass", "RadMon Password", rmPass, 50);
wm.addParameter(&custom_mqttServer);
@@ -235,6 +277,8 @@ void setup() {
wm.addParameter(&custom_mqttPass);
wm.addParameter(&custom_gmcAccountID);
wm.addParameter(&custom_gmcDeviceID);
wm.addParameter(&custom_rmUser);
wm.addParameter(&custom_rmPass);
// wm.resetSettings();
bool res;
@@ -263,12 +307,16 @@ void setup() {
strcpy(mqttPass, custom_mqttPass.getValue());
strcpy(gmcAccountID, custom_gmcAccountID.getValue());
strcpy(gmcDeviceID, custom_gmcDeviceID.getValue());
strcpy(rmUser, custom_rmUser.getValue());
strcpy(rmPass, custom_rmPass.getValue());
Serial.println("The values in the file are: ");
Serial.println("\tmqtt_server : " + String(mqttServer));
Serial.println("\tmqtt_user : " + String(mqttUser));
Serial.println("\tmqtt_pass : " + String(mqttPass));
Serial.println("\tgmc_AccountID : " + String(gmcAccountID));
Serial.println("\tgmc_DeviceID : " + String(gmcDeviceID));
Serial.println("\trm_User : " + String(rmUser));
Serial.println("\trm_Pass : " + String(rmPass));
if (shouldSaveConfig)
{