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

Reading logger gives struct.error #36

Open
stretch4x4 opened this issue Jan 20, 2019 · 25 comments
Open

Reading logger gives struct.error #36

stretch4x4 opened this issue Jan 20, 2019 · 25 comments

Comments

@stretch4x4
Copy link

I am getting the following traceback when trying to read one of my dataloggers currently. I think I have seen similar previously but usually rerunning my script solves it. However, the same logger fails on both get_data() and get_devinfo() currently repeatedly.

Traceback (most recent call last):
  File ".\build_excel - Copy.py", line 23, in <module>
    for row in device.get_data():
  File "C:\Python27\lib\site-packages\elitech\__init__.py", line 120, in get_data
    devinfo = self.get_devinfo()
  File "C:\Python27\lib\site-packages\elitech\__init__.py", line 94, in get_devinfo
    res = self._talk(req, DevInfoResponse(self.encode))
  File "C:\Python27\lib\site-packages\elitech\__init__.py", line 68, in _talk
    response.read(self._ser)
  File "C:\Python27\lib\site-packages\elitech\msg.py", line 222, in read
    res)
struct.error: unpack requires a string argument of length 160

Not sure if a newer version of pyserial would help as it seems quite old?
If there is any other information I can provide to help debug this, let me now.

@stretch4x4
Copy link
Author

stretch4x4 commented Jan 23, 2019

Not sure what has changed (other than a lot more data points) but the script ran fine this morning.
So I won't be able to reproduce this bug reliably anymore.

@BjornFJohansson
Copy link

BjornFJohansson commented Sep 30, 2021

I now have the same problem... I reinitialized on a windows computer and it seems to work fine....

06:46 $ elitech-datareader --command devinfo --encode=utf8 /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
Traceback (most recent call last):
  File "/home/bjorn/anaconda3/envs/elitech-datareader/bin/elitech-datareader", line 8, in <module>
    sys.exit(main())
  File "/home/bjorn/anaconda3/envs/elitech-datareader/lib/python3.9/site-packages/scripts/elitech_device.py", line 27, in main
    command_devinfo(args)
  File "/home/bjorn/anaconda3/envs/elitech-datareader/lib/python3.9/site-packages/scripts/elitech_device.py", line 152, in command_devinfo
    dev_info = device.get_devinfo()
  File "/home/bjorn/anaconda3/envs/elitech-datareader/lib/python3.9/site-packages/elitech/__init__.py", line 94, in get_devinfo
    res = self._talk(req, DevInfoResponse(self.encode))
  File "/home/bjorn/anaconda3/envs/elitech-datareader/lib/python3.9/site-packages/elitech/__init__.py", line 68, in _talk
    response.read(self._ser)
  File "/home/bjorn/anaconda3/envs/elitech-datareader/lib/python3.9/site-packages/elitech/msg.py", line 194, in read
    alarm, temp_unit, temp_calib, humi_upper_limit, humi_lower_limit, _, humi_calib, _) = unpack(
struct.error: unpack requires a buffer of 160 bytes

@akeonly
Copy link

akeonly commented Oct 17, 2021

I have the same problem, I used to be able to download data from RC5 with elitech-datareader command.
*I'm on ubuntu

~$ elitech-datareader --command get /dev/ttyUSB0 > fan_replacement.txt
Traceback (most recent call last):
File "/usr/local/bin/elitech-datareader", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.8/dist-packages/scripts/elitech_device.py", line 23, in main
command_get(args)
File "/usr/local/lib/python3.8/dist-packages/scripts/elitech_device.py", line 68, in command_get
device.get_data(callback=output)
File "/usr/local/lib/python3.8/dist-packages/elitech/init.py", line 120, in get_data
devinfo = self.get_devinfo()
File "/usr/local/lib/python3.8/dist-packages/elitech/init.py", line 94, in get_devinfo
res = self._talk(req, DevInfoResponse(self.encode))
File "/usr/local/lib/python3.8/dist-packages/elitech/init.py", line 68, in _talk
response.read(self._ser)
File "/usr/local/lib/python3.8/dist-packages/elitech/msg.py", line 194, in read
alarm, temp_unit, temp_calib, humi_upper_limit, humi_lower_limit, _, humi_calib, _) = unpack(
struct.error: unpack requires a buffer of 160 bytes

@BjornFJohansson
Copy link

Mine stopped working after using the windows software that you can download from the elitech site. Perhaps it updates the reader somehow. Now it only works with their software on windows.

@PhilipPlant
Copy link

PhilipPlant commented Oct 24, 2021

Everything was working well last week under Ubuntu 20.04, now this happens with a week's worth of data (325 log entries):

$ elitech-datareader --command devinfo --value_only /dev/ttyUSB0 
Traceback (most recent call last):
  File "/usr/local/bin/elitech-datareader", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/scripts/elitech_device.py", line 27, in main
    command_devinfo(args)
  File "/usr/local/lib/python3.8/dist-packages/scripts/elitech_device.py", line 152, in command_devinfo
    dev_info = device.get_devinfo()
  File "/usr/local/lib/python3.8/dist-packages/elitech/__init__.py", line 94, in get_devinfo
    res = self._talk(req, DevInfoResponse(self.encode))
  File "/usr/local/lib/python3.8/dist-packages/elitech/__init__.py", line 68, in _talk
    response.read(self._ser)
  File "/usr/local/lib/python3.8/dist-packages/elitech/msg.py", line 194, in read
    alarm, temp_unit, temp_calib, humi_upper_limit, humi_lower_limit, _, humi_calib, _) = unpack(
struct.error: unpack requires a buffer of 160 bytes

No huge changes that I can think of to have created this issue. I've popped the battery on the logger (RC-5), tried a simple-set etc with same error message, but the error persists.

Any ideas would be greatly appreciated, thanks!

@BjornFJohansson
Copy link

@PhilipPlant, you can try the windows software from the website.
http://www.elitechlog.com/softwares
I would love to have this working again on linux, but I do not know how to even begin.

@skgrange
Copy link

skgrange commented Nov 1, 2021

Hello,
I too would like to flag that my Ubuntu 20.04 system is now raising a struct.error when I try and get the data from the sensor. The error is the same as above, a buffer issue. A dump is below:

# Get the observations from the sensor
elitech-datareader --command get /dev/ttyUSB0

Traceback (most recent call last):
  File "/home/stuart/.local/bin/elitech-datareader", line 8, in <module>
    sys.exit(main())
  File "/home/stuart/.local/lib/python3.8/site-packages/scripts/elitech_device.py", line 23, in main
    command_get(args)
  File "/home/stuart/.local/lib/python3.8/site-packages/scripts/elitech_device.py", line 68, in command_get
    device.get_data(callback=output)
  File "/home/stuart/.local/lib/python3.8/site-packages/elitech/__init__.py", line 120, in get_data
    devinfo = self.get_devinfo()
  File "/home/stuart/.local/lib/python3.8/site-packages/elitech/__init__.py", line 94, in get_devinfo
    res = self._talk(req, DevInfoResponse(self.encode))
  File "/home/stuart/.local/lib/python3.8/site-packages/elitech/__init__.py", line 68, in _talk
    response.read(self._ser)
  File "/home/stuart/.local/lib/python3.8/site-packages/elitech/msg.py", line 194, in read
    alarm, temp_unit, temp_calib, humi_upper_limit, humi_lower_limit, _, humi_calib, _) = unpack(
struct.error: unpack requires a buffer of 160 bytes

Any ideas what has changed to cause this issue? Many thanks,
Stuart.

@tictactux
Copy link

tictactux commented Nov 5, 2021

I think it's an "incompatibility" with the pyserial package - the interface name was not properly called:
in .../dist-packages/elitech/__init__py, lines 40 ff read:

class Device:
def init(self, serial_port, baudrate=115200, timeout=5):
if serial_port is not None:
self._ser = serial.Serial(serial_port, baudrate=baudrate, timeout=timeout) <---- this one!
self._ser.close()
self.debug = False
self.wait_time = 0.5
self.encode = 'utf8'

Replace "serial.Serial(serial_port, ....)" with "serial.Serial(port=serial_port, ....)" and everything will be good.

EDIT: False Alarm. It's still shaky. I wonder if accessing the port via PHP might yield different results (is it the port, or is it the implementation...) Sigh.

@skgrange
Copy link

skgrange commented Nov 5, 2021

Hello tictactux,
I was just looking at this and made the change, purged the old version, and installed the updated package version. Like you have added in your edit, the same issue remains. I might have to do some digging!

@tictactux
Copy link

tictactux commented Nov 6, 2021 via email

@civic
Copy link
Owner

civic commented Nov 9, 2021

I checked RC-4 on ubuntu 20.04. It works well. What device did you all use? RC-4/5? (NOTICE RC-5+ *Plus* doesn't work)

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal

$ elitech-datareader -c devinfo /dev/ttyUSB0 
alarm=AlarmSetting.NONE
current=2021-11-09 18:58:26
delay=0.0
dev_num=123456789
humi_calibration=0.0
humi_lower_limit=0.0
humi_upper_limit=0.0
last_online=2021-11-09 18:53:38
lower_limit=-10.0
model_no=40
rec_count=0
rec_interval=00:00:10
start_time=2021-11-09 16:41:06
station_no=0
stop_button=StopButton.ENABLE
temp_calibration=0.0
temp_unit=TemperatureUnit.C
tone_set=ToneSet.NONE
upper_limit=80.0
user_info=info
work_sts=WorkStatus.NOT_START

@BjornFJohansson

Mine stopped working after using the windows software that you can download from the elitech site. Perhaps it updates the reader somehow. Now it only works with their software on windows.

I already have ElitechLog Win v6.1.0. After using the ElitechLog, the elitech-datareader still worked well.
ElitechLog shows the Firmware version. It shows V1.0. Could you check the Firmware vision?

image

@BjornFJohansson
Copy link

BjornFJohansson commented Nov 10, 2021

I have V1.3 of the firmware, Version V6.2.0 of the software

@BjornFJohansson
Copy link

2021-11-10

@tictactux
Copy link

tictactux commented Nov 10, 2021 via email

@civic
Copy link
Owner

civic commented Nov 11, 2021

Thank you for your information. Is the device RC-4? Mine is RC-4.
If your devices are RC-4, I will update my firmware to v1.3 and try to check whether the same problem will happen.

@tictactux
Copy link

tictactux commented Nov 11, 2021 via email

@BjornFJohansson
Copy link

Thank you for your information. Is the device RC-4? Mine is RC-4. If your devices are RC-4, I will update my firmware to v1.3 and try to check whether the same problem will happen.

Mine is RC-5 as well, not the plus version.

@civic
Copy link
Owner

civic commented Nov 12, 2021

Thank you, I also have RC-5. but my RC-5 firmware version is V1.1.
image

I updated windows software ElitechLog Win to v6.2.0. After setting up RC-5 by using the software, the firmware version was not updated. It is still V1.1. I tried command devinfo on the python program, it worked well.

I don't know how to update the firmware.

@tictactux
Copy link

tictactux commented Nov 12, 2021 via email

@FrankRay78
Copy link

Hello all,

I'm considering writing a native Linux kernel module for the Elitech devices, particularly since this repo seems not to be developed any more and also doesn't support the RC-5+ device. However, it would greatly help me first to understand your preference to using the python script on the Linux terminal, over and above either the Windows or Mac software provided here: http://www.elitechlog.com/softwares/ Additionally, is there anything majorly missing from the current python script that you'd welcome seeing?

Thanks,
Frank

@BjornFJohansson
Copy link

@FrankRay78 thanks for picking this up. My use case is simply extracting to csv for further processing on linux.
The features are fine as they are, I only ever used the it to download data.
The windows app is bloated and not very easy to use IMHO.

@stretch4x4
Copy link
Author

I haven't used my loggers much recently for a multitude of reasons but I was using this api to automate data collection. Collecting via the windows app requires a lot of manual interaction.
One thing this API couldn't do on my RC-5s was restart the logging which would have allowed me to completely automate everything. I can't remember if it was the start, the stop or the clearing that was the issue but one of the commands didn't exist or didn't work so I ended up giving up as there would always be a manual step involved to reset it.

@FrankRay78
Copy link

One thing this API couldn't do on my RC-5s was restart the logging

I'll keep this in mind @stretch4x4 as something worth adding. I might actually just port the current python script over to C/C# to begin with, languages I know well so that I can consider making changes like this and adding in the RC5+ support. It should then be an easier migration path into a proper kernel module from there.

@civic
Copy link
Owner

civic commented Feb 14, 2023

RC-5+ is totally different. so I couldn't research the messages. If the device worked as a serial communication device, I would have improved the software more.

@FrankRay78
Copy link

A seriously good piece of software you developed here @civic - really excellent work btw.

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

8 participants