How to store data in flash



  • I am modifying the certain parameters at run time via Bluetooth which need to be stored permanently into Lopy module. Please provide method to store data in to flash.



  • You can access files on the device's flash just like you would any other file in python:

    with open("/flash/my_config.json", 'w') as conf_file:
        conf_file.write(json.dumps(my_config_dict))
    
    with open("/flash/my_config.json", 'r') as conf_file:
        my_config_dict =  json.loads(conf_file.read())
    


  • I use JSON file for this. In my application class instance the config is a dictionary. You can call json.dumps() on it and write the result into a file.

    Later you can read the string from the file and call json.loads() on the result to "create" config dictionary.

    Consider NVS if storing integers is all you need.


Log in to reply
 

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.