-1

I want to use raspberry pico W to register current temperature value on MySql server:

Raspberry Pico W --> PHP --> MySQL.

I am trying to use urequest.post to send temperature value to php script on http server. Script can not recognize posted temperature value. To explain more easier I will use just some easy example.

MicroPython program (Raspberry Pico W):

    request_url = 'http://kam****.webd.pro/php/test.php'      
    payload = {'test1': 'test1', 'test2': 'test2', 'test3':'test3'}
    headers = {'Content-Type':'application/json'}
    data = (json.dumps(payload)).encode()
    r = urequests.post(request_url, data=data, headers=headers)
    
    print(r.status_code)
    print(r.content)
    text = r.text
    print(text) 

PHP script on HTTP server:

  <?php
  $test1 = $_POST['test1'];
  $test2 = $_POST['test2'];
  $test3 = $_POST['test3'];

  $response["aaa"] = $test1;
  $response["bbb"] = $test2;
  $response["ccc"] = $test3;
  echo json_encode($response);
  ?>

Thony output:

  200
  b'{"aaa":null,"bbb":null,"ccc":null}'
  {"aaa":null,"bbb":null,"ccc":null}

I already try many of solutions, unfortunately without good result. Thanks for help :)

Kamito
  • 77
  • 6

1 Answers1

0

Problem fixed after change PHP script to:

<?php
// Get the JSON contents
$json = file_get_contents('php://input');
// decode the json data
$response = json_decode($json);
echo json_encode($response);
?>
Kamito
  • 77
  • 6