Lernfabrik 4.0 MQTT Client

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
helu
Beiträge: 2
Registriert: 18 Mai 2020, 14:12

Lernfabrik 4.0 MQTT Client

Beitrag von helu » 18 Mai 2020, 14:26

Hallo an alle,

Ich würde gerne die Daten der Lernfabrik über MQTT auslesen, aber da ich mit Fischertechnik bis jetzt noch nicht zu tun hatte, tue ich mir noch etwas schwer. Als ersten Schritt würde ich gern wie auf Githhub beschrieben ist, einen Client erstellen. Dazu habe ich mir MQTT.fx heruntergeladen und mich mit dem TP-Link Router verbunden und die angegeben Parameter angegeben. Aber ich kann keine Verbindung zum MQTT Broker (TXT0) herstellen. Was mache ich falsch?

Als nächsten Schritt würde ich dann gerne eine Verbindung zu Thingworx erstellen.

lg Lukas

vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Lernfabrik 4.0 MQTT Client

Beitrag von vleeuwen » 18 Mai 2020, 16:52

See documentation sectie on https://mosquitto.org/
From the TXT command line (Putty, remote console) with a MQTT client and a MQTT server on you development system you can do all the test you like.

You can use also a second TXT as MQTT-server
===============================
Siehe Dokumentationsabschnitt unter https://mosquitto.org/
Über die TXT-Befehlszeile (Putty, Remote-Konsole) mit einem MQTT-Client und einem MQTT-Server auf Ihrem Entwicklungssystem können Sie alle gewünschten Tests durchführen.
Sie können auch einen zweiten TXT als MQTT-Server verwenden.

helu
Beiträge: 2
Registriert: 18 Mai 2020, 14:12

Re: Lernfabrik 4.0 MQTT Client

Beitrag von helu » 18 Mai 2020, 17:43

vleeuwen hat geschrieben:
18 Mai 2020, 16:52
See documentation sectie on https://mosquitto.org/
From the TXT command line (Putty, remote console) with a MQTT client and a MQTT server on you development system you can do all the test you like.

You can use also a second TXT as MQTT-server
===============================
Siehe Dokumentationsabschnitt unter https://mosquitto.org/
Über die TXT-Befehlszeile (Putty, Remote-Konsole) mit einem MQTT-Client und einem MQTT-Server auf Ihrem Entwicklungssystem können Sie alle gewünschten Tests durchführen.
Sie können auch einen zweiten TXT als MQTT-Server verwenden.
@vleeuwen thanks for your reply.
If I understand you correctly, I connect via putty to a TXT Controller and run on there the commands from mosqitto.org. I will test that tomorrow :)

Just another question: For connecting to Thingworx (IoT Plaftorm) I have to configure a new mqtt brigde. According to the github documentation the file /etc/mosquitto/ft-txt-bridge-cloud.conf must be created as root. On which TXT controller must this file be created, TXT0 as the broker or all TXT? And do I have root right via the webserver ?

vleeuwen
Beiträge: 1560
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Lernfabrik 4.0 MQTT Client

Beitrag von vleeuwen » 18 Mai 2020, 23:32

I did my tests a while ago under firmware 4.6.6.
If all the device are in a LAN then you don't need a bridge. You will only need a bridge to pass a router with a NAT (WLAN <==> LAN).
You can start on the TXT your own Mosquitto-server (Broker) from the data area (it runs the ROBOPro account) and put your own conf their
(in one of the maps in /opt/Knobloch)
/usr/bin/ for the Mosquitto MQTT client
/usr/bins/ for the Mosquitto MQTT server/broker
(I did not try it in firmware 4.7.0.)

Have fun with it,
Kind regards, CvL

[b][u]Hereby my notes about MQTT from a while ago:[/u][/b]
Mosquitto is also installed on my WIndow systems and Raspberry Py.
A client and a broker can run both on the same system.
The broker doesn't need to run on a TXT but can also run on a PC in the same LAN. This can be in different sub-networks.
[u]Info[/u]
https://www.hivemq.com/blog/mqtt-essent ... blishment/
https://www.myelectronicslab.com/wp-con ... cs-Lab.pdf
http://www.indigoo.com/dox/wsmw/1_Middleware/MQTT.pdf
https://test.mosquitto.org/

[b]CLients[/b]
<start map on PC>
"H:\Program Files\mosquitto\mosquitto_passwd.exe"
/opt/Knobloch/C-program (start map on the TXT)
“/usr/bin/mosquitto_password”

mosquitto_passwd is a tool for managing password files for mosquitto.
Usage: mosquitto_passwd [-c | -D] passwordfile username
mosquitto_passwd -b passwordfile username password
mosquitto_passwd -U passwordfile
-b : run in batch mode to allow passing passwords on the command line.
-c : create a new password file. This will overwrite existing files.
-D : delete the username rather than adding/updating its password.
-U : update a plain text password file to use hashed passwords.
See http://mosquitto.org/ for more information.

<start map on PC>
"H:\Program Files\mosquitto\mosquitto_pub.exe"
/opt/Knobloch/C-program (start map on the TXT)
“/usr/bin/ mosquitto_pub”
Error: Both topic and message must be supplied.
mosquitto_pub is a simple mqtt client that will publish a message on a single topic and exit.
mosquitto_pub version 1.5.4 running on libmosquitto 1.5.4.
Usage: mosquitto_pub {[-h host] [-p port] [-u username [-P password]] -t topic | -L URL}
{-f file | -l | -n | -m message}
[-c] [-k keepalive] [-q qos] [-r]
[-A bind_address]
[-i id] [-I id_prefix]
[-d] [--quiet]
[-M max_inflight]
[-u username [-P password]]
[--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]
[{--cafile file | --capath dir} [--cert file] [--key file]
[--ciphers ciphers] [--insecure]]
[--psk hex-key --psk-identity identity [--ciphers ciphers]]
[--proxy socks-url]
mosquitto_pub --help
-A : bind the outgoing socket to this host/ip address. Use to control which interface
the client communicates over.
-d : enable debug messages.
-f : send the contents of a file as the message.
-h : mqtt host to connect to. Defaults to localhost.
-i : id to use for this client. Defaults to mosquitto_pub_ appended with the process id.
-I : define the client id as id_prefix appended with the process id. Useful for when the
broker is using the clientid_prefixes option.
-k : keep alive in seconds for this client. Defaults to 60.
-L : specify user, password, hostname, port and topic as a URL in the form:
mqtt(s)://[username[:password]@]host[:port]/topic
-l : read messages from stdin, sending a separate message for each line.
-m : message payload to send.
-M : the maximum inflight messages for QoS 1/2..
-n : send a null (zero length) message.
-p : network port to connect to. Defaults to 1883 for plain MQTT and 8883 for MQTT over TLS.
-P : provide a password
-q : quality of service level to use for all messages. Defaults to 0.
-r : message should be retained.
-s : read message from stdin, sending the entire input as a message.
-t : mqtt topic to publish to.
-u : provide a username
-V : specify the version of the MQTT protocol to use when connecting.
Can be mqttv31 or mqttv311. Defaults to mqttv311.
--help : display this message.
--quiet : don't print error messages.
--will-payload : payload for the client Will, which is sent by the broker in case of unexpected disconnection. If not given and will-topic is set, a zero length message will be sent.
--will-qos : QoS level for the client Will.
--will-retain : if given, make the client Will retained.
--will-topic : the topic on which to publish the client Will.
--cafile : path to a file containing trusted CA certificates to enable encrypted communication.
--capath : path to a directory containing trusted CA certificates to enable encrypted communication.
--cert : client certificate for authentication, if required by server.
--key : client private key for authentication, if required by server.
--ciphers : openssl compatible list of TLS ciphers to support.
--tls-version : TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1.
Defaults to tlsv1.2 if available.
--insecure : do not check that the server certificate hostname matches the remote
hostname. Using this option means that you cannot be sure that the
remote host is the server you wish to connect to and so is insecure.
Do not use this option in a production environment.
--psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.
--psk-identity : client identity string for TLS-PSK mode.
--proxy : SOCKS5 proxy URL of the form:
socks5h://[username[:password]@]hostname[:port]
Only "none" and "username" authentication is supported.

<start map on PC>
"H:\Program Files\mosquitto\mosquitto_sub.exe" –help
/opt/Knobloch/C-program (start map on the TXT)
“/usr/bin/ mosquitto_pub”

mosquitto_sub is a simple mqtt client that will subscribe to a set of topics and print all messages it receives.
mosquitto_sub version 1.5.4 running on libmosquitto 1.5.4.
Usage: mosquitto_sub {[-h host] [-p port] [-u username [-P password]] -t topic | -L URL [-t topic]}
[-c] [-k keepalive] [-q qos]
[-C msg_count] [-R] [--retained-only] [-T filter_out] [-U topic ...]
[-F format]
[-A bind_address]
[-i id] [-I id_prefix]
[-d] [-N] [--quiet] [-v]
[--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]
[{--cafile file | --capath dir} [--cert file] [--key file]
[--ciphers ciphers] [--insecure]]
[--psk hex-key --psk-identity identity [--ciphers ciphers]]
[--proxy socks-url]
mosquitto_sub --help

-A : bind the outgoing socket to this host/ip address. Use to control which interface
the client communicates over.
-c : disable 'clean session' (store subscription and pending messages when client disconnects).
-C : disconnect and exit after receiving the 'msg_count' messages.
-d : enable debug messages.
-F : output format.
-h : mqtt host to connect to. Defaults to localhost.
-i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.
-I : define the client id as id_prefix appended with the process id. Useful for when the
broker is using the clientid_prefixes option.
-k : keep alive in seconds for this client. Defaults to 60.
-L : specify user, password, hostname, port and topic as a URL in the form:
mqtt(s)://[username[:password]@]host[:port]/topic
-N : do not add an end of line character when printing the payload.
-p : network port to connect to. Defaults to 1883 for plain MQTT and 8883 for MQTT over TLS.
-P : provide a password
-q : quality of service level to use for the subscription. Defaults to 0.
-R : do not print stale messages (those with retain set).
-t : mqtt topic to subscribe to. May be repeated multiple times.
-T : topic string to filter out of results. May be repeated.
-u : provide a username
-U : unsubscribe from a topic. May be repeated.
-v : print published messages verbosely.
-V : specify the version of the MQTT protocol to use when connecting.
Can be mqttv31 or mqttv311. Defaults to mqttv311.
--help : display this message.
--quiet : don't print error messages.
--retained-only : only handle messages with the retained flag set, and exit when the
first non-retained message is received.
--will-payload : payload for the client Will, which is sent by the broker in case of unexpected disconnection. If not given and will-topic is set, a zero length message will be sent.
--will-qos : QoS level for the client Will.
--will-retain : if given, make the client Will retained.
--will-topic : the topic on which to publish the client Will.
--cafile : path to a file containing trusted CA certificates to enable encrypted
certificate based communication.
--capath : path to a directory containing trusted CA certificates to enable encrypted communication.
--cert : client certificate for authentication, if required by server.
--key : client private key for authentication, if required by server.
--ciphers : openssl compatible list of TLS ciphers to support.
--tls-version : TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1.
Defaults to tlsv1.2 if available.
--insecure : do not check that the server certificate hostname matches the remote
hostname. Using this option means that you cannot be sure that the
remote host is the server you wish to connect to and so is insecure.
Do not use this option in a production environment.
--psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.
--psk-identity : client identity string for TLS-PSK mode.
--proxy : SOCKS5 proxy URL of the form:
socks5h://[username[:password]@]hostname[:port]
Only "none" and "username" authentication is supported.
See http://mosquitto.org/ for more information.

Antworten