Trying to get over this bump to begin getting my Home Automation projects going.
- I created a Blazor Server App using the template in VS 2022.
- Added a menu item called "Lights" that brings up a Lights.razor page.
- In it, I added the below MQTTServer code:
@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;
}
}
}
- I hit run. It seems to launch its own web server, likely IISExpress; not sure.
- The Blazor template web site comes up fine.
- I click the Lights menu item I added, the Light page comes up fine.
- The page runs MQTTServer as per the above code.
- I run my MicroPython MQTTClient code from my Raspberry Pico W and successfully connect with that MQTTServer.
- I stop the Blazor app.
- I publish it to my IIS Server on this same machine.
- I goto that IIS Hosted Blazor app with Chrome.
- Click on the Lights menu item.
- I run my MicroPython MQTTClient code from my Raspberry Pico W and it fails with the error: "Traceback (most recent call last): File "umqttsimple.py", line 61, in connect OSError: [Errno 103] ECONNABORTED"
Anyone has any idea why it works from VS but fails from IIS? Any good techniques out there I could follow to get over that bump?