try and fix mqtt panic
This commit is contained in:
parent
dc206625bf
commit
1a25129495
3 changed files with 19 additions and 10 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "pico/cyw43_arch.h"
|
#include "pico/cyw43_arch.h"
|
||||||
#include "lwip/apps/mqtt.h"
|
#include "lwip/apps/mqtt.h"
|
||||||
|
#include "hardware/watchdog.h"
|
||||||
// #include <cstdio>
|
// #include <cstdio>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -65,9 +66,15 @@ static void start_client(MQTT_CLIENT_DATA_T *state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_client_pub_message(mqtt_client_config *config, const char *message) {
|
void mqtt_client_pub_message(mqtt_client_config *config, const char *message) {
|
||||||
if (mqtt_publish(config->state.mqtt_client_inst, config->topic, message, strlen(message), MQTT_PUBLISH_QOS, MQTT_PUBLISH_RETAIN, pub_request_cb, NULL) != ERR_OK) {
|
|
||||||
panic("MQTT publish error");
|
if (config->state.connect_done || !mqtt_client_is_connected(config->state.mqtt_client_inst)) {
|
||||||
}
|
printf("Can't send MQTT message because client is not connected\n");
|
||||||
|
}
|
||||||
|
cyw43_arch_lwip_begin();
|
||||||
|
if (mqtt_publish(config->state.mqtt_client_inst, config->topic, message, strlen(message), MQTT_PUBLISH_QOS, MQTT_PUBLISH_RETAIN, pub_request_cb, NULL) != ERR_OK) {
|
||||||
|
panic("MQTT publish error");
|
||||||
|
}
|
||||||
|
cyw43_arch_lwip_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mqtt_client_init(mqtt_client_config *config, const char *topic, const char *device_name) {
|
void mqtt_client_init(mqtt_client_config *config, const char *topic, const char *device_name) {
|
||||||
|
|
|
||||||
15
node1.c
15
node1.c
|
|
@ -15,7 +15,8 @@
|
||||||
|
|
||||||
// 5 sec loop is for testing
|
// 5 sec loop is for testing
|
||||||
// #define LOOP_INTERVAL_MS 5000
|
// #define LOOP_INTERVAL_MS 5000
|
||||||
#define LOOP_INTERVAL_MS 30000
|
#define LOOP_INTERVAL_MS 10000
|
||||||
|
// #define LOOP_INTERVAL_MS 30000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Balcony Weather Station Node 1
|
* Balcony Weather Station Node 1
|
||||||
|
|
@ -35,17 +36,15 @@ bool comms_led_state = false;
|
||||||
void comms_led_blink() {
|
void comms_led_blink() {
|
||||||
printf("COMMS LED BLINK COUNT: %d\n", comms_led_blink_count);
|
printf("COMMS LED BLINK COUNT: %d\n", comms_led_blink_count);
|
||||||
comms_led_blink_count++;
|
comms_led_blink_count++;
|
||||||
if(!comms_led_state) {
|
comms_led_state = true;
|
||||||
gpio_put(16, true);
|
|
||||||
comms_led_state = true;
|
|
||||||
}
|
|
||||||
comms_led_off_time = make_timeout_time_ms(1000);
|
comms_led_off_time = make_timeout_time_ms(1000);
|
||||||
|
gpio_put(16, comms_led_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void comms_led_update() {
|
void comms_led_update() {
|
||||||
if (comms_led_state && time_reached(comms_led_off_time)) {
|
if (time_reached(comms_led_off_time)) {
|
||||||
gpio_put(16, false);
|
|
||||||
comms_led_state = false;
|
comms_led_state = false;
|
||||||
|
gpio_put(16, comms_led_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,6 +136,7 @@ static bool cb_30(__unused struct repeating_timer *t) {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
watchdog_enable(60000, 1);
|
||||||
|
|
||||||
// Initialize communication LED
|
// Initialize communication LED
|
||||||
comms_led_init();
|
comms_led_init();
|
||||||
|
|
@ -158,5 +158,6 @@ int main() {
|
||||||
sleep_us(100);
|
sleep_us(100);
|
||||||
tight_loop_contents();
|
tight_loop_contents();
|
||||||
mqtt_client_do_network_stuff(&mqtt_config);
|
mqtt_client_do_network_stuff(&mqtt_config);
|
||||||
|
watchdog_update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ static void on_uart_rx() {
|
||||||
// end of message
|
// end of message
|
||||||
if (rx_i == 31) {
|
if (rx_i == 31) {
|
||||||
readings[reading_i] = extract_pm_values_from_rx_buf();
|
readings[reading_i] = extract_pm_values_from_rx_buf();
|
||||||
|
printf("pm1: %f, pm2.5: %f, pm10: %f\n", readings[reading_i].pm1, readings[reading_i].pm2_5, readings[reading_i].pm10);
|
||||||
reading_i++;
|
reading_i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue