Difference between revisions of "Flash script linux"

From Let's Control It
Jump to navigation Jump to search
Line 6: Line 6:
 
* the local directory (with the script and firmware files)
 
* the local directory (with the script and firmware files)
  
<source lang="bash">
 
#!/bin/bash
 
  
selectst=""
+
    #!/bin/bash
for i in ESPEasy*bin
 
do
 
selectst="$i $i off $selectst"
 
done
 
  
# check for esptool
+
    selectst=""
esptoolbin=$(which esptool)
+
    for i in ESPEasy*bin
if [ ! -x "$esptoolbin" ] ; then
+
    do
if [ -x "./esptool" ] ; then
+
            selectst="$i $i off $selectst"
esptoolbin="./esptool"
+
    done
else
 
eardu=$(find $HOME/.arduino15/packages/esp8266/tools/esptool/* -name esptool|sort|tail -1)
 
if [ -x "$eardu" ] ; then
 
echo "found esptool: $eardu"
 
esptoolbin="$eardu"
 
fi
 
fi
 
fi
 
if [ ! -x "$esptoolbin" ] ; then
 
echo "esptool not found, you can link it here or put in \$PATH"
 
exit 2
 
else
 
echo "using esptool $esptoolbin"
 
fi
 
  
read -e -p "serial device, (USB2serial devices: $(ls /dev/ttyUSB*)):" -i "/dev/ttyUSB0" serdev
+
    # check for esptool
 +
    esptoolbin=$(which esptool)
 +
    if [ ! -x "$esptoolbin" ] ; then
 +
            if [ -x "./esptool" ] ; then
 +
                    esptoolbin="./esptool"
 +
            else
 +
                    eardu=$(find $HOME/.arduino15/packages/esp8266/tools/esptool/* -name esptool|sort|tail -1)
 +
                    if [ -x "$eardu" ] ; then
 +
                            echo "found esptool: $eardu"
 +
                            esptoolbin="$eardu"
 +
                    fi
 +
            fi
 +
    fi
 +
    if [ ! -x "$esptoolbin" ] ; then
 +
            echo "esptool not found, you can link it here or put in \$PATH"
 +
            exit 2
 +
    else
 +
            echo "using esptool $esptoolbin"
 +
    fi
  
if [ ! -r "$serdev" ] ; then
+
    read -e -p "serial device, (USB2serial devices: $(ls /dev/ttyUSB*)):" -i "/dev/ttyUSB0" serdev
echo "device '$serdev' does not exist"
 
exit 2
 
fi
 
  
if [ -n "$(which dialog)" ] ; then
+
    if [ ! -r "$serdev" ] ; then
cmd=(dialog --radiolist "Select firmware" 22 76 16)
+
            echo "device '$serdev' does not exist"
choice=$("${cmd[@]}" ${selectst} 2>&1 >/dev/tty)
+
            exit 2
else
+
    fi
# bash only, do it with an array
 
fa=(ESPEasy_*.bin)
 
cnt=0
 
nfa=${#fa[*]}
 
while [ $cnt -lt $nfa ]
 
do
 
echo $cnt ${fa[$cnt]}
 
                ((cnt++))
 
done
 
read -p "choose number of firmware file to flash [0-$((nfa-1))]: " nsel
 
choice=${fa[$nsel]}
 
if [ ! -f "$choice" ] ; then  
 
echo "cannot find file \"$choice\", exiting"
 
exit 2
 
fi
 
fi
 
  
echo "----"
+
    if [ -n "$(which dialog)" ] ; then
read -p "flash $choice? [Y/n]" yn
+
            cmd=(dialog --radiolist "Select firmware" 22 76 16)
if [ "$yn" != "n" ] ; then
+
            choice=$("${cmd[@]}" ${selectst} 2>&1 >/dev/tty)
    "$esptoolbin" -vv -cd nodemcu -cb 115200 -cp "$serdev" -ca 0x00000 -cf "$choice"
+
    else
fi
+
            # bash only, do it with an array
</source>
+
            fa=(ESPEasy_*.bin)
 +
            cnt=0
 +
            nfa=${#fa[*]}
 +
            while [ $cnt -lt $nfa ]
 +
            do
 +
                    echo $cnt ${fa[$cnt]}
 +
                    ((cnt++))
 +
            done
 +
            read -p "choose number of firmware file to flash [0-$((nfa-1))]: " nsel
 +
            choice=${fa[$nsel]}
 +
            if [ ! -f "$choice" ] ; then
 +
                    echo "cannot find file \"$choice\", exiting"
 +
                    exit 2
 +
            fi
 +
    fi
 +
 
 +
    echo "----"
 +
    read -p "flash $choice? [Y/n]" yn
 +
    if [ "$yn" != "n" ] ; then
 +
        "$esptoolbin" -vv -cd nodemcu -cb 115200 -cp "$serdev" -ca 0x00000 -cf "$choice"
 +
    fi

Revision as of 13:57, 26 February 2017

To flash an ESP8266 on Linux, you need the esptool as it is shipped with Arduino IDE or as standalone tool, see github [source](https://github.com/igrr/esptool-ck) and [binary releases](https://github.com/igrr/esptool-ck/releases/).

The following script tries to find the esptool binary

  • in Arduino IDE install paths
  • in a dir of the PATH variable
  • the local directory (with the script and firmware files)


   #!/bin/bash
   selectst=""
   for i in ESPEasy*bin
   do
           selectst="$i $i off $selectst"
   done
   # check for esptool
   esptoolbin=$(which esptool)
   if [ ! -x "$esptoolbin" ] ; then
           if [ -x "./esptool" ] ; then
                   esptoolbin="./esptool"
           else
                   eardu=$(find $HOME/.arduino15/packages/esp8266/tools/esptool/* -name esptool|sort|tail -1)
                   if [ -x "$eardu" ] ; then
                           echo "found esptool: $eardu"
                           esptoolbin="$eardu"
                   fi
           fi
   fi
   if [ ! -x "$esptoolbin" ] ; then
           echo "esptool not found, you can link it here or put in \$PATH"
           exit 2
   else
           echo "using esptool $esptoolbin"
   fi
   read -e -p "serial device, (USB2serial devices: $(ls /dev/ttyUSB*)):" -i "/dev/ttyUSB0" serdev
   if [ ! -r "$serdev" ] ; then
           echo "device '$serdev' does not exist"
           exit 2
   fi
   if [ -n "$(which dialog)" ] ; then
           cmd=(dialog --radiolist "Select firmware" 22 76 16)
           choice=$("${cmd[@]}" ${selectst} 2>&1 >/dev/tty)
   else
           # bash only, do it with an array
           fa=(ESPEasy_*.bin)
           cnt=0
           nfa=${#fa[*]}
           while [ $cnt -lt $nfa ]
           do
                   echo $cnt ${fa[$cnt]}
                   ((cnt++))
           done
           read -p "choose number of firmware file to flash [0-$((nfa-1))]: " nsel
           choice=${fa[$nsel]}
           if [ ! -f "$choice" ] ; then 
                   echo "cannot find file \"$choice\", exiting"
                   exit 2
           fi
   fi
   echo "----"
   read -p "flash $choice? [Y/n]" yn
   if [ "$yn" != "n" ] ; then
       "$esptoolbin" -vv -cd nodemcu -cb 115200 -cp "$serdev" -ca 0x00000 -cf "$choice"
   fi