shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
552 stars 179 forks source link

Some explanation about mqtt and flutter #328

Closed kekko7072 closed 3 years ago

kekko7072 commented 3 years ago

Hey, this is not an issue, I simply have some questions about how to connect an iOT device with a flutter app. I am completely new at MQTT but experienced in Flutter, Firebase and API calls.

Context I have an iOT device (a bike for sharing) witch works using MQTT protocol and I need to create a flutter app for the user to rent the bike. I read lots docs on how the protocol works. Now I know how MQTT works clearly.

Question 1) I need to create a MQTT broker, can I configure IOT Core of Google as broker, right? Is it hard to configure? I saw some docs on how to configure, it's safe If I configure it using the official documentation?

2) Is it safe to use this package to connect the flutter app of the user directly to the iOT Core broker? Because I think Isn't safe to have the broker keys directly on user app, right or it's different on MQTT? If it's not how can I connect to load data and send messages to the iOT device?

3) Can I send messages to the broker and then to the bike? For example I have the command to rent I bike, How can i send this request to the device?

Thank you so much for the help! Francesco

shamblett commented 3 years ago

OK, firstly I'm not a flutter user do I can't help you with any specific flutter stuff, but there are packages in pub like this one that show you how to use this package in flutter apps, there may be more if you have a look.

To your other points -

  1. You can use GCE IOT Core as your broker, I use this, there is an example in the examples directory named iot_core.dart that shows you how to do this, there is also this project in github that I put together to show this in action. You need to read the Google docs to configure the IOT core side of this.

  2. Yes its safe, there are no keys as such, IOT Core uses a JWT token that's regenerated every 24 hours from a public key file in your project, the private file stays within GCE, agian read the Google docs.

  3. You will need an mqtt client on your bike(doesn't have to be Dart of course, any mqtt client will do) to subscribe to whatever topics you set up your IOT Core broker to service, the flutter app will publish to these topics, all as per the MQTT spec. In practice your bike client will also publish messages back to your flutter app client for monitoring, diagnostics etc.

kekko7072 commented 3 years ago

@shamblett thank you so much