Last active
November 29, 2017 19:04
-
-
Save ubergesundheit/a326c2d0fec88210bbe088c8581855f9 to your computer and use it in GitHub Desktop.
Read Raspberry Pi CPU Temperature and HTTP Post systemd timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/cpu_temp.service | |
[Unit] | |
Description=HTTP Post cpu temperature to endpoint | |
[Service] | |
Type=oneshot | |
# set your post url as normal environment variable | |
# should have the form https://ingress.opensensemap.org/boxes/<boxID>/<sensorID> | |
Environment="URL=https://ingress.opensensemap.org/boxes/<boxID>/<sensorID>" | |
# use systemctl set-environment to execute the vgencmd command and set as environment variable | |
ExecStartPre=/bin/bash -c 'systemctl set-environment CPUTEMP="\"$(/opt/vc/bin/vcgencmd measure_temp | cut -b 6-9)\""' | |
# Execute curl | |
ExecStart=/bin/bash -c '/usr/bin/curl --silent --fail -H "Content-type: application/json" -X POST -d "{\\"value\\":${CPUTEMP}}" "${URL}"' | |
# unset the CPUTEMP environment variable | |
ExecStop=/bin/bash -c 'systemctl unset-environment CPUTEMP' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/systemd/system/cpu_temp.timer | |
[Unit] | |
Description=Run cpu_temp.service every 10 minutes | |
[Timer] | |
OnCalendar=*:0/10 | |
; ;Other way to do this: | |
;OnActiveSec=1 minute | |
;OnUnitActiveSec=1 minute | |
;AccuracySec=1 second | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment