-
Notifications
You must be signed in to change notification settings - Fork 0
/
HIH9130.cpp
31 lines (28 loc) · 1.44 KB
/
HIH9130.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "HIH9130.h"
#include "stdio.h"
bool HIH9130Wireless::parseSensorData(byte* data, int len){
int sensorType = getSensorType(data[sensorTypeMSBIndex], data[sensorTypeLSBIndex]);
if(data[0] != headerByte || sensorType != HIH9130SensorType){
return false;
}
char publishData[100];
sprintf(publishData, "NodeID:%i|firmware:%i|battery voltage:%0.2f|transmissionID:%i|sensorType:%i|humidity:%0.2f|temperature:%0.2f", data[nodeIDIndex], data[firmwareVersionIndex], getBatteryVoltage(data[batteryVotageMSBIndex], data[batteryVoltageLSBIndex]), data[transmitCounterIndex], getSensorType(data[sensorTypeMSBIndex], data[sensorTypeLSBIndex]), getHumidity(data[humidityMSBIndex], data[humidityLSBIndex]), getTemperature(data[temperatureMSBIndex],data[temperatureLSBIndex]));
Serial.println(publishData);
return Particle.publish(String(data[nodeIDIndex]), String(publishData));
}
float HIH9130Wireless::getBatteryVoltage(byte msb, byte lsb){
float battery = ((msb * 256) + lsb);
float voltage = 0.00322 * battery;
return voltage;
}
float HIH9130Wireless::getTemperature(byte msb, byte lsb){
float temp = ((msb * 256) + (lsb & 0xFC)) / 4;
float cTemp = (temp / 16384.0) * 165.0 - 40.0;
return cTemp * 1.8 + 32;
}
float HIH9130Wireless::getHumidity(byte msb, byte lsb){
return ((((msb & 0x3F) * 256) + lsb) * 100.0) / 16383.0;
}
int HIH9130Wireless::getSensorType(byte msb, byte lsb){
return((msb * 265)+lsb);
}