def on_disconnect(client, userdata, rc): print("\n*** Queda de conexao ***") client = mqtt.Client() client.will_set(topico, no_connection_message, 0, True) print("\nStarting subscriber...") client.on_disconnect = on_disconnect client.connect(ip_broker) client.loop_start() print("\nStarting publisher...") btn = Button('GPIO-A') ##################### # rotina principal # ##################### ledOn = 0 ledstatus = "" while True: sleep(0.3) if btn.is_pressed(): if ledOn == 0: ledOn = 1 ledstatus = "ON" else: ledOn = 0 ledstatus = "OFF"
from libsoc import gpio from time import sleep from libsoc_zero.GPIO import Button # Define GPIO to use spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz=10000 spi.mode = 0b00 spi.bits_per_word = 8 channel_select=[0x01, 0xA0, 0x00] channel_select2=[0x01, 0x80, 0x00] READ_SENSE = gpio.GPIO(18, gpio.DIRECTION_OUTPUT) tilt = Button('GPIO-C') # read if Tilt happened def hasEarthQuake(): if tilt.is_pressed(): print({'earthquake':'true'}) return json.dumps({'earthquake':'true'}) else: print({'earthquake':'false'}) return json.dumps({'earthquake':'false'}) # read the temperature sensor def readTempSense(): READ_SENSE.set_high()
from libsoc_zero.GPIO import Button from time import sleep segundos = 10 btn1 = Button('GPIO-A') btn2 = Button('GPIO-C') path = 'dados.txt' arquivo = open(path, 'w') while segundos != 0: sleep(1) if btn1.is_pressed(): arquivo.write('O touch foi pressionado!\t') else: arquivo.write('O touch não foi pressionado!\t') if btn2.is_pressed(): arquivo.write('Há luz no ambiente!\n') else: arquivo.write('Não há luz no ambiente!\n') segundos -= 1 arquivo.close()
from libsoc_zero.GPIO import Button touch = Button('GPIO-C') while True: if touch.is_pressed(): print("Button is pressed") else: print("Button is not pressed")
from libsoc_zero.GPIO import Button from libsoc_zero.GPIO import LED from time import sleep btn = Button('GPIO-G') led = LED('GPIO-E') while True: btn.wait_for_press() if led.is_lit: led.off() else: led.off() sleep(1)
#!/usr/bin/python from libsoc_zero.GPIO import Button from time import sleep btnA = Button("GPIO-A") btnB = Button("GPIO-B") btnC = Button("GPIO-C") btnD = Button("GPIO-D") btnE = Button("GPIO-E") while True: sleep(0.25) if btnA.is_pressed(): print("Button A is pressed") elif btnB.is_pressed(): print("Button B is pressed") elif btnC.is_pressed(): print("Button C is pressed") elif btnD.is_pressed(): print("Button D is pressed") elif btnE.is_pressed(): print("Button E is pressed") else: print("Button not pressed")
from libsoc_zero.GPIO import Button from libsoc_zero.GPIO import LED from time import sleep sensor = Button('GPIO-A') gpio_red = LED('GPIO-B') gpio_red.off() sleep(2) while True: if sensor.is_pressed(): gpio_red.on() sleep(0.5) else: gpio_red.off() sleep(0.5)
from libsoc_zero.GPIO import Button touch = Button('GPIO-C') print('Waiting for press event...') touch.wait_for_press() print('Button was pressed!')
print(media_url) media_urls.append(media_url) send_alert_to_phone_number(twilio_phone_number, verified_phone_number, msg_body, media_urls) # Button Callback function to create new reference frame, firstFrame def btn_cb(): # In order to reference the global variable, need to declare callback variable as global global firstFrame firstFrame = None print("Button Pressed!") btnA = Button("GPIO-A") btnA.when_pressed(btn_cb) # Boto S3 Constants s3_bucket = "your-s3-bucket-name" aws_access_key_id = "your-aws-access-key-id" aws_secret_key = "your-aws-secret-key" # Set the Host to get around 400 Bad Request Error # Example format something like -> "s3.us-east-2.amazonaws.com" REGION_HOST = "your-region-host" # Connect to AWS S3 s3_connection = S3Connection(aws_access_key_id, aws_secret_key,
#coding: utf-8 from libsoc_zero.GPIO import Button from time import sleep import paho.mqtt.client as mqtt #import time # This is the Publisher # Cria cliente mqtt client = mqtt.Client() # Cria o testamento para o topico "topic/9", mensagem = "Desconectando..". QOS = 1 # Conecta o cliente ao Broker fornecido em aula client.connect("192.168.123.17",1883,60) # Publica a mensagem "Conectado" no topico "topic/AULA", com o QOS = 0 client.publish("topic/grupo9", "Conectado", 2) btn1 = Button('GPIO-A') while True: sleep(0.25) if btn1.is_pressed(): client.publish("topic/grupo9", "1") else: client.publish("topic/grupo9", "0")
from libsoc_zero.GPIO import Button #GPIO Libraries from libsoc_zero.GPIO import Buzzer from time import sleep from time import time helpButton = Button('GPIO-A0') cancelButton = Button('GPIO-AB') buzzerPin = Buzzer('GPIO-D5') helpButton.wait_for_press() falseAlarm = False while falseAlarm == False: start = time() while start < 3: buzzerPin = HIGH while start < 120 and falseAlarm == False: if cancelButton.is_pressed(): falseAlarm = True if falseAlarm == False: findLocation() #using GPS or Wifi #then send to HTML
from libsoc_zero.GPIO import Button from time import sleep btn = Button('GPIO-G') while True: sleep(0.25) if btn.is_pressed(): print('Button is pressed!') else: print('Button is not pressed!')
) message = ('Atenção, foi detectado alagamento na região dos sensores ' 'grande risco de enchente nos próximos minutos.') payload = { "default": message, "GCM": "{\"data\":{\"message\":\"%s\"}}" % message } sns_client.publish( TopicArn='arn:aws:sns:us-east-1:ACCOUNT:StormDetected', Message=json.dumps(payload), MessageStructure='json', Subject='Alerta de enchente') last_notification_sent = datetime.utcnow() else: logger.info( 'Notification not sended: seconds_ago={}'.format(seconds_ago)) def water_level_event(): publisher.send({'water_level': 1}, debug=True) send_sns_notification() logger.warning("water_level 1") if __name__ == '__main__': water_level = Button('GPIO_25') water_level.when_pressed(water_level_event) while True: publisher.send({'water_level': 0}, debug=True) time.sleep(5)
THING_PRIVATE_KEY = "/home/linaro/xxxxxxxxxx-private.pem.key" spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz=10000 spi.mode = 0b00 spi.bits_per_word = 8 channel_select_temp=[0x01, 0xA0, 0x00] #1010 0000 ADC2 temperatura (CH 1) - terminal A2 e A3 channel_select_ldr=[0x01, 0xC0, 0x00] #1100 0000 ADC1 ldr (CH 2) - terminal A0 e A1 channel_select_potenciometro=[0x01, 0xE0, 0x00] #1110 0000 ADC2 potenciometro (CH 3) - terminal A2 e A3 arq = open('TARC.txt', 'w') relay = LED('GPIO-A') #Saída digital D1 (saída de alarme) water_level = Button('GPIO-C') #Entrada digital D2 (sensor de nível) tilt = Tilt('GPIO-G') #Entrada digital D4 (terremoto) x = 1 temp_value_old = 0 ldr_value_old = 0 shake_value = 0 shake_var = 0 shake_value_old = 0 temperature = 0 ldr = 0 state = 0 terremoto = "OK" enchente = "OK" tempestade = "OK" timetopublish = 0