logo elektroda
logo elektroda
X
logo elektroda

Wemos D1 mini ESP8266 PHP Mysql empty variable in POST method

pitron 1515 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16930736
    pitron
    Level 24  
    I am trying to modify data in a database on an external Mysql server.
    The database and PHP work correctly tested with a form on the server and from disk.
    Wemos also connects to the database but modifies the record to a null value every time.
    Something is wrong with passing a variable in the POST method.
    Serial.println shows the value of the PostData variable.
    Asking for help possibly an example of a full header with POST method and variables.

    Code: C / C++
    Log in, to see the code
    .

    Libraries in the project:
    #include <ESP8266WiFi.h>
    #include <ESP8266Ping.h>
    #include <ESP8266HTTPClient.h>
    #include <SPI.h>
  • ADVERTISEMENT
  • #2 16930826
    JacekCz
    Level 42  
    1. you open such a little-known google.com page, type POST and click on the first or second item
    2. and we have to guess the PostData values and possibly nuances in PHP?


    To those allergic to the word Arduino: are you still getting your hopes up about filtering?
  • ADVERTISEMENT
  • #3 16931098
    pitron
    Level 24  
    This was not the answer I was looking for.
    My POST works but with a php or html form to test a variable permanently assigned string type.
    It doesn't work on arduino, there are topics but lots of people in the comments have similar problems and they remain unsolved.
    I think the problem is the correctness of the header, but if you are more knowledgeable then I would prefer the answer no can do look for another method or move the code to the RPi.
  • #4 16931279
    gaskoin
    Level 38  
    And what is coming out of the Arduino? Is the PostData variable set well? Have you debugged this program? Show how it sets the headers for you (wireshark or debug).

    This request is sent to this site on PHP? Post preferably all the code from the arduino and this page in php.
  • ADVERTISEMENT
  • #5 16931407
    jestam
    Automation specialist
    My guess: maybe you close the connection from the client side before the server sends back an acknowledgement.

    Paste the entire code.
  • #6 16934686
    pitron
    Level 24  
    After uploading the whole thing to the local server and analysing wireshark it looks like the header is not correct.
    The name of the variable does not appear at all, instead there is its value.

    Code: C / C++
    Log in, to see the code
    .

    wemos
    Wemos D1 mini ESP8266 PHP Mysql empty variable in POST method
    mozilla
    Wemos D1 mini ESP8266 PHP Mysql empty variable in POST method .
  • #7 16934730
    JacekCz
    Level 42  
    There wouldn't be a thread at all if you had given the full code including PostData beforehand.
    HOWEVER you are posting it wrong.
  • ADVERTISEMENT
  • #8 16934797
    pitron
    Level 24  
    I have painfully modified the code according to the header examples on the web and the value is always empty even "PostData=ABC" does not work.
    Starting to suspect a bug in the arduino library.
    Added after 13 [minutes]: .
    Success, seemingly trivial but maybe someone will find it useful :-) .
    The whole string must be defined in a variable together with the equal signs and values otherwise Length truncates the value just after the variable name and value is empty:

    Code: C / C++
    Log in, to see the code
    .

Topic summary

The discussion addresses an issue with sending POST requests from a Wemos D1 mini ESP8266 to a remote MySQL database via PHP. Although the PHP script and database function correctly when tested with standard HTML forms, the ESP8266 client sends POST data that results in null values in the database. The problem was traced to the format of the POST data string and HTTP headers. The key mistake was sending only the value (e.g., "ABC") without the variable name, causing the server to receive an empty variable. The solution involved constructing the POST data string with both the variable name and value (e.g., "PostData=ABC") and correctly setting the Content-Length header to match the full string length. Proper HTTP headers including "Content-Type: application/x-www-form-urlencoded" and "Connection: close" were also necessary. Debugging with Wireshark confirmed the malformed header and missing variable name in the original requests. This highlights the importance of precise HTTP header and body formatting when using ESP8266 clients to interact with PHP scripts on external servers.
Summary generated by the language model.
ADVERTISEMENT