This commit is contained in:
parent
b7a995e94b
commit
2b07102b69
1 changed files with 6 additions and 8 deletions
|
@ -46,8 +46,7 @@ static void publish_state(){
|
||||||
|
|
||||||
extern "C" void beat_task(void *pvParameters) {
|
extern "C" void beat_task(void *pvParameters) {
|
||||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
|
while (true) {
|
||||||
while (1) {
|
|
||||||
vTaskDelayUntil(&xLastWakeTime, 20000 / portTICK_PERIOD_MS);
|
vTaskDelayUntil(&xLastWakeTime, 20000 / portTICK_PERIOD_MS);
|
||||||
publish_state();
|
publish_state();
|
||||||
}
|
}
|
||||||
|
@ -216,7 +215,7 @@ static void topic_received(mqtt_message_data_t *md) {
|
||||||
publish_state();
|
publish_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_my_id(void) {
|
static const char *get_my_id() {
|
||||||
// Use MAC address for Station as unique ID
|
// Use MAC address for Station as unique ID
|
||||||
static char my_id[13];
|
static char my_id[13];
|
||||||
static bool my_id_done = false;
|
static bool my_id_done = false;
|
||||||
|
@ -225,7 +224,7 @@ static const char *get_my_id(void) {
|
||||||
if(my_id_done)
|
if(my_id_done)
|
||||||
return my_id;
|
return my_id;
|
||||||
if(!sdk_wifi_get_macaddr(STATION_IF, (uint8_t *) my_id))
|
if(!sdk_wifi_get_macaddr(STATION_IF, (uint8_t *) my_id))
|
||||||
return NULL;
|
return nullptr;
|
||||||
for (i = 5; i >= 0; --i) {
|
for (i = 5; i >= 0; --i) {
|
||||||
x = my_id[i] & 0x0F;
|
x = my_id[i] & 0x0F;
|
||||||
if(x > 9) x += 7;
|
if(x > 9) x += 7;
|
||||||
|
@ -241,7 +240,7 @@ static const char *get_my_id(void) {
|
||||||
|
|
||||||
extern "C" void mqtt_task(void *pvParameters) {
|
extern "C" void mqtt_task(void *pvParameters) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct mqtt_network network;
|
mqtt_network network{};
|
||||||
mqtt_client_t client = mqtt_client_default;
|
mqtt_client_t client = mqtt_client_default;
|
||||||
char mqtt_client_id[20];
|
char mqtt_client_id[20];
|
||||||
uint8_t mqtt_buf[1000];
|
uint8_t mqtt_buf[1000];
|
||||||
|
@ -253,7 +252,7 @@ extern "C" void mqtt_task(void *pvParameters) {
|
||||||
strcpy(mqtt_client_id, "fiatlux-");
|
strcpy(mqtt_client_id, "fiatlux-");
|
||||||
strcat(mqtt_client_id, get_my_id());
|
strcat(mqtt_client_id, get_my_id());
|
||||||
|
|
||||||
while (1) {
|
while (true) {
|
||||||
xSemaphoreTake(wifi_alive, portMAX_DELAY);
|
xSemaphoreTake(wifi_alive, portMAX_DELAY);
|
||||||
printf("%s: started\n\r", __func__);
|
printf("%s: started\n\r", __func__);
|
||||||
printf("%s: (Re)connecting to MQTT server %s ... ", __func__,
|
printf("%s: (Re)connecting to MQTT server %s ... ", __func__,
|
||||||
|
@ -309,12 +308,11 @@ extern "C" void mqtt_task(void *pvParameters) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (true) {
|
||||||
|
|
||||||
char msg[PUB_MSG_LEN - 1] = "\0";
|
char msg[PUB_MSG_LEN - 1] = "\0";
|
||||||
while (xQueueReceive(publish_queue, (void *) msg, 0) ==
|
while (xQueueReceive(publish_queue, (void *) msg, 0) ==
|
||||||
pdTRUE) {
|
pdTRUE) {
|
||||||
printf("got message to publish\r\n");
|
|
||||||
mqtt_message_t message;
|
mqtt_message_t message;
|
||||||
message.payload = msg;
|
message.payload = msg;
|
||||||
message.payloadlen = strlen(msg);
|
message.payloadlen = strlen(msg);
|
||||||
|
|
Loading…
Reference in a new issue