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 09:39] 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 git | ||
| git clone https://github.com/ccwienk/temper.git | git clone https://github.com/ccwienk/temper.git | ||
| - | apt install python3-serial | + | |
| - | apt install jq | + | |
| </code> | </code> | ||
| Linha 15: | Linha 16: | ||
| <code> | <code> | ||
| - | temperatura=$( /pastatal/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) | ||
| if [ $teste = '1' ]; then | if [ $teste = '1' ]; then | ||
| + | |||
| echo "temperature $temperaturaºC is smaller than $maximoºC"; | echo "temperature $temperaturaºC is smaller than $maximoºC"; | ||
| + | |||
| else | else | ||
| - | VAR=1; | + | |
| - | echo 'alert!'; | + | echo 'Alert! Temperature $temperaturaºC is biggest than $maximoºC'; |
| - | fi | + | |
| - | + | echo "Enviando email..." | |
| - | if [ "$VAR" == "1" ]; then | + | set smtp=smtps://smtp.grude.ufmg.br:465 |
| - | set smtp=smtps://smtp.grude.ufmg.br:465 | + | set from="sddr@icb.ufmg.br" |
| - | set from="sddr@icb.ufmg.br" | + | set smtp-auth-user=icb-smtp |
| - | set smtp-auth-user=icb-smtp | + | set smtp-auth-password=SENHANOWIKI |
| - | set smtp-auth-password=SENHA | + | set smtp-auth=login |
| - | set smtp-auth=login | + | set smtp-verify=ignore |
| - | set smtp-verify=ignore | + | echo "Temperatura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" gti@icb.ufmg.br |
| - | echo "Enviando email..." | + | echo "Temperatura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" miguel@icb.ufmg.br |
| - | echo "Tempertura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" gti@icb.ufmg.br | + | echo "Enviado com sucesso" |
| - | echo "Tempertura: $temperatura" | /bin/mailx -v -s "[SDDR] Temperatura acima de $maximo graus" miguel@icb.ufmg.br | + | curl https://sistemas.icb.ufmg.br/whatsapp/api_tal.php?temperatura=$temperatura&key=094845968309298375 |
| - | echo "OK" | + | |
| fi; | fi; | ||
| </code> | </code> | ||
| Linha 43: | 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> | ||