Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/bin/ash
  2. # MQTT SETTINGS
  3. host="broker.shiftr.io"
  4. user="<user>"
  5. password="<password>"
  6. port=1883
  7. topic="<topic>"
  8.  
  9. #ONION OMEGA2 GPIO PID SETTING
  10. io_pid=0
  11. gpioctl dirout $io_pid > /dev/null
  12.  
  13. p="backpipe"
  14.  
  15. ctrl_c() {
  16. echo "Cleaning up..."
  17. pid=$(cat pidfile)
  18. rm -f $p;rm cmds;rm pidfile;kill $pid 2>/dev/null
  19. if [[ "$?" -eq "0" ]];
  20. then
  21. echo "Exit success";exit 0
  22. else
  23. exit 1
  24. fi
  25. }
  26.  
  27.  
  28. listen(){
  29. ([ ! -p "$p" ]) && mkfifo $p
  30. (mosquitto_sub -h $host -u $user -P $password -p $port -t $topic >$p) &
  31. echo "$!" > pidfile
  32. while read line <$p
  33. do
  34. echo $line > cmds
  35. if grep -q "toogle" cmds; then
  36. gpioctl dirout-high 0 > /dev/null && sleep 1 && gpioctl dirout-low 0 > /dev/null
  37. fi
  38. done
  39. }
  40.  
  41. trap ctrl_c INT
  42. listen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement