I'm having a problem with a project. I need to do a detection system which uses python to communicate with electronic devices. I'm creating a detection system. The problem is that I want to detect and then send to a php file which serves as my user interface.
Python:
if led is on, send on to php,
if led is off, send off to php,
PHP:
display [value receive from python]
If you want to call php script directly:
php code:
<?php
$state = $argv[1];
echo $state;
?>
python code:
from subprocess import *
#ledstate='on'
p = Popen(['/usr/bin/php','<php file name>',ledstate],stdout=PIPE)
print p.stdout.read()
If you want to call via server:
php code:
<?php
$state = $_GET["led"];
echo $state;
?>
python code:
import urllib2
#ledstate='on'
req = urllib2.Request(url='http://example.com/<php file name>?led=%s' % ledstate )
f = urllib2.urlopen(req)
print f.read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With