Zustünde Switch und Power publishen

This commit is contained in:
Bernhard
2025-12-08 19:36:05 +01:00
parent 48d3251247
commit b10547e070
7 changed files with 79 additions and 14 deletions

View File

@@ -24,6 +24,15 @@ int iMqttMotor2Gear = 0;
const char* mqtt_topic_motor2_power = "Pool/Motor2/Power";
int iMqttMotor2Power = 0;
const char* mqtt_topic_motor1_switchstate = "Pool/Motor1/SwitchState";
unsigned char nMqttMotor1SwitchState = 0;
const char* mqtt_topic_motor2_switchstate = "Pool/Motor1/SwitchState";
unsigned char nMqttMotor2SwitchState = 0;
const char* mqtt_topic_motor1_actualpowerw = "Pool/Motor1/ActualPowerW";
int iMqttMotor1ActualPowerW = 0;
const char* mqtt_topic_motor2_actualpowerw = "Pool/Motor1/ActualPowerW";
int iMqttMotor2ActualPowerW = 0;
const char* mqtt_broker_addr = "127.0.0.1";
const int mqtt_broker_port = 1883;
struct mosquitto *mosq; /**< Libmosquito MQTT client instance. */
@@ -278,4 +287,53 @@ void MqttClient_Publish_MotorPower(int iMotorIndex, int iPower)
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_power, strlen(message), message, 0, false);
}
}
}
void MqttClient_Publish_MotorSwitchState(int iMotorIndex, unsigned char nSwitchState)
{
if (iMotorIndex == 0)
{
if (nSwitchState != nMqttMotor1SwitchState)
{
nMqttMotor1SwitchState = nSwitchState;
char message[100];
snprintf(message, sizeof(message), "%d", nSwitchState);
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_switchstate, strlen(message), message, 0, false);
}
}
else if (iMotorIndex == 1)
{
if (nSwitchState != nMqttMotor2SwitchState)
{
nMqttMotor2SwitchState = nSwitchState;
char message[100];
snprintf(message, sizeof(message), "%d", nSwitchState);
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_switchstate, strlen(message), message, 0, false);
}
}
}
void MqttClient_Publish_MotorActualPowerW(int iMotorIndex, int iMotorPowerW)
{
if (iMotorIndex == 0)
{
if (iMotorPowerW != iMqttMotor1ActualPowerW)
{
iMqttMotor1ActualPowerW = iMotorPowerW;
char message[100];
snprintf(message, sizeof(message), "%d", iMotorPowerW);
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_actualpowerw, strlen(message), message, 0, false);
}
}
else if (iMotorIndex == 1)
{
if (iMotorPowerW != iMqttMotor2ActualPowerW)
{
iMqttMotor2ActualPowerW = iMotorPowerW;
char message[100];
snprintf(message, sizeof(message), "%d", iMotorPowerW);
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_actualpowerw, strlen(message), message, 0, false);
}
}
}