modified: firmware/main/include/wifi.h
modified: firmware/main/src/leds.c modified: firmware/main/src/main.c modified: firmware/main/src/sht31.c modified: firmware/main/src/wifi.c modified: firmware/sdkconfig
This commit is contained in:
1 parent
2f48a98556
commit
b693e31141
6 files changed
+36
-19
No files matched your search
@@ -8,6 +8,8 @@ extern "C" {
|
||||
|
||||
esp_err_t wifi_init(void);
|
||||
esp_err_t wifi_sleep();
|
||||
void wifi_on();
|
||||
void wifi_off();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ esp_err_t led_init() {
|
||||
gpio_set_direction(LED1,GPIO_MODE_OUTPUT);
|
||||
gpio_set_direction(LED2,GPIO_MODE_OUTPUT);
|
||||
gpio_set_direction(LED_INT,GPIO_MODE_OUTPUT);
|
||||
led0_on();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "controller.h"
|
||||
|
||||
|
||||
|
||||
static const char * TAG = "main.c";
|
||||
|
||||
void vApplicationIdleHook(void) {
|
||||
@@ -29,13 +28,12 @@ void app_main()
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(led_init());
|
||||
//ESP_ERROR_CHECK(wifi_init());
|
||||
ESP_ERROR_CHECK(wifi_init());
|
||||
//ESP_ERROR_CHECK(uart_init());
|
||||
ESP_ERROR_CHECK(controller_init());
|
||||
|
||||
led0_on();
|
||||
|
||||
xTaskCreate(led_blink_task, "led_blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
|
||||
//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(sht31_sensor_test_task, "sht31_sensor_test_task", 2048, NULL, 10, NULL);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <esp_log.h>
|
||||
#include "functions.h"
|
||||
#include "sht31.h"
|
||||
#include "wifi.h"
|
||||
|
||||
#define SDA_PIN GPIO_NUM_14
|
||||
#define CLK_PIN GPIO_NUM_13
|
||||
@@ -40,6 +41,10 @@ void sht31_sensor_test_task(void *pvParameters)
|
||||
split_float(humidity, &hum_int_part, &hum_dec_part);
|
||||
//ESP_LOGI(TAG, "Temperature: %.2f°C, Humidity: %.2f%%", temperature, humidity);
|
||||
ESP_LOGI(TAG, "Temperature: %i.%i°C, Humidity: %i.%i%%", temp_int_part, (int)(temp_dec_part*1000), hum_int_part, (int)(hum_dec_part*1000));
|
||||
//Testing how much head it produced if wifi is turned on to send temp. This doesnt go here irl.
|
||||
wifi_on();
|
||||
vTaskDelay(5000 / portTICK_RATE_MS);
|
||||
wifi_off();
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to read from SHT31 sensor");
|
||||
}
|
||||
|
||||
+24
-13
@@ -2,10 +2,12 @@
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_http_client.h>
|
||||
//#include <esp_http_client.h>
|
||||
#include "functions.h"
|
||||
#include "wifi.h"
|
||||
|
||||
static const char * TAG = "wifi.c";
|
||||
|
||||
esp_err_t wifi_init(void) {
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
@@ -13,6 +15,7 @@ esp_err_t wifi_init(void) {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
|
||||
wifi_config_t sta_config = {
|
||||
@@ -23,22 +26,30 @@ esp_err_t wifi_init(void) {
|
||||
};
|
||||
|
||||
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());
|
||||
//ESP_ERROR_CHECK(esp_wifi_start());
|
||||
//ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
|
||||
// Enable power saving
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
|
||||
//ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MAX_MODEM));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t wifi_sleep() {
|
||||
/*
|
||||
// Enter light sleep mode
|
||||
wifi_fpm_open(); // Enable modem sleep
|
||||
wifi_fpm_do_sleep(0xFFFFFFF); // Enter sleep mode indefinitely
|
||||
// The system will wake up when an interrupt occurs
|
||||
wifi_fpm_close(); // Close modem sleep mode after waking up
|
||||
*/
|
||||
return ESP_OK;
|
||||
// Function to turn on WiFi
|
||||
void wifi_on() {
|
||||
ESP_LOGI(TAG, "Turning WiFi ON...");
|
||||
esp_wifi_start(); // Start WiFi
|
||||
ESP_LOGI(TAG, "WiFi is ON and connecting...");
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
ESP_LOGI(TAG, "WiFi is ON and connected to AP.");
|
||||
}
|
||||
|
||||
// Function to turn off WiFi
|
||||
void wifi_off() {
|
||||
ESP_LOGI(TAG, "Disconnecting from AP and turning off WiFi...");
|
||||
ESP_ERROR_CHECK(esp_wifi_disconnect())
|
||||
ESP_LOGI(TAG, "WiFi disconnected. Turning WiFi OFF...");
|
||||
esp_wifi_stop(); // Stop WiFi
|
||||
ESP_LOGI(TAG, "WiFi is OFF.");
|
||||
}
|
||||
+2
-2
@@ -69,8 +69,8 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
|
||||
# CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER is not set
|
||||
CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL=74880
|
||||
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
|
||||
CONFIG_ESP_WIFI_SSID="ZERO"
|
||||
CONFIG_ESP_WIFI_PASSWORD="Triemlistrasse0815"
|
||||
CONFIG_ESP_WIFI_SSID="INTERNET"
|
||||
CONFIG_ESP_WIFI_PASSWORD=""
|
||||
CONFIG_ESP_MAXIMUM_RETRY=5
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||
|
||||
Reference in new issue
Block a user