This says ERROR: bitwise op between ‘string’ and ‘string’ on line 88 (which is the first for() loop). data is “binary: 00 00 81 ff ff ff” and len is 2.
`function crc8(data, len) {
/*
*
- CRC-8 formula from page 14 of SHT spec pdf
- Test data 0xBE, 0xEF should yield 0x92
- Initialization data 0xFF
- Polynomial 0x31 (x8 + x5 +x4 +1)
- Final XOR 0x00
*/
local POLYNOMIAL = (0x131);
local crc = (0xFF);
server.log(data);
for(local byteCtr = 0; byteCtr < len; byteCtr++)
{
crc = crc ^ (data[byteCtr].tointeger());
for(local bit = 8; bit > 0; --bit)
{
if(crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
else crc = (crc << 1);
}
}
return crc;`