Ahhh.. stupid Maurice, forgot to call setup() on the sensors from the new SensorBase. Sensors are back in order now.

This commit is contained in:
Maurice Makaay 2020-07-14 22:05:31 +02:00
parent e508f29a3e
commit 52b33de7aa
4 changed files with 17 additions and 50 deletions

View File

@ -75,5 +75,18 @@ void mqttOnConnectCallback(Dough::MQTT *mqtt)
void mqttOnMessageCallback(String &topic, String &payload) void mqttOnMessageCallback(String &topic, String &payload)
{ {
callbackLogger.log("s", "MQTT message received"); callbackLogger.log("ssss", "MQTT message received: ", topic.c_str(), " = ", payload.c_str());
if (topic.endsWith("/container_height"))
{
Dough::App::Instance()->config.setContainerHeight(payload.toInt());
}
else if (topic.endsWith("/temperature_offset"))
{
Dough::App::Instance()->config.setTemperatureOffset(payload.toInt());
}
else
{
callbackLogger.log("ss", "ERROR - Unhandled MQTT message, topic = ", topic.c_str());
}
} }

View File

@ -12,34 +12,8 @@ namespace Dough
_containerHeight = 0.00; _containerHeight = 0.00;
_containerHeightSet = false; _containerHeightSet = false;
_temperatureOffset = 0; _temperatureOffset = 0;
// MQTT *mqtt = MQTT::Instance();
// mqtt->onConnect(Configuration::handleMqttConnect);
// mqtt->onMessage(Configuration::handleMqttMessage);
} }
// void Configuration::handleMqttConnect(MQTT *mqtt)
// {
// mqtt->subscribe("container_height");
// mqtt->subscribe("temperature_offset");
// }
// void Configuration::handleMqttMessage(String &key, String &payload)
// {
// if (key.equals("container_height"))
// {
// App::Instance()->config.setContainerHeight(payload.toInt());
// }
// if (key.equals("temperature_offset"))
// {
// App::Instance()->config.setTemperatureOffset(payload.toInt());
// }
// else
// {
// App::Instance()->config._logger.log("ss", "ERROR - Unhandled MQTT message, key = ", key.c_str());
// }
// }
bool Configuration::isOk() bool Configuration::isOk()
{ {
return _containerHeightSet; return _containerHeightSet;

View File

@ -22,6 +22,8 @@ namespace Dough
void SensorController::setup() void SensorController::setup()
{ {
_sensor->setup();
// Format the key to use for publishing the average (i.e. "<mqttKey>/average"). // Format the key to use for publishing the average (i.e. "<mqttKey>/average").
auto lenAverageKey = strlen(_mqttKey) + 9; // +9 for the "/average\0" suffix auto lenAverageKey = strlen(_mqttKey) + 9; // +9 for the "/average\0" suffix
_mqttAverageKey = new char[lenAverageKey]; _mqttAverageKey = new char[lenAverageKey];

View File

@ -24,10 +24,6 @@ namespace Dough
_mqttClient.begin(MQTT_BROKER, MQTT_PORT, _wifi->client); _mqttClient.begin(MQTT_BROKER, MQTT_PORT, _wifi->client);
} }
// ----------------------------------------------------------------------
// Loop
// ----------------------------------------------------------------------
bool MQTT::isConnected() bool MQTT::isConnected()
{ {
return _mqttClient.connected(); return _mqttClient.connected();
@ -63,23 +59,6 @@ namespace Dough
_mqttClient.loop(); _mqttClient.loop();
} }
// // static
// void MQTT::handleMessage(String &topic, String &payload)
// {
// MQTT::Instance()->_logger.log("sSsS", "<<< ", topic, " = ", payload);
// MQTT *mqtt = MQTT::Instance();
// if (mqtt->_onMessage != nullptr)
// {
// int pos = topic.lastIndexOf('/');
// if (pos != -1)
// {
// topic.remove(0, pos + 1);
// mqtt->_onMessage(topic, payload);
// }
// }
// }
void MQTT::subscribe(const char *key) void MQTT::subscribe(const char *key)
{ {
char topic[200]; char topic[200];
@ -92,7 +71,7 @@ namespace Dough
{ {
char topic[200]; char topic[200];
snprintf(topic, sizeof(topic) / sizeof(topic[0]), "%s/%s/%s", MQTT_TOPIC_PREFIX, _mqttDeviceId, key); snprintf(topic, sizeof(topic) / sizeof(topic[0]), "%s/%s/%s", MQTT_TOPIC_PREFIX, _mqttDeviceId, key);
_logger.log("ssss", ">>> ", topic, " = ", payload); _logger.log("ssss", "Send message: ", topic, " = ", payload);
_mqttClient.publish(topic, payload); _mqttClient.publish(topic, payload);
} }
@ -114,5 +93,4 @@ namespace Dough
publish(key, "null"); publish(key, "null");
} }
} }
} }