padelt / temper-python

libusb/PyUSB-based driver to read TEMPer USB HID devices (USB ID 0c45:7401) and serve as a NetSNMP passpersist module
Other
182 stars 76 forks source link

Support for TEMPerX232 (1a86:5523) #138

Open Strykar opened 8 months ago

Strykar commented 8 months ago

Please consider adding support for the TEMPerX232 1a86:5523 TEMPerX232_V2.0 Temperature & Humidity USB sensor. This may add another dependency, pyserial, seeing as ccwienk/temper could only get it working via UART (see below).

Notes from https://github.com/ccwienk/temper on this model:


TEMPerX232

https://i.imgur.com/h0eA4mF.jpg White plastic USB stick marked "TEMPerX232", "0-100%RH", and "-40 - +85C"; with a green button marked "press". On the reverse, "PCsensor". On the end opposite the USB connector, there is a jack for an external temperature sensor (which I do not have and did not try).

When the button is pressed and held down until the red LED is solid, a blue LED will flash every second. In this mode, the USB vendor:product changes to 413d:2107, but only one HID device is available, and protocol sent to the hidraw device is rejected with an error.

When the LED is flashing blue, and the button is pressed momentarily, the following are sent (the temperature line repeats every second).

www.PCsensor.com
TEMPerX232-V2.0
type:inner-H2
inner-temperinner-humidityinterval
30.48 [C]40.19 [%RH]1

When the button is pressed and held down until the red LED is solid, a green LED will flash every second. This is the mode temper.py uses. In this mode, if "Help" is sent to the serial device, the following will be sent back:

   >>PCsensor<<
Welcome to use TEMPerX232!
Firmware Version:TEMPerX232_V2.0
The command is:
    ReadTemp                     -->read temperature,temp_value = sensor_value + calibration
    ReadCalib                    -->read calibration
    SetCalib-type:xx.x,xx.x>     -->set calibration, xx.x(-10.0~+10.0)
    EraseFlash                   -->erase calibration
    Version                      -->read firmware version
    ReadType                     -->read the sensor type
    ReadAlert-Temp               -->read temp alert value
    SetTempUpperAlert-type:xx.xx>-->set temp upper alert value,xx.xx(-40.00~+85.00)
    SetTempLowerAlert-type:xx.xx>-->set temp lower alert value,xx.xx(-40.00~+85.00)
    ReadAlert-Hum                -->read hum alert value
    SetHumUpperAlert-type:xx.xx> -->set hum upper alert value,xx.xx(00.00~99.99)
    SetHumLowerAlert-type:xx.xx> -->set hum lower alert value,xx.xx(00.00~99.99)
    SetMode-Temp:x>              -->set tempmode, x(0~1)
    ReadMode-Temp                -->read tempmode
    Help                         -->command help
    ?                            -->command help
The COM configuration is:
    Mode:       ASCII
    Baud Rate:  9600bps
    Data Bit:   8
    Parity Bit: None
    Stop Bit:   1
SHENZHEN RDing Tech CO.,LTD
www.PCsensor.com

This is the mode that temper.py uses. I was not successful getting this device to respond to any commands sent via the HID device.

I initially had trouble getting a reply to ReadTemp when using a terminal program (e.g., cu), but the example in the temper.py works without any problems, perhaps because no newline is sent after the command.


$ lsusb -d 1a86:5523
Bus 003 Device 015: ID 1a86:5523 QinHeng Electronics CH341 in serial mode, usb to serial port converter
Bus 003 Device 042: ID 1a86:5523 QinHeng Electronics CH341 in serial mode, usb to serial port converter

$ sudo temper-poll -p
Found 0 devices

$ sudo temper-poll -p -v -s all
INFO:temperusb.temper:Found 0 TEMPer devices
Found 0 devices

$ sudo ./temper.py --json
[
    {
        "vendorid": 6790,
        "productid": 21795,
        "manufacturer": "PCsensor",
        "product": "TEMPerX232",
        "busnum": 3,
        "devnum": 15,
        "devices": [
            "ttyUSB0"
        ],
        "port": "3-12",
        "firmware": "TEMPerX232_V2.5",
        "internal temperature": 28.57,
        "internal humidity": 45.88
    },
    {
        "vendorid": 6790,
        "productid": 21795,
        "manufacturer": "PCsensor",
        "product": "TEMPerX232",
        "busnum": 3,
        "devnum": 42,
        "devices": [
            "ttyUSB1"
        ],
        "port": "3-2",
        "firmware": "TEMPerX232_V2.5",
        "internal temperature": 27.32,
        "internal humidity": 53.78
    }
]

Adding support for these devices would close issues downstream - https://github.com/home-assistant/core/issues/105544 I have two of these devices plugged in, please let me know what I may do to help.