This commit is contained in:
j3d1 2022-06-27 20:00:48 +02:00
parent 7424a80945
commit 8b0020c387
7 changed files with 79 additions and 20 deletions

View file

@ -3,6 +3,7 @@
//
#include "mqtt.h"
#include "wifi.h"
#include <stdio.h>
#include <string.h>
@ -22,15 +23,18 @@ extern "C" {
/* You can use http://test.mosquitto.org/ to test mqtt_client instead
* of setting up your own MQTT server */
#define MQTT_HOST ("172.16.0.42")
//#define MQTT_HOST ("172.16.0.42")
#define MQTT_HOST ("10.23.42.187")
#define MQTT_PORT 1883
#define MQTT_USER NULL
#define MQTT_PASS NULL
QueueHandle_t publish_queue;
#define PUB_MSG_LEN 16
QueueHandle_t publish_queue;
extern "C" void beat_task(void *pvParameters) {
TickType_t xLastWakeTime = xTaskGetTickCount();
char msg[PUB_MSG_LEN];
@ -98,13 +102,14 @@ extern "C" void mqtt_task(void *pvParameters) {
strcat(mqtt_client_id, get_my_id());
while (1) {
xSemaphoreTake(wifi_alive, portMAX_DELAY);
printf("%s: started\n\r", __func__);
printf("%s: (Re)connecting to MQTT server %s ... ", __func__,
MQTT_HOST);
ret = mqtt_network_connect(&network, MQTT_HOST, MQTT_PORT);
if(ret) {
printf("error: %d\n\r", ret);
taskYIELD();
printf("error 1: %d\n\r", ret);
vTaskDelay(1000 / portTICK_PERIOD_MS);
continue;
}
printf("done\n\r");
@ -121,9 +126,9 @@ extern "C" void mqtt_task(void *pvParameters) {
printf("Send MQTT connect ... ");
ret = mqtt_connect(&client, &data);
if(ret) {
printf("error: %d\n\r", ret);
printf("error 2: %d\n\r", ret);
mqtt_network_disconnect(&network);
taskYIELD();
vTaskDelay(1000 / portTICK_PERIOD_MS);
continue;
}
printf("done\r\n");