- 剖析器 (Parser) 瘦身, 加上移除無用之程式碼使得大部分的板子來說韌體大小下降, 但 ESP8266 與 STM32 的韌體大小卻因為新增功能而變大, 例如更豐富的 frambuf 模組的格式, 以及新增了 ujson.dump() 函數.
- 新增內部 Python 堆疊以增進記憶體暫存之效率與彈性.
- 內部原始碼重構, 原始碼覆蓋率顯著提升.
# http://micropython.org/resources/micropython-ChangeLog.txt
燒錄韌體方法參考 :
# MicroPython on ESP8266 (一) : 燒錄韌體
# WeMOS D1 Mini 開發板測試
使用 D1 Mini 板的話要先將 D3 接地 (ESP-01 模組則為 D0) 再插入 USB 槽, 使用 ESP8266Flasher 軟體以 115200 速率燒錄到 4MB 的 Flash 中. 燒錄完成後拔除 ESP8266 接地線後按 Reset 鈕或重插拔 USB 槽, 開啟 Putty 的 Serial 埠以 115200 速率連線, 測試如下 :
MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266
Type "help()" for more information.
>>> help()
Welcome to MicroPython!
For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .
For diagnostic information to include in bug reports execute 'import port_diag'.
Basic WiFi configuration:
import network
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if.scan() # Scan for available access points
sta_if.connect("<AP_name>", "<password>") # Connect to an AP
sta_if.isconnected() # Check for successful connection
# Change name/password of ESP8266's AP:
ap_if = network.WLAN(network.AP_IF)
ap_if.config(essid="<AP_NAME>", authmode=network.AUTH_WPA_WPA2_PSK, password="<password>")
Control commands:
CTRL-A -- on a blank line, enter raw REPL mode
CTRL-B -- on a blank line, enter normal REPL mode
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, do a soft reset of the board
CTRL-E -- on a blank line, enter paste mode
For further help on a specific object, type help(obj)
>>> import sys
>>> dir(sys)
['__class__', '__name__', 'argv', 'byteorder', 'exit', 'implementation', 'maxsize', 'modules', 'path', 'platform', 'print_exception', 'stderr', 'stdin', 'stdout', 'version', 'version_info']
不過我測試 WDT 功能, 還是一樣無法傳入參數來設定 Timeout 秒數, 不傳參數預設就是 5 秒鐘, 但我沒呼叫 feed() 阻止 timeout, 板子也沒有 Reset, 可見目前 ESP8266 上的 WDT 還是無作用, 下面這篇也說 ESP8266 沒有 WDT 功能, 殘念 :
# 【ESP8266】没有WDT功能
"虽然在官方文档中,有WDT模块,但实际上,ESP8266中还没有提供这个功能,这个功能目前只支持WiPY模块。"
>>> from machine import WDT
>>> wdt = WDT(timeout=2000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function does not take keyword arguments
>>> wdt = WDT()
>>> wdt.feed()
>>> wdt = WDT(id=0, timeout=10000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function does not take keyword arguments
>>> type(wdt)
<class 'WDT'>
>>> dir(WDT)
['__class__', '__name__', 'deinit', 'feed']
>>> wdt.deinit()
參考 :
# class WDT – watchdog timer
不過我在下面這篇文章找到一個模擬 WDT 的方法 :
# How can I reset ESP8266 MicroPython after main.py crashes?
其程式複製如下 :
# Simple WD - Global Variable
wd_feeder = 0
wd_buffer = 0
wd_counter = 0
wd_threshold = 4
def wd_checker(calledvalue):
print('watchdog is checking... feeder= {} buffer= {}'.format(wd_feeder, wd_buffer))
global wd_counter
global wd_buffer
global wd_feeder
if wd_feeder == wd_buffer:
print('state is suspicious ... counter is {} incrementing the counter'.format(wd_counter))
wd_counter += 1
else:
wd_counter = 0
wd_feeder = wd_buffer
if wd_counter == wd_threshold:
print('Counter is reached its threshold, following function will be called')
wd_feeder = wd_buffer = wd_counter = 0
machine.reset()
if __name__ == '__main__':
scheduler_wd = machine.Timer(-1)
scheduler_wd.init(period=3000, mode=machine.Timer.PERIODIC, callback=wd_checker)
有空再來想個實驗測試一下.
# Is there a built-in function to print all the current properties and values of an object?
使用 D1 Mini 板的話要先將 D3 接地 (ESP-01 模組則為 D0) 再插入 USB 槽, 使用 ESP8266Flasher 軟體以 115200 速率燒錄到 4MB 的 Flash 中. 燒錄完成後拔除 ESP8266 接地線後按 Reset 鈕或重插拔 USB 槽, 開啟 Putty 的 Serial 埠以 115200 速率連線, 測試如下 :
MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266
Type "help()" for more information.
>>> help()
Welcome to MicroPython!
For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .
For diagnostic information to include in bug reports execute 'import port_diag'.
Basic WiFi configuration:
import network
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if.scan() # Scan for available access points
sta_if.connect("<AP_name>", "<password>") # Connect to an AP
sta_if.isconnected() # Check for successful connection
# Change name/password of ESP8266's AP:
ap_if = network.WLAN(network.AP_IF)
ap_if.config(essid="<AP_NAME>", authmode=network.AUTH_WPA_WPA2_PSK, password="<password>")
Control commands:
CTRL-A -- on a blank line, enter raw REPL mode
CTRL-B -- on a blank line, enter normal REPL mode
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, do a soft reset of the board
CTRL-E -- on a blank line, enter paste mode
For further help on a specific object, type help(obj)
>>> import sys
>>> dir(sys)
['__class__', '__name__', 'argv', 'byteorder', 'exit', 'implementation', 'maxsize', 'modules', 'path', 'platform', 'print_exception', 'stderr', 'stdin', 'stdout', 'version', 'version_info']
不過我測試 WDT 功能, 還是一樣無法傳入參數來設定 Timeout 秒數, 不傳參數預設就是 5 秒鐘, 但我沒呼叫 feed() 阻止 timeout, 板子也沒有 Reset, 可見目前 ESP8266 上的 WDT 還是無作用, 下面這篇也說 ESP8266 沒有 WDT 功能, 殘念 :
# 【ESP8266】没有WDT功能
"虽然在官方文档中,有WDT模块,但实际上,ESP8266中还没有提供这个功能,这个功能目前只支持WiPY模块。"
>>> wdt = WDT(timeout=2000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function does not take keyword arguments
>>> wdt = WDT()
>>> wdt.feed()
>>> wdt = WDT(id=0, timeout=10000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function does not take keyword arguments
>>> type(wdt)
<class 'WDT'>
>>> dir(WDT)
['__class__', '__name__', 'deinit', 'feed']
>>> wdt.deinit()
參考 :
# class WDT – watchdog timer
不過我在下面這篇文章找到一個模擬 WDT 的方法 :
# How can I reset ESP8266 MicroPython after main.py crashes?
# Simple WD - Global Variable
wd_feeder = 0
wd_buffer = 0
wd_counter = 0
wd_threshold = 4
def wd_checker(calledvalue):
print('watchdog is checking... feeder= {} buffer= {}'.format(wd_feeder, wd_buffer))
global wd_counter
global wd_buffer
global wd_feeder
if wd_feeder == wd_buffer:
print('state is suspicious ... counter is {} incrementing the counter'.format(wd_counter))
wd_counter += 1
else:
wd_counter = 0
wd_feeder = wd_buffer
if wd_counter == wd_threshold:
print('Counter is reached its threshold, following function will be called')
wd_feeder = wd_buffer = wd_counter = 0
machine.reset()
if __name__ == '__main__':
scheduler_wd = machine.Timer(-1)
scheduler_wd.init(period=3000, mode=machine.Timer.PERIODIC, callback=wd_checker)
有空再來想個實驗測試一下.
# Is there a built-in function to print all the current properties and values of an object?
沒有留言:
張貼留言