modified: firmware/main/include/controller.h
modified: firmware/main/include/wifi.h modified: firmware/main/src/controller.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
bf4b6e5442
commit
19b7b5791f
7 files changed
+71
-21
No files matched your search
@@ -60,7 +60,7 @@ static bool register_device(unsigned *id) {
|
||||
return 1; //1 as test ID
|
||||
}
|
||||
|
||||
static bool send_sensor_data(unsigned id, float humidity, float temperature) {
|
||||
esp_err_t send_sensor_data(unsigned id, float humidity, float temperature) {
|
||||
esp_err_t err;
|
||||
int content_length = 0;
|
||||
char output_buffer[MAX_HTTP_OUTPUT_BUFFER];
|
||||
@@ -77,9 +77,14 @@ static bool send_sensor_data(unsigned id, float humidity, float temperature) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
cJSON_AddNumberToObject(json_payload, "temperature", temperature);
|
||||
cJSON_AddNumberToObject(json_payload, "humidity", humidity);
|
||||
cJSON_AddNumberToObject(json_payload, "id", id);
|
||||
// Add data to the JSON object
|
||||
if (!cJSON_AddNumberToObject(json_payload, "temperature", temperature) ||
|
||||
!cJSON_AddNumberToObject(json_payload, "humidity", humidity) ||
|
||||
!cJSON_AddNumberToObject(json_payload, "id", id)) {
|
||||
ESP_LOGE(TAG, "Failed to add data to JSON object");
|
||||
cJSON_Delete(json_payload);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
/*
|
||||
char tmp[100] = "{\"humidity\": ";
|
||||
strcat(tmp, floatToString(humidity));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <nvs_flash.h>
|
||||
#include <esp_system.h>
|
||||
#include <esp_sleep.h>
|
||||
#include <esp_log.h>
|
||||
//#include <esp_log.h>
|
||||
//#include <esp_event_loop.h>
|
||||
#include <esp_err.h>
|
||||
@@ -23,19 +24,66 @@ void vApplicationIdleHook(void) {
|
||||
//wifi_sleep();
|
||||
led0_on();
|
||||
}
|
||||
/*
|
||||
void mainTask(void *pvParameters) {
|
||||
float temperature, humidity, temp_dec_part, hum_dec_part;
|
||||
int temp_int_part, hum_int_part;
|
||||
|
||||
void app_main()
|
||||
{
|
||||
while (1) {
|
||||
if (sht31_read_temp_hum(&temperature, &humidity) == ESP_OK) {
|
||||
split_float(temperature, &temp_int_part, &temp_dec_part);
|
||||
split_float(humidity, &hum_int_part, &hum_dec_part);
|
||||
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));
|
||||
|
||||
if(wifi_on() == ESP_OK) {
|
||||
// Send temperature...
|
||||
send_sensor_data(0, humidity, temperature);
|
||||
wifi_off();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed to read from SHT31 sensor");
|
||||
}
|
||||
vTaskDelay(10000 / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
*/
|
||||
void app_main() {
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
ESP_ERROR_CHECK(led_init());
|
||||
ESP_ERROR_CHECK(wifi_init());
|
||||
ESP_ERROR_CHECK(sht31_init());
|
||||
//ESP_ERROR_CHECK(uart_init());
|
||||
ESP_ERROR_CHECK(controller_init());
|
||||
|
||||
//xTaskCreate(mainTask, "mainTask", 2048, NULL, 10, 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);
|
||||
//xTaskCreate(sht31_sensor_test_task, "sht31_sensor_test_task", 2048, NULL, 10, NULL);
|
||||
|
||||
|
||||
float temperature, humidity, temp_dec_part, hum_dec_part;
|
||||
int temp_int_part, hum_int_part;
|
||||
|
||||
while (1) {
|
||||
if (sht31_read_temp_hum(&temperature, &humidity) == ESP_OK) {
|
||||
split_float(temperature, &temp_int_part, &temp_dec_part);
|
||||
split_float(humidity, &hum_int_part, &hum_dec_part);
|
||||
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));
|
||||
|
||||
if(wifi_on() == ESP_OK) {
|
||||
// Send temperature...
|
||||
send_sensor_data(0, humidity, temperature);
|
||||
wifi_off();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(TAG, "Failed to read from SHT31 sensor");
|
||||
}
|
||||
vTaskDelay(10000 / portTICK_RATE_MS);
|
||||
}
|
||||
|
||||
|
||||
//vTaskStartScheduler();
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
#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
|
||||
@@ -41,10 +40,6 @@ 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");
|
||||
}
|
||||
|
||||
@@ -38,21 +38,23 @@ esp_err_t wifi_init(void) {
|
||||
}
|
||||
|
||||
// Function to turn on WiFi
|
||||
void wifi_on() {
|
||||
esp_err_t 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_wifi_connect();
|
||||
ESP_LOGI(TAG, "WiFi is ON and connected to AP.");
|
||||
led1_on();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Function to turn off WiFi
|
||||
void wifi_off() {
|
||||
esp_err_t wifi_off() {
|
||||
ESP_LOGI(TAG, "Disconnecting from AP and turning off WiFi...");
|
||||
ESP_ERROR_CHECK(esp_wifi_disconnect())
|
||||
esp_wifi_disconnect();
|
||||
ESP_LOGI(TAG, "WiFi disconnected. Turning WiFi OFF...");
|
||||
esp_wifi_stop(); // Stop WiFi
|
||||
ESP_LOGI(TAG, "WiFi is OFF.");
|
||||
led1_off();
|
||||
return ESP_OK;
|
||||
}
|
||||
Reference in new issue
Block a user