Extract IP address for telnet server from MQTT
This commit is contained in:
parent
d309315e28
commit
621cef2ab5
@ -1,38 +1,46 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
IP=$1
|
MQTTSERVER=$1
|
||||||
|
MQTTPREFIX=$2
|
||||||
|
|
||||||
FLASHTOOL=./tools/tcpFlash.py
|
FLASHTOOL=./tools/tcpFlash.py
|
||||||
|
|
||||||
|
UPGRADEPREP=/tmp/upgradeCMD4clock.txt
|
||||||
|
|
||||||
if [ ! -f $FLASHTOOL ]; then
|
if [ ! -f $FLASHTOOL ]; then
|
||||||
echo "Execute the script in root folder of the project"
|
echo "Execute the script in root folder of the project"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$IP" == "" ]; then
|
if [[ "$MQTTPREFIX" == "" ]] || [[ "$MQTTSERVER" == "" ]]; then
|
||||||
echo "IP address of ESP required"
|
echo "MQTTSERVER: ip address to mqtt server"
|
||||||
|
echo "MQTTPREFIX: configured prefex in MQTT of ESP required"
|
||||||
echo "usage:"
|
echo "usage:"
|
||||||
echo "$0 <IP>"
|
echo "$0 <MQTTSERVER> <MQTTPREFIX>"
|
||||||
echo "$0 192.168.0.2"
|
echo "$0 192.168.0.2 basetopic"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check the connection
|
# check the connection
|
||||||
echo "Searching $IP ..."
|
echo "Searching $MQTTPREFIX ..."
|
||||||
ping $IP -c 2 >> /dev/null
|
mosquitto_sub -h $MQTTSERVER -t "$MQTTPREFIX/#" -C 1 -v
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Entered IP address: $IP is NOT online"
|
echo "Entered Wordclock address: $MQTTPREFIX on $MQTTSERVER is NOT online"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
echo "Upgrading $IP"
|
echo "Activate Telnet server"
|
||||||
|
mosquitto_pub -h $MQTTSERVER -t "$MQTTPREFIX/cmd/telnet" -m "a"
|
||||||
|
TELNETIP=$(mosquitto_sub -h $MQTTSERVER -t "$MQTTPREFIX/telnet" -C 1)
|
||||||
|
echo "Upgrading $MQTTPREFIX via telenet on $TELNETIP"
|
||||||
|
|
||||||
echo "stopWordclock()" > /tmp/wordClockCMD.txt
|
echo "stopWordclock()" > $UPGRADEPREP
|
||||||
echo "uart.write(0, tostring(node.heap())" >> /tmp/wordClockCMD.txt
|
echo "uart.write(0, tostring(node.heap())" >> $UPGRADEPREP
|
||||||
echo "c = string.char(0,0,128)" >> /tmp/wordClockCMD.txt
|
echo "c = string.char(0,0,128)" >> $UPGRADEPREP
|
||||||
echo "w = string.char(0,0,0)" >> /tmp/wordClockCMD.txt
|
echo "w = string.char(0,0,0)" >> $UPGRADEPREP
|
||||||
echo "ws2812.write(w:rep(4) .. c .. w:rep(15) .. c .. w:rep(9) .. c .. w:rep(30) .. c .. w:rep(41) .. c )" >> /tmp/wordClockCMD.txt
|
echo "ws2812.write(w:rep(4) .. c .. w:rep(15) .. c .. w:rep(9) .. c .. w:rep(30) .. c .. w:rep(41) .. c )" >> $UPGRADEPREP
|
||||||
$FLASHTOOL -f /tmp/wordClockCMD.txt -t $IP -v
|
$FLASHTOOL -f $UPGRADEPREP -t $TELNETIP -v
|
||||||
|
|
||||||
|
exit 2
|
||||||
FILES="displayword.lua main.lua timecore.lua webpage.html webserver.lua wordclock.lua init.lua"
|
FILES="displayword.lua main.lua timecore.lua webpage.html webserver.lua wordclock.lua init.lua"
|
||||||
|
|
||||||
echo "Start Flasing ..."
|
echo "Start Flasing ..."
|
||||||
@ -43,7 +51,7 @@ for f in $FILES; do
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "------------- $f ------------"
|
echo "------------- $f ------------"
|
||||||
$FLASHTOOL -t $IP -f $f
|
$FLASHTOOL -t $TELNETIP -f $f
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "STOOOOP"
|
echo "STOOOOP"
|
||||||
exit 1
|
exit 1
|
||||||
@ -51,6 +59,6 @@ for f in $FILES; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "TODO: Reboot the ESP"
|
echo "TODO: Reboot the ESP"
|
||||||
#echo "node.restart()" | nc $IP 80
|
#echo "node.restart()" | nc $TELNETIP 23
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user