From 57b81d01b1175cc52d3262c1df58c4c4bdc81f6c Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Sat, 20 Dec 2025 18:13:58 +0100 Subject: [PATCH] Gpt test post --- README.md | 5 +++-- main/CMakeLists.txt | 2 +- main/station_example_main.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c855c5..55bbac5 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-S2 | ESP32-S3 | ESP32-P4 | ESP32-H2 | -| ----------------- | ----- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | -------- | +# Notes + +Remember to enable BOYA chip in the menuconfig. # Wi-Fi Station Example diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 1e86bfe..ccde765 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "station_example_main.c" - PRIV_REQUIRES esp_wifi nvs_flash esp_adc + PRIV_REQUIRES esp_wifi nvs_flash esp_adc esp_http_client INCLUDE_DIRS ".") diff --git a/main/station_example_main.c b/main/station_example_main.c index 115ed2a..98d2893 100755 --- a/main/station_example_main.c +++ b/main/station_example_main.c @@ -22,7 +22,9 @@ #include "esp_adc/adc_continuous.h" #include "esp_adc/adc_cali.h" +#include "esp_http_client.h" +#define SERVER_URL "http://192.168.178.157:8080/data" /* The examples use WiFi configuration that you can set via project configuration menu @@ -163,6 +165,31 @@ void wifi_init_sta(void) } } +void send_voltage(float v) +{ + char payload[64]; + snprintf(payload, sizeof(payload), + "{\"voltage\":%.2f}", v); + + esp_http_client_config_t cfg = { + .url = SERVER_URL, + .method = HTTP_METHOD_POST, + .timeout_ms = 2000, + }; + + esp_http_client_handle_t client = + esp_http_client_init(&cfg); + + esp_http_client_set_header( + client, "Content-Type", "application/json"); + esp_http_client_set_post_field( + client, payload, strlen(payload)); + + esp_http_client_perform(client); + esp_http_client_cleanup(client); +} + + void app_main(void) { //Initialize NVS @@ -181,4 +208,5 @@ void app_main(void) ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); wifi_init_sta(); + send_voltage(0.5); }