Aqui você vê as diferenças entre duas revisões dessa página.
Ambos lados da revisão anterior Revisão anterior Próxima revisão | Revisão anterior | ||
informatica:restrita:sensor_temper [2025/07/08 10:14] davidysson |
informatica:restrita:sensor_temper [2025/07/08 11:07] (atual) davidysson |
||
---|---|---|---|
Linha 7: | Linha 7: | ||
<code> | <code> | ||
echo baixando/instalando os pacotes/arquivos necessarios | echo baixando/instalando os pacotes/arquivos necessarios | ||
- | apt install python3-serial jq git | + | #apt install python3-serial jq git |
+ | apt install python3-serial git | ||
git clone https://github.com/ccwienk/temper.git | git clone https://github.com/ccwienk/temper.git | ||
Linha 15: | Linha 16: | ||
<code> | <code> | ||
- | #temperatura=$( /opt/temper/temper.py | awk '{print $7}' ) | + | #temperatura=$( /opt/temper/temper.py --json | jq --raw-output '.[] ."internal temperature"' ) |
- | temperatura=$( /opt/temper/temper.py --json | jq --raw-output '.[] ."internal temperature"' ) | + | temperatura=$( /opt/temper/temper.py | awk '{print $7}' | sed 's/C//' ) |
echo $temperatura | echo $temperatura | ||
- | maximo=25.0 | + | maximo=26.0 |
teste=$(echo "$temperatura < $maximo" | bc) | teste=$(echo "$temperatura < $maximo" | bc) | ||
Linha 40: | Linha 41: | ||
echo "Temperatura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" miguel@icb.ufmg.br | echo "Temperatura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" miguel@icb.ufmg.br | ||
echo "Enviado com sucesso" | echo "Enviado com sucesso" | ||
+ | curl https://sistemas.icb.ufmg.br/whatsapp/api_tal.php?temperatura=$temperatura&key=094845968309298375 | ||
| | ||
fi; | fi; | ||
Linha 46: | Linha 48: | ||
===== No XenServer/XCP-NG / redhat ou seus forks ===== | ===== No XenServer/XCP-NG / redhat ou seus forks ===== | ||
+ | * Instale os pacotes necessarios (comandos adaptados do site, mas precisa testar) | ||
+ | |||
+ | <code> | ||
+ | #sudo apt install libhidapi-dev cmake | ||
+ | sudo yum install hidapi cmake | ||
+ | mkdir /opt | ||
+ | cd /opt | ||
+ | git clone https://github.com/edorfaus/TEMPered | ||
+ | cd TEMPered | ||
+ | cmake . | ||
+ | cd utils | ||
+ | make | ||
+ | sudo /opt/TEMPered/utils/hid-query /dev/hidraw0 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 | ||
+ | </code> | ||
+ | |||
+ | * Crie o seguinte script | ||
+ | |||
+ | <code> | ||
+ | #!/bin/bash | ||
+ | |||
+ | ## | ||
+ | ## temper.sh | ||
+ | ## reads and print temperature from TEMPer device(s) | ||
+ | ## requires hid-query from the TEMPered project | ||
+ | ## https://cylab.be/blog/92/measure-ambient-temperature-with-temper-and-linux | ||
+ | ## | ||
+ | |||
+ | for device in /dev/hidraw*; do | ||
+ | ## quey $device and grep for return value | ||
+ | #hexvalue=`/opt/TEMPered/utils/hid-query "$device" 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 2> /dev/null | grep -oP "80 80 K([0-9a-fA-F]{2} [0-9a-fA-F]{2})" | tr -d ' '` | ||
+ | hexvalue=$(/opt/TEMPered/utils/hid-query "$device" 0x01 0x80 0x33 0x01 0x00 0x00 0x00 0x00 2> /dev/null | grep "80 80" | tr -d ' ') | ||
+ | hexvalue=${hexvalue:5:4} | ||
+ | |||
+ | ## convert hex to dec | ||
+ | decvalue=`printf "%d" $((16#$hexvalue))` | ||
+ | |||
+ | ## divide by 100 | ||
+ | decvalue=`bc <<< "scale=2; ${decvalue}/100"` | ||
+ | printf "%s : %s °C | ||
+ | " $device $decvalue | ||
+ | done; | ||
+ | |||
+ | # continuar o codigo aqui para testar a temperatura se tiver acima de 26 graus e enviar e-mail de alerta | ||
+ | # ... | ||
+ | |||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== Criando a cron para automatizar o teste de temperatura ===== | ||
+ | |||
+ | * Se redhat ou derivados: Edite o arquivo /var/spool/cron/root | ||
+ | * Se debian ou devirados: execute "crontab -e" | ||
+ | * Cole o seguinte conteudo: | ||
+ | |||
+ | <code> | ||
+ | 00-59/10 * * * * bash /opt/temper/cron.sh >> /opt/temper/cron.log | ||
+ | </code> | ||