Move network management stuff to own class

This commit is contained in:
Robert Marshall 2018-10-07 16:09:43 +01:00
parent a3068a2d15
commit 20d0263812
5 changed files with 110 additions and 60 deletions

View file

@ -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);
}