diff --git a/controller/config/copy__init__.py.example b/controller/config/copy__init__.py.example index eb166f2..37c72fc 100644 --- a/controller/config/copy__init__.py.example +++ b/controller/config/copy__init__.py.example @@ -15,5 +15,6 @@ CONTROLLER_ID = '120' # every controller must have a different one STATE_FILE = '/mnt/zoblakdata/controller_state' PICTURE_TRANSFER_FILE='/mnt/zoblakdata/picture_transfer_ready.jpg' 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' +ONE_WIRE_TERMO_SENSORS = ['/dev/sys/bus/w1/devices/xxx/w1_slave'] # xxx is a serial number diff --git a/controller/drivers/onewire/__init__.py b/controller/drivers/onewire/__init__.py new file mode 100644 index 0000000..1947bf4 --- /dev/null +++ b/controller/drivers/onewire/__init__.py @@ -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 diff --git a/controller/sensors.py b/controller/sensors.py index 70ea964..a0795db 100644 --- a/controller/sensors.py +++ b/controller/sensors.py @@ -4,6 +4,7 @@ import requests import Adafruit_DHT import config import RPi.GPIO as GPIO +import onewire # Try to read the state of GPIO_PIN_TANKLEVELx and GPIO_PIN_TANKFULL 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). 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. # temperature = temperature * 9/5.0 + 32 @@ -58,7 +65,8 @@ if tankFull is not None: # "tankLevel3": "1" if tankLevel3 else "0", "tankLevel4": "1" if tankLevel4 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 'Humidity={0:0.1f}%'.format(humidity)