Python starten met php: script stop halvewege

Status
Niet open voor verdere reacties.

phobia

Terugkerende gebruiker
Lid geworden
4 sep 2006
Berichten
1.777
Als ik onderstaande code uitvoer met php
$result = shell_exec('cd /home/pi/wiringPi/examples/lights; python SwitchHeater.py');

Dan stop het script na "setup pins 19, 26>>"

Ik ben een newby in python en google heeft me na een dag proberen niks kunnen helpen.

py file is root:pi
[CPP]
#! /usr/bin/python

import urllib2, urllib
import json
from pprint import pprint
from decimal import Decimal
import RPi.GPIO as GPIO

# Pin Definitons:
print "set pins vars >>"
heaterPin = 19 # Broadcom pin 19 (P1 pin 35)
ledPin = 26 # Broadcom pin 26 (P1 pin 37)

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
print "setup pins 19, 26>>"
GPIO.setup(ledPin, GPIO.OUT) # LED pin set as output
GPIO.setup(heaterPin, GPIO.OUT) # PWM pin set as output
print "request heater state >>"
# Get the requested temperature and heater state
path = 'http://192.168.2.16/Heater/state'
req = urllib2.Request(path)
req.add_header("Content=type","application/x-www-form-urlencoded")
# use site data as json object
#with open(urllib2.urlopen(req).read()) as data_file:
# data = json.load(data_file)
data = urllib2.urlopen(req).read()
jdata = json.loads(data)

requested = jdata['request_temp']
requested_min = float(requested) - 0.4
heater_state = jdata["state"]
print "Switch output pins >>"
if(heater_state == False):
# turn off heater GPIO pin LOW
GPIO.output(ledPin, GPIO.LOW)
GPIO.output(heaterPin, GPIO.LOW)
print "Heater has been turned Off"
else:
# turn on heater GPIO pin HIGH
GPIO.output(ledPin, GPIO.HIGH)
GPIO.output(heaterPin, GPIO.HIGH)
print "Heater has been turned On"
print "program end >>"
[/CPP]
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan