Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #!/bin/bash
  2. #
  3. # ESPurna Deploy Script
  4. #
  5. # Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. MQTT_HOST=192.168.1.10
  21. function help() {
  22. echo "Syntax: $0 <device> <target>"
  23. devices
  24. }
  25. function devices() {
  26. echo "Defined devices:"
  27. cat platformio.ini | grep 'device]' | sed 's/\[env:/ - /g' | sed 's/\-device]//g'
  28. }
  29. function valid_ip() {
  30. local stat=0
  31. rx='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
  32. if [[ $ip =~ ^$rx\.$rx\.$rx\.$rx$ ]]; then
  33. stat=1
  34. fi
  35. return $stat
  36. }
  37. # Check arguments
  38. if [ "$#" -ne 2 ]; then
  39. help
  40. exit 1
  41. fi
  42. device=$1-device
  43. target=$2
  44. # Get IP
  45. topic=`cat platformio.ini | grep $device -A 2 | grep "topic" | cut -d' ' -f3`
  46. if [ "$topic" == "" ]; then
  47. echo "Unknown device $device or topic not defined"
  48. devices
  49. exit 2
  50. fi
  51. ip=`mosquitto_sub -t $topic -h $MQTT_HOST -N -C 1`
  52. if valid_ip $ip; then
  53. echo "Could not get a valid IP from MQTT broker"
  54. exit 3
  55. fi
  56. platformio run -vv -e $device --target $target --upload-port $ip