picture sending scripts ready
This commit is contained in:
@@ -18,3 +18,4 @@ 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 -f image2 -vframes 1 /mnt/zoblakdata/picture.jpg' # filename must match PICTURE_FILE path
|
||||
PICTURE_URL = 'http://agrar.zoblak.com/api/v1.0/picture/'
|
||||
|
||||
@@ -8,27 +8,27 @@ import camera
|
||||
|
||||
# Try to read the state of GPIO_PIN_TANKLEVELx and GPIO_PIN_TANKFULL
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(config.GPIO_PIN_TANKLEVEL0, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(config.GPIO_PIN_TANKLEVEL1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(config.GPIO_PIN_TANKLEVEL2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(config.GPIO_PIN_TANKLEVEL3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
#GPIO.setup(config.GPIO_PIN_TANKLEVEL0, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
#GPIO.setup(config.GPIO_PIN_TANKLEVEL1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
#GPIO.setup(config.GPIO_PIN_TANKLEVEL2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
#GPIO.setup(config.GPIO_PIN_TANKLEVEL3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(config.GPIO_PIN_TANKLEVEL4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(config.GPIO_PIN_TANKFULL, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
# tank sensor has inverse logic - 0 when it is full 1 when it is not
|
||||
# so we are inverting its value here
|
||||
tankLevel0 = (GPIO.input(config.GPIO_PIN_TANKLEVEL0) == GPIO.LOW)
|
||||
tankLevel1 = (GPIO.input(config.GPIO_PIN_TANKLEVEL1) == GPIO.LOW)
|
||||
tankLevel2 = (GPIO.input(config.GPIO_PIN_TANKLEVEL2) == GPIO.LOW)
|
||||
tankLevel3 = (GPIO.input(config.GPIO_PIN_TANKLEVEL3) == GPIO.LOW)
|
||||
# tankLevel0 = (GPIO.input(config.GPIO_PIN_TANKLEVEL0) == GPIO.LOW)
|
||||
# tankLevel1 = (GPIO.input(config.GPIO_PIN_TANKLEVEL1) == GPIO.LOW)
|
||||
# tankLevel2 = (GPIO.input(config.GPIO_PIN_TANKLEVEL2) == GPIO.LOW)
|
||||
# tankLevel3 = (GPIO.input(config.GPIO_PIN_TANKLEVEL3) == GPIO.LOW)
|
||||
tankLevel4 = (GPIO.input(config.GPIO_PIN_TANKLEVEL4) == GPIO.LOW)
|
||||
tankFull = (GPIO.input(config.GPIO_PIN_TANKFULL) == GPIO.LOW)
|
||||
|
||||
GPIO.cleanup()
|
||||
print 'Bacva Level0: {}'.format(tankLevel0)
|
||||
print 'Bacva Level1: {}'.format(tankLevel1)
|
||||
print 'Bacva Level2: {}'.format(tankLevel2)
|
||||
print 'Bacva Level3: {}'.format(tankLevel3)
|
||||
# print 'Bacva Level0: {}'.format(tankLevel0)
|
||||
# print 'Bacva Level1: {}'.format(tankLevel1)
|
||||
# print 'Bacva Level2: {}'.format(tankLevel2)
|
||||
# print 'Bacva Level3: {}'.format(tankLevel3)
|
||||
print 'Bacva Level4: {}'.format(tankLevel4)
|
||||
print 'Bacva puna: {}'.format(tankFull)
|
||||
|
||||
@@ -43,9 +43,6 @@ 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)
|
||||
|
||||
picture_base64 = camera.get_transfer_picture_base64()
|
||||
if picture_base64 is not None:
|
||||
camera.remove_transfer_picture()
|
||||
|
||||
# Un-comment the line below to convert the temperature to Fahrenheit.
|
||||
# temperature = temperature * 9/5.0 + 32
|
||||
@@ -55,9 +52,14 @@ if picture_base64 is not None:
|
||||
# guarantee the timing of calls to read the sensor).
|
||||
# If this happens try again!
|
||||
if tankFull is not None:
|
||||
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity, "tankLevel0": "1" if tankLevel0 else "0","tankLevel1": "1" if tankLevel1 else "0","tankLevel2": "1" if tankLevel2 else "0","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,
|
||||
'picture': picture_base64
|
||||
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity,
|
||||
# "tankLevel0": "1" if tankLevel0 else "0",
|
||||
# "tankLevel1": "1" if tankLevel1 else "0",
|
||||
# "tankLevel2": "1" if tankLevel2 else "0",
|
||||
# "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
|
||||
})
|
||||
print 'Temp={0:0.1f}*C'.format(temperature)
|
||||
print 'Humidity={0:0.1f}%'.format(humidity)
|
||||
|
||||
@@ -67,9 +67,9 @@ class Changer(object):
|
||||
self.local_state['out_valve'] = 'closed'
|
||||
|
||||
def fulfill_picture_request(self):
|
||||
if self.remote_state['transfer_picture'] == 'true':
|
||||
if self.remote_state['picture_requested'] == 'true':
|
||||
make_transfer_picture()
|
||||
self.local_state['transfer_picture'] = 'false'
|
||||
self.local_state['picture_requested'] = 'false'
|
||||
|
||||
|
||||
def validate_states(self):
|
||||
|
||||
Reference in New Issue
Block a user