Nonvalatile storage on WiPy?



  • I'm not sure if I'm missing something but I haven't seen any way of saving data on the WiPy itself that didn't originate outside. Obviously I can write a module with something (say passwords) externally and push it to the WiPy, but I'm looking at using the WiPy as an IOT device and needing it to connect to end users' routers. Obviously their credentials will have to be stored somewhere but where?

    The obvious choice would have been to write to the filesystem but that doesn't seem possible. The uos module has no provisions for reading or writing a file. All that module seems to do is list files and delete them.

    Any insights would be greatly appreciated.

    -- mfallavol



  • Thanks for the replies. I figured I must be missing something. I didn't find anything about read() or write() in the PyCom docs and the uio micropython library isn't mentioned either. I'll give it a shot today. Sounds like it will work perfectly for my needs.



  • You have 512 Kb user available internal storage, a.k.a /flash



  • @mfallavol

    You can use the standard Python file operations for open, read and write to /flash (internal) or /sd (if you have an SD card mounted)

    https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

    Write:

    > f = open('/flash/saveddata.bin', 'w') # open for writing
    > f.write(bytes([1,2,3,4,5,6,7,8]))
    8
    > f.close()
    

    Read:

    > f = open('/flash/saveddata.bin', 'r') # open for reading
    > f.read()
    '\x01\x02\x03\x04\x05\x06\x07\x08'
    > f.close()
    

Log in to reply
 

Pycom on Twitter