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

TEMPerHumM12V1.2 0C45:7402 #33

Open
G0lph3r opened this issue Nov 26, 2014 · 12 comments
Open

TEMPerHumM12V1.2 0C45:7402 #33

G0lph3r opened this issue Nov 26, 2014 · 12 comments

Comments

@G0lph3r
Copy link

G0lph3r commented Nov 26, 2014

Made by PCsensor (http://www.pcsensor.com/index.php?_a=document&doc_id=6), metallic enclosure with blue TXT push button and titled "TEMPerHUM", windows driver TEMPer V24.4.4.zip.
It seems to be (I didn't opened enclosure) that used Silabs Si7006 sensor - http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7006-A10.pdf
Following request bytes - .data = (unsigned char[]){ 0, 1, 0x80, 0x33, 1, 0, 0, 0, 0 }

hid-query /dev/hidraw1 1 0x80 0x33 1
Device /dev/hidraw1 : 0c45:7402 interface 1 : RDing TEMPERHUM1V1.2
Writing data (9 bytes):
00 01 80 33 01 00 00 00 00
Response from device (8 bytes):
80 04 6b 80 43 32 2e 32
where - 80 04 and 2e 32 - technical (not interesting for me at least, please add info if matters)
6b 80 - temperature
43 32 - humidity

from sensor description -
_tempC = ((float)temp)_175.72 / 65536-46.8;
float relhum = ((float)rh)*125 / 65536 - 6;

lsusb -v output
Bus 002 Device 015: ID 0c45:7402 Microdia
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0c45 Microdia
idProduct 0x7402
bcdDevice 0.01
iManufacturer 1
iProduct 2
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 59
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 1 Boot Interface Subclass
bInterfaceProtocol 1 Keyboard
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 65
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 1 Boot Interface Subclass
bInterfaceProtocol 2 Mouse
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.10
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 41
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10

@JuanKman94
Copy link

@G0lph3r Hey, man, did you manage to get it working? I'm currently trying to make it work according to another issue post from ourmoonflass.
If I manage to get it working I'll let you know.

P.S: I have the exact same model you do

@G0lph3r
Copy link
Author

G0lph3r commented Dec 31, 2014

Yeah, working like a clock on Udoo board. Little bit modified source for myself also if interested I can post. IMHO integration with openHAB is weird = through SNMP, but maybe it's Ok, cause I'm not linux guru. Happy New Year!

@Diggensag
Copy link

In temper_type.c I modified:

snip
.get_subtype_data = &(struct tempered_type_hid_subtype_from_string_data)
{
.query = {
.length = 9,
.data = (unsigned char[]){ 0, 1, 0x86, 0xFF, 1, 0, 0, 0, 0 }
},
.response_count = 2,
.subtype_strings = (char *[]){
"TEMPerHumV1.0rHu",
"TEMPerHumM12V1.0",
"TEMPerHumM12V1.2",
NULL
}
}, ...

and added a struct:
(struct temper_subtype*)&(struct temper_subtype_hid){
.base = {
.id = 2,
.name = "TEMPerHum2V1.2",
.open = tempered_type_hid_subtype_open,
.read_sensors = tempered_type_hid_read_sensors,
.get_temperature = tempered_type_hid_get_temperature,
.get_humidity = tempered_type_hid_get_humidity
},
.sensor_group_count = 1,
.sensor_groups = (struct tempered_type_hid_sensor_group[]){
{
.query = {
.length = 9,
.data = (unsigned char[]){ 0, 1, 0x80, 0x33, 1, 0, 0, 0, 0 }
},
.read_sensors = tempered_type_hid_read_sensor_group,
.sensor_count = 1,
.sensors = (struct tempered_type_hid_sensor[]){
{
.get_temperature = tempered_type_hid_get_temperature_si7006,
.get_humidity = tempered_type_hid_get_humidity_si7006,
.temperature_high_byte_offset = 2,
.temperature_low_byte_offset = 3,
.humidity_high_byte_offset = 4,
.humidity_low_byte_offset = 5
}
}
}
}
},

then i copied the si7005.c and si7005.h and adapted a bit...

#include <stdbool.h>
#include <string.h>

#include "type-info.h"
#include "../tempered-internal.h"

bool tempered_type_hid_get_temperature_si7006(
tempered_device *device, struct tempered_type_hid_sensor *sensor,
struct tempered_type_hid_query_result *group_data, float *tempC
) {
if (
group_data->length <= sensor->temperature_high_byte_offset ||
group_data->length <= sensor->temperature_low_byte_offset
) {
tempered_set_error(
device, strdup( "Not enough data was read from the sensor." )
);
return false;
}

    // Convert from two separate data bytes to a single integer.
    // The result should be an unsigned int between 0x0000 and 0xFFFF.
    int low_byte_offset = sensor->temperature_low_byte_offset;
    int high_byte_offset = sensor->temperature_high_byte_offset;
    int temp = ( group_data->data[low_byte_offset] & 0xFF )
            + ( ( group_data->data[high_byte_offset] & 0xFF ) << 8 )
    ;

    // According to the Silicon Labs Si7006 datasheet,
    *tempC = ((float)temp) * 175.72 / 65536 - 46.8;  // Seen in the Datasheet
    // my custom values ... *tempC = ((float)temp) * 175.72 / 65536 - 48;

    return true;

}

bool tempered_type_hid_get_humidity_si7006(
tempered_device *device, struct tempered_type_hid_sensor *sensor,
struct tempered_type_hid_query_result *group_data, float *rel_hum
) {
float tempC;
if (
!tempered_type_hid_get_temperature_si7006(
device, sensor, group_data, &tempC
)
) {
return false;
}

    if (
            group_data->length <= sensor->humidity_high_byte_offset ||
            group_data->length <= sensor->humidity_low_byte_offset
    )
    {
            tempered_set_error(
                    device, strdup( "Not enough data was read from the sensor." )
            );
            return false;
    }

    int low_byte_offset = sensor->humidity_low_byte_offset;
    int high_byte_offset = sensor->humidity_high_byte_offset;
    int rh = ( group_data->data[low_byte_offset] & 0xFF )
            + ( ( group_data->data[high_byte_offset] & 0xFF ) << 8 )
    ;

    // These formulas and values are based on the Silicon Labs Si7005 datasheet

    // There's 16 codes per %RH, with 0x0000 = -24%RH
    // float relhum = ((float)rh) / 16 - 24;
    float relhum = ((float)rh)*125 / 65536 - 6;

    // Linearization
    // relhum -= -0.00393 * relhum * relhum + 0.4008 * relhum - 4.7844;

    // Temperature compensation
    // relhum += ( tempC - 30 ) * ( 0.00237 * relhum + 0.1973 );

    *rel_hum = relhum;

    return true;

}

@JuanKman94
Copy link

Thanks! I'm currently updating the make files to try Diggensag's code; but
@G0lph3r if you could upload a fork or the code you used to compile it/ make it work that would awesome! Because I'm kind of on a deadline

@G0lph3r
Copy link
Author

G0lph3r commented Jan 1, 2015

Sorry didn't have private Github, so posting changes vs this project source. My aim was "it working for me, let's forget", so code must be definitely better and IMHO Diggensag wrote it already here. Just search and replace. If you give mail address will send directly to you zipped project.
temper_type.c
***** My changes
"TEMPerHumV1.0rHu",
"TEMPerHumM12V1.2",
NULL
***** Source code taken from this github fork
"TEMPerHumV1.0rHu",
"TEMPerHumM12V1.0",
NULL


***** My changes
.id = 1,
.name = "TEMPerHumM12V1.2",
.open = tempered_type_hid_subtype_open,
***** Source code taken from this github fork
.id = 1,
.name = "TEMPerHumM12V1.0",
.open = tempered_type_hid_subtype_open,



tempered.c
***** My changes
printf(
"%.2f\n"
"%.1f\n",
tempC,
rel_hum
);
}
else if ( type & TEMPERED_SENSOR_TYPE_TEMPERATURE )
{
printf(
"%s %i: temperature %.2f %s\n",
tempered_get_device_path( device ), sensor,
***** Source file taked from here
printf(
"%s %i: temperature %.2f %s"
", relative humidity %.1f%%"
", dew point %.1f %s\n",
tempered_get_device_path( device ), sensor,


***** My changes
options->temp_scale->from_celsius( tempC ),
options->temp_scale->symbol
***** Source file taked from here
options->temp_scale->from_celsius( tempC ),
options->temp_scale->symbol,
rel_hum,
options->temp_scale->from_celsius(
tempered_util__get_dew_point( tempC, rel_hum )
),
options->temp_scale->symbol


***** My changes
}
else if ( type & TEMPERED_SENSOR_TYPE_HUMIDITY )
{
***** Source file taked from here
}
else if ( type & TEMPERED_SENSOR_TYPE_TEMPERATURE )
{


***** My changes
printf(
"%s %i: relative humidity %.1f%%\n",
tempered_get_device_path( device ), sensor,
rel_hum
);
***** Source file taked from here
printf(
"%s %i: temperature %.2f %s\n",
tempered_get_device_path( device ), sensor,
options->temp_scale->from_celsius( tempC ),
options->temp_scale->symbol
);


***** My changes
}
else
{
***** Source file taked from here
}
else if ( type & TEMPERED_SENSOR_TYPE_HUMIDITY )
{


***** My changes
printf(
"%s %i: no sensor data available\n",
tempered_get_device_path( device ), sensor
);
***** Source file taked from here
printf(
"%s %i: relative humidity %.1f%%\n",
tempered_get_device_path( device ), sensor,
rel_hum
);


***** My changes
}
}
***** Source file taked from here
}
else
{
printf(
"%s %i: no sensor data available\n",
tempered_get_device_path( device ), sensor
);
}
}



si7005.c
***** Source code taken from this github fork
// with 0x0000 = -50?.
*tempC = ((float)temp) / 32 - 50;

***** My changes
// with 0x0000 = -50?.

    *tempC = ((float)temp) *175.72/ 65536 - 46.8;

***** Source code taken from this github fork
// There's 16 codes per %RH, with 0x0000 = -24%RH
float relhum = ((float)rh) / 16 - 24;

    // Linearization
    relhum -= -0.00393 * relhum * relhum + 0.4008 * relhum - 4.7844;

***** My changes
// There's 16 codes per %RH, with 0x0000 = -24%RH
//float relhum = ((float)rh) / 16 - 24;
float relhum = ((float)rh)*125 / 65536 - 6;

    // Linearization
    //relhum -= -0.00393 * relhum * relhum + 0.4008 * relhum - 4.7844;

***** Source code taken from this github fork
// Temperature compensation
relhum += ( tempC - 30 ) * ( 0.00237 * relhum + 0.1973 );

***** My changes
// Temperature compensation
//relhum += ( tempC - 30 ) * ( 0.00237 * relhum + 0.1973 );


@Diggensag
Copy link

I created a repository under https://github.com/Diggensag/TEMPered ... hope i didn´t forget something (i am not firm to git yet).

@JuanKman94
Copy link

Thanks to both of you, I succesfully added the si7006 sensor to the type_hid folder and updated the build files and this sweet sensor is up and running.

Thanks a lot!

@ybabel
Copy link

ybabel commented Jul 5, 2015

Hello,
I tryed to make it work on rapsberry pi (raspbian)

lsusb :
Bus 001 Device 014: ID 0c45:7402 Microdia TEMPerHUM Temperature & Humidity Sensor

dmesg
[ 319.875624] usb 1-1.2.4: new low-speed USB device number 14 using dwc_otg
[ 320.003241] usb 1-1.2.4: New USB device found, idVendor=0c45, idProduct=7402
[ 320.003278] usb 1-1.2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 320.003295] usb 1-1.2.4: Product: TEMPERHUM1V1.2
[ 320.003309] usb 1-1.2.4: Manufacturer: RDing
[ 320.023894] input: RDing TEMPERHUM1V1.2 as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4:1.0/input/input1
[ 320.048794] hid-generic 0003:0C45:7402.0003: input,hidraw0: USB HID v1.10 Keyboard [RDing TEMPERHUM1V1.2] on usb-bcm2708_usb-1.2.4/input0
[ 320.088099] hid-generic 0003:0C45:7402.0004: hiddev0,hidraw1: USB HID v1.10 Device [RDing TEMPERHUM1V1.2] on usb-bcm2708_usb-1.2.4/input1

./hidtest-libusb
Device Found
type: 0c45 7402
path: 0001:000e:00
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 1
Interface: 0

Device Found
type: 0c45 7402
path: 0001:000e:01
serial_number: (null)
Manufacturer: (null)
Product: (null)
Release: 1
Interface: 1

unable to open device

./hidtest-hidraw
unable to open device

I tryed @JuanKman94 and @Diggensag version.
both says :
sudo ./tempered
Failed to enumerate devices: No HID devices were found.
sudo ./hid-query -e
No HID devices were found.

any help ?

@G0lph3r
Copy link
Author

G0lph3r commented Jul 6, 2015

Hi,
Did you installed https://github.com/signal11/hidapi before temperhum?

@ybabel
Copy link

ybabel commented Jul 6, 2015

@G0lph3r yes, sure, I posted the log of hidtest-libusb and hidtest-hidraw
In the meanwhile, I managed to make it work on my laptop, and raspberry pi2. Maybe there is some access problems on my old raspberry pi...

@normanr
Copy link

normanr commented Mar 31, 2016

fyi: see #40 for V1.2 and V1.3 support

@normanr
Copy link

normanr commented Mar 25, 2023

and this is now superseded by mwerezak#4

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

5 participants