Skip to content

Commit

Permalink
Merge pull request #46 from Neuroquila-n8fall/Fix-missing-change
Browse files Browse the repository at this point in the history
Fix missing change
  • Loading branch information
Neuroquila-n8fall authored Feb 8, 2024
2 parents 4732adb + 4bac825 commit 3125c38
Showing 1 changed file with 49 additions and 47 deletions.
96 changes: 49 additions & 47 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,51 +91,53 @@ void callback(char *topic, byte *payload, unsigned int length)
{
ShowActivityLed();
payload[length] = '\0';
// Check if the payload translates to a valid string.
PayloadBuf = String((char *)payload);
if (!PayloadBuf)
String payloadBuf = String((char *)payload);
if (!payloadBuf)
{
return;
}

TopicBuf = topic;

// Command Topics for HA auto discovery.
if (TopicBuf.endsWith(F("/set")))
{
WriteToConsoles("Received SET Topic: ");
WriteToConsoles(TopicBuf);
WriteToConsoles("\r\n");
// Remove prefixes
TopicBuf.replace(configuration.HomeAssistant.AutoDiscoveryPrefix + "/","");
TopicBuf.replace(configuration.HomeAssistant.DeviceId + "/","");
// Try to get the category
String category = TopicBuf.substring(0,TopicBuf.indexOf('/'));
category.replace("/","");
// Remove Category from string
TopicBuf.replace(category,"");
TopicBuf.replace(F("/set"),"");
String parameterName = TopicBuf.substring(TopicBuf.lastIndexOf('/'),TopicBuf.length());
parameterName.replace(F("/"),"");

WriteToConsoles("Received Values for Category: ");
WriteToConsoles(category);
WriteToConsoles(" Parameter Name: ");
WriteToConsoles(parameterName);
WriteToConsoles(" Payload: ");
WriteToConsoles(PayloadBuf);
WriteToConsoles("\r\n");

// Setting Values coming from HA.
// NOTE: This is all hardcoded on purpose as we have no means of determining which variable is targeted
if(category == "Heating")
{
if(parameterName == "BoostDuration")
{

}
}
}

/*
NOTE: This is supposed to be in the HA branch.
*/
//TopicBuf = topic;
//
//// Command Topics for HA auto discovery.
//if (TopicBuf.endsWith(F("/set")))
//{
// WriteToConsoles("Received SET Topic: ");
// WriteToConsoles(TopicBuf);
// WriteToConsoles("\r\n");
// // Remove prefixes
// TopicBuf.replace(configuration.HomeAssistant.AutoDiscoveryPrefix + "/","");
// TopicBuf.replace(configuration.HomeAssistant.DeviceId + "/","");
// // Try to get the category
// String category = TopicBuf.substring(0,TopicBuf.indexOf('/'));
// category.replace("/","");
// // Remove Category from string
// TopicBuf.replace(category,"");
// TopicBuf.replace(F("/set"),"");
// String parameterName = TopicBuf.substring(TopicBuf.lastIndexOf('/'),TopicBuf.length());
// parameterName.replace(F("/"),"");
//
// WriteToConsoles("Received Values for Category: ");
// WriteToConsoles(category);
// WriteToConsoles(" Parameter Name: ");
// WriteToConsoles(parameterName);
// WriteToConsoles(" Payload: ");
// WriteToConsoles(PayloadBuf);
// WriteToConsoles("\r\n");
//
// // Setting Values coming from HA.
// // NOTE: This is all hardcoded on purpose as we have no means of determining which variable is targeted
// if(category == "Heating")
// {
// if(parameterName == "BoostDuration")
// {
//
// }
// }
//}


// Status Requested
Expand All @@ -147,7 +149,7 @@ void callback(char *topic, byte *payload, unsigned int length)

if (error)
{
Log.printf("[Status Request] Error Processing JSON: %s\r\n", error.c_str());
Log.printf("[Status Request] Error Processing JSON: %payloadBuf\r\n", error.c_str());
return;
}
/* Example JSON:
Expand Down Expand Up @@ -226,7 +228,7 @@ void callback(char *topic, byte *payload, unsigned int length)

if (error)
{
Log.printf("[Heating Parameters] Error Processing JSON: %s\r\n", error.c_str());
Log.printf("[Heating Parameters] Error Processing JSON: %payloadBuf\r\n", error.c_str());
return;
}

Expand Down Expand Up @@ -279,7 +281,7 @@ void callback(char *topic, byte *payload, unsigned int length)

if (error)
{
Log.printf("[Water Parameters] Error Processing JSON: %s\r\n", error.c_str());
Log.printf("[Water Parameters] Error Processing JSON: %payloadBuf\r\n", error.c_str());
return;
}

Expand All @@ -291,7 +293,7 @@ void callback(char *topic, byte *payload, unsigned int length)
// On-Demand Boost
if (strcmp(topic, configuration.Mqtt.Topics.Boost) == 0)
{
int i = s.toInt();
int i = payloadBuf.toInt();
commandedValues.Heating.Boost = i == 1;
commandedValues.Heating.BoostTimeCountdown = commandedValues.Heating.BoostDuration;
SetFeedTemperature();
Expand All @@ -300,7 +302,7 @@ void callback(char *topic, byte *payload, unsigned int length)
// Fast Heatup
if (strcmp(topic, configuration.Mqtt.Topics.FastHeatup) == 0)
{
int i = s.toInt();
int i = payloadBuf.toInt();
commandedValues.Heating.FastHeatup = i == 1;
commandedValues.Heating.ReferenceAmbientTemperature = commandedValues.Heating.AmbientTemperature;
SetFeedTemperature();
Expand Down

0 comments on commit 3125c38

Please sign in to comment.