--- a/mqtt/mqtt_template.c Wed Jan 22 22:05:08 2025 +0100
+++ b/mqtt/mqtt_template.c Sun Jan 26 14:58:13 2025 +0100
@@ -260,8 +260,11 @@
}}
-typedef int(*callback_fptr_t)(char* topic, char* data, uint32_t datalen);
-static callback_fptr_t __mqtt_python_callback_fptr_{name} = NULL;
+typedef int(*cb_onmsg_fptr_t)(char* topic, char* data, uint32_t datalen);
+static cb_onmsg_fptr_t __mqtt_python_cb_onmsg_fptr_{name} = NULL;
+
+typedef int(*cb_resub_fptr_t)(void);
+static cb_resub_fptr_t __mqtt_python_cb_resub_fptr_{name} = NULL;
static int messageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message)
{{
@@ -309,8 +312,8 @@
high = mid - 1;
}}
// If we reach here, then the element was not present
- if(__mqtt_python_callback_fptr_{name} &&
- (*__mqtt_python_callback_fptr_{name})(topicName,
+ if(__mqtt_python_cb_onmsg_fptr_{name} &&
+ (*__mqtt_python_cb_onmsg_fptr_{name})(topicName,
(char*)message->payload,
message->payloadlen) == 0){{
// Topic was handled in python
@@ -405,7 +408,7 @@
#define PUBLISH_JSON(Topic, QoS, C_type, c_loc_name, Retained) \
int res = json_gen_##c_loc_name(&MQTT_##c_loc_name##_buf); \
if(res == 0) {{ \
- _PUBLISH(Topic, QoS, json_out_len, json_out_buf, Retained) \
+ _PUBLISH(#Topic, QoS, json_out_len, json_out_buf, Retained) \
}}
#define INIT_PUBLICATION(encoding, Topic, QoS, C_type, c_loc_name, Retained) \
@@ -458,6 +461,10 @@
{init_pubsub}
+ if(__mqtt_python_cb_resub_fptr_{name}){{
+ (*__mqtt_python_cb_resub_fptr_{name})();
+ }}
+
return MQTTCLIENT_SUCCESS;
}}
@@ -630,8 +637,9 @@
return 0;
}}
-int __mqtt_python_callback_setter_{name}(callback_fptr_t cb)
-{{
- __mqtt_python_callback_fptr_{name} = cb;
+int __mqtt_python_callback_setter_{name}(cb_onmsg_fptr_t cb_onmsg, cb_resub_fptr_t cb_resub)
+{{
+ __mqtt_python_cb_onmsg_fptr_{name} = cb_onmsg;
+ __mqtt_python_cb_resub_fptr_{name} = cb_resub;
return 0;
}}