Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. [Gelöst] MQTT-Verbindung via Python script

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Gelöst] MQTT-Verbindung via Python script

    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Steinmetz_4 @Homoran last edited by

      @homoran

      Wen meinst Du?
      MQTT Adapter? läuft in IoBroker unter 192.168.178.185

      Homoran 1 Reply Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @Steinmetz_4 last edited by

        @steinmetz_4 sagte in MQTT-Verbindung:

        MQTT Adapter

        ja, den!

        @homoran sagte in MQTT-Verbindung:

        der ist als Broker konfiguriert?

        als Client nutzt er dir nichts.

        S 1 Reply Last reply Reply Quote 0
        • S
          Steinmetz_4 @Homoran last edited by

          @homoran

          Ich denke schon.

          dc56de23-c039-4973-a8cb-1af0e632e691-image.png

          Watermeter läuft damit.

          929a75b2-d2f7-4d76-b907-59b92e585d8e-image.png

          Homoran 1 Reply Last reply Reply Quote 0
          • Homoran
            Homoran Global Moderator Administrators @Steinmetz_4 last edited by

            @steinmetz_4 sagte in MQTT-Verbindung:

            Ich denke schon.

            jepp! dann ist die Frage auch eindeutig geklärt

            S 2 Replies Last reply Reply Quote 0
            • S
              Steinmetz_4 @Homoran last edited by

              @homoran

              Ich kann Dir nicht mehr sagen.
              Wenn ich wüsste was falsch ist, würde ich hier nicht fragen.

              🤷‍♂️

              Marc Berg 1 Reply Last reply Reply Quote 0
              • Marc Berg
                Marc Berg Most Active @Steinmetz_4 last edited by Marc Berg

                @steinmetz_4 ist das das aktive Skript???

                b45847f4-bad6-48c9-a223-360125309150-grafik.png

                S 1 Reply Last reply Reply Quote 0
                • S
                  Steinmetz_4 @Marc Berg last edited by

                  @marc-berg

                  Sorry, nein !

                  ich tüftel an allen Ecken und Enden!#

                  aktuel:

                  #!/usr/bin/python3
                  import sys
                  import paho.mqtt.client as mqtt
                  import ssl
                  
                  # set the variables
                  # Path to the Sensor systempath
                  # 28-01142f7ba71a has to be changed to you sensor path!
                  sensor = '/sys/bus/w1/devices/28-3c01f096929e/w1_slave'
                  broker='192.168.178.185'
                  port=1879
                  publish_topic="house/pi-ds18b20"
                  clientid='python-mqtt-ds18b20'
                  username='Tom'
                  password='Atomameise'
                  insecure=True
                  qos=1
                  retain_message=True
                  
                  # do the stuff
                  def readTempSensor(sensorName) :
                      f = open(sensorName, 'r')
                      lines = f.readlines()
                      f.close()
                      return lines
                  
                  def readTempLines(sensorName) :
                      lines = readTempSensor(sensorName)
                      while lines[0].strip()[-3:] != 'YES':
                          time.sleep(0.2)
                          lines = readTempSensor(sensorName)
                      temperaturStr = lines[1].find('t=')
                      if temperaturStr != -1 :
                          tempData = lines[1][temperaturStr+2:]
                          tempCelsius = float(tempData) / 1000.0
                          tempKelvin = 273 + float(tempData) / 1000
                          tempFahrenheit = float(tempData) / 1000 * 9.0 / 5.0 + 32.0
                          return [tempCelsius, tempKelvin, tempFahrenheit]
                  
                  #MQTT Connection
                  client=mqtt.Client(clientid)
                  client.username_pw_set(username, password)
                  client.tls_set(cert_reqs=ssl.CERT_NONE) #no client certificate needed
                  client.tls_insecure_set(insecure)
                  client.connect(broker, port)
                  client.loop_start()
                  
                  client.publish("{}/temperature".format(publish_topic),"{:.2f}".format(readTempLines(sensor)[0]),qos,retain_message)
                  
                  client.disconnect()
                  client.loop_stop()
                  
                  
                  

                  Mfg

                  Marc Berg 1 Reply Last reply Reply Quote 0
                  • S
                    Steinmetz_4 @Homoran last edited by Steinmetz_4

                    @homoran sagte in MQTT-Verbindung:

                    @steinmetz_4 sagte in MQTT-Verbindung:

                    Ich denke schon.

                    jepp! dann ist die Frage auch eindeutig geklärt

                    Verzeiht

                    Ich weiß, dass ich nichts weiß (https://de.wikipedia.org/wiki/Ich_weiß,_dass_ich_nichts_weiß)

                    1 Reply Last reply Reply Quote 0
                    • Marc Berg
                      Marc Berg Most Active @Steinmetz_4 last edited by Marc Berg

                      @steinmetz_4
                      Wenn ich die Fehlermeldung richtig interpretiere, versucht dein Skript eine verschlüsselte Verbindung, die du hier:

                      client.tls_set….
                      

                      auch so aktivierst. Dein Broker ist aber nicht mit SSL konfiguriert.
                      Schalte SSL im Skript ab.

                      Und: Du musst ruhiger werden … 🙂

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        Steinmetz_4 @Marc Berg last edited by

                        @marc-berg

                        Tada, es funktioniert!
                        Ich danke Dir!
                        War ein holpriger Weg aber es läuft...

                        Habe beide Punkte auskommentiert.

                        afad0031-d184-471a-b744-48fb1d2b13a4-image.png

                        P.S. Ich bin die Ruhe in Person...

                        Mfg
                        Tom

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate
                        FAQ Cloud / IOT
                        HowTo: Node.js-Update
                        HowTo: Backup/Restore
                        Downloads
                        BLOG

                        943
                        Online

                        31.9k
                        Users

                        80.1k
                        Topics

                        1.3m
                        Posts

                        4
                        21
                        2214
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo