gpio.digital_write(SOL, GPIO.HIGH) adcout = (r[1] << 8) & 0b1100000000 adcout2 = adcout | (r[2] & 0xff) #print("Luminosidade: %d" %adcout) return adcout2 #def readDweet(): if __name__ == '__main__': with GPIO(pins) as gpio: while True: digital = [0, 0] resposta = dweet.latest_dweet(name="murilo_inatel") digital[0] = resposta['with'][0]['content']['iluminacao'] digital[1] = resposta['with'][0]['content']['irrigacao'] # era aqui writeDigital(gpio, digital) sol = readLumi(gpio) vol = readVol(gpio) hum = readHum(gpio) writeDigital(gpio, digital) #digital = readDigital(gpio) temp = readTemp(gpio) print "\n\nLEITURA: Sistema iRRigacao\nTemperatura: %2.1f\nSol: %d\nIluminacao: %d\nIrrigacao: %d\nVolume Dagua:%d\nHumidade do Ar:%d" % ( temp, sol, digital[0], digital[1], vol, hum) dweet.dweet_by_name(name="murilo_inatel",
GPIO.setup(15,GPIO.OUT) dweet = Dweet()#initialise dweet object while 1==1:#infinite loop/program loop GPIO.output(7,False);#turning off all LEDs GPIO.output(11,False); GPIO.output(13,False); GPIO.output(15,True);#LED 15 is the ON indicator. Indicates the program is running #receiving command from server try: rdata=dweet.latest_dweet(name=devicename) #checking for HTTP connection except Exception, e:#if error found print "Connection Error Occured" # dweet class is configured to only return a Connection Error so any error thrown is a Connection error GPIO.output(13,True) sleep(0.5) GPIO.output(13,False) sleep(0.5) GPIO.output(13,True)#blink the RED LED to indicate this error continue#continue to the next iteration #checking the received data if(rdata['this']=='failed'):#if the received data contains a value of 'failed' for the 'this' key, it means the devicename has no commands print "No data, Check Device name" GPIO.output(11,True)#Light the BLUE Led to indicate this error sleep(0.2) GPIO.output(11,False)
from datetime import datetime from time import sleep import sys if __name__ == "__main__": devicename='t27testing' if len(sys.argv)>1: devicename=sys.argv[1] prev=datetime.strptime("00:00:00","%H:%M:%S"); dweet = Dweet() while 1==1: #timenow=str(datetime.now()) #receiving command from server try: rdata=dweet.latest_dweet(name=devicename) except Exception, e: print "Connection error!!" exit() if(rdata['this']=='failed'): print "No data, Check Device name" if(rdata['this']=='succeeded'): commandreceived=rdata['with'][0]['content']['command'] #calculating timestamp of servers command modifieddate=rdata['with'][0]['created'] mtime=modifieddate.split('T')[1] curr=datetime.strptime(mtime.split('.')[0],"%H:%M:%S"); #checking if timestamp is new if curr>prev:
def desligaled(): gpio.digital_write(LED, GPIO.LOW) def respostadweet(): resposta = dweet.latest_dweet(name="iplug_sabrina_q4") dwligarele = resposta['with'][0]['content']['rele'] dwligaled = resposta['with'][0]['content']['led'] with GPIO(pins) as gpio: while True: button_value = gpio.digital_read(TOQUE) resposta = dweet.latest_dweet(name="iplug_sabrina_q4") dwligatoque = resposta['with'][0]['content']['toque'] dwligaled = resposta['with'][0]['content']['led'] dwligarele = resposta['with'][0]['content']['rele'] if button_value == 0 and dwligatoque == 0: vtemp = temperatura(gpio) vlumi = luminosidade(gpio) print "Sua casa esta sendo controlada automaticamente" #time.sleep(5) if vtemp > 23 and vlumi < sensibilidade: ligarele() ligaled() dweet.dweet_by_name(name="iplug_sabrina_q4", data={ "led": 1,
adcout = (r[1] << 8) & 0b1100000000 adcout = adcout | (r[2] & 0xff) #print("Luminosidade: %d" %adcout) return adcout #def readDweet(): if __name__ == '__main__': with GPIO(pins) as gpio: while True: digital = [0, 0] if detectaButton(gpio) == 1: resposta = dweet.latest_dweet(name="inatel_ead") digital[0] = resposta['with'][0]['content']['led'] digital[1] = resposta['with'][0]['content']['rele'] writeDigital(gpio, digital) temp = readTemp(gpio) lumi = readLumi(gpio) digital = readDigital(gpio) print "Temp: %2.1f\nlumi: %d\nled: %d\nrele: %d" % ( temp, lumi, digital[0], digital[1]) dweet.dweet_by_name(name="inatel_ead", data={ "led": digital[0], "rele": digital[1], "Temperatura": temp, "Luminosidade": lumi })
#!/usr/bin/env python from dweet import Dweet if __name__ == "__main__": dweet = Dweet() #dweet an dweet without a thing name. Returns a a thing name in the response print dweet.dweet({"hello": "world"}) #dweet with a thing name print dweet.dweet_by_name(name="test_thing", data={"hello": "world"}) #get the latest dweet by thing name. Only returns one dweet. print dweet.latest_dweet(name="test_thing") #get all the dweets by dweet name. print dweet.all_dweets(name="test_thing")
def readTemp(gpio): gpio.digital_write(TEMP, GPIO.HIGH) time.sleep(0.0002) gpio.digital_write(TEMP, GPIO.LOW) r = spi.xfer2([0x01, 0xA0, 0x00]) gpio.digital_write(TEMP, GPIO.HIGH) adcout = (r[1] << 8) & 0b1100000000 adcout = adcout | (r[2] & 0xff) adc_temp = (adcout *5.0/1023-0.5)*100 return adc_temp if __name__=='__main__': with GPIO(pins) as gpio: while True: dados = [0,0] resposta = dweet.latest_dweet(name="minhacasa") dados[0] = resposta['with'][0]['content']['led'] dados[1] = resposta['with'][0]['content']['rele'] writeDigital(gpio, digital) temp = readTemp(gpio) digital = readDigital(gpio) print "Monitoramento Residencial\n" print "Temp: %2.1f\n led: %d\nrele: %d" %(temp, digital[0], digital[1]) print "Registrando na Nuvem\n" dweet.dweet_by_name(name="minhacasa", data={"led":digital[0],"rele": digital[1], "Temperatura":temp}) time.sleep(30)