# HG changeset patch # User Michiel Broek # Date 1681640832 -7200 # Node ID 7448b8dd42889d90e63cdf0a101c276203cafcf1 # Parent 551a53b31373e7cf9fdf13b36585ad53b8b8d5cb Preparations for BLE GATT. Added extra time after INA219 is powered on before measurement. Reduced LEDC frequency to 60 Hz, that makes the LED lights less nervous. Hardware mod on output 4, now needs external pulldown resistor. diff -r 551a53b31373 -r 7448b8dd4288 main/CMakeLists.txt --- a/main/CMakeLists.txt Sat Apr 15 13:29:40 2023 +0200 +++ b/main/CMakeLists.txt Sun Apr 16 12:27:12 2023 +0200 @@ -1,2 +1,8 @@ -idf_component_register(SRCS config.c iotbalkon.c task_bmp280.c task_ina219.c task_apds9930.c task_wifi.c task_mqtt.c task_out.c xutil.c nvsio.c - INCLUDE_DIRS ".") +if(CONFIG_ENABLE_BLE_GATT) + set(srcs config.c iotbalkon.c task_bmp280.c task_ina219.c task_apds9930.c task_wifi.c task_mqtt.c task_ble.c task_out.c xutil.c nvsio.c) +else() + set(srcs config.c iotbalkon.c task_bmp280.c task_ina219.c task_apds9930.c task_wifi.c task_mqtt.c task_out.c xutil.c nvsio.c) +endif() + +idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS ".") diff -r 551a53b31373 -r 7448b8dd4288 main/Kconfig.projbuild --- a/main/Kconfig.projbuild Sat Apr 15 13:29:40 2023 +0200 +++ b/main/Kconfig.projbuild Sun Apr 16 12:27:12 2023 +0200 @@ -120,4 +120,10 @@ endmenu + config ENABLE_BLE_GATT + bool "Enable Bluetooth LE" + help + Select this is you want to include the BLE GATT server. + + endmenu diff -r 551a53b31373 -r 7448b8dd4288 main/config.h --- a/main/config.h Sat Apr 15 13:29:40 2023 +0200 +++ b/main/config.h Sun Apr 16 12:27:12 2023 +0200 @@ -34,6 +34,13 @@ #include "esp_wifi.h" #include "esp_event.h" #include "esp_netif.h" +#ifdef CONFIG_ENABLE_BLE_GATT +#include "esp_bt.h" +#include "esp_gap_ble_api.h" +#include "esp_gatts_api.h" +#include "esp_bt_defs.h" +#include "esp_bt_main.h" +#endif #include "nvs_flash.h" #include "lwip/err.h" #include "lwip/sys.h" @@ -53,6 +60,9 @@ #include "task_bmp280.h" #include "task_ina219.h" #include "task_apds9930.h" +#ifdef CONFIG_ENABLE_BLE_GATT +#include "task_ble.h" +#endif #include "task_wifi.h" #include "task_mqtt.h" #include "task_out.h" diff -r 551a53b31373 -r 7448b8dd4288 main/iotbalkon.c --- a/main/iotbalkon.c Sat Apr 15 13:29:40 2023 +0200 +++ b/main/iotbalkon.c Sun Apr 16 12:27:12 2023 +0200 @@ -29,6 +29,9 @@ static TaskHandle_t xTaskAPDS9930 = NULL; static TaskHandle_t xTaskMQTT = NULL; static TaskHandle_t xTaskWifi = NULL; +#ifdef CONFIG_ENABLE_BLE_GATT +static TaskHandle_t xTaskBLE = NULL; +#endif static TaskHandle_t xTaskOUT = NULL; #define DS_TIME 60 @@ -404,6 +407,9 @@ xTaskCreate(&task_out, "task_out", 2560, NULL, 9, &xTaskOUT); xTaskCreate(&task_mqtt, "task_mqtt", 4096, NULL, 5, &xTaskMQTT); xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); +#ifdef CONFIG_ENABLE_BLE_GATT + xTaskCreate(&task_ble, "task_ble", 4096, NULL, 3, &xTaskBLE); +#endif vTaskDelay(10 / portTICK_PERIOD_MS); diff -r 551a53b31373 -r 7448b8dd4288 main/task_ina219.c --- a/main/task_ina219.c Sat Apr 15 13:29:40 2023 +0200 +++ b/main/task_ina219.c Sun Apr 16 12:27:12 2023 +0200 @@ -104,7 +104,7 @@ */ ESP_ERROR_CHECK(ina219_configure(&ina219_b_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125, INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS)); - vTaskDelay(10 / portTICK_PERIOD_MS); + vTaskDelay(20 / portTICK_PERIOD_MS); ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_b_dev, &bus_voltage)); vTaskDelay(10 / portTICK_PERIOD_MS); ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_b_dev, &shunt_voltage)); @@ -139,7 +139,7 @@ if (! ina219_state->Solar.fake) { ESP_ERROR_CHECK(ina219_configure(&ina219_s_dev, INA219_BUS_RANGE_32V, INA219_GAIN_0_125, INA219_RES_12BIT_1S, INA219_RES_12BIT_1S, INA219_MODE_CONT_SHUNT_BUS)); - vTaskDelay(10 / portTICK_PERIOD_MS); + vTaskDelay(20 / portTICK_PERIOD_MS); ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_s_dev, &bus_voltage)); vTaskDelay(10 / portTICK_PERIOD_MS); ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_s_dev, &shunt_voltage)); diff -r 551a53b31373 -r 7448b8dd4288 main/task_out.c --- a/main/task_out.c Sat Apr 15 13:29:40 2023 +0200 +++ b/main/task_out.c Sun Apr 16 12:27:12 2023 +0200 @@ -55,10 +55,10 @@ * Prepare the LEDC PWM channels */ ledc_timer_config_t ledc_timer = { - .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use high speed timer + .speed_mode = LEDC_LOW_SPEED_MODE, ///< Use high speed timer .timer_num = LEDC_TIMER_0, ///< Timer 0 .duty_resolution = LEDC_TIMER_10_BIT, ///< 10 bits resolution - .freq_hz = 100, ///< 100 Hz + .freq_hz = 60, ///< 60 Hz .clk_cfg = LEDC_AUTO_CLK ///< Auto select PWM clock }; ledc_timer_config(&ledc_timer); @@ -76,7 +76,7 @@ ledc_channel_config_t dimmer_channel4 = { .channel = LEDC_CHANNEL_1, - .duty = 1024, ///< Default 0% (inverted value) + .duty = 0, ///< Default 0% .gpio_num = OutputPin4, ///< Dimmer4 pin .speed_mode = LEDC_LOW_SPEED_MODE, .hpoint = 0,