MQTT-Handling optimiert
This commit is contained in:
@@ -140,7 +140,6 @@ void Can_SetMotorGear(int iMotorIndex, int iGear)
|
|||||||
{
|
{
|
||||||
if (motctrl[iMotorIndex].iMotorGear != MOTOR_GEAR_FORWARD)
|
if (motctrl[iMotorIndex].iMotorGear != MOTOR_GEAR_FORWARD)
|
||||||
{
|
{
|
||||||
MqttClient_Publish_MotorGear(iMotorIndex, iGear);
|
|
||||||
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_FORWARD;
|
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_FORWARD;
|
||||||
// motor is switched to forward -> set min. power
|
// motor is switched to forward -> set min. power
|
||||||
Can_SetMotorPower(iMotorIndex, 1);
|
Can_SetMotorPower(iMotorIndex, 1);
|
||||||
@@ -152,7 +151,6 @@ void Can_SetMotorGear(int iMotorIndex, int iGear)
|
|||||||
{
|
{
|
||||||
if (motctrl[iMotorIndex].iMotorGear != MOTOR_GEAR_REVERSE)
|
if (motctrl[iMotorIndex].iMotorGear != MOTOR_GEAR_REVERSE)
|
||||||
{
|
{
|
||||||
MqttClient_Publish_MotorGear(iMotorIndex, iGear);
|
|
||||||
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_REVERSE;
|
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_REVERSE;
|
||||||
// motor is switched to reverse -> set min. power
|
// motor is switched to reverse -> set min. power
|
||||||
Can_SetMotorPower(iMotorIndex, 1);
|
Can_SetMotorPower(iMotorIndex, 1);
|
||||||
@@ -164,7 +162,6 @@ void Can_SetMotorGear(int iMotorIndex, int iGear)
|
|||||||
{
|
{
|
||||||
if (motctrl[iMotorIndex].iMotorGear != MOTOR_GEAR_NEUTRAL)
|
if (motctrl[iMotorIndex].iMotorGear != MOTOR_GEAR_NEUTRAL)
|
||||||
{
|
{
|
||||||
MqttClient_Publish_MotorGear(iMotorIndex, iGear);
|
|
||||||
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_NEUTRAL;
|
motctrl[iMotorIndex].iMotorGear = MOTOR_GEAR_NEUTRAL;
|
||||||
}
|
}
|
||||||
// motor is switch to neutral -> set power to 0
|
// motor is switch to neutral -> set power to 0
|
||||||
@@ -172,6 +169,7 @@ void Can_SetMotorGear(int iMotorIndex, int iGear)
|
|||||||
WriteOutputPin(GPIO_LED_MOTRUN, LOW);
|
WriteOutputPin(GPIO_LED_MOTRUN, LOW);
|
||||||
mylog(LOG_INFO, "CAN: Motor[%d]: Set gear neutral.", iMotorIndex);
|
mylog(LOG_INFO, "CAN: Motor[%d]: Set gear neutral.", iMotorIndex);
|
||||||
}
|
}
|
||||||
|
MqttClient_Publish_MotorGear(iMotorIndex, iGear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,30 +8,30 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <mqtt/mqtt_client.h>
|
#include <mqtt/mqtt_client.h>
|
||||||
#include <can/can_client.h>
|
#include <can/can_client.h>
|
||||||
|
#include <settings/settings.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <mosquitto.h>
|
#include <mosquitto.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Topics to subscribe
|
||||||
|
const char* mqtt_topic_motor_gear_request = "Pool/Motor_Gear_Request";
|
||||||
|
const char* mqtt_topic_motor_power_request = "Pool/Motor_Power_Request";
|
||||||
|
|
||||||
|
// Topics to publish
|
||||||
const char* mqtt_topic_status_cyclecounter = "Pool/Status/CycleCounter";
|
const char* mqtt_topic_status_cyclecounter = "Pool/Status/CycleCounter";
|
||||||
|
|
||||||
const char* mqtt_topic_motor1_gear = "Pool/Motor1/Gear";
|
const char* mqtt_topic_motor1_gear = "Pool/Motor1/Gear";
|
||||||
int iMqttMotor1Gear = 0;
|
|
||||||
const char* mqtt_topic_motor1_power = "Pool/Motor1/Power";
|
const char* mqtt_topic_motor1_power = "Pool/Motor1/Power";
|
||||||
int iMqttMotor1Power = 0;
|
|
||||||
const char* mqtt_topic_motor2_gear = "Pool/Motor2/Gear";
|
const char* mqtt_topic_motor2_gear = "Pool/Motor2/Gear";
|
||||||
int iMqttMotor2Gear = 0;
|
|
||||||
const char* mqtt_topic_motor2_power = "Pool/Motor2/Power";
|
const char* mqtt_topic_motor2_power = "Pool/Motor2/Power";
|
||||||
int iMqttMotor2Power = 0;
|
|
||||||
|
|
||||||
const char* mqtt_topic_motor1_switchstate = "Pool/Motor1/SwitchState";
|
const char* mqtt_topic_motor1_switchstate = "Pool/Motor1/SwitchState";
|
||||||
unsigned char nMqttMotor1SwitchState = 0;
|
unsigned char nMotor1SwitchState = 255;
|
||||||
const char* mqtt_topic_motor2_switchstate = "Pool/Motor1/SwitchState";
|
const char* mqtt_topic_motor2_switchstate = "Pool/Motor1/SwitchState";
|
||||||
unsigned char nMqttMotor2SwitchState = 0;
|
unsigned char nMotor2SwitchState = 255;
|
||||||
const char* mqtt_topic_motor1_actualpowerw = "Pool/Motor1/ActualPowerW";
|
const char* mqtt_topic_motor1_actualpowerw = "Pool/Motor1/ActualPowerW";
|
||||||
int iMqttMotor1ActualPowerW = 0;
|
int iMqttMotor1ActualPowerW = -1;
|
||||||
const char* mqtt_topic_motor2_actualpowerw = "Pool/Motor1/ActualPowerW";
|
const char* mqtt_topic_motor2_actualpowerw = "Pool/Motor1/ActualPowerW";
|
||||||
int iMqttMotor2ActualPowerW = 0;
|
int iMqttMotor2ActualPowerW = -1;
|
||||||
|
|
||||||
const char* mqtt_broker_addr = "127.0.0.1";
|
const char* mqtt_broker_addr = "127.0.0.1";
|
||||||
const int mqtt_broker_port = 1883;
|
const int mqtt_broker_port = 1883;
|
||||||
@@ -50,60 +50,46 @@ void my_message_callback(struct mosquitto *mosq, void *userdata, const struct mo
|
|||||||
memcpy(topic_value, message->payload, message->payloadlen);
|
memcpy(topic_value, message->payload, message->payloadlen);
|
||||||
topic_value[message->payloadlen] = '\0';
|
topic_value[message->payloadlen] = '\0';
|
||||||
|
|
||||||
if (strcmp(message->topic, mqtt_topic_motor1_gear) == 0)
|
if (strcmp(message->topic, mqtt_topic_motor_gear_request) == 0)
|
||||||
{
|
{
|
||||||
int val = 9999;
|
int val = 123456789;
|
||||||
if (sscanf(topic_value, "%d", &val))
|
if (sscanf(topic_value, "%d", &val))
|
||||||
{
|
{
|
||||||
mylog(LOG_DEBUG, "MQTT: Received value for mqtt_topic_motor1_gear: %d", val);
|
mylog(LOG_INFO, "MQTT: Received value for mqtt_topic_motor_gear_request: %d", val);
|
||||||
iMqttMotor1Gear = val;
|
if (val == 123456789)
|
||||||
Can_SetMotorGear(0, val);
|
{
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<settings.iMotorCount; i++)
|
||||||
|
{
|
||||||
|
Can_SetMotorGear(i, val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(LOG_WARNING, "MQTT: Received mqtt_topic_motor1_gear: %s", topic_value);
|
mylog(LOG_WARNING, "MQTT: Received mqtt_topic_motor_gear_request: %s", topic_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strcmp(message->topic, mqtt_topic_motor1_power) == 0)
|
else if (strcmp(message->topic, mqtt_topic_motor_power_request) == 0)
|
||||||
{
|
{
|
||||||
int val = 9999;
|
int val = 123456789;
|
||||||
if (sscanf(topic_value, "%d", &val))
|
if (sscanf(topic_value, "%d", &val))
|
||||||
{
|
{
|
||||||
mylog(LOG_DEBUG, "MQTT: Received value for mqtt_topic_motor1_power: %d", val);
|
mylog(LOG_INFO, "MQTT: Received value for mqtt_topic_motor_power_request: %d", val);
|
||||||
iMqttMotor1Power = val;
|
if (val == 123456789)
|
||||||
Can_SetMotorPower(0, val);
|
{
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<settings.iMotorCount; i++)
|
||||||
|
{
|
||||||
|
Can_SetMotorPower(i, val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(LOG_WARNING, "MQTT: Received mqtt_topic_motor1_power: %s", topic_value);
|
mylog(LOG_WARNING, "MQTT: Received mqtt_topic_motor_gear_request: %s", topic_value);
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (strcmp(message->topic, mqtt_topic_motor2_gear) == 0)
|
|
||||||
{
|
|
||||||
int val = 9999;
|
|
||||||
if (sscanf(topic_value, "%d", &val))
|
|
||||||
{
|
|
||||||
mylog(LOG_DEBUG, "MQTT: Received value for mqtt_topic_motor2_gear: %d", val);
|
|
||||||
iMqttMotor2Gear = val;
|
|
||||||
Can_SetMotorGear(1, val);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(LOG_WARNING, "MQTT: Received mqtt_topic_motor2_gear: %s", topic_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (strcmp(message->topic, mqtt_topic_motor2_power) == 0)
|
|
||||||
{
|
|
||||||
int val = 9999;
|
|
||||||
if (sscanf(topic_value, "%d", &val))
|
|
||||||
{
|
|
||||||
mylog(LOG_DEBUG, "MQTT: Received value for mqtt_topic_motor2_power: %d", val);
|
|
||||||
iMqttMotor2Power = val;
|
|
||||||
Can_SetMotorPower(1, val);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(LOG_WARNING, "MQTT: Received mqtt_topic_motor2_power: %s", topic_value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -114,6 +100,38 @@ void my_message_callback(struct mosquitto *mosq, void *userdata, const struct mo
|
|||||||
free(topic_value);
|
free(topic_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief callback function after connection
|
||||||
|
void my_connect_callback(struct mosquitto *mosq, void *obj, int rc)
|
||||||
|
{
|
||||||
|
if (rc == 0)
|
||||||
|
{
|
||||||
|
if (mosquitto_subscribe(mosq, NULL, mqtt_topic_motor_gear_request, 0) != MOSQ_ERR_SUCCESS)
|
||||||
|
{
|
||||||
|
mylog(LOG_ERR, "MQTT: mosquitto_subscribe(mqtt_topic_motor_gear_request) failed!");
|
||||||
|
}
|
||||||
|
if (mosquitto_subscribe(mosq, NULL, mqtt_topic_motor_power_request, 0) != MOSQ_ERR_SUCCESS)
|
||||||
|
{
|
||||||
|
mylog(LOG_ERR, "MQTT: mosquitto_subscribe(mqtt_topic_motor_power_request) failed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
char message[10];
|
||||||
|
snprintf(message, sizeof(message), "0");
|
||||||
|
if (mosquitto_publish(mosq, NULL, mqtt_topic_motor_gear_request, strlen(message), &message, 0, false) != MOSQ_ERR_SUCCESS)
|
||||||
|
{
|
||||||
|
mylog(LOG_ERR, "MQTT: mosquitto_publish(mqtt_topic_motor_gear_request) failed!");
|
||||||
|
}
|
||||||
|
if (mosquitto_publish(mosq, NULL, mqtt_topic_motor_power_request, strlen(message), &message, 0, false) != MOSQ_ERR_SUCCESS)
|
||||||
|
{
|
||||||
|
mylog(LOG_ERR, "MQTT: mosquitto_publish(mqtt_topic_motor_power_request) failed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<settings.iMotorCount; i++)
|
||||||
|
{
|
||||||
|
MqttClient_Publish_MotorSwitchState(i, 0);
|
||||||
|
MqttClient_Publish_MotorActualPowerW(i, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief connect to mqtt broker
|
/// @brief connect to mqtt broker
|
||||||
/// @return
|
/// @return
|
||||||
@@ -138,6 +156,7 @@ int MqttClient_Connect()
|
|||||||
|
|
||||||
// Define a function which will be called by libmosquitto client every time when there is a new MQTT message
|
// Define a function which will be called by libmosquitto client every time when there is a new MQTT message
|
||||||
mosquitto_message_callback_set(mosq, my_message_callback);
|
mosquitto_message_callback_set(mosq, my_message_callback);
|
||||||
|
mosquitto_connect_callback_set(mosq, my_connect_callback);
|
||||||
|
|
||||||
// Connect to MQTT broker
|
// Connect to MQTT broker
|
||||||
if (mosquitto_connect(mosq, mqtt_broker_addr, mqtt_broker_port, 60) != MOSQ_ERR_SUCCESS)
|
if (mosquitto_connect(mosq, mqtt_broker_addr, mqtt_broker_port, 60) != MOSQ_ERR_SUCCESS)
|
||||||
@@ -155,76 +174,6 @@ int MqttClient_Connect()
|
|||||||
sleep(500);
|
sleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish all topics we want to subscribe
|
|
||||||
char message[10];
|
|
||||||
snprintf(message, sizeof(message), "0");
|
|
||||||
if (mosquitto_publish(mosq, NULL, mqtt_topic_motor1_gear, strlen(message), &message, 0, false) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_publish(mqtt_topic_motor1_gear) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
if (mosquitto_publish(mosq, NULL, mqtt_topic_motor1_power, strlen(message), &message, 0, false) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_publish(mqtt_topic_motor1_power) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 11;
|
|
||||||
}
|
|
||||||
if (mosquitto_publish(mosq, NULL, mqtt_topic_motor2_gear, strlen(message), &message, 0, false) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_publish(mqtt_topic_motor2_gear) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 12;
|
|
||||||
MqttClient_Close();
|
|
||||||
}
|
|
||||||
if (mosquitto_publish(mosq, NULL, mqtt_topic_motor2_power, strlen(message), &message, 0, false) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_publish(mqtt_topic_motor2_power) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 13;
|
|
||||||
}
|
|
||||||
|
|
||||||
// subscribe all needed topics
|
|
||||||
if (mosquitto_subscribe(mosq, NULL, mqtt_topic_motor1_gear, 0) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_subscribe(mqtt_topic_motor1_gear) failed!");
|
|
||||||
iHadConnectError++;
|
|
||||||
return 20;
|
|
||||||
}
|
|
||||||
if (mosquitto_subscribe(mosq, NULL, mqtt_topic_motor1_power, 0) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_subscribe(mqtt_topic_motor1_power) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 21;
|
|
||||||
}
|
|
||||||
if (mosquitto_subscribe(mosq, NULL, mqtt_topic_motor2_gear, 0) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_subscribe(mqtt_topic_motor2_gear) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 22;
|
|
||||||
}
|
|
||||||
if (mosquitto_subscribe(mosq, NULL, mqtt_topic_motor2_power, 0) != MOSQ_ERR_SUCCESS)
|
|
||||||
{
|
|
||||||
mylog(LOG_ERR, "MQTT: mosquitto_subscribe(mqtt_topic_motor2_power) failed!");
|
|
||||||
MqttClient_Close();
|
|
||||||
iHadConnectError++;
|
|
||||||
return 23;
|
|
||||||
}
|
|
||||||
|
|
||||||
nMqttMotor1SwitchState = 255;
|
|
||||||
MqttClient_Publish_MotorSwitchState(0, 0);
|
|
||||||
nMqttMotor2SwitchState = 255;
|
|
||||||
MqttClient_Publish_MotorSwitchState(1, 0);
|
|
||||||
iMqttMotor1ActualPowerW = -1;
|
|
||||||
MqttClient_Publish_MotorActualPowerW(0, 0);
|
|
||||||
iMqttMotor2ActualPowerW = -1;
|
|
||||||
MqttClient_Publish_MotorActualPowerW(1, 0);
|
|
||||||
|
|
||||||
mylog(LOG_INFO, "MQTT: Connected successfull after %d errors!", iHadConnectError);
|
mylog(LOG_INFO, "MQTT: Connected successfull after %d errors!", iHadConnectError);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -266,23 +215,15 @@ void MqttClient_Publish_MotorGear(int iMotorIndex, int iGear)
|
|||||||
{
|
{
|
||||||
if (iMotorIndex == 0)
|
if (iMotorIndex == 0)
|
||||||
{
|
{
|
||||||
if (iGear != iMqttMotor1Gear)
|
char message[100];
|
||||||
{
|
snprintf(message, sizeof(message), "%d", iGear);
|
||||||
iMqttMotor1Gear = iGear;
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_gear, strlen(message), message, 0, false);
|
||||||
char message[100];
|
|
||||||
snprintf(message, sizeof(message), "%d", iGear);
|
|
||||||
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_gear, strlen(message), message, 0, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (iMotorIndex == 1)
|
else if (iMotorIndex == 1)
|
||||||
{
|
{
|
||||||
if (iGear != iMqttMotor2Gear)
|
char message[100];
|
||||||
{
|
snprintf(message, sizeof(message), "%d", iGear);
|
||||||
iMqttMotor2Gear = iGear;
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_gear, strlen(message), message, 0, false);
|
||||||
char message[100];
|
|
||||||
snprintf(message, sizeof(message), "%d", iGear);
|
|
||||||
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_gear, strlen(message), message, 0, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,23 +235,15 @@ void MqttClient_Publish_MotorPower(int iMotorIndex, int iPower)
|
|||||||
{
|
{
|
||||||
if (iMotorIndex == 0)
|
if (iMotorIndex == 0)
|
||||||
{
|
{
|
||||||
if (iPower != iMqttMotor1Power)
|
char message[100];
|
||||||
{
|
snprintf(message, sizeof(message), "%d", iPower);
|
||||||
iMqttMotor1Power = iPower;
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_power, strlen(message), message, 0, false);
|
||||||
char message[100];
|
|
||||||
snprintf(message, sizeof(message), "%d", iPower);
|
|
||||||
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_power, strlen(message), message, 0, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (iMotorIndex == 1)
|
else if (iMotorIndex == 1)
|
||||||
{
|
{
|
||||||
if (iPower != iMqttMotor2Power)
|
char message[100];
|
||||||
{
|
snprintf(message, sizeof(message), "%d", iPower);
|
||||||
iMqttMotor2Power = iPower;
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_power, strlen(message), message, 0, false);
|
||||||
char message[100];
|
|
||||||
snprintf(message, sizeof(message), "%d", iPower);
|
|
||||||
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_power, strlen(message), message, 0, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,9 +255,9 @@ void MqttClient_Publish_MotorSwitchState(int iMotorIndex, unsigned char nSwitchS
|
|||||||
{
|
{
|
||||||
if (iMotorIndex == 0)
|
if (iMotorIndex == 0)
|
||||||
{
|
{
|
||||||
if (nSwitchState != nMqttMotor1SwitchState)
|
if (nSwitchState != nMotor1SwitchState)
|
||||||
{
|
{
|
||||||
nMqttMotor1SwitchState = nSwitchState;
|
nMotor1SwitchState = nSwitchState;
|
||||||
char message[100];
|
char message[100];
|
||||||
snprintf(message, sizeof(message), "%2X", nSwitchState);
|
snprintf(message, sizeof(message), "%2X", nSwitchState);
|
||||||
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_switchstate, strlen(message), message, 0, false);
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor1_switchstate, strlen(message), message, 0, false);
|
||||||
@@ -332,9 +265,9 @@ void MqttClient_Publish_MotorSwitchState(int iMotorIndex, unsigned char nSwitchS
|
|||||||
}
|
}
|
||||||
else if (iMotorIndex == 1)
|
else if (iMotorIndex == 1)
|
||||||
{
|
{
|
||||||
if (nSwitchState != nMqttMotor2SwitchState)
|
if (nSwitchState != nMotor2SwitchState)
|
||||||
{
|
{
|
||||||
nMqttMotor2SwitchState = nSwitchState;
|
nMotor2SwitchState = nSwitchState;
|
||||||
char message[100];
|
char message[100];
|
||||||
snprintf(message, sizeof(message), "%2X", nSwitchState);
|
snprintf(message, sizeof(message), "%2X", nSwitchState);
|
||||||
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_switchstate, strlen(message), message, 0, false);
|
mosquitto_publish(mosq, NULL, mqtt_topic_motor2_switchstate, strlen(message), message, 0, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user