feat: topic name for sensor update can now be set in terminal
This commit is contained in:
committed by
Sylvan Arnold
parent
32618389d1
commit
6b75285228
@@ -37,8 +37,6 @@
|
||||
#define TOPIC_NAME_BATTERY_POWER "homeassistant/sensor/powerwall_battery_now/state"
|
||||
#define TOPIC_NAME_BATTERY_PERCENTAGE "homeassistant/sensor/powerwall_charge/state"
|
||||
#define TOPIC_NAME_CHARGER_CHARGING_POWER "home/charger/power"
|
||||
#elif MQTT_CLIENT_IS_SENSOR
|
||||
#define TOPIC_NAME_SENSORS_UPDATE "sylvan/Home/PicoSensor/update" /*<user>/<room>/<device>/update*/
|
||||
#endif
|
||||
|
||||
typedef enum topic_ID_e {
|
||||
@@ -61,6 +59,7 @@ typedef enum topic_ID_e {
|
||||
#define MQTT_DEFAULT_USER "user"
|
||||
#define MQTT_DEFAULT_PASS "password"
|
||||
#define MQTT_DEFAULT_PUBLISH true
|
||||
#define DEFAULT_TOPIC_NAME_SENSORS_UPDATE "user/room/device/update" /*<user>/<room>/<device>/update*/
|
||||
|
||||
typedef struct mqtt_t {
|
||||
mqtt_client_t *mqtt_client; /* lwIP MQTT client handle */
|
||||
@@ -69,6 +68,7 @@ typedef struct mqtt_t {
|
||||
unsigned char client_id[32]; /* client ID used for connection: each client should have a unique ID */
|
||||
unsigned char client_user[32]; /* client user name used for connection */
|
||||
unsigned char client_pass[96]; /* client user password */
|
||||
unsigned char sensors_update_topic[64]; /* topic name for sensor updates */
|
||||
topic_ID_e in_pub_ID; /* incoming published ID, set in the incoming_publish_cb and used in the incoming_data_cb */
|
||||
/* configuration settings */
|
||||
bool doLogging; /* if it shall write log messages */
|
||||
@@ -119,7 +119,7 @@ int MqttClient_Publish_SensorValues(float temperature, float humidity) {
|
||||
McuUtility_strcatNumFloat(buf, sizeof(buf), humidity, 2);
|
||||
McuUtility_strcat(buf, sizeof(buf), (unsigned char*)"}}");
|
||||
|
||||
res = mqtt_publish(mqtt.mqtt_client, TOPIC_NAME_SENSORS_UPDATE, buf, strlen(buf), qos, retain, mqtt_publish_request_cb, NULL);
|
||||
res = mqtt_publish(mqtt.mqtt_client, mqtt.sensors_update_topic, buf, strlen(buf), qos, retain, mqtt_publish_request_cb, NULL);
|
||||
if (res != ERR_OK) {
|
||||
McuLog_error("Failed sensor values mqtt_publish: %d", res);
|
||||
(void)MqttClient_Disconnect(); /* try disconnect and connect again */
|
||||
@@ -304,7 +304,7 @@ static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len
|
||||
} else if (McuUtility_strcmp(topic, TOPIC_NAME_CHARGER_CHARGING_POWER)==0) {
|
||||
mqtt.in_pub_ID = Topic_ID_Charging_Power;
|
||||
#elif MQTT_CLIENT_IS_SENSOR
|
||||
if (McuUtility_strcmp(topic, TOPIC_NAME_SENSORS_UPDATE)==0) {
|
||||
if (McuUtility_strcmp(topic, mqtt.sensors_update_topic)==0) {
|
||||
mqtt.in_pub_ID = Topic_ID_Sensor_Update;
|
||||
#endif
|
||||
} else { /* unknown */
|
||||
@@ -405,6 +405,7 @@ uint8_t MqttClient_Connect(void) {
|
||||
McuMinINI_ini_gets(NVMC_MININI_SECTION_MQTT, NVMC_MININI_KEY_MQTT_CLIENT, MQTT_DEFAULT_CLIENT, mqtt.client_id, sizeof(mqtt.client_id), NVMC_MININI_FILE_NAME);
|
||||
McuMinINI_ini_gets(NVMC_MININI_SECTION_MQTT, NVMC_MININI_KEY_MQTT_USER, MQTT_DEFAULT_USER, mqtt.client_user, sizeof(mqtt.client_user), NVMC_MININI_FILE_NAME);
|
||||
McuMinINI_ini_gets(NVMC_MININI_SECTION_MQTT, NVMC_MININI_KEY_MQTT_PASS, MQTT_DEFAULT_PASS, mqtt.client_pass, sizeof(mqtt.client_pass), NVMC_MININI_FILE_NAME);
|
||||
McuMinINI_ini_gets(NVMC_MININI_SECTION_MQTT, NVMC_TOPIC_NAME_SENSORS_UPDATE, DEFAULT_TOPIC_NAME_SENSORS_UPDATE, mqtt.sensors_update_topic, sizeof(mqtt.sensors_update_topic), NVMC_MININI_FILE_NAME);
|
||||
mqtt.doPublishing = McuMinINI_ini_getbool(NVMC_MININI_SECTION_MQTT, NVMC_MININI_KEY_MQTT_PASS, MQTT_DEFAULT_PUBLISH, NVMC_MININI_FILE_NAME);
|
||||
#else
|
||||
McuUtility_strcpy(mqtt.broker, sizeof(mqtt.broker), MQTT_DEFAULT_BROKER);
|
||||
|
||||
Reference in New Issue
Block a user