38 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
---
 | 
						|
title: "Upload script for uPython"
 | 
						|
date: 2020-03-16T14:00:00+01:00
 | 
						|
draft: false
 | 
						|
summary: More on micropython ...
 | 
						|
---
 | 
						|
 | 
						|
My university exams for this semester are mostly done by now. And with all the corona-virus-measures the new semester doesn't start for another month. Hopefully I will finish some of those procrastinated projects of mine ;)
 | 
						|
 | 
						|
Anyways. [Micropython](https://micropython.org/) is still on my radar (I even used it in one university assignment and it really shined there).
 | 
						|
Here is a small script which uploads all files to the controller (when web-REPL is enables of course):
 | 
						|
 | 
						|
```bash
 | 
						|
#!/bin/bash
 | 
						|
md5files=$(cat .uploaded)
 | 
						|
 | 
						|
IP=192.168.222.31
 | 
						|
if [ "$#" != 0 ]; then
 | 
						|
	IP="$1"
 | 
						|
fi
 | 
						|
 | 
						|
for i in $(ls *.py)
 | 
						|
do
 | 
						|
   if [[ $md5files != *"$(md5sum $i | cut -d' ' -f1)"* ]]; then
 | 
						|
       echo $(md5sum $i)
 | 
						|
       webrepl_cli.py -p asdf $i $IP:/$i
 | 
						|
       md5files=$(echo $md5files | sed 's|:\([^:]*\)'"$i"'||g'):$(md5sum "$i")
 | 
						|
       echo "$md5files" > .uploaded
 | 
						|
   fi
 | 
						|
done
 | 
						|
```
 | 
						|
You can provide the IP of the microcontroller as an argument, otherwise 192.168.222.31 is used (which is the IP my prototype ESP32 gets assigned, so you should probably change that ;) ).
 | 
						|
The script also saves the md5 hashes of the uploaded files in a file called `.uploaded` so unchanged files don't get constantly uploaded again. The script doesn't check if the upload is successful, so only run the script when the upload is going to work ;)
 | 
						|
It uses the `webrepl_cli.py` script from the official micropython [github page](https://github.com/micropython/webrepl).
 | 
						|
As you can see my script is hacked together and i should probably feel bad for making it public here, but it works and im going to update it if i feel the need to[^1].
 | 
						|
 | 
						|
[^1]: which means i had to `rm .uploaded` too often, cause the upload didn't work but the md5-file is updated.
 |