[英]ASP.NET Core keep-alive to ESP32
I would like to have ASP.NET Core based website with communication to ESP32 (microcontroller with program based on Arduino code) which would have keep-alive connection. 我希望有一个基于ASP.NET Core的网站,可以与ESP32(带有基于Arduino代码的程序的微控制器)进行通信,并且可以保持活动连接。 Something like serial-port without cable over network.
类似于串行端口,而无需通过网络电缆。 I figured out that websocket might work and be the best solution (or not?).
我发现websocket可能有效,并且是最好的解决方案(不是吗?)。 ESP32 doesn't support SignalR so I have to go raw websocket.
ESP32不支持SignalR,因此我必须使用原始websocket。 I found only middle-ware solutions without support to be called from controller.
我发现只能从控制器调用不支持的中间件解决方案。
Idea is: Keep-alive connection between ESP32 and ASP.NET Core website. 想法是:ESP32和ASP.NET Core网站之间保持活动连接。 User can go to website and trigger action (from browser/api) which will send data to ESP32.
用户可以访问网站并触发操作(从浏览器/ api),将数据发送到ESP32。 Website is public-part.
网站是公共部分。 Browser and ESP32 are closed parts (I mean.. no public ip address).
浏览器和ESP32是封闭的部分(我的意思是..没有公共IP地址)。 Also I would like to send data immediately after action is triggered.
我也想在触发动作后立即发送数据。 It would be nice if ESP32 would receive data within 3 seconds.
如果ESP32会在3秒内接收数据,那将是很好的。
Is websocket correct idea? websocket是正确的主意吗? Can you show me or direct me how to send data from action to websocket client?
您能告诉我或指示我如何将数据从操作发送到websocket客户端吗? I couldnt find enough informations how to make it.
我找不到足够的信息来做到这一点。
Instead of Websocket I finally used TCP via TcpListener running as IHostedService. 我最终没有使用Websocket,而是通过以IHostedService运行的TcpListener使用TCP。 I made Singleton class with Queue to queue messages from API calls.
我使用Queue制作了Singleton类,以对来自API调用的消息进行排队。 In IHostedService while cycle I checked if there is any new queue message to send.
在IHostedService周期中,我检查是否有任何新的队列消息要发送。
ESP32 connected via Wifi using WiFiClient library. 使用WiFiClient库通过Wifi连接的ESP32。
Simple & fast 简单快捷
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.