MQTT Clients: Unterschied zwischen den Versionen

Aus hyperdramatik
Zur Navigation springen Zur Suche springen
(Der Seiteninhalt wurde durch einen anderen Text ersetzt: „old“)
 
Zeile 1: Zeile 1:
see also [[MQTT Brokers]] and https://www.kobakant.at/DIY/?p=9140
old
 
Shiftr has libraries for various platforms including Arduino and Processing that make it very easy to code MQTT Clients.
 
https://www.shiftr.io/
 
 
=CLIENT: ARDUINO with SHIFTR ONLINE=
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"
 
scroll down until you see "MQTT by Joel Gaehwiller"
 
==Open 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);
 
.... }
 
=CLIENT: PROCESSING with SHIFTR ONLINE=
 
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"
 
 
if you need to use a different port number other than the default 1883 (for example 2883), you can specify it like this:
 
"mqtt://name_of_your_instance:token_secret@url_of_your_instance.cloud.shiftr.io:2883"
</em>
 
=CLIENT: ARDUINO with SHIFTR Desktop App=
 
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);
.... }
 
 
if you need to use a different port number other than the default 1883 (for example 2883), you can specify it like this:
 
client.begin(“192.168.0.10”, 2883, net);
 
more info: https://github.com/256dpi/arduino-mqtt#api
 
=CLIENT: PROCESSING with SHIFTR Desktop App=
 
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”);
 
 
if you need to use a different port number other than the default 1883 (for example 2883), you can specify it like this:
 
client.connect("mqtt://192.168.0.9:2883", "processing”);

Aktuelle Version vom 1. Mai 2022, 23:07 Uhr

old