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.

  • @seb Is it possible to use this method with encrypted flash? I mean, is application capable of writing/modifying the json file if the flash is encrypted? And if so, does these changes count for those 3 FW flashs overs USB?

  • 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:
    with open("/flash/my_config.json", 'r') as conf_file:
        my_config_dict =  json.loads(

  • 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