In [1]:
import os
In [14]:
com_port = 'COM12'
# com_port = 'COM13'
com_port = 'COM15'
# com_port = 'COM16'
In [ ]:
# 現存檔案
files = !ampy --port {com_port} ls
files
In [ ]:
# 清空
for file in files:
print('Deleting {0}'.format(file))
!ampy --port {com_port} rm {file}
In [3]:
def copy_one_file(folder, file):
print('Copying {0}'.format(file))
!ampy --port {com_port} put {os.path.join(folder, file)}
def copy_all_files(folders, main_filename = 'main.py'):
files = !ampy --port {com_port} ls
if main_filename in files:
print('Deleting {0}'.format(main_filename))
!ampy --port {com_port} rm {main_filename}
for folder in folders:
for file in os.listdir(folder):
if not file.startswith('_') and not file.startswith(main_filename):
print('Copying {0}'.format(file))
!ampy --port {com_port} put {os.path.join(folder, file)}
In [9]:
folders = ['..\\codes\\micropython', '..\\codes\\node', '..\\codes\\shared']
main_filename = 'main.py'
copy_all_files(folders, main_filename)
copy_one_file('..\\codes\\micropython', main_filename)
In [ ]:
copy_one_file('..\\..\\dmz', 'config.py')
In [7]:
copy_one_file('..\\codes\\shared', 'config.py')
In [16]:
copy_one_file('..\\codes\\node', 'node.py')
In [15]:
copy_one_file('..\\codes\\micropython', 'u_python.py')
In [ ]:
# !ampy --port {com_port} ls
In [ ]:
# !ampy --port {com_port} get boot.py
In [ ]:
# !ampy --port {com_port} get main.py
In [ ]:
# 連上網路
# import network; nic=network.WLAN(network.STA_IF); nic.active(True); nic.connect('SSID','password');nic.ifconfig()
# import network; nic=network.WLAN(network.STA_IF); nic.active(True); nic.connect('Kingnet-70M-$370', '');nic.ifconfig()
# import network; nic=network.WLAN(network.STA_IF);nic.ifconfig();nic.config('mac');nic.ifconfig((['mac',])
In [ ]:
# 發出 http request
# import socket;addr=socket.getaddrinfo('micropython.org',80)[0][-1]
# s = socket.socket();s.connect(addr);s.send(b'GET / HTTP/1.1\r\nHost: micropython.org\r\n\r\n');data = s.recv(1000);s.close()
In [ ]:
# Delete all files
# import u_python;u_python.del_all_files();import os;os.listdir()
copy folder 'codes' to Raspberry Pi under folder '/data/elastic_network_of_things_with_micropython',
so Raspberry Pi has folder '/data/elastic_network_of_things_with_micropython/codes'
then run the command below on Raspberry Pi.
docker run -it -p 9662:9662 --name=Broker --hostname=Broker --volume=/data/elastic_network_of_things_with_micropython:/project wei1234c/python_armv7 /bin/sh -c "cd /project/codes/broker && python3 broker.py"