示例#1
0
文件: hackiot.py 项目: 3wells/hackiot
    def start(self):

        s = Settings('config/settings.json')

        client = MqqtClient(s.device_id, s.device_endpoint, s.device_port,
                            'config/root-ca.pem', 'config/private.pem.key',
                            'config/certificate.pem.crt')

        client.start_callback_loop(Raspberry().callback)
示例#2
0
def watcher_photos():
    if Raspberry.Isrun and watcher.Isrun and today.Isbusinessday(
    ) and today.Isworktime() and Raspberry.Muvement():
        loop.create_task(send_photo(CHAT))
    return LOOP_DELAY
示例#3
0
async def send_photo(chat):
    await bot.send_photo(chat, Raspberry.Capture())
示例#4
0
from keyboard import keyboard
from states import watcher, periodic

with open('private_config.conf', 'r') as configFile:
    config = json.load(configFile)

TOKEN, CHAT = config['TOKEN'], config['CHAT']

with open('config.conf', 'r') as configFile:
    config = json.load(configFile)

LOOP_DELAY, Timelist = config['DELAY'], config['Timelist']

logging.basicConfig(level=logging.INFO)
today = Today(config['Time'])
Raspberry = Raspberry(config['Raspberry'])
watcher = watcher()
periodic = periodic()
keyboard = keyboard(watcher, periodic, Timelist)
bot = Bot(TOKEN)
dp = Dispatcher(bot)
loop = asyncio.get_event_loop()


def repeat(wrapped):
    def wrapper():
        loop.call_later(wrapped(), wrapper)

    return wrapper

示例#5
0
from raspberry import Raspberry
import time
import os
import threading
from Queue import Queue
import signal
import sys
import log, logging

logger = logging.getLogger(__name__)

FILA = Queue(maxsize=0)

RASPBERRY = Raspberry()
RASPBERRY.config_pins()


def signal_handler(sig, frame):
    logger.info('You pressed Ctrl+C!')
    sys.exit(0)


def FILA_thread():
    while True:
        try:
            while not FILA.empty():
                frame = FILA.get()

                if frame[0] == '\x03':
                    if frame[2] is '\x20':
                        RASPBERRY.Status_OPTO = True
def dispose():
    Raspberry().dispose()
def read(pin):
    value = Raspberry().read(pin)
    return jsonify(status='OK', value=value)
def setup_in(pin):
    Raspberry().setupIn(pin, GPIO.PUD_DOWN)
    return jsonify(status='OK')
def out_low(pin):
    Raspberry().setupOutLow(pin)
    return jsonify(status='OK')
def out_high(pin):
    Raspberry().setupOutHigh(pin)
    return jsonify(status='OK')
示例#11
0
import threading

from raspberry import Raspberry
from database import Database
import server

d = Database()
r = Raspberry(d)


def startRaspberry():
    r.loop()


def startServer():
    server.run(r, d)


if __name__ == '__main__':
    import webbrowser

    rasp_thread = threading.Thread(target=startRaspberry)
    rasp_thread.start()

    server_thread = threading.Thread(target=startServer)
    server_thread.start()

    webbrowser.open("http://127.0.0.1:5000/")
示例#12
0
class MyRaspberry(Raspberry) :
    
    AlarmePresence = 0
    AlarmeChaudiere = 0
    MaxTemperatureChaudiereEmail = 73
    MaxTemperatureChaudiereSirene = 78
    temperatures = []
    EmailChaudiereEnvoye = False

    
    # SireneAlarme = Raspberry.Sirene('/home/pi/poussoir/lancesirene.py','SIRENE_ALARME')
    SireneAlarme = Raspberry.Sirene('/home/gilles/charlevoix/lancesirene.py','SIRENE_ALARME')
    BoutonPresence = Raspberry.Button(BOUTON_PRESENCE,'BOUTON PRESENCE')
    BoutonChaudiere = Raspberry.Button(BOUTON_CHAUDIERE,'BOUTON CHAUDIERE')
    PowerLed = Raspberry.Led(LED_POWER,'POWER')
    ChaudiereLedOn = Raspberry.Led(LED_CHAUDIERE_on,'CHAUD GREEN LED')
    ChaudiereLedOff = Raspberry.Led(LED_CHAUDIERE_off,'CHAUD RED LED')
    PresenceLedOn = Raspberry.Led(LED_PRESENCE_on,'PRESENCE GREEN LED')
    PresenceLedOff = Raspberry.Led(LED_PRESENCE_off,'PRESENCE RED LED')
    RelaiAlarme = Raspberry.Relay(RELAIS,'RELAI ALARME')
    BuzzerAlarme = Raspberry.Buzzer(BUZZER,'BUZZER')
    PresenceDetecteur = Raspberry.PirDetector(PIR_DETECTOR,'DETECTEUR PRESENCE')
    # SondeTemperatureExterieur = Raspberry.TemperatureSensor("/sys/bus/w1/devices/28-01191285ec0d/w1_slave",'TEMPERATURE EXTERIEUR')
    # SondeTemperatureCave = Raspberry.TemperatureSensor("/sys/bus/w1/devices/28-01191286c32d/w1_slave",'TEMPERATURE CAVE')
    # SondeTemperatureChaudiere = Raspberry.TemperatureSensor("/sys/bus/w1/devices/28-01191eda1932/w1_slave",'TEMPERATURE CHAUDIERE')
    SondeTemperatureExterieur = Raspberry.TemperatureSensor("/home/gilles/py-raspberry/sondeExt",'TEMPERATURE EXTERIEUR')
    SondeTemperatureCave = Raspberry.TemperatureSensor("/home/gilles/py-raspberry/sondeCave",'TEMPERATURE CAVE')
    SondeTemperatureChaudiere = Raspberry.TemperatureSensor("/home/gilles/py-raspberry/sondeChaudiere",'TEMPERATURE CHAUDIERE')

    def __init__(self):
        super().__init__()
        # self.BoutonPresence.Events.onTurnedOn += self.onBoutonPresenceOn
        # self.BoutonPresence.Events.onTurnedOff += self.onBoutonPresenceOff
        # self.BoutonChaudiere.Events.onTurnedOn += self.onBoutonChaudiereOn
        # self.BoutonChaudiere.Events.onTurnedOff += self.onBoutonChaudiereOff
    
    
    def setup(self):
        self.BoutonPresence.setup()
        self.BoutonChaudiere.setup()
        self.PowerLed.setup()
        self.ChaudiereLedOn.setup()
        self.ChaudiereLedOff.setup()
        self.PresenceLedOn.setup()
        self.PresenceLedOff.setup()
        self.RelaiAlarme.setup()
        self.BuzzerAlarme.setup()
        self.PresenceDetecteur.setup()
    
    def initStates(self):
        self.PowerLed.initState()
        self.ChaudiereLedOn.initState()
        self.ChaudiereLedOff.initState()
        self.PresenceLedOn.initState()
        self.PresenceLedOff.initState()
        self.RelaiAlarme.initState()
        self.BuzzerAlarme.initState()
        self.PresenceDetecteur.initState()
        self.BoutonPresence.initState()
        self.BoutonChaudiere.initState()
    
    def ActiverAlarmePresence(self):
        self.AlarmePresence = 1
        delayRELAIS1 = 15
        delayRELAIS2 = 10
        for x in range(1, delayRELAIS1):
            statusBoutonPresence = self.BoutonPresence.Value
            if statusBoutonPresence == 0:
                self.AlarmePresence = 0
                return
            self.BuzzerAlarme.turnOn()
            time.sleep(0.25)
            self.BuzzerAlarme.turnOff()
            time.sleep(0.25)
        for x in range(1, delayRELAIS2):
            statusBoutonPresence = self.BoutonPresence.Value
            
            if statusBoutonPresence == 0:
                self.AlarmePresence = 0
                return
            self.BuzzerAlarme.turnOn()
            time.sleep(0.125)
            self.BuzzerAlarme.turnOff()
            time.sleep(0.125)

    # def onBoutonPresenceOn(self):
    #     # print("---------Bouton Presence ON----------")
    #     self.SireneAlarme.activated = False
    #     self.AlarmePresence = 1
    #     self.PresenceLedOn.turnOff()
    #     self.PresenceLedOff.turnOn()
    #     self.ActiverAlarmePresence()
    #     if self.AlarmePresence==1:
    #         self.PresenceDetecteur.addEventListner(self.ON_RISING_EVENT,self.F_pir,3000000)
    
    # def onBoutonPresenceOff(self):
    #     # print("---------Bouton Presence OFF----------")
    #     self.BuzzerAlarme.turnOff()  
    #     if self.SireneAlarme.activated :
    #         self.SireneAlarme.stop()
    #     self.AlarmePresence = 0
    #     self.RelaiAlarme.deactivate()
    #     self.PresenceLedOn.turnOn()
    #     self.PresenceLedOff.turnOff()
    #     self.PresenceDetecteur.removeEventListner()
    
    # def checkTemperatureChaudiere(self):
    #     self.temperatures.insert(0, self.SondeTemperatureChaudiere.Value)
    #     print(self.temperatures)
    #     if(len(self.temperatures)>10):
    #         self.temperatures.pop()
    #     if(self.EmailChaudiereEnvoye and max(self.temperatures)<self.MaxTemperatureChaudiereEmail ) :
    #         self.EmailChaudiereEnvoye = False
    #     if(self.EmailChaudiereEnvoye!=True and self.temperatures[0] > self.MaxTemperatureChaudiereEmail):
    #         self.sendEmailAlarmeChaudiere()
    #     if(self.SireneAlarme.activated!=True and self.temperatures[0] > self.MaxTemperatureChaudiereSirene ):
    #         print('----------Activation SIRENE--------')
    #         self.SireneAlarme.start()
        
    # def sendEmailAlarmeChaudiere(self):
    #     print('----------Envoi mail Chaudiere')
    #     self.EmailChaudiereEnvoye = True

    # def onBoutonChaudiereOn(self):
    #     # print("---------Bouton Presence ON----------")
    #     self.temperatures.clear()
    #     self.AlarmeChaudiere = 1
    #     self.ChaudiereLedOn.turnOff()
    #     self.ChaudiereLedOff.turnOn()
    
    # def onBoutonChaudiereOff(self):
         
    #     if(self.SireneAlarme.activated):
    #         print("---------DESACTIVATION SIRENE----------")
    #         self.SireneAlarme.stop()
    #     self.temperatures.clear()
    #     self.AlarmeChaudiere = 0
    #     self.ChaudiereLedOn.turnOn()
    #     self.ChaudiereLedOff.turnOff()

       
    
    # def F_pir(self,channel):
    #     now = datetime.datetime.now()    
    #     timee=now.strftime("%Y-%m-%d %H:%M:%S")
    #     print ("----------------------f3 pir detect something-----------:" + timee +" alarmesirene:")
    #     self.SireneAlarme.start()
    
    # def checkUpdate(self):
    #     self.AlarmePresence = self.BoutonPresence.Value
    #     self.AlarmeChaudiere = self.BoutonChaudiere.Value
    #     # print(f"AlarmePresence : {self.AlarmePresence}")
    #     # print(f"AlarmeChaudiere : {self.AlarmeChaudiere}")
    #     if(self.AlarmePresence) :
    #         print('----------Alarme Presence Activée')
    #     if(self.AlarmeChaudiere) :
    #         self.checkTemperatureChaudiere()

    #     time.sleep(1)