Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp8266 cann't send data to my php (IDFGH-14458) (GIT8266O-873) #1295

Open
3 tasks done
Hehee6082 opened this issue Jan 19, 2025 · 0 comments
Open
3 tasks done

esp8266 cann't send data to my php (IDFGH-14458) (GIT8266O-873) #1295

Hehee6082 opened this issue Jan 19, 2025 · 0 comments
Assignees

Comments

@Hehee6082
Copy link

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.

  1. Step
  2. Step
  3. Step
    ...

Build or installation Logs.


More Information.

No response

@github-actions github-actions bot changed the title esp8266 can send data to my php esp8266 can send data to my php (IDFGH-14458) Jan 19, 2025
@Hehee6082 Hehee6082 changed the title esp8266 can send data to my php (IDFGH-14458) esp8266 cann't send data to my php (IDFGH-14458) Jan 19, 2025
@wujiangang wujiangang transferred this issue from espressif/esp-idf Jan 20, 2025
@github-actions github-actions bot changed the title esp8266 cann't send data to my php (IDFGH-14458) esp8266 cann't send data to my php (IDFGH-14458) (GIT8266O-873) Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants