简体   繁体   English

ASP.NET Core与ESP32保持连接

[英]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.

相关问题 ASP.NET HTTP保持活动连接上下文 - ASP.NET HTTP Keep-Alive Connection Context 如何在ASP.NET Web服务客户端请求上禁用keep-alive? - How can I disable keep-alive on ASP.NET Web Service client requests? 如何在ASP.NET Core中保持对象存活? - How to keep object alive in ASP.NET Core? ASP.NET Core 3.0 MVC 连接中的 SignalR 无法正常工作? - SignalR in ASP.NET Core 3.0 MVC connection keep alive not working? 如何在 asp net core 3.1 中保持托管服务的活动状态? - How to keep a hosted service alive in asp net core 3.1? ASP .Net Core/Razor 页面:在工作时保持会话处于活动状态 - ASP .Net Core/Razor pages : Keep session alive while working 即使在请求完成后,asp.net core 中的 HTTPCientFactory 是否像 .net Framework 中的 HttpClient 一样保持连接活跃 - Does the HTTPCientFactory in asp.net core keep the connection alive even after the request is completed like HttpClient in .net Framework asp.net WebSocket Action 完成后保持活动状态 - asp.net WebSocket keep alive after Action is done 使Asp.net页面生命周期/会话对象保持活动状态 - Keep Asp.net page life cycle/session objects alive ASP.Net Core:保持Windows身份验证 - ASP.Net Core: keep windows authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM