cannot post data with micropython on an ESP32 |

Trending 2 months ago

I can't get micropython to station information to a php book properly... I americium utilizing Thonny and an ESP32, which for nan infinitesimal conscionable provides web connectivity to a MAMP instance.

I person nan pursuing python codification which I usage for some micropython connected my ESP32 and trial pinch python 3.10. You tin astir apt show I americium caller to programming. The past connection I utilized was Forth ~ 35 years agone ;)

a usability which creates a dictionary

# Parameters to beryllium sent timeatsense=str(time.localtime()) # print('timeatsense= ',timeatsense) information = { 'api_key': 'heyplastuny', 'sensor': 'temphumpres', 'location': 'office', 'temperature': round(100*random.random(),2), 'humidity': round(20*random.random(),2), 'whenitwas': timeatsense } return data``` # nan main usability that tries to station nan dictionary to nan script ```import urequests import random import time # URL of nan PHP book connected nan web server url = '' datapost=getdata() p# print(datapost,"\r\n") consequence =,data=datapost) print("response successful python is ",response.text,"\r\n")``` and a very elemental php book called test1 domiciled successful nan htdocs subdirectory of MAMP ```<?php //$api_key = $_POST["api_key"]; if ($_SERVER["REQUEST_METHOD"] == "POST") { echo "dumping contented of station now <br>"; var_dump($_POST); //;echo "this is nan cardinal <br>" . $api_key . "<br>"; } else { echo "Was not a POST request"; } ?>``` If I usage micropython I get this error But nan codification throws this error **TypeError: entity pinch buffer protocol required** I tried utilizing urequests successful micropython thus response =,data=datapost) because this page says that I should beryllium capable to nonstop that dictionary successful nan mode I americium using using python 3.10 I get nan correct reply utilizing nan aforesaid code dumping contented of station now <br>array(6) { ["api_key"]=> string(11) "testkey" ["sensor"]=> string(11) "temphumpres" ["location"]=> string(6) "office" ["temperature"]=> string(5) "42.97" ["humidity"]=> string(5) "18.73" ["whenitwas"]=> string(24) "Wed Feb 14 22:06:27 2024" } pinch magnitude 304 If alternatively I usage consequence =,json=datapost) I get esponse successful python is dumping contented of station now <br>array(0) { } The conception of utilizing json was from immoderate station I person forgotten, but nan constituent is that it shows that I americium astatine slightest getting done to nan php book complete nan network. Any denotation arsenic to wherever I americium going incorrect would beryllium astir appreciated. I person spent a agelong clip looking astatine various posts to nary avail. Thanks, particularly if you tin lick this..