def gas_sensor_callback(GAS_GPIO): poruka = random.choice(gasMessages) print('\nSenzor plina: ' + poruka) redis_conn.writeToDb('Senzor_plin', jsonBuilder.createRedisEntry(6,poruka)) mysql_conn.insertAlarm(6, poruka) payload = jsonBuilder.createPOSTmessage(6, poruka) print("Server response: {0}").format(restClient.sendPOSTMessage(payload))
def photo_sensor_callback(PHOTO_GPIO): poruka = random.choice(photoMessages) print('\nFoto senzor: ' + poruka) redis_conn.writeToDb('Senzor_foto', jsonBuilder.createRedisEntry(3,poruka)) mysql_conn.insertAlarm(3, poruka) payload = jsonBuilder.createPOSTmessage(3, poruka) print("Server response: {0}").format(restClient.sendPOSTMessage(payload))
def flame_sensor_callback(FLAME_GPIO): poruka = random.choice(flameMessages) print('\nSenzor vatre: ' + poruka) redis_conn.writeToDb('Senzor_vatra', jsonBuilder.createRedisEntry(8,poruka)) mysql_conn.insertAlarm(8, poruka) payload = jsonBuilder.createPOSTmessage(8, poruka) print("Server response: {0}").format(restClient.sendPOSTMessage(payload))
def rain_sensor_callback(RAIN_GPIO): poruka = random.choice(rainMessages) print('\nSenzor vode: ' + poruka) redis_conn.writeToDb('Senzor_voda', jsonBuilder.createRedisEntry(7,poruka)) mysql_conn.insertAlarm(7, poruka) payload = jsonBuilder.createPOSTmessage(7, poruka) print("Server response: {0}").format(restClient.sendPOSTMessage(payload))
def temp_sensor_callback(): humidity, temperature = Adafruit_DHT.read_retry(11, TEMP_GPIO) if humidity == None and temperature == None: data = 'Greska kod mjerenja temperature i vlage' print(data) else: data = 'Dohvacena temperatura: {0:0.1f} C i vlaga: {1:0.1f} %'.format( temperature, humidity) print('\n' + data) redis_conn.writeToDb('temperatura', jsonBuilder.createRedisEntry(1, data)) mysql_conn.insertTermolog(1, ('{:0.2f}').format(round(temperature, 2)), ('{:0.2f}').format(round(humidity, 2)), 'Izmjerena temperatura i vlaga') is_between_temp = int(temperature) in range(18, 26) if not is_between_temp: poruka = random.choice(tempMessages) print(poruka) mysql_conn.insertAlarm(1, poruka) payload = jsonBuilder.createPOSTmessage(1, poruka) print("Server response: {0}").format( restClient.sendPOSTMessage(payload)) is_between_hum = int(humidity) in range(20, 80) if not is_between_hum: poruka = random.choice(humMessages) print(poruka) mysql_conn.insertAlarm(1, poruka) payload = jsonBuilder.createPOSTmessage(1, poruka) print("Server response: {0}").format( restClient.sendPOSTMessage(payload))
def pir_sensor_callback(PIR_GPIO): poruka = random.choice(pirMessages) print('\nSenzor pokreta: ' + poruka) mysql_conn.insertAlarm(4, poruka) payload = jsonBuilder.createPOSTmessage(4, poruka) print("Server response: {0}").format(restClient.sendPOSTMessage(payload)) redis_entry = redis_conn.getFromDb("Senzor_pokreta") if upaljeno == False: powerON() message = jsonBuilder.createRedisLightEntry(4, poruka, "UPALJENO") redis_conn.writeToDb("Senzor_pokreta", message) elif upaljeno == True: powerOFF() if redis_entry is not None: new_message = jsonBuilder.createRedisLightEntry(4, poruka, "UGASENO") data = json.loads(redis_entry) time_from = data["vrijeme"] new_data = json.loads(new_message) time_to = new_data["vrijeme"] razlika = datetime.strptime(time_to, '%Y-%m-%d %H:%M:%S') - datetime.strptime(time_from, '%Y-%m-%d %H:%M:%S') mysql_conn.insertLightLog(4, razlika, time_from, time_to)