I have Raspberry Pi RFID reader which is collecting simple ID numbers from tags nearby. Those are stored as a string variable. I want to continuously send this string value over to PHP script and display it on the web page and then store it in database. How do I pass this string value over using JSON in python?
Python Script:
import serial, os, httplib, json, urllib
#pyserial setup
tagID = tagID[:8] #true string tagID - 73203842
#JSON setup
headers = { "charset" : "utf-8", "Content-Type" : "application/json" }
conn = httplib.HTTPConnection("192.168.XX.XXX")
sample = { "ID" : tagID }
sJson = json.dumps(sample, ensure_ascii = 'False')
while True:
conn.request("POST", "/test.php", sJson, headers)
response = conn.getresponse()
print(response.read())
PHP File:
<?php
$data = json_decode($_POST['results']);
echo($data);
?>