コード例 #1
0
ファイル: database.py プロジェクト: amigueti/raspberry-wsn
    def insertar_medida(self, datos, lista_medidas):
        (db, cursor) = self.iniciar_db()
        sensores = Sensores()

        for medida in lista_medidas:
            cursor.execute(
                """INSERT INTO medidas (mota, sensor, valor, hora) VALUES (%s,%s,%s,%s)""",
                (
                    int(datos['source_id'].encode('hex'), 16),
                    medida['id'],
                    medida['valor'],
                    #int(medida['valor'].encode('hex'), 16),
                    datetime.datetime.fromtimestamp(
                        medida['hora'] - 7200).strftime('%Y-%m-%d %H:%M:%S')))
            db.commit()

        self.cerrar_db(db, cursor)
コード例 #2
0
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

Config = ConfigParser.ConfigParser()
Config.read('conf.ini')

PORT = str(Config.get('XBEE', 'port'))
BAUD_RATE = str(Config.get('XBEE', 'baud_rate'))
TIMEOUT = int(Config.get('MOTA', 'timeout'))
ser = serial.Serial(PORT, BAUD_RATE, timeout=TIMEOUT)

frame_buffer = list()
xbee = DigiMesh(ser, escaped=True)
sender = Sender()
sensores = Sensores()
handler = Handler()


class Mota:
    def __init__(self):
        self.num_sensores = 0
        self.num_seq = 1
        self.contador = 0
        self.contador_interrupciones = 0
        self.mensaje = ''
        self.mensaje_interrupcion = ''

    def interrupcion_hall(self, channel):
        print "se ha disparado el gpio: " + str(channel)
        dt = datetime.datetime.now()
コード例 #3
0
ファイル: handler.py プロジェクト: amigueti/raspberry-wsn
 def __init__(self):
     self.sensores = Sensores()
     self.sender = Sender()
     #self.database = DataBase()
     self.mqtt = Mqtt()
     self.Config = ConfigParser.ConfigParser()
コード例 #4
0
import json


def criandoJson(info):
    return json.dumps(info)


broker = "test.mosquitto.org"
topic = "inatel/ICT/horta-inteligente"

cliente = mqtt.Client("Cliente")
cliente.connect(broker)

sensorUmidade = Sensores(
    name="Umidade",
    bounds=(0, 1))  #trabalhado em % (considerando status atual)
sensorLuminosidade = Sensores(name="Luminosidade", bounds=(
    0.5,
    1))  #trabalhado em % (considerando últimas 12 horas e 100% como ideal)
carteiraDigital = 311.86

while True:

    info = {
        "dataHora": datetime.now().strftime("%d/%m/%Y\n\n%H:%M:%S"),
        "valorUmidade": sensorUmidade.getValor(),
        "valorIluminacao": sensorLuminosidade.getValor()
    }

    #Irrigação