fix compilation errors

This commit is contained in:
Dawid Chyrzynski
2020-12-20 12:46:04 +01:00
parent 2c8749ae33
commit c6b6d18025
8 changed files with 33 additions and 14 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ sentence=Home Assistant MQTT integration for Arduino
paragraph=Lightweight library that provides easy to use API for integrating your Arduin-based device with Home Assistant.
category=Communication
url=https://github.com/dawidchyrzynski/arduino-home-assistant
architectures=avr
architectures=*
depends=PubSubClient
+4 -4
View File
@@ -22,7 +22,7 @@
_devicesTypes(nullptr)
static const char* DefaultDiscoveryPrefix = "homeassistant";
HAMqtt* instance = nullptr;
static HAMqtt* instance = nullptr;
void onMessageReceived(char* topic, uint8_t* payload, uint16_t length)
{
@@ -128,7 +128,7 @@ bool HAMqtt::publish(const char* topic, const char* payload, bool retained)
#endif
_mqtt->beginPublish(topic, strlen(payload), retained);
_mqtt->write(payload, strlen(payload));
_mqtt->write((const uint8_t*)(payload), strlen(payload));
return _mqtt->endPublish();
}
@@ -151,7 +151,7 @@ bool HAMqtt::beginPublish(
bool HAMqtt::writePayload(const char* data, uint16_t length)
{
return (_mqtt->write(data, length) > 0);
return (_mqtt->write((const uint8_t*)(data), length) > 0);
}
bool HAMqtt::writePayload_P(const char* src)
@@ -159,7 +159,7 @@ bool HAMqtt::writePayload_P(const char* src)
char data[strlen_P(src) + 1];
strcpy_P(data, src);
return _mqtt->write(data, strlen(data));
return _mqtt->write((const uint8_t*)(data), strlen(data));
}
bool HAMqtt::endPublish()
+19
View File
@@ -88,7 +88,26 @@ public:
bool writePayload(const char* data, uint16_t length);
bool writePayload_P(const char* src);
bool endPublish();
/**
* Subscribes to the given topic.
* Whenever a new message is received the onMqttMessage callback in all
* devices types is called.
*
* Please note that you need to subscribe topic each time the connection
* with the broker is acquired.
*
* @param topic Topic to subscribe
*/
bool subscribe(const char* topic);
/**
* Processes MQTT message received from the broker (subscription).
*
* @param topic Topic of the message.
* @param payload Content of the message.
* @param length Length of the message.
*/
void processMessage(char* topic, uint8_t* payload, uint16_t length);
private:
+1 -1
View File
@@ -17,7 +17,7 @@ public:
virtual void onMqttConnected() = 0;
virtual void onMqttMessage(
const char* topic,
const char* payload,
const uint8_t* payload,
const uint16_t& length
) { };
+2 -2
View File
@@ -38,7 +38,7 @@ void HASwitch::onMqttConnected()
void HASwitch::onMqttMessage(
const char* topic,
const char* payload,
const uint8_t* payload,
const uint16_t& length
)
{
@@ -56,7 +56,7 @@ void HASwitch::onMqttMessage(
strcat(suffix, CommandTopic);
if (HAUtils::endsWith(topic, suffix)) {
bool onState = (strncmp(payload, StateOn, length) == 0);
bool onState = (length == strlen(StateOn));
setState(onState);
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ public:
*/
virtual void onMqttMessage(
const char* topic,
const char* payload,
const uint8_t* payload,
const uint16_t& length
) override;
+3 -3
View File
@@ -31,7 +31,7 @@ bool HATriggers::add(const char* type, const char* subtype)
return false;
}
HATrigger* triggers = realloc(_triggers, sizeof(HATrigger) * (_triggersNb + 1));
HATrigger* triggers = (HATrigger*)realloc(_triggers, sizeof(HATrigger) * (_triggersNb + 1));
if (triggers == nullptr) {
return false;
}
@@ -133,7 +133,7 @@ void HATriggers::publishConfig()
uint16_t HATriggers::calculateTopicLength(
const char* component,
HATrigger *trigger,
const HATrigger *trigger,
const char* suffix,
bool includeNullTerminator
) const
@@ -150,7 +150,7 @@ uint16_t HATriggers::calculateTopicLength(
uint16_t HATriggers::generateTopic(
char* output,
const char* component,
HATrigger *trigger,
const HATrigger *trigger,
const char* suffix
) const
{
+2 -2
View File
@@ -22,7 +22,7 @@ public:
protected:
uint16_t calculateTopicLength(
const char* component,
HATrigger *trigger,
const HATrigger *trigger,
const char* suffix,
bool includeNullTerminator = true
) const;
@@ -30,7 +30,7 @@ protected:
uint16_t generateTopic(
char* output,
const char* component,
HATrigger *trigger,
const HATrigger *trigger,
const char* suffix
) const;