示例#1
0
def auto_vent():
    temp = environment_temp()
    sleep(2)
    if temp > 25:
        vent_open()
        vent_pos = 1
        sleep(5)
    else:
        vent_close()
        vent_pos = 0
        sleep(5)
    return vent_pos
示例#2
0
def writeData(
    temperature, humidity, Water_level, door_mag, vent_pos
):  #this fuction takes in the parameters that are to be written to thingspeak in teh cloud (field5 is already used as a calcualtion channel)
    client.publish(
        "channels/%s/publish/%s" % (channelID, apiKey),
        'field1=%s&field2=%s&field3=%s&field4=%s&field6=%s' % (
            temperature,
            humidity,
            Water_level,
            door_mag,
            vent_pos,
        ))


while True:  #this while loop will cycle through, takes just under a minute to get through the variuos functions
    temp = environment_temp()  # calls up the temperature  sensor reading
    humid = environment_humid()  #calls up the humidity sensor reading
    level = reading(
    )  #calls up the return value of voluem in tank from function reading in Tank.py
    door_state = door_mag.door(
    )  #checks the door fucntion in door mag py fiel. Was originall a magnet but changed it to a push button
    vent_condition = vent.auto_vent(
    )  #checks if vent is open or closed based on last servo position
    writeData(temp, humid, level, door_state,
              vent_condition)  #writes into the writeData for the MQTT publish
    time.sleep(10)
    http_request.auto_water(
    )  #calling function auto_water in http_request py file, if condion on is met, then the watering takes place, with the last requested ammount
    cam(
    )  #taking a picture and sending to firebase database, which shows up on the web app
    time.sleep(30)
示例#3
0
def read_virtual_pin_handler(pin1):
    temp = environment_temp()
    #print('V2 Read:' + str(temp), 'Degrees C')  # print temperature to console
    blynk.virtual_write(pin1, temp)
示例#4
0
#!/usr/bin/python3

from urllib.request import urlopen
import json
import time
from temp_hum import environment_temp
from temp_hum import environment_humid
from Tank import reading
import door_mag

WRITE_API_KEY = 'K89UM98Z1CQD03BA'

baseURL = 'https://api.thingspeak.com/update?api_key=%s' % WRITE_API_KEY


def writeData(temperature, humidity, Water_level, door_mag):
    # Sending the data to thingspeak in the query string
    conn = urlopen(baseURL + '&field1=%s&field2=%s&field3=%s&field4=%s' %
                   (temperature, humidity, Water_level, door_mag))
    # Closing the connection
    conn.close()


while True:
    temp = environment_temp()
    humid = environment_humid()
    level = reading()
    door_state = door_mag.door()
    time.sleep(5)
    writeData(temp, humid, level, door_state)
    time.sleep(60)