<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 上傳檔案到 NodeMCU (Upload files to NodeMCU)
需先安裝 ampy ( Adafruit MicroPython Tool )
pip install adafruit-ampy
https
Step1:  設定COM port (set current COM port)
Step2:  列出檔案 (list files)
Step3:  刪除檔案 (delete all files)
Step4:  Functions for copying files
Step5:  Copy 檔案到開發板 (copy files onto ESP8266 / NodeMCU, all needed fils will be put in the same folder)
Step6:  單一檔案上傳 (single file upload, in case needed)
Step7:  列出檔案 (list files)
Step8:  檢查檔案內容 (check file content)
Step9:  連網測試 (network config and test)
<ASSISTANT_TASK:>
Python Code:
import os
Explanation: 上傳檔案到 NodeMCU (Upload files to NodeMCU)
需先安裝 ampy ( Adafruit MicroPython Tool )
pip install adafruit-ampy
https://github.com/adafruit/ampy
End of explanation
com_port = 'COM12'
# com_port = 'COM13'
com_port = 'COM15'
# com_port = 'COM16'
Explanation: 設定COM port (set current COM port)
End of explanation
# 現存檔案
files = !ampy --port {com_port} ls
files
Explanation: 列出檔案 (list files)
End of explanation
# 清空
for file in files:
    print('Deleting {0}'.format(file))
    !ampy --port {com_port} rm {file}
Explanation: 刪除檔案 (delete all files)
End of explanation
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)}    
Explanation: Functions for copying files
End of explanation
folders = ['..\\codes\\micropython', '..\\codes\\node', '..\\codes\\shared']
main_filename = 'main.py'
copy_all_files(folders, main_filename)
            
copy_one_file('..\\codes\\micropython', main_filename)            
Explanation: Copy 檔案到開發板 (copy files onto ESP8266 / NodeMCU, all needed fils will be put in the same folder)
End of explanation
copy_one_file('..\\..\\dmz', 'config.py')
copy_one_file('..\\codes\\shared', 'config.py')
copy_one_file('..\\codes\\node', 'node.py')
copy_one_file('..\\codes\\micropython', 'u_python.py')
Explanation: 單一檔案上傳 (single file upload, in case needed)
End of explanation
# !ampy --port {com_port} ls
Explanation: 列出檔案 (list files)
End of explanation
# !ampy --port {com_port} get boot.py
# !ampy --port {com_port} get main.py
Explanation: 檢查檔案內容 (check file content)
End of explanation
# 連上網路
# 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',])
# 發出 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()
# Delete all files
# import u_python;u_python.del_all_files();import os;os.listdir()
Explanation: 連網測試 (network config and test)
End of explanation
<END_TASK>