问题描述
如何为具有 GET 请求的标准 HTTP/1.1 网络服务器长轮询运行 uasyncio 任务?
因为我还需要从这些客户端运行 GET 或 POST 请求,所以这需要是非阻塞的。
我的搜索只显示了这个脚本: https://github.com/brianmay/robotica-remote/blob/master/src/arequests.py
我是这样尝试的
# MicroPython v1.15 on 2021-04-18; ESP32
import uasyncio as asyncio
import arequests,wifi
async def poll():
r= arequests.get('http://10.0.0.125:8000/long')
print( r ) #>>> <generator object 'get' at 3ffedf50>
await response= r.__next__()
await response= r.read()
await response= r.text()
yield r.
async def main():
while True:
await asyncio.sleep(1)
print(' . ',end='')
def run():
loop = asyncio.get_event_loop()
loop.create_task( poll() )
loop.run_until_complete( main() )
run()
目标是使用现有基础设施(无 MQTT、CoAP 可用)在防火墙后面运行自定义 micropython 传感器
(阻止请求起作用,浏览器测试中的长轮询也起作用)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)