Beispiel #1
0
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
Beispiel #2
0
# Aquire temperature measurement
temp.start_convertion()

# Open an appendable file at /sd/test.txt and write [
f = open('/sd/measurements.txt', 'a')
f.write("[")

# Start and record temperature measurement for 12 cycles
for cycles in range(12):
    # Measure temperature and address it to tmp
    tmp = temp.read_temp_async()
    temp.start_convertion()
    print(tmp)
    #sleep(5)
    # Write the tmp to SD and TTN, if it's not None
    if tmp != None:
        #print("Writing to SD-Card")
        f.write(str(tmp) + ",")
        #sleep(5)
        #print("Sending with LoRaWAN")
        ln.send(str(tmp))
    # Sleep for 5 seconds
    sleep(5)

# Writes ] to SD and closes the file
f.write("]")
f.close()

# Deepsleep for 3540 seconds (59 minutes)
ds.go_to_sleep(3540)
Beispiel #3
0
    # Set the lora battery level
    lora_bat_level = int(pct * 254)
    lora.set_battery_level(lora_bat_level)

    # Return the battery capacity in range [0, 100]
    return pct * 100


'''
################################################################################
#
# Main script
#
# 1. Read the distance from the sensor
# 2. Read battery value
# 3. Join Lorawan
# 4. Transmit the data if join was successful
# 5. Deepsleep for a given amount of time
#
################################################################################
'''

distance = read_distance()
battery = read_battery_level()
if join_lora(config.FORCE_JOIN):
    for i in range(config.N_TX):
        send_LPP_over_lora(distance, battery)

gc.collect()
ds.go_to_sleep(config.INT_SAMPLING)
Beispiel #4
0
                    print("spengo pompa")
                    eval(pinOut).value(0)  # turn off the water pump
                    pycom.nvs_set(
                        'count%s' % numeroOrto,
                        1)  # if irrigation is complete, then increase counter
                else:
                    print("Nessun dato ricevuto")
            else:
                print("Non posso irrigare, SERBATOIO VUOTO"
                      )  # if there isn't water, print an error message
        else:
            pycom.nvs_set('count%s' % numeroOrto,
                          (pycom.nvs_get('count%s' % numeroOrto) +
                           1))  # if isn't time to irrigate, increase counter

    else:
        print("Orto_%s: SPENTO" %
              (numeroOrto))  # if garden is turned off, print a message

    time.sleep(1)  # wait a second before start with a new garden

ds.disable_pullups(['P10', 'P17', 'P18'])
ds.disable_wake_on_raise(['P10', 'P17', 'P18'])
ds.disable_wake_on_fall(['P10', 'P17', 'P18'])
#ds.go_to_sleep(2)
print("Sleep for %s seconds" % (deepSleepSeconds))
gc.collect()
ds.go_to_sleep(
    int(deepSleepSeconds))  # deepSleep for deepSleepHours*60*60 seconds
#ds.go_to_sleep(3600)
Beispiel #5
0
# 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)
print("this should never happen")