示例#1
0
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))
示例#2
0
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))
示例#3
0
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))
示例#4
0
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))
示例#5
0
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))