Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

Ich möchte Temperatur Daten mit einer Callback Funktion an meinen MQTT Broker senden.

Welche Variable des example_callback scripts enthält denn die Temperaturwerte?

Mit t.CALLBACK_TEMPERATURE bekomme ich immer nur den Wert 8?

 

meine Skript sieht so aus:

 

HOST = "10.208.216.149"

PORT = 4223

UID = "t8u" # Change to your UID

 

import time

 

import paho.mqtt.client as mqtt

 

from tinkerforge.ip_connection import IPConnection

from tinkerforge.bricklet_temperature import BrickletTemperature

 

def on_connect(client, userdata, flags, rc):

    print("Connected with result code " + str(rc))

 

# Callback function for temperature callback (parameter has unit °C/100)

def cb_temperature(temperature):

    print("Temperature: " + str(temperature/100.0) + " °C")

 

   

if __name__ == "__main__":

    ipcon = IPConnection() # Create IP connection

    t = BrickletTemperature(UID, ipcon) # Create device object

 

    ipcon.connect(HOST, PORT) # Connect to brickd

    # Don't use device before ipcon is connected

 

    # Register temperature callback to function cb_temperature

    t.register_callback(t.CALLBACK_TEMPERATURE, cb_temperature)

 

    # Set period for temperature callback to 1s (1000ms)

    # Note: The temperature callback is only called every second

    #      if the temperature has changed since the last call!

    t.set_temperature_callback_period(1000)

 

client = mqtt.Client()

client.on_connect = on_connect

 

client.connect("vmiot01srv", 1883, 60)

 

#client.loop_start()

 

while True:

    time.sleep(2)

    client.publish("tinkerforge/bricklet/temperature/t8u/temperature", str(t.CALLBACK_TEMPERATURE))

 

 

raw_input()

ipcon.disconnect()

Geschrieben

Du registrierst hier die cb_temperature Funktion für den Temperatur Callback:

 

# Register temperature callback to function cb_temperature
t.register_callback(t.CALLBACK_TEMPERATURE, cb_temperature)

 

Die t.CALLBACK_TEMPERATURE Konstante identifiziert den Temperatur Callback, damit register_callback weiss worum es geht.

 

Die Bindings rufen dann deine cb_temperature Funktion auf und übergeben die aktuelle Temperatur sobald das Bricklet eine Änderung der Temperatur meldet.

 

Du kannst also deinen publish() Aufruf in die cb_temperature() Funktion verlegen.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.