modified: firmware/main/include/leds.h

new file:   firmware/main/include/uart.h
new file:   firmware/main/include/wifi.h
modified:   firmware/main/src/functions.c
modified:   firmware/main/src/http_client.c
modified:   firmware/main/src/leds.c
modified:   firmware/main/src/main.c
modified:   firmware/main/src/sht31.c
new file:   firmware/main/src/uart.c
new file:   firmware/main/src/wifi.c
This commit is contained in:
Sven Luethi committed 2024-08-11 22:07:45 +02:00
1 parent f4436308dc
commit 5b58ad5e41
10 files changed
+167 -134

No files matched your search

+12 -93
View File
@@ -1,103 +1,23 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs_flash.h"
#include "esp_system.h"
#include "esp_log.h"
#include "esp_event_loop.h"
#include "esp_wifi.h"
#include "esp_http_client.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <nvs_flash.h>
#include <esp_system.h>
//#include <esp_log.h>
//#include <esp_event_loop.h>
#include <esp_err.h>
#include "driver/uart.h"
//#include <stdio.h>
#include <string.h>
//#include <EEPROM.h>
#include "leds.h"
#include "sht31.h"
#include "uart.h"
#include "wifi.h"
#include "functions.h"
#include "http_client.h"
static const char * TAG = "main.c";
static void wifi_init(void) {
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
wifi_config_t sta_config = {
.sta = {
.ssid = CONFIG_ESP_WIFI_SSID,
.password = CONFIG_ESP_WIFI_PASSWORD,
},
};
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_connect());
}
static void split_float(float num, int *int_part, float *dec_part) {
// Extract the integer part
*int_part = (float)((int)num);
// Calculate the fractional part by subtracting the integer part from the original number
*dec_part = num - *int_part;
}
// Task to read data from UART
void uart_read_task(void *pvParameters) {
const unsigned bufferSize = 1024;
// Initialize UART
uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_param_config(UART_NUM_0, &uart_config);
//uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART_NUM_0, bufferSize * 2, 0, 0, NULL, 0);
// Capture input
uint8_t data[bufferSize];
while (1) {
// Read data from UART
int length = uart_read_bytes(UART_NUM_0, data, bufferSize, 20 / portTICK_RATE_MS);
if (length > 0) {
// Null-terminate the received string
data[length] = '\0';
// Print the received data
printf("Received data: %s\n", data);
if(strcmp((void*)data,"1") == 0) led_on(LED1);
else if(strcmp((void*)data,"2") == 0) led_on(LED2);
else if(strcmp((void*)data,"3") == 0) led_on(LED_INT);
else if(strcmp((void*)data,"4") == 0) {
led_off(LED1);
led_off(LED2);
led_off(LED_INT);
}
}
vTaskDelay(100 / portTICK_RATE_MS); // Delay to prevent task from consuming too much CPU time
}
}
/*
void main_task(void* args) {
float humidity = 0;
float temperature = 0;
vTaskDelay(2000 / portTICK_PERIOD_MS);
//Register device with Server
unsigned id;
hc_register(&id);
while (1)
{
hc_send_sensor_data(id,0,0); //test
}
}
*/
void app_main()
{
//ESP_ERROR_CHECK(nvs_flash_init());
@@ -106,7 +26,6 @@ void app_main()
initLEDs();
xTaskCreate(&led_blink_task, "led_blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
//xTaskCreate(uart_read_task, "uart_read_task", 2048, NULL, 10, NULL);
xTaskCreate(uart_read_task, "uart_read_task", 2048, NULL, 10, NULL);
xTaskCreate(sht31_sensor_test_task, "sht31_sensor_test_task", 2048, NULL, 10, NULL);
//xTaskCreate(main_task, "main task", 2048, NULL, tskIDLE_PRIORITY, NULL);
}