Program is erased from internal memory



  • I've made a lora sensor node using the Lopy +PyTrack and I'm seeing some weird behaviour which I'm wondering is expected.

    The program itself reads a file from the internal memory, does some sensing, transmits some parameters over LoRa, saves a file again and goes into deep sleep using the pytrack library.

    I think that every time my battery runs out somehow the internal memory is erased/corrupted because when I connect the LoPy over USB the blue LED starts flashing and my boot/main.py and the data folder are gone. After I sync through Atom everything is fine again.

    What could be going on here? The internal flash should be non volatile right?

    I'm writing to the file using

    import json
    
    with open('/data/state.json') as stateFile:
      stateFile.write(json.dumps(state))
    

    And going into deep sleep with

    import pytrack
    
    pytrack.setup_sleep(10)
    pytrack.go_to_sleep()
    


  • You need to close the file as soon as the write is complete. If the unit shuts down while the file is open there's a good chance to corrupt the flash. This will erase the flash when it reboots.



  • Allright. I'll use the SD card. That will increase the power consumption a bit though.

    It has happened a few times already, I can't believe the battery runs out exactly while I'm saving the state (which is just a few bytes)



  • @joeri
    If you look into history
    you can find same posts as yours.

    I do not know what is the check rule - but if partition is broken in some way it is automatically formated during boot. Then you goot fresh boot.py and main.py

    better is saving to SD card


Log in to reply
 

Pycom on Twitter