ButtPinList = list(ButtDict.keys()) # print('\nButtDict', ButtDict, '\nButtPinList', ButtPinList) PreviousButtonValueDict = dict.fromkeys(ButtPinList, 1) print('\nAfter ButtDict', time.ticks_us() / 1000, 'ms') # Button Interrupts for x in ButtPinList: ButtDict[x].callback(trigger=machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING, handler=button_event) print('\nAfter button interrupts', time.ticks_us() / 1000, 'ms') machine.pin_deepsleep_wakeup(['P23'], machine.WAKEUP_ALL_LOW, enable_pull=True) if machine.reset_cause() == machine.DEEPSLEEP_RESET: # sleep if button not being held then continue on release print('\nReturn from DEEP SLEEP') mode_button = 'P23' if not ButtDict[mode_button].value(): deep_down_flag = True else: print('ENTER deep sleep AGAIN\n') machine.deepsleep() while 1: machine.idle() time.sleep_ms(10)
###pycom run this file when booting ###setting up interrupt pin and disable wifi on boot from machine import Pin import machine import pycom #Setting up Pin mode and Initialize interrupt pinAlert = Pin('P10', mode=Pin.IN, pull=Pin.PULL_DOWN) machine.pin_deepsleep_wakeup(['P10'], machine.WAKEUP_ALL_LOW, True) #Disable Wifi to reduce power consumption pycom.wifi_on_boot([False])
return volts/i if (machine.wake_reason()[0])==1: #pin wakeup pycom.rgbled(0x7f0000) # green total_count = pycom.nvs_get('counter') +1 pycom.nvs_set('counter', total_count) print('remaining deepsleep time is {}'.format(machine.remaining_sleep_time())) print('Counted: {} people'.format(total_count)) while chrono.read() < 5: pass machine.pin_deepsleep_wakeup(pins = ['P10'], mode = machine.WAKEUP_ANY_HIGH, enable_pull = True) print("RST1: Wake & Sleep") pycom.rgbled(0) utime.sleep(0.5) if machine.remaining_sleep_time()-5000 < 1: sleeping = 1 else: sleeping = machine.remaining_sleep_time()-5000 machine.deepsleep(sleeping) else: #RTC timer complete string = '{"val":'+str(pycom.nvs_get('counter'))+',"msgID":'+str(pycom.nvs_get('num'))+',"volt":'+str(voltage())+'}'
#pycom.heartbeat(False) # create a LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # set the LoRaWAN data rate s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) s.setblocking(True) s.bind(1) print(bytes(struct.pack('>4s', "ping"))) s.send(bytes(struct.pack('>4s', "ping"))) s.setblocking(False) data = s.recv(64) if data: print("recvd data: {}".format(data)) if data == b'\x01': pycom.rgbled(0x007f00) elif data == b'\x00': pycom.rgbled(0x000000) print("going to sleep") from machine import Pin import machine pinAlert = Pin('P13', mode=Pin.IN, pull=Pin.PULL_DOWN) machine.pin_deepsleep_wakeup(['P13'], machine.WAKEUP_ANY_HIGH, True) machine.deepsleep(600000) #ds.enable_pullups('G30') #ds.enable_wake_on_fall('G30') #ds.go_to_sleep(60) print("this should never happen")
def pin_handler(arg): time.sleep(0.5) print("Setting %s to listen for wakeup" % (arg.id())) machine.pin_deepsleep_wakeup([arg.id()], machine.WAKEUP_ALL_LOW, True) print("Going into deepsleep: %s" % (arg.id())) machine.deepsleep(10000)
###########SETUP RFM################ if machine.wake_reason()[0] == 0: #If the LoPy just got startet, configure RFM69 and go to deepsleep for power saving print("Gerade hochgefahren, führe Setup durch") rfm = RFM69.RFM69(RF69_433MHZ, 1, 42, False) results = rfm.readAllRegs() for result in results: print(result) rfm.rcCalibration() rfm.setHighPower(True) rfm.encrypt("sampleEncryptKey") rfm.receiveBegin() f = open('/flash/data.csv', 'w') f.write('') f.close() print("Gute Nacht") machine.pin_deepsleep_wakeup(['P9'], machine.WAKEUP_ANY_HIGH) machine.deepsleep(200000) elif machine.wake_reason()[0] == 2: print("Timer interrupt") elif machine.wake_reason()[0] == 1: #If the LoPy woke up from deepsleep, define the class, but don't reset the RFM chip print("Pin Interrupt") rfm = RFM69.RFM69(RF69_433MHZ, 1, 42, False, wakeup = True) rfm.receiveMessage() receivedData = (["".join([chr(letter) for letter in rfm.DATA]), rfm.SENDERID, rfm.RSSI]) if rfm.ACKRequested(): rfm.sendACK() # #####UNGETESTET########## # f = open('/flash/data.csv', 'a') # oldData = f.readall()
def go_back_to_sleep(): machine.pin_deepsleep_wakeup(pins=['P2'], mode=machine.WAKEUP_ANY_HIGH) machine.deepsleep(machine.remaining_sleep_time())