我有一个正在运行的 ESP32 项目,该项目于 2022 年开始,使用 Micropython Ver1.18。该项目获取网络以获取当前位置以及根据该位置的正确时间和正确时区。 (代码如下)
def getLocation():
global lng,lat,acu,udf
headers = {"Content-Type": "application/json"}
locationStr = "https://www.googleapis.com/geolocation/v1/geolocate?key=" + APIKey
try:
response = urequests.post(locationStr, headers=headers, data=ujson.dumps(data))
location = ujson.loads(response.content)
lng = location["location"]["lng"]
lat = location["location"]["lat"]
acu = location["accuracy"]
print ("the current Location is lat %s, Log %s with accuracy %s" % (lat,lng,acu))
response.close()
except:
print("unable to read the current location %s" %OSError)
从此处下载两个 Micropython 版本https://micropython.org/download/ESP32_GENERIC/
我正在使用操作系统 windows 11 和编程编辑器 Thonny 4.1.4
如前所述,该程序自 2022 年以来一直运行良好。在将 MicroPython 更新到新版本后,我决定将程序升级到 Micropython Ver 1.22.2。程序在“urequest.post”命令中因内存错误 16 而崩溃。当我将 locationStr 变量中的“https”更改为“http”时,程序不会中断,但会返回错误,指出服务器仅支持 https。
有人遇到过这个问题或者有解释吗?
提前致谢
我尝试将程序缩小到最小大小,但没有成功
https 是内存密集型操作(与 http 相比)。有可能新版本的 micropython 占用了更多内存,为您的代码留下了更少的内存,结果是您的内存不足。
有多种方法可以减少安装的内存占用:
.mpy file
文档涵盖了优化和MicroPython清单文件下的一些选项。