Ich bin jetzt mit meinem Latein am Ende...
Ich will auf meinem RasPi Zero folgendes zum Laufen bringen (Brick mit VoltageCurrentBricklet hängt am RasPi, eingeloggt über ssh vom PC):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
HOST = "localhost"
PORT = 4223
UID = "dcs" # Change XYZ to the UID of your Voltage/Current Bricklet 2.0
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_voltage_current import BrickletVoltageCurrent
if __name__ == "__main__":
ipcon = IPConnection() # Create IP connection
vc = BrickletVoltageCurrent(UID, ipcon) # Create device object
ipcon.connect(HOST, PORT) # Connect to brickd
# Don't use device before ipcon is connected
# Get current voltage
voltage = vc.get_voltage()
print("Voltage: " + str(voltage/1000.0) + " V")
# Get current current
current = vc.get_current()
print("Current: " + str(current/1000.0) + " A")
input("Press key to exit\n") # Use input() in Python 3
ipcon.disconnect()
Obwohl die Python-Bindings installiert sind (mit pip3) und der BrickD läuft, kommt immer die Fehlermeldung:
pi@raspberrypi:~ $ python3 example_voltagecurrent.py
Traceback (most recent call last):
File "example_voltagecurrent.py", line 19, in <module>
voltage = vc.get_voltage()
File "/home/pi/.local/lib/python3.7/site-packages/tinkerforge/bricklet_voltage_current.py", line 140, in get_voltage
return self.ipcon.send_request(self, BrickletVoltageCurrent.FUNCTION_GET_VOLTAGE, (), '', 'i')
File "/home/pi/.local/lib/python3.7/site-packages/tinkerforge/ip_connection.py", line 1195, in send_request
raise Error(Error.TIMEOUT, msg, suppress_context=True)
tinkerforge.ip_connection.Error: Did not receive response for function 2 in time (-1)
Komischerweise funktioniert das Script, wenn ich den Brick an meinen Windows-PC anschließe.