-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_to_server.py
30 lines (22 loc) · 1.05 KB
/
upload_to_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# python -m pip install spur
# python -m pip install pysftp
# c:\Users\halil\.atom\packages\platformio-ide\penv\Scripts>pip.exe install spur
# c:\Users\halil\.atom\packages\platformio-ide\penv\Scripts>pip.exe install pysftp
import pysftp
import spur
import sys
from CONFIG import * # host, username, password and port is in CONFIG.py
which = sys.argv[1]
print "UPLOADING TO SERVER: ", which
path_to_firmware = '.pioenvs/nucleo_f042k6_' + which + '/firmware.bin'
target_path_to_firmware = '/home/pi/firmware.bin'
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None # disable host key checking.
cinfo = {'host':host, 'username':username, 'password':password, 'port':port, 'cnopts':cnopts}
with pysftp.Connection(**cinfo) as sftp:
sftp.put(path_to_firmware, target_path_to_firmware)
print "UPLOAD COMPLETED!!"
shell = spur.SshShell(hostname=host, username=username, password=password, port=port, missing_host_key=spur.ssh.MissingHostKey.accept)
result = shell.run(["st-flash", "write", target_path_to_firmware, "0x08000000"])
print result.output
print "FLASH COMPLETED!!"