Skip to content

Instantly share code, notes, and snippets.

@artms
Created Sep 29, 2020
Embed
What would you like to do?
Reading from temper temperature sensor in bash only
#!/bin/bash
exec 5<> /dev/hidraw1
echo -e '\x00\x01\x80\x33\x01\x00\x00\x00\x00\c' >&5
OUT=$(dd count=1 bs=8 <&5 2>/dev/null | xxd -p)
HEX4=${OUT:4:4}
DVAL=$((16#$HEX4))
CTEMP=$(bc <<< "scale=2; $DVAL/100")
echo $CTEMP
@allureGOT

This comment has been minimized.

Copy link

@allureGOT allureGOT commented Nov 13, 2020

Great! Reading the temperature works!
Can you help me, to read the humidy-value from the device?

@artms

This comment has been minimized.

Copy link
Owner Author

@artms artms commented Nov 13, 2020

Great! Reading the temperature works!
Can you help me, to read the humidy-value from the device?

Unfortunetely my device doesn't have humidity sensor so I cannot actually test. I can check how it is read elsewhere and make equivalent

@allureGOT

This comment has been minimized.

Copy link

@allureGOT allureGOT commented Nov 13, 2020

I can test things for you when you need input?

@artms

This comment has been minimized.

Copy link
Owner Author

@artms artms commented Nov 14, 2020

Add this lines at the end of script and check with any know humidity sensor if value makes sense

HEX4=${OUT:8:4}
DVAL=$((16#$HEX4))
HUM=$(bc <<< "scale=2; $DVAL/100")
echo $HUM
@allureGOT

This comment has been minimized.

Copy link

@allureGOT allureGOT commented Nov 14, 2020

#!/bin/bash
exec 5<> /dev/hidraw1
echo -e '\x00\x01\x80\x33\x01\x00\x00\x00\x00\c' >&5
OUT=$(dd count=1 bs=8 <&5 2>/dev/null | xxd -p)
HEX4=${OUT:8:4}
DVAL=$((16#$HEX4))
HUM=$(bc <<< "scale=2; $DVAL/100")
echo $HUM

Works! that gives me an value of 39 at the moment, i'm verifing that with an analog meter.

@allureGOT

This comment has been minimized.

Copy link

@allureGOT allureGOT commented Nov 14, 2020

Ok, i measured the humidity with an analog hygrometer, it seems to have an offset of 5%RH. (negative)
But it works, yeah!

@maurerr

This comment has been minimized.

Copy link

@maurerr maurerr commented Dec 21, 2020

modified a bit to work under openwrt 19.07 (only kmod-usb-hid && xxd added to default build - tested on ath79 tl-wr703n with only 4mb flash)

#!/bin/sh
exec 5<> /dev/hidraw1
echo -e '\x00\x01\x80\x33\x01\x00\x00\x00\x00\c' >&5
OUT=$(dd count=1 bs=8 <&5 2>/dev/null | xxd -p)
HEX4=${OUT:4:4}
DVAL=$(printf "%d\n" 0x$HEX4)
awk "BEGIN {print $DVAL/100}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment