3 // ** WH2 Temperature and Humidity Outdoor Sensor **
 
   5 uint8_t crc8( uint8_t *addr, uint8_t len)
 
   9   // Indicated changes are from reference CRC-8 function in OneWire library
 
  11     uint8_t inbyte = *addr++;
 
  14       uint8_t mix = (crc ^ inbyte) & 0x80; // changed from & 0x01
 
  15       crc <<= 1; // changed from right shift
 
  16       if (mix) crc ^= 0x31;// changed from 0x8C;
 
  17         inbyte <<= 1; // changed from right shift
 
  23 static int wh2_callback(uint8_t bb[BITBUF_ROWS][BITBUF_COLS],int16_t bits_per_row[BITBUF_ROWS]) {
 
  27     int received_crc8,payload_crc8;
 
  33     if (bb[0][0] != 0xFE) return 0;
 
  35     payload[0] = bb[0][1]>>1;
 
  36     payload[1] = bb[0][2]>>1 | ((bb[0][1]&1) << 7 );
 
  37     payload[2] = bb[0][3]>>1 | ((bb[0][2]&1) << 7 );
 
  38     payload[3] = bb[0][4]>>1 | ((bb[0][3]&1) << 7 );
 
  40     received_crc8 = (bb[0][5]>>1) | ((bb[0][4]&1) << 7 );
 
  42     payload_crc8 = crc8(payload,4);
 
  44     if (payload_crc8 != received_crc8) {
 
  45         fprintf(stderr,"Bad WH2 payload CRC, skipping...\n");
 
  49     wh2_id = (payload[0] << 4) + (payload[1] >> 4);
 
  50     wh2_temp = ((payload[1] & 0x7) << 8) + payload[2];
 
  51     if (payload[1] & 0x8) {
 
  54     wh2_temp = wh2_temp/10;
 
  56     wh2_humidity = payload[3];
 
  58     fprintf(stdout, "SENSOR:TYPE=WH2,ID=%X,HUMIDITY=%g,TEMPERATURE=%g\n",wh2_id,wh2_humidity,wh2_temp);
 
  66     /* .name           = */ "WH2 Weather Station",
 
  67     /* .modulation     = */ OOK_PWM_P,
 
  68     /* .short_limit    = */ 150,
 
  69     /* .long_limit     = */ 400, 
 
  70     /* .reset_limit    = */ 20000,
 
  71     /* .json_callback  = */ &wh2_callback,