Skip to content

Commit

Permalink
Revised to pass char*
Browse files Browse the repository at this point in the history
  • Loading branch information
iprak committed Oct 21, 2022
1 parent 1471131 commit 92b4bf1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,15 +1303,15 @@ int http_fn_ha_discovery(http_request_t* request) {

//Invoke publishChannles after the last topic
if (dev_info != NULL) {
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, MQTT_COMMAND_PUBLISH_CHANNELS);
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, PublishChannels);
hass_free_device_info(dev_info);
}
}

if (pwmCount == 5 || isLedDriverChipRunning()) {
// Enable + RGB control + CW control
dev_info = hass_init_light_device_info(ENTITY_LIGHT_RGBCW);
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, MQTT_COMMAND_PUBLISH_CHANNELS);
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, PublishChannels);
hass_free_device_info(dev_info);
}
else if (pwmCount > 0) {
Expand All @@ -1331,7 +1331,7 @@ int http_fn_ha_discovery(http_request_t* request) {
}

if (dev_info != NULL) {
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, MQTT_COMMAND_PUBLISH_CHANNELS);
MQTT_QueuePublishWithCommand(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN, PublishChannels);
hass_free_device_info(dev_info);
}
}
Expand Down Expand Up @@ -1677,7 +1677,7 @@ int http_fn_cfg(http_request_t* request) {
http_html_end(request);
poststr(request, NULL);
return 0;
}
}

int http_fn_cfg_pins(http_request_t* request) {
int iChanged = 0;
Expand Down Expand Up @@ -1741,7 +1741,7 @@ int http_fn_cfg_pins(http_request_t* request) {
iChanged++;
}
}
}
}
if (iChangedRequested > 0) {
// Anecdotally, if pins are configured badly, the
// second-timer breaks. To reconfigure, force
Expand Down
15 changes: 11 additions & 4 deletions src/mqtt/new_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ MqttPublishItem_t* find_queue_reusable_item(MqttPublishItem_t* head) {
/// @param value
/// @param flags
/// @param command Command to execute after the publish
void MQTT_QueuePublishWithCommand(char* topic, char* channel, char* value, int flags, const char* command) {
void MQTT_QueuePublishWithCommand(char* topic, char* channel, char* value, int flags, PostPublishCommands command) {
if (g_MqttPublishItemsQueued >= MQTT_MAX_QUEUE_SIZE) {
addLogAdv(LOG_ERROR, LOG_FEATURE_MQTT, "Unable to queue! %i items already present\r\n", g_MqttPublishItemsQueued);
return;
Expand Down Expand Up @@ -1237,7 +1237,7 @@ void MQTT_QueuePublishWithCommand(char* topic, char* channel, char* value, int f
/// @param value
/// @param flags
void MQTT_QueuePublish(char* topic, char* channel, char* value, int flags) {
MQTT_QueuePublishWithCommand(topic, channel, value, flags, NULL);
MQTT_QueuePublishWithCommand(topic, channel, value, flags, None);
}


Expand All @@ -1262,8 +1262,15 @@ OBK_Publish_Result PublishQueuedItems() {
//Stop if last publish failed
if (result != OBK_PUBLISH_OK) break;

if (head->command != NULL) {
CMD_ExecuteCommand(head->command, COMMAND_FLAG_SOURCE_MQTT);
switch (head->command) {
case None:
break;
case PublishAll:
CMD_ExecuteCommand(MQTT_COMMAND_PUBLISH_ALL, COMMAND_FLAG_SOURCE_MQTT);
break;
case PublishChannels:
CMD_ExecuteCommand(MQTT_COMMAND_PUBLISH_CHANNELS, COMMAND_FLAG_SOURCE_MQTT);
break;
}
}
else {
Expand Down
11 changes: 9 additions & 2 deletions src/mqtt/new_mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ typedef struct obk_mqtt_request_tag {
#define MQTT_PUBLISH_ITEM_CHANNEL_LENGTH 64
#define MQTT_PUBLISH_ITEM_VALUE_LENGTH 1023

typedef enum PostPublishCommands_e {
None,
PublishAll,
PublishChannels
} PostPublishCommands;


/// @brief Publish queue item
typedef struct MqttPublishItem
{
Expand All @@ -49,7 +56,7 @@ typedef struct MqttPublishItem
char value[MQTT_PUBLISH_ITEM_VALUE_LENGTH];
int flags;
struct MqttPublishItem* next;
const char* command;
PostPublishCommands command;
} MqttPublishItem_t;

#define MQTT_COMMAND_PUBLISH "publish"
Expand Down Expand Up @@ -88,7 +95,7 @@ OBK_Publish_Result MQTT_PublishMain_StringString(const char* sChannel, const cha
OBK_Publish_Result MQTT_ChannelChangeCallback(int channel, int iVal);
void MQTT_PublishOnlyDeviceChannelsIfPossible();
void MQTT_QueuePublish(char* topic, char* channel, char* value, int flags);
void MQTT_QueuePublishWithCommand(char* topic, char* channel, char* value, int flags, const char* command);
void MQTT_QueuePublishWithCommand(char* topic, char* channel, char* value, int flags, PostPublishCommands command);
OBK_Publish_Result MQTT_Publish(char* sTopic, char* sChannel, char* value, int flags);
bool MQTT_IsReady();

Expand Down

0 comments on commit 92b4bf1

Please sign in to comment.