diff --git a/firmware/.vscode/c_cpp_properties.json b/firmware/.vscode/c_cpp_properties.json index c2b35c91..d92e91f7 100644 --- a/firmware/.vscode/c_cpp_properties.json +++ b/firmware/.vscode/c_cpp_properties.json @@ -2,7 +2,7 @@ "configurations": [ { "name": "ESP-IDF", - "compilerPath": "/home/snips/.espressif/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/riscv32-esp-elf-gcc", + "compilerPath": "${config:idf.toolsPath}/tools/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin/riscv32-esp-elf-gcc", "includePath": [ "${config:idf.espIdfPath}/components/**", "${config:idf.espIdfPathWin}/components/**", diff --git a/firmware/.vscode/settings.json b/firmware/.vscode/settings.json index 17550758..155c97b6 100644 --- a/firmware/.vscode/settings.json +++ b/firmware/.vscode/settings.json @@ -7,6 +7,7 @@ "idf.portWin": "COM4", "idf.flashType": "UART", "files.associations": { + "*.php7": "php", "esp_event.h": "c", "array": "c", "string": "c", @@ -26,7 +27,8 @@ "deque": "cpp", "vector": "cpp", "mutex": "cpp", - "*.tcc": "cpp" + "*.tcc": "cpp", + "esp_sleep.h": "c" }, "idf.port": "/dev/ttyACM0" } diff --git a/firmware/main/EventParticipationTrendsFirmware.cpp b/firmware/main/EventParticipationTrendsFirmware.cpp index e50e5784..fb936915 100644 --- a/firmware/main/EventParticipationTrendsFirmware.cpp +++ b/firmware/main/EventParticipationTrendsFirmware.cpp @@ -28,7 +28,7 @@ typedef struct { uint8_t mac[6]; } newPacket; -#define QUEUE_SIZE 5000 +#define QUEUE_SIZE 1000 QueueHandle_t packetQueue; std::mutex macs_mutex; @@ -74,8 +74,10 @@ static void SendBufferAsSingleJsonArray(void*){ data += "]}"; macs.clear(); macs_mutex.unlock(); + esp_wifi_set_promiscuous(false); mqtt_publish_sensor(data.c_str()); flashLed(); + esp_wifi_set_promiscuous(true); vTaskDelete(NULL); } diff --git a/firmware/main/mqtt.c b/firmware/main/mqtt.c index 5ab2316b..99da1e95 100644 --- a/firmware/main/mqtt.c +++ b/firmware/main/mqtt.c @@ -1,5 +1,6 @@ #include "mqtt.h" #include "utils.h" +#include "esp_sleep.h" const char *MQTT_TAG = "MQTT_H"; static esp_mqtt_client_handle_t mqtt_client = NULL; @@ -45,8 +46,16 @@ static void mqtt_event_handler(void *args, esp_event_base_t base, int32_t event_ ESP_LOGW(MQTT_TAG, "MQTT Client has disconnected... Trying to reconnect"); esp_mqtt_client_reconnect(mqtt_client); mqtt_client_connected = false; + while (!mqtt_client_connected) + { + ESP_LOGI(MQTT_TAG, "Waiting for MQTT connection..."); + vTaskDelay(1000 / portTICK_PERIOD_MS); + } + esp_mqtt_client_subscribe(mqtt_client, "/reset", 0); + esp_mqtt_client_subscribe(mqtt_client, "/sleep", 0); break; case MQTT_EVENT_ERROR: + esp_restart(); ESP_LOGE(MQTT_TAG, "MQTT Client has encountered an Error..."); break; case MQTT_EVENT_DATA: @@ -61,6 +70,10 @@ static void mqtt_event_handler(void *args, esp_event_base_t base, int32_t event_ ESP_LOGI(MQTT_TAG, "Resetting device..."); esp_restart(); } + if(strcmp(topic_buffer, "/sleep") == 0){ + ESP_LOGI(MQTT_TAG, "Going to sleep..."); + esp_deep_sleep_start(); + } free(topic_buffer); free(data_buffer); break; @@ -105,5 +118,6 @@ esp_mqtt_client_handle_t INITIALIZE_MQTT(bool wait_for_connection) vTaskDelay(1000 / portTICK_PERIOD_MS); } esp_mqtt_client_subscribe(mqtt_client, "/reset", 0); + esp_mqtt_client_subscribe(mqtt_client, "/sleep", 0); return mqtt_client; } \ No newline at end of file