publish battery drain and max current
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define mqtt_topc_voltage "nuki/battery/voltage"
|
#define mqtt_topic_battery_voltage "nuki/battery/voltage"
|
||||||
|
#define mqtt_topic_battery_drain "nuki/battery/drain"
|
||||||
|
#define mqtt_topic_battery_max_turn_current "nuki/battery/maxTurnCurrent"
|
||||||
|
|
||||||
#define mqtt_topc_lockstate "nuki/lock/state"
|
#define mqtt_topic_lockstate "nuki/lock/state"
|
||||||
#define mqtt_topc_lockstate_action "nuki/lock/action"
|
#define mqtt_topic_lockstate_action "nuki/lock/action"
|
||||||
28
Network.cpp
28
Network.cpp
@@ -70,7 +70,7 @@ bool Network::reconnect()
|
|||||||
Serial.println(F("MQTT connected"));
|
Serial.println(F("MQTT connected"));
|
||||||
|
|
||||||
// ... and resubscribe
|
// ... and resubscribe
|
||||||
_mqttClient.subscribe(mqtt_topc_lockstate_action);
|
_mqttClient.subscribe(mqtt_topic_lockstate_action);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -121,7 +121,7 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
|||||||
|
|
||||||
value[l] = 0;
|
value[l] = 0;
|
||||||
|
|
||||||
if(strcmp(topic, mqtt_topc_lockstate_action) == 0)
|
if(strcmp(topic, mqtt_topic_lockstate_action) == 0)
|
||||||
{
|
{
|
||||||
if(strcmp(value, "") == 0) return;
|
if(strcmp(value, "") == 0) return;
|
||||||
|
|
||||||
@@ -131,13 +131,13 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
|||||||
{
|
{
|
||||||
_lockActionReceivedCallback(value);
|
_lockActionReceivedCallback(value);
|
||||||
}
|
}
|
||||||
_mqttClient.publish(mqtt_topc_lockstate_action, "");
|
_mqttClient.publish(mqtt_topic_lockstate_action, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::publishKeyTurnerState(const char* state)
|
void Network::publishKeyTurnerState(const char* state)
|
||||||
{
|
{
|
||||||
_mqttClient.publish(mqtt_topc_lockstate, state);
|
_mqttClient.publish(mqtt_topic_lockstate, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::setLockActionReceived(void (*lockActionReceivedCallback)(const char *))
|
void Network::setLockActionReceived(void (*lockActionReceivedCallback)(const char *))
|
||||||
@@ -145,9 +145,23 @@ void Network::setLockActionReceived(void (*lockActionReceivedCallback)(const cha
|
|||||||
_lockActionReceivedCallback = lockActionReceivedCallback;
|
_lockActionReceivedCallback = lockActionReceivedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::publishBatteryVoltage(const float &value)
|
void Network::publishBatteryReport(const BatteryReport& batteryReport)
|
||||||
|
{
|
||||||
|
publishFloat(mqtt_topic_battery_voltage, (float)batteryReport.batteryVoltage / 1000.0);
|
||||||
|
publishFloat(mqtt_topic_battery_drain, (float)batteryReport.batteryDrain / 1000.0); // milliwatt seconds
|
||||||
|
publishInt(mqtt_topic_battery_max_turn_current, batteryReport.maxTurnCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Network::publishFloat(const char* topic, const float value, const uint8_t precision)
|
||||||
{
|
{
|
||||||
char str[30];
|
char str[30];
|
||||||
dtostrf(value, 0, 2, str);
|
dtostrf(value, 0, precision, str);
|
||||||
_mqttClient.publish(mqtt_topc_voltage, str);
|
_mqttClient.publish(topic, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Network::publishInt(const char *topic, const int value)
|
||||||
|
{
|
||||||
|
char str[30];
|
||||||
|
itoa(value, str, 10);
|
||||||
|
_mqttClient.publish(topic, str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
void publishKeyTurnerState(const char* state);
|
void publishKeyTurnerState(const char* state);
|
||||||
void publishBatteryVoltage(const float& value);
|
void publishBatteryReport(const BatteryReport& batteryReport);
|
||||||
|
|
||||||
void setLockActionReceived(void (*lockActionReceivedCallback)(const char* value));
|
void setLockActionReceived(void (*lockActionReceivedCallback)(const char* value));
|
||||||
|
|
||||||
@@ -23,6 +23,9 @@ private:
|
|||||||
static void onMqttDataReceivedCallback(char* topic, byte* payload, unsigned int length);
|
static void onMqttDataReceivedCallback(char* topic, byte* payload, unsigned int length);
|
||||||
void onMqttDataReceived(char*& topic, byte*& payload, unsigned int& length);
|
void onMqttDataReceived(char*& topic, byte*& payload, unsigned int& length);
|
||||||
|
|
||||||
|
void publishFloat(const char* topic, const float value, const uint8_t precision = 2);
|
||||||
|
void publishInt(const char* topic, const int value);
|
||||||
|
|
||||||
bool reconnect();
|
bool reconnect();
|
||||||
|
|
||||||
PubSubClient _mqttClient;
|
PubSubClient _mqttClient;
|
||||||
|
|||||||
2
Nuki.cpp
2
Nuki.cpp
@@ -109,7 +109,7 @@ void Nuki::updateBatteryState()
|
|||||||
Serial.print(F("Crit. State: ")); Serial.println(_batteryReport.criticalBatteryState);
|
Serial.print(F("Crit. State: ")); Serial.println(_batteryReport.criticalBatteryState);
|
||||||
Serial.print(F("Lock Dist: ")); Serial.println(_batteryReport.lockDistance);
|
Serial.print(F("Lock Dist: ")); Serial.println(_batteryReport.lockDistance);
|
||||||
|
|
||||||
_network->publishBatteryVoltage((float)_batteryReport.batteryVoltage / (float)1000);
|
_network->publishBatteryReport(_batteryReport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user