Move network management stuff to own class
This commit is contained in:
parent
a3068a2d15
commit
20d0263812
5 changed files with 110 additions and 60 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "sensors.h"
|
||||
|
||||
Sensors::Sensors(int temperaturePin, char *temperatureTopic, char *phTopic, PubSubClient mqttClient) {
|
||||
_mqttClient = mqttClient;
|
||||
Sensors::Sensors(int temperaturePin, char *temperatureTopic, char *phTopic, Networking* networking) {
|
||||
_networking = networking;
|
||||
OneWire oneWire = OneWire(temperaturePin);
|
||||
_ds18b20 = DallasTemperature(&oneWire);
|
||||
_temperaturePin = temperaturePin;
|
||||
|
@ -37,12 +37,12 @@ float Sensors::readpH() {
|
|||
void Sensors::publishpH() {
|
||||
float pH = readpH();
|
||||
String pHString(pH, 2);
|
||||
_mqttClient.publish(_phTopic, pHString.c_str(), true);
|
||||
_networking->publish(_phTopic, pHString.c_str(), true);
|
||||
}
|
||||
|
||||
void Sensors::publishTemperature() {
|
||||
_ds18b20.requestTemperatures();
|
||||
float temperature = _ds18b20.getTempCByIndex(0);
|
||||
String temperatureString(temperature, 2);
|
||||
_mqttClient.publish(_temperatureTopic, temperatureString.c_str(), true);
|
||||
_networking->publish(_temperatureTopic, temperatureString.c_str(), true);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue