Python script to read photoresistor stats - help needed
Posted: Sunday 10 April 2016 22:56
Hi
I don't now Python and programming...
I try to read photoresistor status with this script with success but I want to send my result with JSON to Domoticz virtual sensor (IDX - 35).
Script reads photoresistor value but doesn't send this value to DOMOTICZ. I don't know what I have to add to this code to make it works. (I think I must add VALUE variable but I doesn't know how:(
The code:
#!/usr/bin/env python
# Example for RC timing reading for Raspberry Pi
# Must be used with GPIO 0.3.1a or later - earlier verions
# are not fast enough!
import RPi.GPIO as GPIO, time, os
import urllib
DEBUG = 1
GPIO.setmode(GPIO.BCM)
import urllib2
def RCtime (RCpin):
reading = 0
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(RCpin, GPIO.IN)
# This takes about 1 millisecond per loop cycle
while (GPIO.input(RCpin) == GPIO.LOW):
reading += 1
return reading
print RCtime(18) # Read RC timing using pin #18
httpresponse = urllib.urlopen ("http://192.168.0.16:8081/json.htm?type= ... alue=VALUE")
END of code
Best regards
I don't now Python and programming...
I try to read photoresistor status with this script with success but I want to send my result with JSON to Domoticz virtual sensor (IDX - 35).
Script reads photoresistor value but doesn't send this value to DOMOTICZ. I don't know what I have to add to this code to make it works. (I think I must add VALUE variable but I doesn't know how:(
The code:
#!/usr/bin/env python
# Example for RC timing reading for Raspberry Pi
# Must be used with GPIO 0.3.1a or later - earlier verions
# are not fast enough!
import RPi.GPIO as GPIO, time, os
import urllib
DEBUG = 1
GPIO.setmode(GPIO.BCM)
import urllib2
def RCtime (RCpin):
reading = 0
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(RCpin, GPIO.IN)
# This takes about 1 millisecond per loop cycle
while (GPIO.input(RCpin) == GPIO.LOW):
reading += 1
return reading
print RCtime(18) # Read RC timing using pin #18
httpresponse = urllib.urlopen ("http://192.168.0.16:8081/json.htm?type= ... alue=VALUE")
END of code
Best regards