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.

63 lines
1.6 KiB

  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>"
  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 1 ]; then
  39. help
  40. exit 1
  41. fi
  42. device=$1-device
  43. # Get IP
  44. topic=`cat platformio.ini | grep $device -A 10 | grep "topic" | cut -d' ' -f3`
  45. if [ "$topic" == "" ]; then
  46. echo "Unknown device $device or topic not defined"
  47. devices
  48. exit 2
  49. fi
  50. ip=`mosquitto_sub -t $topic -h $MQTT_HOST -N -C 1`
  51. if valid_ip $ip; then
  52. echo "Could not get a valid IP from MQTT broker"
  53. exit 3
  54. fi
  55. platformio run -vv -e $device --target upload --upload-port $ip