dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.46k stars 1.06k forks source link

Broker on Raspberry PI 3 #132

Closed robinsaberi closed 6 years ago

robinsaberi commented 6 years ago

Hi Christian,

I'm trying to run the broker on a PI3 with Windows 10 IoT Core on it, but without luck. If I try to connect using MQTT.Fx, the connection runs into a timeout. If I disable the the firewall, it seems that the conneciton no longer runs into a timeout, but it also breaks after a shorter time.

If I try the same code in a Console-App on my local machine, the client (MQTT.Fx) is connected immediately.

Hope you can help.

Thanks a lot, Robin (also from Germany, Bavaria)

chkr1011 commented 6 years ago

Hi, did you add the required permissions (Internet, Internet Client & Server, Private Networks)? Can you also please share the code you are using?

Viele Grüße 😄 Christian

robinsaberi commented 6 years ago

Hi Chistian,

that’s a kind of funny. In the meanwhile I was playing around with an Hello-World-Socket-App. And right at this moment, when I found out that I’ve to set some Package-Capabilities, your email comes in ☺

Yesterday I also checked your code, because I noticed that the MqttServerAdapter I was not able to debug. I think the reason is, that Uwp-Apps uses another namespace for socket-communication. I think I have to use the MqttServerAdapter.Uwp-Adapter. But when I change the Compiler-Switch for UWP, I’m not able to build. Would it make sense, to put the Uwp-Special classes in an extra project?

Thanks a lot, Robin

P.S. Bin in Bayern/Chiemgau. Du?

chkr1011 commented 6 years ago

I am wondering why the UAP (UWP) platform is now shown in the "debug" menu. Usually I use the UWP test app for testing UWP implementations. Which build errors do you get? I think there is no need to split up the library.

Best regards Christian

P.S.: Aus NRW 😄

robinsaberi commented 6 years ago

Christian,

ok, I will check this out again. Unfortunately, I’ve deleted all my tests, but I will recreate them and give you feedback.

Best regards, Robin

robinsaberi commented 6 years ago

Hi Christian,

I downloaded a fresh package of your implementation from Github and opened the solution with VS 2017. After a Clean and Rebuild I got following errors and warnings:

Severity

Code

Description

Project

File

Line

Suppression State

Error

TS2307

(TS) Cannot find module 'mqtt'.

MQTTnet.TestApp.AspNetCore2 (tsconfig project)

C:\Users\rsa\Temp\MQTTnet-master\Tests\MQTTnet.TestApp.AspNetCore2\wwwroot\app\app.ts

1

Active

Warning

NU1605

Detected package downgrade: Microsoft.NETCore.UniversalWindowsPlatform from 5.4.1 to 5.4.0. Reference the package directly from the project to select a different version. MQTTnet.TestApp.UniversalWindows -> MQTTnet -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.4.1) MQTTnet.TestApp.UniversalWindows -> Microsoft.NETCore.UniversalWindowsPlatform (>= 5.4.0)

Warning

APPX1901

The DefaultLanguage property is either missing from the project file or does not have a value. The fallback language is set to the Visual Studio language: de-DE.

MQTTnet.NetStandard

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets

5042

I updated the NuGet-Package to 5.4.1 > build was successful.

In my opinion, to build the MqttServerAdapter.Uwp.cs instead of the MqttServerAdapter.cs I have to change: MQTTnet.NetStandard > Properties > Build > Conditional compilation symbols > From NETSTANDARD1_3 to WINDOWS_UWP, right?

Thanks a lot, Robin

chkr1011 commented 6 years ago

Hi, no you don't have to change anything. If you start a build all supported platforms will be compiled. Then you will have a dedicated folder in your bin directory per platform. Then you can choose the uap10.0 one which is targeting UWP. But I recommend using the official nuget packages because they will also add additional references (if required). I also just build a UWP background task for IoT Core and Pi2 which is running without problems. All the code I have to add in the startup class is:

using Windows.ApplicationModel.Background;
using MQTTnet.Server;

namespace MQTTnet.WindowsIoTCoreServer
{
    public sealed class StartupTask : IBackgroundTask
    {
        private BackgroundTaskDeferral _deferral;
        private IMqttServer _mqttServer;

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();
            _mqttServer = new MqttFactory().CreateMqttServer();

            var mqttServerOptions = new MqttServerOptionsBuilder()
                .WithDefaultEndpointPort(1884)
                .WithStorage(new MqttServerStorage())
                .WithApplicationMessageInterceptor(MessageInterceptor.Intercept);

            _mqttServer.StartAsync(mqttServerOptions.Build()).GetAwaiter().GetResult();
        }
    }
}

The storage and interceptor are implemented on my own. The storage is simply saving the retained messages in JSON format using JSON.net and the interceptor fills a timestamp JSON property because the devices don't have time information.

Best regards Christian

robinsaberi commented 6 years ago

Hi Christian,

ok, I will check this out, thanks a lot.

One last question: Do you know whether anymobody – maybe you – have the broker in use in a productive environment?

Best regards, Robin

robinsaberi commented 6 years ago

Hi Christian,

I think I had a mistake in my mail before. Everything is working like a charm now.

If you say: > The storage and interceptor are implemented on my own... What about the rest? Isn't it implemented by your own?

Christian, thanks a lot for this very quick response. Doing a great job!

Best, Robin

chkr1011 commented 6 years ago

Thanks. Yes everything is implemented by me 😄 But the mentioned classes are not public 😄 So I assume this ticket can be closed?

Best regards Christian

robinsaberi commented 6 years ago

Aaaaaaha, sure can be closed!

Thanks, Danke und servus