format and try to get tcp working

");
");
");
");
");
", WIFI_SSID);
", WIFI_SSID);
");
");
");
");
", readings_index);
");
");
");
", current_pms5003_reading.pm1);
", current_pms5003_reading.pm2_5);
", current_pms5003_reading.pm10);
");
",
",
");
");
");
");
");
",
",
");
");
");
");
");
");
");
");
", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
", err);
", err);
");
", status);
");
", status);
", len);
", len);
");
");
", err);
");
", write_err);
", err);
");
", write_err);
", output_err);
", output_err);
");
");
", err);
", err);
");
");
", p->tot_len);
", p->tot_len);
",
",
");
");
", err);
", err);
", config->server_ip, config->server_port);
", config->server_ip,
");
");
");
");
", config->server_ip);
", config->server_ip);
",
",
");
");
");
");
This commit is contained in:
Travis Shears 2025-12-26 16:27:58 +01:00
parent e0a5fef8fc
commit e2140561eb
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
2 changed files with 232 additions and 251 deletions

121
node1.c
View file

@ -1,23 +1,23 @@
#include "bme280.h" #include "bme280.h"
#include "pico/cyw43_arch.h"
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "pms5003.h" #include "pms5003.h"
#include "pico/cyw43_arch.h"
#include "tcp_client.h" #include "tcp_client.h"
#include <hardware/gpio.h> #include <hardware/gpio.h>
#include <hardware/i2c.h> #include <hardware/i2c.h>
#include <hardware/uart.h> #include <hardware/uart.h>
#include <hardware/watchdog.h>
#include <pico/time.h> #include <pico/time.h>
#include <pico/types.h> #include <pico/types.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <hardware/watchdog.h>
// 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 10000 // #define LOOP_INTERVAL_MS 10000
// #define LOOP_INTERVAL_MS 30000 #define LOOP_INTERVAL_MS 30000
/** /**
* Balcony Weather Station Node 1 * Balcony Weather Station Node 1
@ -41,22 +41,23 @@ void comms_led_blink() {
gpio_put(16, comms_led_state); gpio_put(16, comms_led_state);
} }
void comms_led_update() { void comms_led_update() {
if (time_reached(comms_led_off_time)) { if (time_reached(comms_led_off_time)) {
comms_led_state = false; comms_led_state = false;
gpio_put(16, comms_led_state); gpio_put(16, comms_led_state);
} }
} }
// Callback to reset the Pico after 24 hours // Callback to reset the Pico after 24 hours
static bool cb_24h(__unused struct repeating_timer *t) { static bool cb_24h(__unused struct repeating_timer *t) {
printf("Restarting Pico after 24 hours...\n"); printf("Restarting Pico after 24 hours...\n");
watchdog_enable(1, 1); // 1 ms timeout, reset on next loop watchdog_enable(1, 1); // 1 ms timeout, reset on next loop
while (1) { tight_loop_contents(); } // Wait for reset while (1) {
return false; // Not reached tight_loop_contents();
} // Wait for reset
return false; // Not reached
} }
static tcp_client_config tcp_config; static tcp_client_config tcp_config;
static bool wifi_connected = false;
static pms5003_config pms_config; static pms5003_config pms_config;
static pms5003_reading current_pms5003_reading; static pms5003_reading current_pms5003_reading;
@ -67,22 +68,23 @@ static bme280_reading current_bem280_reading;
// Initialize WiFi connection // Initialize WiFi connection
bool wifi_init(void) { bool wifi_init(void) {
if (cyw43_arch_init()) { printf("Initializing WiFi...\n");
printf("Failed to initialize CYW43\n"); if (cyw43_arch_init()) {
return false; printf("Failed to initialize CYW43\n");
} return false;
}
cyw43_arch_enable_sta_mode(); cyw43_arch_enable_sta_mode();
printf("Connecting to WiFi '%s'...\n", WIFI_SSID); printf("Connecting to WiFi '%s'...\n", WIFI_SSID);
if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD,
CYW43_AUTH_WPA2_AES_PSK, 30000)) { CYW43_AUTH_WPA2_AES_PSK, 60000)) {
printf("Failed to connect to WiFi\n"); printf("Failed to connect to WiFi\n");
return false; return false;
} }
printf("WiFi connected successfully\n"); printf("WiFi connected successfully\n");
return true; return true;
} }
/** /**
@ -92,13 +94,10 @@ static bool cb_30(__unused struct repeating_timer *t) {
comms_led_blink(); comms_led_blink();
printf("cb_30: %d\n", readings_index); printf("cb_30: %d\n", readings_index);
// Read BME280 // Read BME280
printf("Making BME280 Reading\n"); printf("Making BME280 Reading\n");
current_bem280_reading = bme280_read(&bem_config); current_bem280_reading = bme280_read(&bem_config);
if (readings_index == 2) { if (readings_index == 2) {
printf("Warming up PMSS5003\n"); printf("Warming up PMSS5003\n");
pms5003_warmup(&pms_config); pms5003_warmup(&pms_config);
@ -112,10 +111,6 @@ static bool cb_30(__unused struct repeating_timer *t) {
if (readings_index == 6) { if (readings_index == 6) {
printf("Finished reading PMSS5003\n"); printf("Finished reading PMSS5003\n");
current_pms5003_reading = pms5003_finish_reading(&pms_config); current_pms5003_reading = pms5003_finish_reading(&pms_config);
// TODO: send data to backend server if WiFi is connected
// printf("PM1: %.2f\n", current_pms5003_reading.pm1);
// printf("PM2.5: %.2f\n", current_pms5003_reading.pm2_5);
// printf("PM10: %.2f\n", current_pms5003_reading.pm10);
} }
readings_index++; readings_index++;
@ -123,44 +118,35 @@ static bool cb_30(__unused struct repeating_timer *t) {
readings_index = 0; readings_index = 0;
} }
if (!wifi_connected) {
printf("WiFi not connected, skipping send\n");
return true;
}
char msg[256]; char msg[256];
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg), "M001,%.2f,%.2f,%2f\n",
"M001,%.2f,%.2f,%2f\n", current_bem280_reading.temperature, current_bem280_reading.pressure,
current_bem280_reading.temperature, current_bem280_reading.humidity);
current_bem280_reading.pressure,
current_bem280_reading.humidity);
printf("Sending temperature, pressure, and humidity to backend server...\n"); printf("Sending temperature, pressure, and humidity to backend server...\n");
printf("MSG: %s", msg); printf("MSG: %s", msg);
bool success = tcp_client_send_message(&tcp_config, msg); bool success = tcp_client_send_message(&tcp_config, msg);
if (success) { if (success) {
printf("✓ Data sent successfully\n"); printf("✓ Data sent successfully\n");
comms_led_blink(); comms_led_blink();
} else { } else {
printf("✗ Failed to send data\n"); printf("✗ Failed to send data\n");
return false; return false;
} }
// send PM readings // send PM readings
if (readings_index == 6) { if (readings_index == 6) {
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg), "M02,%.2f,%.2f,%2f\n",
"M02,%.2f,%.2f,%2f\n", current_pms5003_reading.pm1, current_pms5003_reading.pm2_5,
current_pms5003_reading.pm1, current_pms5003_reading.pm10);
current_pms5003_reading.pm2_5,
current_pms5003_reading.pm10);
printf("Sending particulate matter readings to backend server...\n"); printf("Sending particulate matter readings to backend server...\n");
printf("MSG: %s", msg); printf("MSG: %s", msg);
bool success = tcp_client_send_message(&tcp_config, msg); bool success = tcp_client_send_message(&tcp_config, msg);
if (success) { if (success) {
printf("✓ Data sent successfully\n"); printf("✓ Data sent successfully\n");
comms_led_blink(); comms_led_blink();
} else { } else {
printf("✗ Failed to send data\n"); printf("✗ Failed to send data\n");
return false; return false;
} }
} }
@ -170,34 +156,25 @@ static bool cb_30(__unused struct repeating_timer *t) {
int main() { int main() {
stdio_init_all(); stdio_init_all();
watchdog_enable(60000, 1); watchdog_enable(60000, 1);
sleep_ms(2000); // Give time for USB serial sleep_ms(2000); // Give time for USB serial
// Initialize communication LED // Initialize communication LED
comms_led_init(); comms_led_init();
// Initialize WiFi // Initialize WiFi
printf("Initializing WiFi...\n");
if (!wifi_init()) { if (!wifi_init()) {
printf("WiFi initialization failed!\n"); panic("WiFi initialization failed!");
panic("WiFi initialization failed!"); }
} else { if (!tcp_client_init(&tcp_config, BACKEND_SERVER_IP, BACKEND_SERVER_PORT,
wifi_connected = true; 20000)) {
// Initialize TCP client panic("TCP client initialization failed!");
if (!tcp_client_init(&tcp_config, BACKEND_SERVER_IP,
BACKEND_SERVER_PORT, 10000)) {
printf("TCP client initialization failed\n");
panic("TCP client initialization failed!");
wifi_connected = false;
} else {
printf("TCP client ready: %s:%d\n", BACKEND_SERVER_IP, BACKEND_SERVER_PORT);
}
} }
// Setup BME280 // Setup BME280
bme280_init(&bem_config, i2c1, 14, 15); bme280_init(&bem_config, i2c1, 14, 15);
// Setup PMS5003 // Setup PMS5003
// pms5003_init(&pms_config, uart1, 20, 21, 18, 19); pms5003_init(&pms_config, uart1, 20, 21, 18, 19);
struct repeating_timer timer_30; struct repeating_timer timer_30;
add_repeating_timer_ms(LOOP_INTERVAL_MS, cb_30, NULL, &timer_30); add_repeating_timer_ms(LOOP_INTERVAL_MS, cb_30, NULL, &timer_30);

View file

@ -4,247 +4,251 @@
*/ */
#include "tcp_client.h" #include "tcp_client.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include "pico/time.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEBUG_printf printf #define DEBUG_printf printf
#define MAX_RETRY_COUNT 3 #define MAX_RETRY_COUNT 3
typedef struct { typedef struct {
struct tcp_pcb *tcp_pcb; struct tcp_pcb *tcp_pcb;
ip_addr_t remote_addr; ip_addr_t remote_addr;
uint16_t remote_port; uint16_t remote_port;
const char *message; const char *message;
int message_len; int message_len;
int sent_len; int sent_len;
bool complete; bool complete;
bool success; bool success;
bool connected; bool connected;
uint32_t timeout_ms; uint32_t timeout_ms;
absolute_time_t timeout_time; absolute_time_t timeout_time;
} tcp_client_state_t; } tcp_client_state_t;
static err_t tcp_client_close(tcp_client_state_t *state) { static err_t tcp_client_close(tcp_client_state_t *state) {
err_t err = ERR_OK; err_t err = ERR_OK;
if (state->tcp_pcb != NULL) { if (state->tcp_pcb != NULL) {
tcp_arg(state->tcp_pcb, NULL); tcp_arg(state->tcp_pcb, NULL);
tcp_poll(state->tcp_pcb, NULL, 0); tcp_poll(state->tcp_pcb, NULL, 0);
tcp_sent(state->tcp_pcb, NULL); tcp_sent(state->tcp_pcb, NULL);
tcp_recv(state->tcp_pcb, NULL); tcp_recv(state->tcp_pcb, NULL);
tcp_err(state->tcp_pcb, NULL); tcp_err(state->tcp_pcb, NULL);
err = tcp_close(state->tcp_pcb); err = tcp_close(state->tcp_pcb);
if (err != ERR_OK) { if (err != ERR_OK) {
DEBUG_printf("tcp_client: close failed %d, calling abort\n", err); DEBUG_printf("tcp_client: close failed %d, calling abort\n", err);
tcp_abort(state->tcp_pcb); tcp_abort(state->tcp_pcb);
err = ERR_ABRT; err = ERR_ABRT;
}
state->tcp_pcb = NULL;
} }
return err; state->tcp_pcb = NULL;
}
return err;
} }
static err_t tcp_client_result(tcp_client_state_t *state, int status) { static err_t tcp_client_result(tcp_client_state_t *state, int status) {
if (status == 0) { if (status == 0) {
DEBUG_printf("tcp_client: send success\n"); DEBUG_printf("tcp_client: send success\n");
state->success = true; state->success = true;
} else { } else {
DEBUG_printf("tcp_client: send failed %d\n", status); DEBUG_printf("tcp_client: send failed %d\n", status);
state->success = false; state->success = false;
} }
state->complete = true; state->complete = true;
return tcp_client_close(state); return tcp_client_close(state);
} }
static err_t tcp_client_sent(void *arg, struct tcp_pcb *tpcb, u16_t len) { static err_t tcp_client_sent(void *arg, struct tcp_pcb *tpcb, u16_t len) {
tcp_client_state_t *state = (tcp_client_state_t*)arg; tcp_client_state_t *state = (tcp_client_state_t *)arg;
DEBUG_printf("tcp_client: sent %u bytes\n", len); DEBUG_printf("tcp_client: sent %u bytes\n", len);
state->sent_len += len; state->sent_len += len;
if (state->sent_len >= state->message_len) { if (state->sent_len >= state->message_len) {
DEBUG_printf("tcp_client: message sent completely\n"); DEBUG_printf("tcp_client: message sent completely\n");
return tcp_client_result(state, 0); return tcp_client_result(state, 0);
} }
return ERR_OK; return ERR_OK;
} }
static err_t tcp_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err) { static err_t tcp_client_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
tcp_client_state_t *state = (tcp_client_state_t*)arg; tcp_client_state_t *state = (tcp_client_state_t *)arg;
if (err != ERR_OK) { if (err != ERR_OK) {
DEBUG_printf("tcp_client: connect failed %d\n", err); DEBUG_printf("tcp_client: connect failed %d\n", err);
return tcp_client_result(state, err); return tcp_client_result(state, err);
} }
state->connected = true; state->connected = true;
DEBUG_printf("tcp_client: connected, sending message\n"); DEBUG_printf("tcp_client: connected, sending message\n");
// Send the message // Send the message
cyw43_arch_lwip_begin(); cyw43_arch_lwip_begin();
err_t write_err = tcp_write(tpcb, state->message, state->message_len, TCP_WRITE_FLAG_COPY); err_t write_err =
if (write_err != ERR_OK) { tcp_write(tpcb, state->message, state->message_len, TCP_WRITE_FLAG_COPY);
DEBUG_printf("tcp_client: failed to write data %d\n", write_err); if (write_err != ERR_OK) {
cyw43_arch_lwip_end(); DEBUG_printf("tcp_client: failed to write data %d\n", write_err);
return tcp_client_result(state, -1);
}
// Flush the data
err_t output_err = tcp_output(tpcb);
cyw43_arch_lwip_end(); cyw43_arch_lwip_end();
return tcp_client_result(state, -1);
}
if (output_err != ERR_OK) { // Flush the data
DEBUG_printf("tcp_client: failed to output data %d\n", output_err); err_t output_err = tcp_output(tpcb);
return tcp_client_result(state, -1); cyw43_arch_lwip_end();
}
return ERR_OK; if (output_err != ERR_OK) {
DEBUG_printf("tcp_client: failed to output data %d\n", output_err);
return tcp_client_result(state, -1);
}
return ERR_OK;
} }
static err_t tcp_client_poll(void *arg, struct tcp_pcb *tpcb) { static err_t tcp_client_poll(void *arg, struct tcp_pcb *tpcb) {
tcp_client_state_t *state = (tcp_client_state_t*)arg; tcp_client_state_t *state = (tcp_client_state_t *)arg;
DEBUG_printf("tcp_client: poll timeout\n"); DEBUG_printf("tcp_client: poll timeout\n");
return tcp_client_result(state, -1); return tcp_client_result(state, -1);
} }
static void tcp_client_err(void *arg, err_t err) { static void tcp_client_err(void *arg, err_t err) {
tcp_client_state_t *state = (tcp_client_state_t*)arg; tcp_client_state_t *state = (tcp_client_state_t *)arg;
if (err != ERR_ABRT) { if (err != ERR_ABRT) {
DEBUG_printf("tcp_client: error %d\n", err); DEBUG_printf("tcp_client: error %d\n", err);
state->success = false; state->success = false;
state->complete = true; state->complete = true;
} }
} }
static err_t tcp_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { static err_t tcp_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_client_state_t *state = (tcp_client_state_t*)arg; err_t err) {
tcp_client_state_t *state = (tcp_client_state_t *)arg;
if (!p) { if (!p) {
DEBUG_printf("tcp_client: connection closed by server\n"); DEBUG_printf("tcp_client: connection closed by server\n");
return tcp_client_result(state, 0); return tcp_client_result(state, 0);
} }
cyw43_arch_lwip_check(); cyw43_arch_lwip_check();
if (p->tot_len > 0) { if (p->tot_len > 0) {
DEBUG_printf("tcp_client: received %d bytes (ignoring)\n", p->tot_len); DEBUG_printf("tcp_client: received %d bytes (ignoring)\n", p->tot_len);
tcp_recved(tpcb, p->tot_len); tcp_recved(tpcb, p->tot_len);
} }
pbuf_free(p); pbuf_free(p);
return ERR_OK; return ERR_OK;
} }
static bool tcp_client_open(tcp_client_state_t *state) { static bool tcp_client_open(tcp_client_state_t *state) {
DEBUG_printf("tcp_client: connecting to %s port %u\n", DEBUG_printf("tcp_client: connecting to %s port %u\n",
ip4addr_ntoa(&state->remote_addr), state->remote_port); ip4addr_ntoa(&state->remote_addr), state->remote_port);
state->tcp_pcb = tcp_new_ip_type(IP_GET_TYPE(&state->remote_addr)); state->tcp_pcb = tcp_new_ip_type(IP_GET_TYPE(&state->remote_addr));
if (!state->tcp_pcb) { if (!state->tcp_pcb) {
DEBUG_printf("tcp_client: failed to create pcb\n"); DEBUG_printf("tcp_client: failed to create pcb\n");
return false; return false;
} }
tcp_arg(state->tcp_pcb, state); tcp_arg(state->tcp_pcb, state);
tcp_poll(state->tcp_pcb, tcp_client_poll, 10); tcp_poll(state->tcp_pcb, tcp_client_poll, 10);
tcp_sent(state->tcp_pcb, tcp_client_sent); tcp_sent(state->tcp_pcb, tcp_client_sent);
tcp_recv(state->tcp_pcb, tcp_client_recv); tcp_recv(state->tcp_pcb, tcp_client_recv);
tcp_err(state->tcp_pcb, tcp_client_err); tcp_err(state->tcp_pcb, tcp_client_err);
state->sent_len = 0; state->sent_len = 0;
state->timeout_time = make_timeout_time_ms(state->timeout_ms); state->timeout_time = make_timeout_time_ms(state->timeout_ms);
cyw43_arch_lwip_begin(); cyw43_arch_lwip_begin();
err_t err = tcp_connect(state->tcp_pcb, &state->remote_addr, err_t err = tcp_connect(state->tcp_pcb, &state->remote_addr,
state->remote_port, tcp_client_connected); state->remote_port, tcp_client_connected);
cyw43_arch_lwip_end(); cyw43_arch_lwip_end();
if (err != ERR_OK) { if (err != ERR_OK) {
DEBUG_printf("tcp_client: tcp_connect failed %d\n", err); DEBUG_printf("tcp_client: tcp_connect failed %d\n", err);
return false; return false;
} }
return true; return true;
} }
bool tcp_client_init(tcp_client_config *config, const char *server_ip, bool tcp_client_init(tcp_client_config *config, const char *server_ip,
uint16_t server_port, uint32_t timeout_ms) { uint16_t server_port, uint32_t timeout_ms) {
if (!config || !server_ip) { if (!config || !server_ip) {
return false; return false;
} }
strncpy(config->server_ip, server_ip, sizeof(config->server_ip) - 1); strncpy(config->server_ip, server_ip, sizeof(config->server_ip) - 1);
config->server_ip[sizeof(config->server_ip) - 1] = '\0'; config->server_ip[sizeof(config->server_ip) - 1] = '\0';
config->server_port = server_port; config->server_port = server_port;
config->timeout_ms = timeout_ms; config->timeout_ms = timeout_ms;
config->initialized = true; config->initialized = true;
config->internal_state = NULL; config->internal_state = NULL;
DEBUG_printf("tcp_client: initialized for %s:%u\n", config->server_ip, config->server_port); DEBUG_printf("tcp_client: initialized for %s:%u\n", config->server_ip,
return true; config->server_port);
return true;
} }
bool tcp_client_send_message(tcp_client_config *config, const char *message) { bool tcp_client_send_message(tcp_client_config *config, const char *message) {
if (!config || !config->initialized || !message) { if (!config || !config->initialized || !message) {
DEBUG_printf("tcp_client: invalid config or message\n"); DEBUG_printf("tcp_client: invalid config or message\n");
return false; return false;
} }
tcp_client_state_t *state = calloc(1, sizeof(tcp_client_state_t)); tcp_client_state_t *state = calloc(1, sizeof(tcp_client_state_t));
if (!state) { if (!state) {
DEBUG_printf("tcp_client: failed to allocate state\n"); DEBUG_printf("tcp_client: failed to allocate state\n");
return false; return false;
} }
// Convert IP address // Convert IP address
if (!ip4addr_aton(config->server_ip, &state->remote_addr)) { if (!ip4addr_aton(config->server_ip, &state->remote_addr)) {
DEBUG_printf("tcp_client: invalid IP address %s\n", config->server_ip); DEBUG_printf("tcp_client: invalid IP address %s\n", config->server_ip);
free(state);
return false;
}
state->remote_port = config->server_port;
state->message = message;
state->message_len = strlen(message);
state->timeout_ms = config->timeout_ms;
state->complete = false;
state->success = false;
state->connected = false;
DEBUG_printf("tcp_client: sending message (%d bytes): %s\n",
state->message_len, message);
if (!tcp_client_open(state)) {
DEBUG_printf("tcp_client: failed to open connection\n");
free(state);
return false;
}
// Wait for completion or timeout
while (!state->complete) {
if (time_reached(state->timeout_time)) {
DEBUG_printf("tcp_client: operation timed out\n");
tcp_client_close(state);
state->complete = true;
state->success = false;
break;
}
cyw43_arch_poll();
cyw43_arch_wait_for_work_until(make_timeout_time_ms(100));
}
bool success = state->success;
free(state); free(state);
return false;
}
return success; state->remote_port = config->server_port;
state->message = message;
state->message_len = strlen(message);
state->timeout_ms = config->timeout_ms;
state->complete = false;
state->success = false;
state->connected = false;
DEBUG_printf("tcp_client: sending message (%d bytes): %s\n",
state->message_len, message);
if (!tcp_client_open(state)) {
DEBUG_printf("tcp_client: failed to open connection\n");
free(state);
return false;
}
// Wait for completion or timeout
while (!state->complete) {
cyw43_arch_poll();
cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000));
if (time_reached(state->timeout_time)) {
DEBUG_printf("tcp_client: operation timed out\n");
tcp_client_close(state);
state->complete = true;
state->success = false;
break;
}
}
bool success = state->success;
free(state);
return success;
} }
void tcp_client_cleanup(tcp_client_config *config) { void tcp_client_cleanup(tcp_client_config *config) {
if (config) { if (config) {
config->initialized = false; config->initialized = false;
config->internal_state = NULL; config->internal_state = NULL;
} }
} }