MQTT Brokers: Unterschied zwischen den Versionen

Aus hyperdramatik
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „see also: https://www.kobakant.at/DIY/?p=9140 =BROKER OPTIONS= In general these are the different Broker options you have: ==public online== - a public onlin…“)
 
Keine Bearbeitungszusammenfassung
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
see also: https://www.kobakant.at/DIY/?p=9140
see also https://www.kobakant.at/DIY/?p=9140


=BROKER OPTIONS=
=BROKER OPTIONS=
Zeile 16: Zeile 16:
super nice and simple with amazing visualization! and all options from public and free to paid and private to desktop app.
super nice and simple with amazing visualization! and all options from public and free to paid and private to desktop app.


==Notes from working with Shiftr==
==Notes from working with Shiftr Brokers==
https://live.staticflickr.com/65535/49856212336_cf2c240d1e.jpg
https://live.staticflickr.com/65535/49856212336_cf2c240d1e.jpg


Zeile 32: Zeile 32:


Shiftr has libraries for various platforms including Arduino and Processing.
Shiftr has libraries for various platforms including Arduino and Processing.
====CLIENT: ARDUINO====
To code an Arduino Client we use Shiftr's MQTT library for Arduino. There are other MQTT libraries for Arduino that would also work.
Install the Shiftr.io Arduino MQTT library:
Sketch --> Include Library --> Manage Libraries --> search: "MQTT"
the scroll down until you see "MQTT by Joel Gaehwiller"
Open the example:
File --> Examples --> MQTT --> "ESP32DevelopmentBoard"
In the example code, enter your Wifi connection information:
const char ssid[] = "yourNetworkName";
const char pass[] = "yourNetworkPassword";
The client.connect function takes the following information:
<em>client.connect("client ID", "name of your instance", "token secret")</em>
It connects you to the online Shiftr Broker's public namespace called "try":
void connect() {
while (!client.connect("arduino", "try", "try")) { ..... }
}
The client.begin function takes the Broker's URL or IP:
<em>client.begin("URL or IP", net);</em>
void setup() {
client.begin("broker.shiftr.io", net);
.... }</div>
====CLIENT: PROCESSING====
To code a Proccessing Client we use Shiftr's MQTT library for Processing.
Install Library:
Sketch --&gt; Import Library --&gt; Add Library --&gt; filter: "MQTT"
install: "MQTT library for Processing based on the Eclipse Paho project by Joel Gaehwiller"
Open Example:
File --&gt; Examples --&gt; MQTT --&gt; "PublishSubscribe"
The following line of code connects you to the online Shiftr Broker's public namespace called "try" with the Client ID "processing".
client.connect("mqtt://public:public@public.cloud.shiftr.io", "processing");
<em>Notes:
Make sure the URL in your code is the same as the current URL shown on the public namespace website: "mqtt://public:public@public.cloud.shiftr.io"
If you are using your own namespace, make sure you edit the URL to include name_of_your_instance
token_secret
url_of_your_instance
"mqtt://name_of_your_instance:token_secret@url_of_your_instance.cloud.shiftr.io"</em>




===SHIFTR Desktop App===
===SHIFTR Desktop App===
You should be able to see your connections and data in the app, just like in the online visualization. Running this App means your computer is hosting a localhost MQTT broker. How cool is this! If you only need to send data locally, then you don't need to send it over the internet! All the devices publishing and subscribing just need to be in the same network (for example: connected to the same wifi network).
You should be able to see your connections and data in the app, just like in the online visualization. Running this App means your computer is hosting a localhost MQTT broker. How cool is this! If you only need to send data locally, then you don't need to send it over the internet! All the devices publishing and subscribing just need to be in the same network (for example: connected to the same wifi network).
A LITTLE BIT ABOUT IP ADDRESSES:
in the network settings of your computer: if you set your IP address to be dynamic (DHCP) then the router will assign you computer an IP address every time you sign in/out of the network. good routers tend to remember devices and will try to give you the same IP address as before, but no guarantee. so you have two options:
manually give the computer running the Broker a fixed IP address. this will be problematic if/when you switch to a different network, but then just turn it back to DHCP to check the new router’s IP and pick a new fixed IP. because you need to make sure the IP address you manually give your computer corresponds with your router’s IP address so that only the last number is different. for example: my router’s IP is: 192.168.1.1 so i gave my computer the fixed IP: 192.168.1.9
re-programm your clients every time your set up the Broker with it’s current IP address.


https://live.staticflickr.com/65535/51679759731_539ee1e99d_c.jpg
https://live.staticflickr.com/65535/51679759731_539ee1e99d_c.jpg
Zeile 103: Zeile 50:
On a Mac:
On a Mac:
network settings --&gt; Advanced --&gt; TCP/IP --&gt; IPv4 Address: 192.168.0.9 (for example)
network settings --&gt; Advanced --&gt; TCP/IP --&gt; IPv4 Address: 192.168.0.9 (for example)
====CLIENT: ARDUINO====
Download the Shiftr MQTT library (see above).
Open the Shiftr MQTT example (see above).
The following items in the code need to be changed.
Leave the "name of your instance" and the "token secret" blank:
void connect() {
//client.connect("client ID", "name of your instance", "token secret")
while (!client.connect("arduino", "", "")) { ..... }
}
Insert your IP address instead of the Shiftr URL:
void setup() {
client.begin("192.168.0.9", net);
.... }
====CLIENT: PROCESSING====
Download the Shiftr MQTT library (see above).
Open the Shiftr MQTT example (see above).
Insert your IP address instead of the Shiftr URL:
client.connect("mqtt://192.168.0.9", "processing”);

Aktuelle Version vom 1. Mai 2022, 21:06 Uhr

see also https://www.kobakant.at/DIY/?p=9140

BROKER OPTIONS

In general these are the different Broker options you have:

public online

- a public online Broker hosted by somebody else (for example: Shiftr "try" namespace, Mosquitto's "test" server)

private online

- an online service (free or paid) that allows you to host your own Broker (for example: Shiftr)

localhost

- a local Broker that you run on your own computer or a designated computer (like a Rasberry Pi) (for example: Shiftr Desktop App, Mosquitto)

SHIFTR BROKER

super nice and simple with amazing visualization! and all options from public and free to paid and private to desktop app.

Notes from working with Shiftr Brokers

49856212336_cf2c240d1e.jpg

SHIFTR ONLINE

Shiftr has an public online namespace called "try" where you can quickly and easyily start publishing and subscribing data: https://www.shiftr.io/try

When you connect to this space with a Client, You should be able to see yourself pop up as your Client ID name (tip: pick a unique name to see yourself!). When you publish or subscribe data from the Broker you should see black balls flying from you to the center to the topic you are publishing to, or the other way around when you subscribe.

51678953412_d41d0fcac8_c.jpg

The visualization is interactive, you can click on nodes and pull them around to arrange the space. There is a lot going on here. If you want to use Shiftr for a project, you can create your own account for free and can have your own private or public namespaces.

C4k9CPnWcAARBvF.jpg

Shiftr has libraries for various platforms including Arduino and Processing.


SHIFTR Desktop App

You should be able to see your connections and data in the app, just like in the online visualization. Running this App means your computer is hosting a localhost MQTT broker. How cool is this! If you only need to send data locally, then you don't need to send it over the internet! All the devices publishing and subscribing just need to be in the same network (for example: connected to the same wifi network).

A LITTLE BIT ABOUT IP ADDRESSES: in the network settings of your computer: if you set your IP address to be dynamic (DHCP) then the router will assign you computer an IP address every time you sign in/out of the network. good routers tend to remember devices and will try to give you the same IP address as before, but no guarantee. so you have two options: manually give the computer running the Broker a fixed IP address. this will be problematic if/when you switch to a different network, but then just turn it back to DHCP to check the new router’s IP and pick a new fixed IP. because you need to make sure the IP address you manually give your computer corresponds with your router’s IP address so that only the last number is different. for example: my router’s IP is: 192.168.1.1 so i gave my computer the fixed IP: 192.168.1.9 re-programm your clients every time your set up the Broker with it’s current IP address.

51679759731_539ee1e99d_c.jpg

Download App for free: https://www.shiftr.io/desktop

To connect to this Broker, you need to find out the IP address of the computer running the App.

On a Mac: network settings --> Advanced --> TCP/IP --> IPv4 Address: 192.168.0.9 (for example)