• 0 Votes
    3 Posts
    1k Views
    J
    @jcaron Thanks for your reply. 1.) I would say everything below 5 seconds is acceptable. 2. / 3.) This question is hard to answer, since I will try the device with different types of applications so the capacity of the batteries will strongly vary. The battery life should be as long as possible. I also found the machine.idle and machine.sleep in http://docs.micropython.org/en/latest/wipy/library/machine.html. Given the description machine.sleep should work if I trigger the LoPy through Wifi. Is that correct? Thanks in advance.
  • 0 Votes
    2 Posts
    1k Views
    J
    I suffer the same error with the new firmware version (1.10.2.b1). It seems they have not solved it until now... Have you found any solution?+ Thanks
  • LoPy deepsleep general issues/questions

    LoPy deepsleep pysense library
    12
    0 Votes
    12 Posts
    4k Views
    J
    @johncaipa I have quite a lot of stuff going on in my code, but the main differences from yours are: I always to the initial join manually, so I don't try to detect whether that already happened or not. I use OTAA joins I keep the socket blocking I do wake on pin using the Pysense Here's a slimmed down version. Important! Don't use this code as is! This code requires a Pysense firmware which supports INT wake-up. from network import LoRa from network import WLAN from network import Server import socket import time import binascii from pysense import Pysense import pycom import machine app_version = '2017-10-31-01' SLEEP = 150 py = Pysense() def read_pin(): return 1 if py.peek_memory(0xE) & 0x02 else 0 pycom.heartbeat(0) app_eui = binascii.unhexlify('***') app_key = binascii.unhexlify('***') # Whatever happens, init the LoRa stack and (try to) restore its state lora = LoRa(mode=LoRa.LORAWAN, adr=True) lora.nvram_restore() # This part is not called from the code, only manually def doJoin(lora): print(time.localtime(),"LoRa join") lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) while not lora.has_joined(): time.sleep(1) print('Not yet joined...') lora.nvram_save() print(time.localtime(),"done LoRa join") # This is the debug mode, entered when the button is pressed def debugMode(): # set led to orange pycom.rgbled(0x402000) wlan = WLAN() wlan.init(mode=WLAN.AP, ssid='LoPy-'+binascii.hexlify(lora.mac()).decode('ascii'), auth=(WLAN.WPA2,'***'), channel=7, antenna=WLAN.INT_ANT) server = Server() # set led to green once we're ready pycom.rgbled(0x00ff00) # This is a modified version of the Pysense go_to_sleep which keeps INT working def go_to_sleep2(): PORTC_ADDR = const(0x00E) ANSELA_ADDR = const(0x18C) ANSELB_ADDR = const(0x18D) ANSELC_ADDR = const(0x18E) ADCON0_ADDR = const(0x9D) CMD_GO_SLEEP = const(0x21) # disable back-up power to the pressure sensor py.mask_bits_in_memory(PORTC_ADDR, ~(1 << 7)) py.poke_memory(ADCON0_ADDR, 0) # disable the ADC py.poke_memory(ANSELA_ADDR, ~(1 << 3)) # Don't touch RA3 so that button wake up works py.poke_memory(ANSELB_ADDR, 0xFF) py.poke_memory(ANSELC_ADDR, ~((1 << 7)|(1 << 1))) py._write(bytes([CMD_GO_SLEEP]), wait=False) # kill the run pin Pin('P3', mode=Pin.OUT, value=0) def sendData(val): s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, 0) s.send(bytes([val])); # This is the main function def doTheWork(): if py.button_pressed(): debugMode() return p = read_pin() sendData(p) # send is blocking and should have waited long enough, but I'm a belt-and-suspenders kind of guy time.sleep(2) lora.nvram_save() py.setup_sleep(SLEEP) # Set edge py.poke_memory(0x95, py.peek_memory(0x95) & ~0x40 if p else py.peek_memory(0x95) | 0x40) # Enable INTE # If your Pysense is not running a version of the firmware that supports it, this will probably lock it up py.poke_memory(0x0b, py.peek_memory(0x0b) | 0x10) go_to_sleep2() doTheWork() Note: I haven't tried running this version of the code, so I may have cut a bit too much.
  • DeepSleep remaining time

    Getting Started deepsleep deep sleep
    1
    1 Votes
    1 Posts
    681 Views
    No one has replied
  • 0 Votes
    3 Posts
    1k Views
    DDecoeneD
    Hello, Thank you for pointing that out. I changed the pins to G30 (sleep) and G13 (wakeup) and now the system works fine. So, the new code is: from machine import Pin, Timer from deepsleep import DeepSleep import deepsleep def handler(button): ds.enable_pullups('G31') # can also do ds.enable_pullups(['P17', 'P18']) ds.enable_wake_on_fall('G31') # can also do ds.enable_wake_on_fall(['P17', 'P18']) print("Button pushed") ds.go_to_sleep(20) 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") button=Pin("G30",Pin.IN, pull=Pin.PULL_UP) irq=button.callback(trigger=button.IRQ_FALLING, handler=handler) print('booted---')
  • Resetting from DeepSleep wake

    SiPy deepsleep sipy
    3
    0 Votes
    3 Posts
    989 Views
    B
    Ok, thanks for this - didnt see that one. And what are your thoughts on making sure i can resume the deepsleep. For thi, I really need to be able to send the data every 30mins. If its getting restarted because of a deepsleep wake, how do I know how far into the deepsleep the device was so that I dont get a wake 29mins into the deepsleep, and then go to sleep again for another 30mins once the wake is processed? I hope this makes sense. Its almost like I need to write the remaining time to a variable, save the variable in NVRAM, and then call that once the device has been reset. What do you think?
  • deep sleep shield and pycases

    Comments & Feedback deepsleep pycases
    2
    0 Votes
    2 Posts
    676 Views
    RobTuDelftR
    Yes, unfortunately. But it is communicated on the website however. You could try hacking it in there. The spacers are quite...spacious, and you could make it less tall in order to fit, but you would have to mod the shield
  • Pysense - knowing the reset cause

    Issues & Bugs pysense deepsleep wake status
    3
    0 Votes
    3 Posts
    1k Views
    L
    Ok, however, let's imagine the following situation: I boot it up, it's the first boot. It checks the nvs for a certain value, it does not find it. It sets up that value saying that the next boot isn't the first. After the deepsleep, it will know that it isn't the first boot. But, if I reset the board, it will still think that it's not the first boot. How can I get around this ?
  • 0 Votes
    18 Posts
    5k Views
    G
    @robert-hh - Thanks - I'll get a couple and take a look. Since I only do this stuff for my own use, my volume scale is usually 1!
  • LoPy LoraWAN OTAA Deepsleep Example

    LoPy lorawan otaa deepsleep
    11
    0 Votes
    11 Posts
    4k Views
    papasmurphP
    @roadfox Late response, but this doesn't look like a correct approach, as the join (and send) might have failed. Next time it will detect that it comes out of deepsleep and assume that it has joined, which it hasn't, so "if boot" must be replaced by something like "if successfully joined and not boot".
  • 0 Votes
    1 Posts
    885 Views
    No one has replied
  • DeepSleep Shield

    Comments & Feedback deepsleep expansion board
    4
    0 Votes
    4 Posts
    1k Views
    M
    @ledbelly2142 I just tested this. I have a LoPy on a 18650 battery (via an expansion board), with a current shunt inline to monitor battery current. Control test: Without DeepSleep shield: While connected to USB, I observed charging current going into the battery. If I unplug the USB, then the battery discharges: 100mA for active Wifi, 35mA w/o Wifi, and 10mA for disabled WiFi and machine.deepsleep() With DeepSleep shield: Using the "deepsleep" library with the DeepSleep shield, and connected via USB, I put the device to sleep. The charging current for the battery was unchanged. I then disconnected the USB, and the current draw from the battery dropped below 1mA. I can't measure much lower than that with my setup. Conclusion: The DeepSleep board works as expected with batteries.
  • LoPy with deep sleep shield is unstable

    Issues & Bugs deep sleep hangs deepsleep
    12
    0 Votes
    12 Posts
    4k Views
    R
    @daniel the failure is on the first wake-up. I don't have a multimeter handy, but can do that this evening. I added @jojo suggestion and the board wakes now. I have left it in a sleep wake cycle and will see how long it runs.
  • 0 Votes
    1 Posts
    701 Views
    No one has replied
  • 0 Votes
    8 Posts
    2k Views
    J
    @jalperin This works to restore RTC after pysense go-to-sleep. py.setup_sleep(sleepsec) pycom.nvs_set('gtsSec',sleepsec) pycom.nvs_set('ttSec',time.time()) py.go_to_sleep() rtc = RTC() ttSec = pycom.nvs_get('ttSec') # time.time() previous value if ttSec: gtsSec = pycom.nvs_get('gtsSec') # go to sleep seconds # reset clock to prior saved time plus length of sleep (both in seconds) rtc.init(time.gmtime( ttSec + gtsSec )) else: # Initialize your wifi, then rtc.ntp_sync("pool.ntp.org") # rtc.ntp_sync("23.239.26.89") while not rtc.synced(): time.sleep(1) Since I can't distinguish awakening from reset, I am currently setting ttSec manually before running code. pycom.nvs_set('ttSec',0)
  • 0 Votes
    3 Posts
    1k Views
    B
    @rskoniec Thanks, it helped debugging. If I unplug the power completely it shows the POWER_ON_WAKE, but if I do a manual reset (button pressed) it says TIMER_WAKE. I reckon it's a bit confusing. I couldn't see the values after connecting the USB and reconnecting to the console, so I assumed a manual reset would be treated as a POWER_ON_WAKE.
  • 0 Votes
    2 Posts
    795 Views
    robert-hhR
    @iotmaker You can tell both I2C and onewire which Pin to use. For I2c, you do it by i2c.init(), for the onewire driver, it is given in the constructor of the class.
  • Docs Update Deep Sleep - Correction

    Announcements & News docs deepsleep
    1
    0 Votes
    1 Posts
    837 Views
    No one has replied