【发布时间】:2022-08-17 04:25:44
【问题描述】:
试图克服这个障碍,开始我的家庭自动化项目。
- 我使用 VS 2022 中的模板创建了一个 Blazor 服务器应用程序。
- 添加了一个名为“Lights”的菜单项,该菜单项会显示 Lights.razor 页面。
- 在其中,我添加了以下 MQTTServer 代码:
@code {
protected override void OnInitialized()
{
MQTTService.MQTTServer_Start();
}
async void MQTTServer_Start()
{
var options = new MqttServerOptionsBuilder().WithDefaultEndpoint().WithDefaultEndpointPort(1111);
var server = new MqttFactory().CreateMqttServer(options.Build());
server.InterceptingPublishAsync += Server_InterceptingPublishAsync;
await server.StartAsync();
Task Server_InterceptingPublishAsync(InterceptingPublishEventArgs arg)
{
var payload = arg.ApplicationMessage?.Payload == null ? null : Encoding.UTF8.GetString(arg.ApplicationMessage?.Payload);
Debug.WriteLine(arg.ClientId);
return Task.CompletedTask;
}
}
}
- 我点击运行。它似乎启动了自己的 Web 服务器,可能是 IISExpress;没有把握。
- Blazor 模板网站运行良好。
- 我单击添加的灯光菜单项,灯光页面正常显示。
- 页面按照上面的代码运行MQTTServer。
- 我从我的 Raspberry Pico W 运行我的 MicroPython MQTTClient 代码并成功连接到该 MQTTServer。
- 我停止了 Blazor 应用程序。
- 我将它发布到同一台机器上的 IIS 服务器。
- 我使用 Chrome 访问了 IIS Hosted Blazor 应用程序。
- 单击“灯光”菜单项。
- 我从我的 Raspberry Pico W 运行我的 MicroPython MQTTClient 代码,但它失败并出现以下错误: \"回溯(最近一次通话最后): 文件 \"umqttsimple.py\",第 61 行,在连接中 OSError:[Errno 103] ECONABORTED\"
任何人都知道为什么它可以在 VS 中工作但在 IIS 中失败? 有什么好的技术我可以遵循来克服这个障碍吗?
标签: python raspberry-pi-pico mqttnet