status.sh 485 B

123456789101112131415161718192021222324252627
  1. #! /bin/sh
  2. ## set the status
  3. TOPIC="/status"
  4. toSingleLine () {
  5. echo $(echo $1 | tr -s '\t' ' ' | tr -d '\n')
  6. }
  7. if [ "$1" == "" ] ||
  8. [ "$2" == "" ]; then
  9. echo "ERROR: expecting status argument [alarm|bluetooth|wifi|battery] and value"
  10. exit
  11. fi
  12. json='{
  13. "cmd":"update",
  14. "elements": [
  15. { "type": "'"$1"'",
  16. "value": '"$2"'
  17. }
  18. ]
  19. }'
  20. echo "$json"
  21. json=$(toSingleLine "$json")
  22. mosquitto_pub -t $TOPIC -m "$json"