Jump to content

Humidity v2: Python: get_samples_per_second() führt zu Exception


Recommended Posts

Hallo zusammen,

 

beim Versuch einigen Temperatur- und Luftfeuchteunstimmigkeiten von einem Humidity V2 Bricklet und einem Air Quality Bricklet bin ich durch diverse Forenbeiträge auf das Stichwort "Self Heating" gekommen, und wollte daher mal die Samplerate eines Humidity Bricklets auslesen und ggf. reduzieren, um die etwa 3° Übertemperatur zu reduzieren (gemessen zu einem zusätzlichen Temperatur-Bricklet).

 

Bei dem Versuch wird jedoch nur ein leeres Datenpacket zurückgegeben. Wie kann ich hier weiter debuggen, bzw. begehe ich hier einen trivialen Fehler?

 

Hier die Fehlermeldung:

 

(test_packaging) mweigand@pidwig2:~/Projekte/20190406_TF_OW_HUM$ ./bug_hum_v2.py 
Humidity: 53.73 %RH
Temperature: 2279 degC
Traceback (most recent call last):
  File "./bug_hum_v2.py", line 22, in <module>
    print(h.get_samples_per_second())
  File "/home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/bricklet_humidity_v2.py", line 321, in get_samples_per_second
    return self.ipcon.send_request(self, BrickletHumidityV2.FUNCTION_GET_SAMPLES_PER_SECOND, (), '', 'B')
  File "/home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/ip_connection.py", line 1194, in send_request
    return unpack_payload(response[8:], form_ret)
  File "/home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/ip_connection.py", line 251, in unpack_payload
    x = struct.unpack(f, data[:length])
struct.error: unpack requires a buffer of 1 bytes
(test_packaging) mweigand@pidwig2:~/Projekte/20190406_TF_OW_HUM$ vim bug_hum_v2.py 
(test_packaging) mweigand@pidwig2:~/Projekte/20190406_TF_OW_HUM$ ./bug_hum_v2.py 
Humidity: 53.73 %RH
Temperature: 22.8 degC
Traceback (most recent call last):
  File "./bug_hum_v2.py", line 22, in <module>
    print(h.get_samples_per_second())
  File "/home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/bricklet_humidity_v2.py", line 321, in get_samples_per_second
    return self.ipcon.send_request(self, BrickletHumidityV2.FUNCTION_GET_SAMPLES_PER_SECOND, (), '', 'B')
  File "/home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/ip_connection.py", line 1194, in send_request
    return unpack_payload(response[8:], form_ret)
  File "/home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/ip_connection.py", line 251, in unpack_payload
    x = struct.unpack(f, data[:length])
struct.error: unpack requires a buffer of 1 bytes

 

Wenn ich den Testcode (angehängt) mit ipython --pdb laufen lasse sehe ich, dass die Binärdaten leer sind:

error: unpack requires a buffer of 1 bytes
> /home/mweigand/.virtualenvs/test_packaging/lib/python3.7/site-packages/tinkerforge/ip_connection.py(251)unpack_payload()
    249         f = '<' + f
    250         length = struct.calcsize(f)
--> 251         x = struct.unpack(f, data[:length])
    252 
    253         if '!' in o:

ipdb> f                                                                               
'<B'
ipdb> data                                                                            
b''

 

Hier der Testcode:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

HOST = "pi2"
PORT = 4223
UID = "Di5" # Change XYZ to the UID of your Humidity Bricklet 2.0

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_humidity_v2 import BrickletHumidityV2

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    h = BrickletHumidityV2(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current humidity
    humidity = h.get_humidity()
    print("Humidity: " + str(humidity/100.0) + " %RH")
    print("Temperature: {} degC".format(h.get_temperature() / 100.0))
    print(h.get_samples_per_second())

    ipcon.disconnect()

 

Ausgeführt in einem virtualenv auf Debian testing (Python 3.7) mit folgenden Pythonpacketen:

$ pip freeze

backcall==0.1.0

cycler==0.10.0

decorator==4.3.2

ipython==7.3.0

ipython-genutils==0.2.0

jedi==0.13.3

kiwisolver==1.0.1

matplotlib==3.0.3

mw-py-test1==0.8.14

numpy==1.16.2

pandas==0.24.1

parso==0.3.4

pexpect==4.6.0

pickleshare==0.7.5

Pillow==6.0.0

pkg-resources==0.0.0

prompt-toolkit==2.0.9

psycopg2==2.7.7

psycopg2-binary==2.7.7

ptyprocess==0.6.0

Pygments==2.3.1

pyparsing==2.3.1

python-dateutil==2.8.0

pytz==2018.9

rpi-monitoring==0.1.0

six==1.12.0

SQLAlchemy==1.3.1

stdeb==0.8.5

tinkerforge==2.1.21

traitlets==4.3.2

wcwidth==0.1.7

 

Master Brick 2.1 (FW 2.4.10)

Humidity Bricklet 2.0 (FW 2.0.4)

 

Neuster Brickd auf einem Raspberry Pi (Version 2.3.2).

 

Danke für jegliche Hilfe,

 

Maximilian

Link to comment
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...