from loranetwork import LoraNetwork import pycom from time import sleep from machine import Pin from onewire import DS18X20 from onewire import OneWire from deepsleep import DeepSleep from machine import SD # Set LED off pycom.heartbeat(False) # Set Wifi off pycom.wifi_on_boot(False) # Address DeepSleep as ds ds = DeepSleep() # Mounts SD-card onto pycom board and calls file /sd sd = SD() os.mount(sd, '/sd') # Address LoraNetwork to ln and set blocking off ln = LoraNetwork() ln.connect(False) # Address temperature measurements to temp ow = OneWire(Pin('P9')) temp = DS18X20(ow) # Aquire temperature measurement temp.start_convertion()
from deepsleep import DeepSleep import deepsleep ds = DeepSleep() # get the wake reason and the value of the pins during wake up wake_s = ds.get_wake_status() print(wake_s) if wake_s['wake'] == deepsleep.PIN_WAKE: print("Pin wake up") elif wake_s['wake'] == deepsleep.TIMER_WAKE: print("Timer wake up") else: # deepsleep.POWER_ON_WAKE: print("Power ON reset") ds.enable_pullups('P17') # can also do ds.enable_pullups(['P17', 'P18']) ds.enable_wake_on_fall( 'P17') # can also do ds.enable_wake_on_fall(['P17', 'P18']) ds.go_to_sleep(60) # go to sleep for 60 seconds
import pycom import socket import network import cayenneLPP #Low power packet forwarding import time import gc import math import binascii import struct #Enable garbage collection: gc.enable() gc.collect() #Close Unnecessary functions: ds = DeepSleep() #ds.enable_auto_poweroff() #enable auto power off bt = Bluetooth() bt.deinit() #close bluetooth wlan = network.WLAN() wlan.deinit() #close WLAN py = Pytrack() acc = LIS2HH12() l76 = L76GNSS(py, timeout=10) pycom.heartbeat(False) #Lora settings: lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.US915,
# import libraries: # from network import LoRa from pysense.LIS2HH12 import LIS2HH12 # Accelerometer from pysense.pycoproc import Pycoproc # from L76GNSS import L76GNSS # GPS # from pytrack import Pytrack from deepsleep import DeepSleep # import cayenneLPP # Low power packet forwarding from network import Bluetooth # Enable garbage collection: gc.enable() gc.collect() # Close Unnecessary functions: ds = DeepSleep() ds.enable_auto_poweroff() # enable auto power off then li-po can't supply 3.3v bt = Bluetooth() bt.deinit() # close bluetooth wlan = network.WLAN() # close wlan wlan.deinit() # Initializations py = Pycoproc.PYSENSE acc = LIS2HH12() # l76 = L76GNSS(py, timeout=10) pycom.heartbeat(False) ds.enable_auto_poweroff()
# INPUT PINS adc = ADC(0) hum_val = adc.channel(pin='P13') # g5 expansion board lev_in = Pin('P20', Pin.IN, Pin.PULL_DOWN) # g7 expansion board battery_val = adc.channel(pin='P19', attn=3) # g6 expansion board temperature_val = 'P21' #P21' # g8 expansion board # DS18B20 TEMPERATURE SENSOR ow = OneWire(Pin(temperature_val)) temp = DS18X20(ow) # GARBAGE COLLECTOR gc.enable() # DEEP SLEEP SHIELD ds = DeepSleep() # SAVE VALUE for numeroOrto in range(1, 5): if (pycom.nvs_get('count%s' % numeroOrto) == None): pycom.nvs_set('count%s' % numeroOrto, 0) if (pycom.nvs_get('pausa%s' % numeroOrto) == None): pycom.nvs_set('pausa%s' % numeroOrto, 0) if (pycom.nvs_get('pompa%s' % numeroOrto) == None): pycom.nvs_set('pompa%s' % numeroOrto, 0) # LORAWAN lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) dev_addr = struct.unpack(">l", binascii.unhexlify('26011783'))[0] nwk_swkey = ubinascii.unhexlify('CFEFE657C90C2BFE2A6D9ECCEA4B1111') app_swkey = ubinascii.unhexlify('A4D90348A3A516CEB1288C54C54154B0')
gc.enable() # setting up the pin 19 to start/stop the sensor (Pulled down, output) pin_activation_sensor = Pin('P19', mode=Pin.OUT, pull=Pin.PULL_DOWN) # setting up the Analog/Digital Converter with 12 bits adc = ADC(bits=12) # create an analog pin on P20 for the ultrasonic sensor apin = adc.channel(pin='P20', attn=ADC.ATTN_11DB) # create an analog pin on P16 for the battery voltage batt = adc.channel(pin='P16', attn=ADC.ATTN_2_5DB) # deep sleep ds = DeepSleep() # ... uncomment the next two lines if you want to set up auto off # ds.set_min_voltage_limit(3.1) # ds.enable_auto_poweroff() # init Lorawan lora = LoRa(mode=LoRa.LORAWAN, adr=False, tx_retries=0, device_class=LoRa.CLASS_A) # init uart uart1 = UART(1, baudrate=9600, timeout_chars=7) def join_lora(force_join=False):
# # this example assumes the default connection for the I2C Obviously # at P9 = sda and P10 = scl # from deepsleep import DeepSleep import deepsleep #from machine import Pin, I2C #from bmp085 import BMP180 import pycom pycom.heartbeat(False) ds = DeepSleep() #i2c = I2C() #bmp = BMP180(i2c) #bmp.oversample = 2 #bmp.sealevel = 101325 #temp = bmp.temperature #press = bmp.pressure #altitude = bmp.altitude #print("temp: {} pres: {} alt: {}".format(temp, press, altitude)) #pybytes.send_signal(1, temp) #pybytes.send_signal(2, press) #pybytes.send_signal(3, altitude) pybytes.send_signal(4, "ping") print("going to sleep") ds.enable_pullups('G30') ds.enable_wake_on_fall('G30') ds.go_to_sleep(60)