Gpt test post

This commit is contained in:
2025-12-20 18:13:58 +01:00
parent 76967d8451
commit 57b81d01b1
3 changed files with 32 additions and 3 deletions

View File

@@ -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

View File

@@ -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 ".")

View File

@@ -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);
}