modified: main/include/leds.h

modified:   main/src/leds.c
modified:   main/src/main.c
modified:   main/src/sensor.c
This commit is contained in:
Sven Luethi committed 2024-08-07 00:23:17 +02:00
1 parent 9365e04619
commit 075bc3e261
4 files changed
+68 -10

No files matched your search

+16 -3
View File
@@ -1,7 +1,6 @@
#include "leds.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <driver/gpio.h>
#include "esp_log.h"
static const char * TAG = "leds.c";
@@ -35,6 +34,20 @@ void led_blink_task(void *pvParameter)
unsigned initLEDs() {
gpio_set_direction(LED1,GPIO_MODE_OUTPUT);
gpio_set_direction(LED2,GPIO_MODE_OUTPUT);
//gpio_set_direction(LED_INT,GPIO_MODE_OUTPUT);
gpio_set_direction(LED_INT,GPIO_MODE_OUTPUT);
return 0;
}
}
void led_on(gpio_num_t ledNumber)
{
gpio_set_level(ledNumber, 1);
ESP_LOGI(TAG, "LED turned on");
}
void led_off(gpio_num_t ledNumber)
{
gpio_set_level(ledNumber, 0);
ESP_LOGI(TAG, "LED turned off");
}
+49 -6
View File
@@ -1,21 +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 "nvs_flash.h"
#include "esp_wifi.h"
#include "esp_http_client.h"
#include <esp_err.h>
#include "driver/uart.h"
//#include <stdio.h>
#include <string.h>
#include "leds.h"
#include "sensor.h"
#include "http_client.h"
static const char * TAG = "main.c";
//static const char * TAG = "main.c";
/*
static void wifi_init(void) {
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_create_default());
@@ -32,8 +34,47 @@ static void wifi_init(void) {
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_connect());
}
*/
// 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;
@@ -47,12 +88,14 @@ void main_task(void* args) {
hc_send_sensor_data(id,0,0); //test
}
}
*/
void app_main()
{
//ESP_ERROR_CHECK(nvs_flash_init());
//wifi_init();
xTaskCreate(&led_blink_task, "led_blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
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(main_task, "main task", 2048, NULL, tskIDLE_PRIORITY, NULL);
}
-1
View File
@@ -1,6 +1,5 @@
#include "sensor.h"
#include <stdio.h>
#include "i2c_master.h"
#define I2C_SDA_PIN GPIO_NUM_2
#define I2C_CLK_PIN GPIO_NUM_14