mqtt client test (experimental)
This commit is contained in:
parent
05e5d31a53
commit
014bae059e
@ -10,6 +10,7 @@
|
|||||||
#define MQTT_OUTTOPIC "paxcounter_out/"
|
#define MQTT_OUTTOPIC "paxcounter_out/"
|
||||||
#define MQTT_PORT 1883
|
#define MQTT_PORT 1883
|
||||||
#define MQTT_SERVER "broker.hivemq.com"
|
#define MQTT_SERVER "broker.hivemq.com"
|
||||||
|
#define MQTT_RETRYSEC 10 // retry reconnect every 10 seconds
|
||||||
|
|
||||||
extern TaskHandle_t mqttTask;
|
extern TaskHandle_t mqttTask;
|
||||||
extern PubSubClient mqttClient;
|
extern PubSubClient mqttClient;
|
||||||
|
@ -97,13 +97,12 @@ void mqtt_client_task(void *param) {
|
|||||||
} else
|
} else
|
||||||
goto reconnect;
|
goto reconnect;
|
||||||
|
|
||||||
} else { // not connected, thus re-enqueue the undelivered message
|
} else {
|
||||||
|
|
||||||
reconnect:
|
|
||||||
|
|
||||||
mqtt_enqueuedata(&msg);
|
|
||||||
delay(10000);
|
|
||||||
// attempt to reconnect to MQTT server
|
// attempt to reconnect to MQTT server
|
||||||
|
reconnect:
|
||||||
|
mqtt_enqueuedata(&msg); // postpone the undelivered message
|
||||||
|
delay(MQTT_RETRYSEC * 1000);
|
||||||
mqtt_connect(MQTT_SERVER, MQTT_PORT);
|
mqtt_connect(MQTT_SERVER, MQTT_PORT);
|
||||||
}
|
}
|
||||||
} // while(1)
|
} // while(1)
|
||||||
@ -151,11 +150,14 @@ void mqtt_enqueuedata(MessageBuffer_t *message) {
|
|||||||
ESP_LOGW(TAG, "MQTT sendqueue is full");
|
ESP_LOGW(TAG, "MQTT sendqueue is full");
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); }
|
|
||||||
|
|
||||||
void mqtt_callback(char *topic, byte *payload, unsigned int length) {
|
void mqtt_callback(char *topic, byte *payload, unsigned int length) {
|
||||||
ESP_LOGD(TAG, "MQTT %d byte(s) received", length);
|
String s = "";
|
||||||
rcommand(payload, length);
|
for (int i = 0; i < length; i++)
|
||||||
|
s += (char)payload[i];
|
||||||
|
ESP_LOGD(TAG, "MQTT: Received %u byte(s) of payload [%s]", length, s);
|
||||||
|
// rcommand(payload, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mqtt_queuereset(void) { xQueueReset(MQTTSendQueue); }
|
||||||
|
|
||||||
#endif // HAS_MQTT
|
#endif // HAS_MQTT
|
Loading…
Reference in New Issue
Block a user