reading onewire sensors
This commit is contained in:
@@ -15,5 +15,6 @@ CONTROLLER_ID = '120' # every controller must have a different one
|
|||||||
STATE_FILE = '/mnt/zoblakdata/controller_state'
|
STATE_FILE = '/mnt/zoblakdata/controller_state'
|
||||||
PICTURE_TRANSFER_FILE='/mnt/zoblakdata/picture_transfer_ready.jpg'
|
PICTURE_TRANSFER_FILE='/mnt/zoblakdata/picture_transfer_ready.jpg'
|
||||||
PICTURE_INPUT_FILE='/mnt/zoblakdata/picture.jpg' # must match file in PICTURE_COMMAND
|
PICTURE_INPUT_FILE='/mnt/zoblakdata/picture.jpg' # must match file in PICTURE_COMMAND
|
||||||
PICTURE_COMMAND="""avconv -i rtsp://192.168.1.10:554//user=admin_password=_channel=1_stream=0.sdp -i /home/pi/projects/tfm/controller/zoblakLogo.png -filter_complex "[0:v]drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:fontsize=30:box=1:boxcolor=black@0.75:text='%d\.%m\.%Y\. %H\:%M\:%S':fontcolor=white@0.8: x=10: y=10[text]; [text][1:v]overlay=main_w-overlay_w-5:5 [filtered]" -map "[filtered]" -f image2 -vframes 1 /mnt/zoblakdata/picture.jpg""" # filename must match PICTURE_INPUT_FILE path
|
PICTURE_COMMAND="""avconv -i rtsp://192.168.5.10:554//user=admin_password=_channel=1_stream=0.sdp -i /home/pi/projects/tfm/controller/zoblakLogo.png -filter_complex "[0:v]drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:fontsize=30:box=1:boxcolor=black@0.75:text='%d\.%m\.%Y\. %H\:%M\:%S':fontcolor=white@0.8: x=10: y=10[text]; [text][1:v]overlay=main_w-overlay_w-5:5 [filtered]" -map "[filtered]" -f image2 -vframes 1 /mnt/zoblakdata/picture.jpg""" # filename must match PICTURE_INPUT_FILE path
|
||||||
PICTURE_URL = 'http://agrar.zoblak.com/api/v1.0/picture'
|
PICTURE_URL = 'http://agrar.zoblak.com/api/v1.0/picture'
|
||||||
|
ONE_WIRE_TERMO_SENSORS = ['/dev/sys/bus/w1/devices/xxx/w1_slave'] # xxx is a serial number
|
||||||
|
|||||||
17
controller/drivers/onewire/__init__.py
Normal file
17
controller/drivers/onewire/__init__.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def read_one_thermo(filename):
|
||||||
|
NO_OF_DECIMALS = 3
|
||||||
|
textfile = open(filename, 'r')
|
||||||
|
filetext = textfile.read()
|
||||||
|
textfile.close()
|
||||||
|
matches = re.findall("t=(\d+)", filetext)
|
||||||
|
return int(matches[0][0:-NO_OF_DECIMALS]) + (int(matches[0][-NO_OF_DECIMALS:]) / 1000.0)
|
||||||
|
|
||||||
|
def read_many_thermo(filenames):
|
||||||
|
result = []
|
||||||
|
for filename in list(filenames):
|
||||||
|
if filename is None:
|
||||||
|
continue
|
||||||
|
result.append(read_one_thermo(filename))
|
||||||
|
return result
|
||||||
@@ -4,6 +4,7 @@ import requests
|
|||||||
import Adafruit_DHT
|
import Adafruit_DHT
|
||||||
import config
|
import config
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
import onewire
|
||||||
|
|
||||||
# Try to read the state of GPIO_PIN_TANKLEVELx and GPIO_PIN_TANKFULL
|
# Try to read the state of GPIO_PIN_TANKLEVELx and GPIO_PIN_TANKFULL
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
@@ -42,6 +43,12 @@ stopPumpingAt = config.STOP_PUMPING_AT
|
|||||||
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
||||||
humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, config.GPIO_PIN_DHT)
|
humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, config.GPIO_PIN_DHT)
|
||||||
|
|
||||||
|
temperatures = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
temperatures = onewire.read_many_thermo(config.ONE_WIRE_TERMO_SENSORS)
|
||||||
|
except:
|
||||||
|
print("onewire thermo error:", sys.exc_info()[0])
|
||||||
|
|
||||||
# Un-comment the line below to convert the temperature to Fahrenheit.
|
# Un-comment the line below to convert the temperature to Fahrenheit.
|
||||||
# temperature = temperature * 9/5.0 + 32
|
# temperature = temperature * 9/5.0 + 32
|
||||||
@@ -58,7 +65,8 @@ if tankFull is not None:
|
|||||||
# "tankLevel3": "1" if tankLevel3 else "0",
|
# "tankLevel3": "1" if tankLevel3 else "0",
|
||||||
"tankLevel4": "1" if tankLevel4 else "0",
|
"tankLevel4": "1" if tankLevel4 else "0",
|
||||||
"tankFull": "1" if tankFull else "0",
|
"tankFull": "1" if tankFull else "0",
|
||||||
"startPumpingAt": startPumpingAt,"stopPumpingAt": stopPumpingAt,"controllerId": controller_id
|
"startPumpingAt": startPumpingAt,"stopPumpingAt": stopPumpingAt,"controllerId": controller_id,
|
||||||
|
"temperatures": temperatures
|
||||||
})
|
})
|
||||||
print 'Temp={0:0.1f}*C'.format(temperature)
|
print 'Temp={0:0.1f}*C'.format(temperature)
|
||||||
print 'Humidity={0:0.1f}%'.format(humidity)
|
print 'Humidity={0:0.1f}%'.format(humidity)
|
||||||
|
|||||||
Reference in New Issue
Block a user