Zustünde Switch und Power publishen
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,7 @@ void MqttClient_Refresher();
|
||||
void MqttClient_Publisher();
|
||||
void MqttClient_Publish_MotorGear(int iMotorIndex, int iGear);
|
||||
void MqttClient_Publish_MotorPower(int iMotorIndex, int iPower);
|
||||
void MqttClient_Publish_MotorSwitchState(int iMotorIndex, unsigned char nSwitchState);
|
||||
void MqttClient_Publish_MotorActualPowerW(int iMotorIndex, int iMotorPowerW);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user