示例#1
0
def bedroom_lights(textStr):
    k = locker.getContent("ifttt", "key")
    if "off" in textStr:
        r = requests.post(
            "https://maker.ifttt.com/trigger/lightoff/with/key/" + k)
    elif "on" in textStr:
        r = requests.post("https://maker.ifttt.com/trigger/lighton/with/key/" +
                          k)
示例#2
0
 def test_get_content1(self):
     self.assertEqual(my_locker.getContent("roomsensor", "current"),
                      r"/home/pi/currentRoomClimate.txt")
示例#3
0
 def test_get_content2(self):
     self.assertEqual(my_locker.getContent('quandl', 'key'),
                      "mVT2uZx9yVpevoNYzt1n")
示例#4
0
import subprocess
import sys
import RPi.GPIO as gpio
import time
import _thread
import quandl as qd
import requests
import my_news_reader as news
import my_locker as locker
import aiy.assistant.auth_helpers
import aiy.audio
import aiy.voicehat
from google.assistant.library import Assistant
from google.assistant.library.event import EventType

ROOMCLIMATE_FILE = locker.getContent("roomsensor", "current")

BCM_FOR_HAT_RELAY_PIN1 = 4  # Driver 0 on HAT board
BCM_FOR_HAT_RELAY_PIN2 = 17  # Driver 1 on HAT board


def initialize():
    gpio.setmode(gpio.BCM)
    gpio.setup(BCM_FOR_HAT_RELAY_PIN1, gpio.OUT)  #,initial=0)
    gpio.setup(BCM_FOR_HAT_RELAY_PIN2, gpio.OUT)  #,initial=0)


#returns a data set tuple e.g. {'temp':50, 'humidity':100 }
def get_room_temp():
    f = open(ROOMCLIMATE_FILE, 'r')
    ln1 = f.readline()
示例#5
0
 def compile_top_news_url(self, source):
     key = locker.getContent("newsapi.org", "key")
     url = self.NEWS_URL + '?source=' + source + '&sortBy=Top&apiKey=' + key
     return url
示例#6
0
import dht11
import time
import datetime
import RPi.GPIO as GPIO
import my_locker as locker

# Read the Voice Hat BCM pin from the locker
VOICE_HAT_PIN = int(locker.getContent("gpio","dht_bcm_pin"))

def main():
    # initialize GPIO
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.cleanup()
    # read data using pin 14
    # pin-4: (BCM 0 Driver 0 on Voice HAT)
    # pin-17: (BCM 17 Driver 1 on Voice HAT)
    # pin-27: (BCM 27 Driver 2 on Voice HAT)
    # pin-22: (BCM 22 Driver 3 on Voice HAT)
    # pin-26: (BCM 26 Servo 0 on Voice HAT) - to be used in current config
    

    instance = dht11.DHT11(VOICE_HAT_PIN)
    # print ("PIN set in instance is:",instance._DHT11__pin)
    # print (type(instance._DHT11__pin))
    while True:
        result = instance.read()
        if result.is_valid():
            print("Last valid input: " + str(datetime.datetime.now()))
            print("Temperature is: %d degree centigrade" % result.temperature)
            print("Humidity is: %d percent" % result.humidity)