Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for InfluxDB in HTTPS mode #580

Merged
merged 1 commit into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pio/lib/Globals/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct iData
#if API_MQTT_HASSIO
bool hassio = false;
#endif
bool usehttps = false;
};

extern iData myData;
Expand Down
15 changes: 12 additions & 3 deletions pio/lib/Sender/Sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ bool SenderClass::sendGenericPost(String server, String uri, uint16_t port)
return true;
}

bool SenderClass::sendInfluxDB(String server, uint16_t port, String db, String name, String username, String password)
bool SenderClass::sendInfluxDB(String server, uint16_t port, String db, String name, String username, String password, bool usehttps)
{
HTTPClient http;

Expand All @@ -468,7 +468,16 @@ bool SenderClass::sendInfluxDB(String server, uint16_t port, String db, String n

CONSOLELN(String(F("INFLUXDB: posting to db: ")) + uri);
// configure traged server and uri
http.begin(_client, server, port, uri);

if (usehttps == true)
{
_secureClient.setInsecure();
http.begin(_secureClient, server, port, uri);
}
else
{
http.begin(_client, server, port, uri);
}

if (username.length() > 0)
{
Expand Down Expand Up @@ -853,4 +862,4 @@ uint32_t SenderClass::sendBricks()
http.end();
stopclient();
return next_request_ms;
}
}
2 changes: 1 addition & 1 deletion pio/lib/Sender/Sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SenderClass
bool sendThingSpeak(String token, long Channel);
bool sendGenericPost(String server, String uri, uint16_t port = 80);
bool sendHTTPSPost(String server, String uri);
bool sendInfluxDB(String server, uint16_t port, String db, String name, String username, String password);
bool sendInfluxDB(String server, uint16_t port, String db, String name, String username, String password, bool usehttps);
bool sendPrometheus(String server, uint16_t port, String job, String instance);
bool sendUbidots(String token, String name);
bool sendMQTT(String server, uint16_t port, String username, String password, String name);
Expand Down
34 changes: 17 additions & 17 deletions pio/lib/WiFiManagerKT/WiFiManagerKT.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ const char HTTP_STYLE[] PROGMEM = "<style>body,textarea,input,select{background:
const char HTTP_SCRIPT[] PROGMEM = R"V0G0N(
<script>
var lAPI = [
{"name":"Ubidots", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"empty", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"CraftBeerPi","token":0,"server":1,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"HTTP", "token":1,"server":1,"uri":1,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"TControl", "token":0,"server":1,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"FHEM", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"TCP", "token":1,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"iSpindel.de","token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"InfluxDB", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":1,"username":1,"password":1,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"Prometheus", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":1,"instance":1,"warning1":0,"hassio":0},
{"name":"MQTT", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":1,"password":1,"job":0,"instance":0,"warning1":0,"hassio":1},
{"name":"ThingSpeak", "token":1,"server":0,"uri":0,"port":0,"channel":1,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"Blynk", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"Brewblox", "token":0,"server":1,"uri":1,"port":1,"channel":0,"db":0,"username":1,"password":1,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"AWSIOTMQTT", "token":0,"server":1,"uri":1,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":1,"hassio":0},
{"name":"HTTPS Post", "token":1,"server":1,"uri":1,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0},
{"name":"BierBot Bricks", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0}
{"name":"Ubidots", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"empty", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"CraftBeerPi", "token":0,"server":1,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"HTTP", "token":1,"server":1,"uri":1,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"TControl", "token":0,"server":1,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"FHEM", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"TCP", "token":1,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"iSpindel.de", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"InfluxDB", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":1,"username":1,"password":1,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":1},
{"name":"Prometheus", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":1,"instance":1,"warning1":0,"hassio":0,"usehttps":0},
{"name":"MQTT", "token":0,"server":1,"uri":0,"port":1,"channel":0,"db":0,"username":1,"password":1,"job":0,"instance":0,"warning1":0,"hassio":1,"usehttps":0},
{"name":"ThingSpeak", "token":1,"server":0,"uri":0,"port":0,"channel":1,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"Blynk", "token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"Brewblox", "token":0,"server":1,"uri":1,"port":1,"channel":0,"db":0,"username":1,"password":1,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"AWSIOTMQTT", "token":0,"server":1,"uri":1,"port":1,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":1,"hassio":0,"usehttps":0},
{"name":"HTTPS Post", "token":1,"server":1,"uri":1,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0},
{"name":"BierBot Bricks","token":1,"server":0,"uri":0,"port":0,"channel":0,"db":0,"username":0,"password":0,"job":0,"instance":0,"warning1":0,"hassio":0,"usehttps":0}
];

var $ = function (id) { return document.getElementById(id); };
Expand Down
15 changes: 14 additions & 1 deletion pio/src/iSpindel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ iData myData;
//myData.hassio = false;
bool hassio_changed = false;
#endif
bool usehttps_changed = false;

uint32_t DSreqTime = 0;

Expand Down Expand Up @@ -206,6 +207,8 @@ bool readConfig()
if (doc.containsKey("Hassio"))
myData.hassio = doc["Hassio"];
#endif
if (doc.containsKey("UseHTTPS"))
myData.usehttps = doc["UseHTTPS"];
if (doc.containsKey("Offset"))
{
for (size_t i = 0; i < (sizeof(myData.Offset) / sizeof(*myData.Offset)); i++)
Expand Down Expand Up @@ -354,6 +357,8 @@ bool startConfiguration()
WiFiManagerParameter custom_hassio("hassio", "Home Assistant integration via MQTT", "checked", TKIDSIZE,
myData.hassio ? TYPE_CHECKBOX_CHECKED : TYPE_CHECKBOX);
#endif
WiFiManagerParameter custom_usehttps("usehttps", "Connect to server via HTTPS", "checked", TKIDSIZE,
myData.usehttps ? TYPE_CHECKBOX_CHECKED : TYPE_CHECKBOX);
WiFiManagerParameter custom_vfact("vfact", "Battery conversion factor", String(myData.vfact).c_str(), 7, TYPE_NUMBER);
WiFiManagerParameter tempscale_list(HTTP_TEMPSCALE_LIST);
WiFiManagerParameter custom_tempscale("tempscale", "tempscale", String(myData.tempscale).c_str(), 5, TYPE_HIDDEN,
Expand Down Expand Up @@ -392,6 +397,7 @@ bool startConfiguration()
#if API_MQTT_HASSIO
wifiManager.addParameter(&custom_hassio);
#endif
wifiManager.addParameter(&custom_usehttps);
WiFiManagerParameter custom_polynom_lbl(
"<hr><label for=\"POLYN\">Gravity conversion<br/>ex. \"-0.00031*tilt^2+0.557*tilt-14.054\"</label>");
wifiManager.addParameter(&custom_polynom_lbl);
Expand Down Expand Up @@ -434,6 +440,11 @@ bool startConfiguration()
myData.hassio = hassio;
}
#endif
{
auto usehttps = myData.api == DTInfluxDB && String(custom_usehttps.getValue()) == "checked";
usehttps_changed = myData.usehttps != usehttps;
myData.usehttps = usehttps;
}
validateInput(custom_uri.getValue(), myData.uri);

String tmp = custom_vfact.getValue();
Expand Down Expand Up @@ -511,6 +522,7 @@ bool saveConfig()
#if API_MQTT_HASSIO
doc["Hassio"] = myData.hassio;
#endif
doc["UseHTTPS"] = myData.usehttps;
doc["Vfact"] = myData.vfact;
doc["TS"] = myData.tempscale;
doc["OWpin"] = myData.OWpin;
Expand Down Expand Up @@ -644,7 +656,8 @@ bool uploadData(uint8_t service)
CONSOLELN(String(F("Sending to db: ")) + myData.db + String(F(" w/ credentials: ")) + myData.username +
String(F(":")) + myData.password);

return sender.sendInfluxDB(myData.server, myData.port, myData.db, myData.name, myData.username, myData.password);
return sender.sendInfluxDB(myData.server, myData.port, myData.db, myData.name, myData.username, myData.password,
myData.usehttps);
}
#endif

Expand Down