Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with GDX-PYR sensor, using example gdx_getting_started_bluetooth.py #62

Open
eduardo0797 opened this issue Oct 9, 2024 · 8 comments

Comments

@eduardo0797
Copy link

I'm using python 3.9, I've tested the code with other GDX sensors and I can connect without any problem, but when I try to connect the GDX-PYR it gives me this error

C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\Scripts\python.exe C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier\main.py
wait for bluetooth initialization...
C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\lib\site-packages\godirect\backend_bleak.py:21: FutureWarning: The discover function will removed in a future version, use BleakScanner.discover instead.
bleak_devices = await discover()
attempting to open 1 device(s)...
C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\lib\site-packages\godirect\backend_bleak.py:28: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
device.rssi = d.rssi
open device 0 = True

List of sensors for GDX-PYR 1L100046 BLE -38
Traceback (most recent call last):
File "C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier\main.py", line 39, in
gdx.select_sensors()
File "C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier\gdx\gdx.py", line 353, in select_sensors
sensors = gdx.devices[i].list_sensors()
File "C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\lib\site-packages\godirect\device.py", line 205, in list_sensors
if not self._GDX_get_sensor_info_all():
File "C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\lib\site-packages\godirect\device.py", line 300, in _GDX_get_sensor_info_all
if not self._GDX_get_sensor_info(i):
File "C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\lib\site-packages\godirect\device.py", line 560, in _GDX_get_sensor_info
sensor = GoDirectSensor(info)
File "C:\Users\kyo_a\Documents\EduardoRamos\ProgramacionPython\LabER-Solar\SensorVernier.venv\lib\site-packages\godirect\sensor.py", line 23, in init
self._sensor_units = sensorUnit.decode("utf-8").replace('\x00','')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 3: invalid start byte

Process finished with exit code 1

I'm using python 3.9, I've tested the code with other GDX sensors and I can connect without any problem, but when I try to connect the GDX-PYR it gives me this error

How can I solve this error?

@sswartley
Copy link
Contributor

Hello,

I was able to test this and I see the same error with the Pyranometer. I will try to determine the source of the error tomorrow, and will give you an update.

All the best,

Sam

@eduardo0797
Copy link
Author

Thank you, I look forward to your response.

@sswartley
Copy link
Contributor

Hello,

The sensor on GDX-PYR reads irradiance with units of W/m^2. The firmware for GDX-PYR encodes the string for the units and the godirect python library decodes that string. The issue is that the firmware for GDX-PYR has encoded this string in a different format than our other Go Direct devices. The godirect library is not expecting this, and throws an error when trying to decode the units string. The godirect library will need to be updated to fix this problem.

In the meantime, you can go to the godirect library files and replace two files with the files attached. These files have minor changes to the code that handles the decoding. This will fix the issue with GDX-PYR.

  • Unzip/Extract the attached zip file and find the files called "device.py" and "sensor.py"
  • Locate the Python site-packages folder on your computer (this is where installed Python packages are placed)
  • Locate the godirect folder
  • Replace "device.py" and "sensor.py" files with the new files

Let me know if you have any problems with these instructions, and if you are now able to take readings with GDX-PYR.

Files for godirect.zip

@eduardo0797
Copy link
Author

Hello,
I already tried the solution you mentioned in Windows 10 and I no longer had problems measuring with the GDX-PYR, but when trying the same solution with my Raspberry Pi 3 Model B+, I have problems connecting to the following sensors:

  • GDX-PYR
  • GDX-WTHR
  • GDX-TPM

When I select the sensor I want to connect to, I get the following error, that happens to me with all the sensors mentioned

%Run gdx_getting_started_bluetooth.py
wait for bluetooth initialization...
/home/LCT/myenv/lib/python3.11/site-packages/godirect/backend_bleak.py:21: FutureWarning: The discover function will removed in a future version, use BleakScanner.discover instead.
bleak_devices = await discover()
/home/LCT/myenv/lib/python3.11/site-packages/godirect/backend_bleak.py:28: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead
device.rssi = d.rssi

List of found devices
1: GDX-WTHR 134004B0 BLE -34
2: GDX-PYR 1L100046 BLE -36

  • If connecting a single device, type the number (e.g., 1) that
    corresponds with the device, and then press 'enter'.
  • If connnecting multiple devices, type in each number
    separated with commas with no spaces(e.g., 1,2), and then
    press 'enter': 1

attempting to open 1 device(s)...
Error while trying to open device.
Troubleshoot by opening Graphical Analysis to test

List of sensors for GDX-WTHR 134004B0 BLE -34
Traceback (most recent call last):
File "/home/LCT/myenv/lib/python3.11/site-packages/godirect/device_bleak.py", line 87, in _write
self._loop.run_until_complete(self._async_write(self.uuidCommand, data_to_write, wait_for_response=False))
File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/LCT/myenv/lib/python3.11/site-packages/godirect/device_bleak.py", line 65, in _async_write
await self._device.write_gatt_char(uuid, data_to_write, wait_for_response)
File "/home/LCT/myenv/lib/python3.11/site-packages/bleak/init.py", line 776, in write_gatt_char
characteristic = self.services.get_characteristic(char_specifier)
^^^^^^^^^^^^^
File "/home/LCT/myenv/lib/python3.11/site-packages/bleak/init.py", line 697, in services
raise BleakError("Service Discovery has not been performed yet")
bleak.exc.BleakError: Service Discovery has not been performed yet
Traceback (most recent call last):
File "/home/LCT/Documents/Vernier/godirect-examples/python/gdx_getting_started_bluetooth.py", line 39, in
gdx.select_sensors()
File "/home/LCT/Documents/Vernier/godirect-examples/python/gdx/gdx.py", line 353, in select_sensors
sensors = gdx.devices[i].list_sensors()
File "/home/LCT/myenv/lib/python3.11/site-packages/godirect/device.py", line 205, in list_sensors
if not self._GDX_get_sensor_info_all():
File "/home/LCT/myenv/lib/python3.11/site-packages/godirect/device.py", line 294, in _GDX_get_sensor_info_all
availableMask = self._GDX_get_available_sensors()
File "/home/LCT/myenv/lib/python3.11/site-packages/godirect/device.py", line 515, in _GDX_get_available_sensors
mask = struct.unpack("<I", response[6:])[0]
TypeError: 'bool' object is not subscriptable

I hope you can help me with this other problem

@sswartley
Copy link
Contributor

Hello,

I am glad you were able to get the GDX-PYR running on Windows. I do not have a way to test on Raspberry Pi right now. Just to make sure, did you follow the install directions outlined for Linux and Raspberry Pi in the Getting Started document?

The Bleak library is used for the Bluetooth communication. Check what version of the Bleak library is installed and compare that to what is the current version. Also, can you confirm that Bluetooth is working on your Raspberry Pi?

@eduardo0797
Copy link
Author

Hi, I installed go direct following exactly the instructions in the guide you sent.

The bleak library is updated to the latest version. I attached a list of the packages installed on my raspberry

LCT@raspberrypi:~ $ pip list
Package Version


arandr 0.1.11
asgiref 3.6.0
astroid 2.14.2
asttokens 2.2.1
attrs 22.2.0
av 10.0.0
Babel 2.10.3
beautifulsoup4 4.11.2
bleak 0.22.3
blinker 1.5
certifi 2022.9.24
chardet 5.1.0
charset-normalizer 3.0.1
click 8.1.3
colorama 0.4.6
colorzero 2.0
cryptography 38.0.4
cupshelpers 1.0
dbus-fast 2.24.3
dbus-python 1.3.2
dill 0.3.6
distro 1.8.0
docutils 0.19
Flask 2.2.2
godirect 1.1.4
gpiozero 2.0.1
hidapi 0.14.0.post2
html5lib 1.1
idna 3.3
importlib-metadata 4.12.0
isort 5.6.4
itsdangerous 2.1.2
jedi 0.18.2
Jinja2 3.1.2
jsonpointer 2.3
jsonschema 4.10.3
lazy-object-proxy 1.9.0
lgpio 0.2.2.0
libarchive-c 2.9
libevdev 0.5
libusb1 3.1.0
logilab-common 1.9.8
lxml 4.9.2
MarkupSafe 2.1.2
mccabe 0.7.0
meson 1.0.1
more-itertools 8.10.0
mypy 1.0.1
mypy-extensions 0.4.3
numpy 1.24.2
oauthlib 3.2.2
olefile 0.46
parso 0.8.3
pexpect 4.8.0
pgzero 1.2
picamera2 0.3.22
pidng 4.0.9
piexif 1.1.3
pigpio 1.78
Pillow 9.4.0
pip 23.0.1
platformdirs 2.6.0
psutil 5.9.4
ptyprocess 0.7.0
pycairo 1.20.1
pycryptodomex 3.11.0
pycups 2.0.1
pygame 2.1.2
Pygments 2.14.0
PyGObject 3.42.2
pyinotify 0.9.6
PyJWT 2.6.0
pylint 2.16.2
PyOpenGL 3.1.6
pyOpenSSL 23.0.0
PyQt5 5.15.9
PyQt5-sip 12.11.1
pyrsistent 0.18.1
pyserial 3.5
pysmbc 1.0.23
python-apt 2.6.0
python-dotenv 0.21.0
python-prctl 1.8.1
pytz 2022.7.1
pyudev 0.24.0
reportlab 3.6.12
requests 2.28.1
requests-oauthlib 1.3.0
responses 0.18.0
rfc3987 1.3.8
roman 3.3
rpi-lgpio 0.6
RTIMULib 7.2.1
Send2Trash 1.8.1b0
sense-hat 2.6.0
setuptools 66.1.1
simplejpeg 1.6.6
simplejson 3.18.3
six 1.16.0
smbus2 0.4.2
soupsieve 2.3.2
spidev 3.5
ssh-import-id 5.10
thonny 4.1.4
toml 0.10.2
tomlkit 0.11.7
tqdm 4.64.1
twython 3.8.2
types-aiofiles 22.1
types-annoy 1.17
types-appdirs 1.4
types-aws-xray-sdk 2.10
types-babel 2.11
types-backports.ssl-match-hostname 3.7
types-beautifulsoup4 4.11
types-bleach 5.0
types-boto 2.49
types-braintree 4.17
types-cachetools 5.2
types-caldav 0.10
types-certifi 2021.10.8
types-cffi 1.15
types-chardet 5.0
types-chevron 0.14
types-click-spinner 0.1
types-colorama 0.4
types-commonmark 0.9
types-console-menu 0.7
types-contextvars 2.4
types-croniter 1.3
types-cryptography 3.3
types-D3DShot 0.1
types-dateparser 1.1
types-DateTimeRange 1.2
types-decorator 5.1
types-Deprecated 1.2
types-dj-database-url 1.0
types-docopt 0.6
types-docutils 0.19
types-editdistance 0.6
types-emoji 2.1
types-entrypoints 0.4
types-first 2.0
types-flake8-2020 1.7
types-flake8-bugbear 22.10.27
types-flake8-builtins 2.0
types-flake8-docstrings 1.6
types-flake8-plugin-utils 1.3
types-flake8-rst-docstrings 0.2
types-flake8-simplify 0.19
types-flake8-typing-imports 1.14
types-Flask-Cors 3.0
types-Flask-SQLAlchemy 2.5
types-fpdf2 2.5
types-gdb 12.1
types-google-cloud-ndb 1.11
types-hdbcli 2.14
types-html5lib 1.1
types-httplib2 0.21
types-humanfriendly 10.0
types-invoke 1.7
types-JACK-Client 0.5
types-jmespath 1.0
types-jsonschema 4.17
types-keyboard 0.13
types-ldap3 2.9
types-Markdown 3.4
types-mock 4.0
types-mypy-extensions 0.4
types-mysqlclient 2.1
types-oauthlib 3.2
types-openpyxl 3.0
types-opentracing 2.4
types-paho-mqtt 1.6
types-paramiko 2.11
types-parsimonious 0.10
types-passlib 1.7
types-passpy 1.0
types-peewee 3.15
types-pep8-naming 0.13
types-Pillow 9.3
types-playsound 1.3
types-polib 1.1
types-prettytable 3.4
types-protobuf 3.20
types-psutil 5.9
types-psycopg2 2.9
types-pyaudio 0.2
types-PyAutoGUI 0.9
types-pycurl 7.45
types-pyfarmhash 0.3
types-pyflakes 2.5
types-Pygments 2.13
types-pyinstaller 5.6
types-PyMySQL 1.0
types-pynput 1.7
types-pyOpenSSL 22.1
types-pyRFC3339 1.1
types-PyScreeze 0.1
types-pysftp 0.2
types-pytest-lazy-fixture 0.6
types-python-crontab 2.6
types-python-dateutil 2.8
types-python-gflags 3.1
types-python-jose 3.3
types-python-nmap 0.7
types-python-slugify 6.1
types-pytz 2022.6
types-pyvmomi 7.0
types-pywin32 304
types-PyYAML 6.0
types-redis 4.3
types-regex 2022.10.31
types-requests 2.28
types-retry 0.9
types-Send2Trash 1.8
types-setuptools 65.5
types-simplejson 3.17
types-singledispatch 3.7
types-six 1.16
types-slumber 0.7
types-SQLAlchemy 1.4.43
types-stdlib-list 0.8
types-stripe 3.5
types-tabulate 0.9
types-termcolor 1.1
types-toml 0.10
types-toposort 1.7
types-tqdm 4.64
types-tree-sitter 0.20
types-tree-sitter-languages 1.5
types-ttkthemes 3.2
types-typed-ast 1.5
types-tzlocal 4.2
types-ujson 5.5
types-urllib3 1.26
types-vobject 0.9
types-waitress 2.1
types-whatthepatch 1.0
types-xmltodict 0.13
types-xxhash 3.0
types-zxcvbn 4.4
typing_extensions 4.12.2
uritemplate 4.1.1
urllib3 1.26.12
v4l2-python3 0.3.5
webcolors 1.11.1
webencodings 0.5.1
Werkzeug 2.2.2
wheel 0.38.4
wrapt 1.14.1
zipp 1.0.0

I also performed tasks to check the Bluetooth for its correct operation and I had no inconvenience with this.

I leave information about the operating system I am using

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian

I hope you can help me with this

@sswartley
Copy link
Contributor

Hello,

I am not sure how much I will be able to help with this specific problem. I am not familiar with all of the nuances of Raspberry Pi. I will see if I can find a system to do some testing, but it will take some time. In the meantime I would suggest that you run the example called godirect-sensor-readout, found in the "example_without_gdx" folder. This example talks directly with the godirect library, without using the gdx module. This will be better for troubleshooting.

Do you have any success with USB?
Do you have other Raspberry Pi systems you can test?

@eduardo0797
Copy link
Author

I have already solved the problem I have, which is that I cannot get the GDX sensor to connect on the first attempt with my raspberry pi using BLE. The problem I have is that the solution is not exact, since what I do is enter a cycle until I manage to make the connection with the sensor. The problem is that since it can connect immediately, it can take 5 minutes or more.

I attach a zip folder, where sensor.py is located, which is the main code that I use where the loops are to try to make the connection and also the gsx folder, where in the gdx.py file I made some modifications to be able to find the errors that it sends when the connection is not made with the sensor and to be able to enter a cycle.

CodigoVernierPython.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants