I'm tasked to come up with a manufacturing system for our ESP32 based modules. I'm an old school C programmer and new to Python programming, but figured that Python would be ideal for scripting a build system since the tools are based on Python. My initial manufacturing script is going to start off with erasing the flash and creating an NVS partition file to write to flash along with the factory partition. I've got the NVS defined in a CSV file and now trying to run the NVS partition generation utility, but hit a snag.
I'm trying to run $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py, but it fails to find the file. Since the IDF_PATH doesn't get expanded, I used os.environ['IDF_PATH'] to get the string to prepend to the rest of the file path. Unfortunately it doesn't find the file. At first I thought that because I'm running in MSYS that the "E:" at the beginning was the problem, so I tried manually changing it to... "/e/esp-idf-v3.1.1", but that didn't work either.
Also just trying to run esptool.py --help for simplicity gets the same problem.
Neither....
$ python make_sag2.py
python: can't open file 'E:/esp-idf-v3.1.1/components/esptool_py/esptool/esptool.py --help': [Errno 2] No such file or directory
nor...
$ python make_sag2.py
python: can't open file '/e/esp-idf-v3.1.1/components/esptool_py/esptool/esptool.py --help': [Errno 2] No such file or directory
But this works....
$ python /e/esp-idf-v3.1.1/components/esptool_py/esptool/esptool.py --help
My Python looks like this....
esp_tool = "/components/esptool_py/esptool/esptool.py"
nvs_tool = "/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py"
idf_path = "/e/esp-idf-v3.1.1"
subprocess.call(['python', idf_path + esp_tool + ' ' + '--help'])
Any advice for this Python handicapped coder?
Using Python for manufacturing question
Re: Using Python for manufacturing question
OK, it looks like I can't pass command line parameters.
i.e. this works...
esp_tool = "/components/esptool_py/esptool/esptool.py"
idf_path = os.environ['IDF_PATH']
subprocess.call(['python', idf_path + esp_tool])
but this doesn't...
subprocess.call(['python', idf_path + esp_tool + ' --help'])
i.e. this works...
esp_tool = "/components/esptool_py/esptool/esptool.py"
idf_path = os.environ['IDF_PATH']
subprocess.call(['python', idf_path + esp_tool])
but this doesn't...
subprocess.call(['python', idf_path + esp_tool + ' --help'])
Re: Using Python for manufacturing question
Might have figured it out. This works....
subprocess.call(['python', idf_path + esp_tool,'--help'])
subprocess.call(['python', idf_path + esp_tool,'--help'])
Re: Using Python for manufacturing question
Getting weird now. If I run it from the command line it works. But if I run it from my python script it thinks the csv file had no field names, and hence no rows.
Re: Using Python for manufacturing question
OK, it only sees an empty CSV file. I'm creating the file right before calling the nvs generation script.
f = open("nvs.csv", "w")
f.write("key,type,encoding,value\n")
f.write(nspace + "," + "namespace" + ",,\n")
f.write("SERNUM" + "," + "data" + "," + "string" + "," + serial_device + "\n")
subprocess.call(['python', idf_path + nvs_tool,'nvs.csv','nvs.bin'])
The result is that the file has nothing in it. But after the python script exits it does.
SOLUTION: Putting a f.flush before the subprocess.call fixes the problem.
f = open("nvs.csv", "w")
f.write("key,type,encoding,value\n")
f.write(nspace + "," + "namespace" + ",,\n")
f.write("SERNUM" + "," + "data" + "," + "string" + "," + serial_device + "\n")
subprocess.call(['python', idf_path + nvs_tool,'nvs.csv','nvs.bin'])
The result is that the file has nothing in it. But after the python script exits it does.
SOLUTION: Putting a f.flush before the subprocess.call fixes the problem.
Who is online
Users browsing this forum: Bing [Bot] and 131 guests