Von English mit KI übersetzt ·
Ja. Dieser Blog ist für einen Broker in Ihrem eigenen Heimnetz gedacht, deshalb steht dort eine 192.168-Adresse. Für Hermetry sollten Sie überhaupt keine IP verwenden: Verbinden Sie sich über den Host-Namen aus der Karte Connection details, TLS auf 8883. TLS benötigt den Namen (SNI), deshalb schlägt die angepingte IP fehl, und einfaches 1883 wird abgelehnt, sofern das Profil kein unverschlüsseltes MQTT erlaubt, was standardmäßig nicht der Fall ist. rc=5 bedeutet „not authorised“, der eigentliche Grund landet im Tab Log des Geräts, das lohnt einen Blick.
import ssl, json, paho.mqtt.client as mqtt
HOST = "<host from Connection details>"
TOKEN = "<access token>"
c = mqtt.Client(client_id="reefer-01")
c.username_pw_set(TOKEN) # token as username, no password
c.tls_set(cert_reqs=ssl.CERT_REQUIRED) # normal public CA bundle
c.connect(HOST, 8883, keepalive=60)
c.loop_start()
c.publish("v1/telemetry", json.dumps({"temperature": -18.2}), qos=1)
Mit paho 2.x müssen Sie stattdessen mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="reefer-01") verwenden.
Yes. That blog is for a broker on your own home network, that’s why it has a 192.168 address. For Hermetry there’s no IP you should use at all: connect by the host name from the Connection details card, TLS on 8883. TLS needs the name (SNI), so the pinged IP fails, and plain 1883 is refused unless the profile allows plain MQTT, which it doesn’t by default. rc=5 is „not authorised“, and the actual reason ends up on the device’s Log tab, worth a look.
import ssl, json, paho.mqtt.client as mqtt
HOST = "<host from Connection details>"
TOKEN = "<access token>"
c = mqtt.Client(client_id="reefer-01")
c.username_pw_set(TOKEN) # token as username, no password
c.tls_set(cert_reqs=ssl.CERT_REQUIRED) # normal public CA bundle
c.connect(HOST, 8883, keepalive=60)
c.loop_start()
c.publish("v1/telemetry", json.dumps({"temperature": -18.2}), qos=1)
With paho 2.x you need mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id="reefer-01") instead.

