Open
Description
Answers checklist.
- I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
ESP8266_RTOS_SDK v3.0
Operating System used.
Windows
How did you build your project?
Command line with Make
If you are using Windows, please specify command line type.
None
What is the expected behavior?
hi to all.
i'm using esp8266 kit + php +mysql +xampp ( localhost), try to using POST request to my php. I'm able to connect to wifi rourter and using this code:
`static void post_rest_function()
{
esp_http_client_config_t config = {
.url = "http://192.168.56.1/final/updateHX711data_and_recordtable.php",
.method = HTTP_METHOD_POST,
.cert_pem = NULL,
.event_handler=_http_event_handler,
esp_http_client_handle_t client = esp_http_client_init(&config);
const char *post_data="id=esp8266_01&name=DaoDuyAnh&weight=10.5&status_read_sensor_hx711=SUCCESS&led_01=OFF&led_02=OFF");
esp_http_client_set_header(client, "Content-Type", "application/x-www-form-urlencoded");
esp_http_client_set_post_field(client, post_data, strlen(post_data));
esp_http_client_perform(client);
esp_http_client_cleanup(client);
} This is my php code :
<?php
require 'database.php';
if (!empty($_POST)) {
$id = $_POST['id'];
$weight = $_POST['weight'];
$name = $_POST['name'];
$status_read_sensor_hx711 = $_POST['status_read_sensor_hx711'];
$led_01 = $_POST['led_01'];
$led_02 = $_POST['led_02'];
date_default_timezone_set("Etc/GMT+7"); // Look here for your timezone : https://www.php.net/manual/en/timezones.php
$tm = date("H:i:s");
$dt = date("Y-m-d");
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE esp8266_table_hx711_leds_update SET weight = ?, status_read_sensor_hx711 = ?, time = ?, date = ? WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($weight,$status_read_sensor_hx711,$tm,$dt,$id));
Database::disconnect();
}
function generate_string_id($strength = 16) {
$permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$input_length = strlen($permitted_chars);
$random_string = '';
for($i = 0; $i < $strength; $i++) {
$random_character = $permitted_chars[mt_rand(0, $input_length - 1)];
$random_string .= $random_character;
}
return $random_string;
}
?>
i test postman to send data to "http://192.168.56.1/final/updateHX711da ... dtable.php" and success update data in mysql database but when i run the esp-idf code, i have a trouble:
"E (20789) HTTP_CLIENT: Connection failed, sock < 0
E (20790) HTTP: HTTP POST request failed: ESP_ERR_HTTP_CONNECT "
How to fix this or I use wrong way.
Thank everyone
Regard
What is the actual behavior?
.
Steps to reproduce.
- Step
- Step
- Step
...
Build or installation Logs.
More Information.
No response
Metadata
Metadata
Assignees
Labels
No labels