ESP8266/Programmer

Aus C3MAWiki
Version vom 17. April 2015, 17:41 Uhr von Ollo (Diskussion | Beiträge) (Programmer)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

ESP8266 Programmer

Mit diesem Tool können lua Dateien auf einen ESP gespielt werden.

Interface

  • Seriell
  • TCP

Beispiel

Beamer mit neuer Lokig bespielen

 ./programESP.sh 10.23.xx.xx beamer_init.lua init.lua

Paanik wir können nur noch über die Serielle Schnittstelle mit dem ESP reden:

sudo ./programESP.sh serial beamer_init.lua init.lua

Quellcode

#!/bin/bash

DEVICE=/dev/ttyUSB0
SLEEPTIME=0.2
TCPPORT=2323

function usage() {
  echo "$0 usage:"
  echo "$0 serial|ip fileOnHost.lua (fileOnESP.lua)"
  echo ""
  echo "The flash logic can be done via ethernet or serial"
  echo "The first filename is mandatory!"
  echo ""
  echo "The second filename is the filename on the LUA devic."
  echo ""
  echo "Example:"
  echo -e "$0 serial hello.txt\tSends the content of hello.txt to the ESP (directly as if you type it)"
  echo -e "$0 serial init_example.lua init.lua\tUpdates the init.lua on the ESP"
  echo "   (The init.lua file is executed each time, the ESP starts)"
  exit 1
}

case "$1" in
serial)
  IP=""
  if [ "$EUID" -ne 0 ]
    then echo "Please run as root"
    exit 1
  fi
  ;;

*)
  if [[ $1 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]];then
    IP=$1
  else
    usage
  fi
esac


if [ ! -f $2 ]; then
 usage
fi

if [ $IP != "" ]; then
    echo "Using network: $IP "
    echo "Checking connection ..."
    ping -c 3 $IP >> /dev/null
    if [ $? -ne 0 ]; then
      echo "Cannot find ESP at $IP"
      exit 1
    fi
    DEVICE=/dev/tcp/$IP/$TCPPORT
fi

# The flashing logic
if [ "$3" == "" ]; then
  echo "Sending to shell..."
  cat $2  | while read a; do echo -e "$a\r" >> $DEVICE; echo -e "$a"; sleep $SLEEPTIME; done
else
  echo "Writing $3 on the ESP"
  echo "========================="
  echo "" >> $DEVICE; sleep $SLEEPTIME
  echo "file.open(\"$3\",\"w\")" >> $DEVICE; sleep $SLEEPTIME
  cat $2 | while read a; do echo "file.writeline([[${a}]])" >> $DEVICE; echo -e "\r" >> $DEVICE; echo "$a"; sleep $SLEEPTIME; done
  # Close the init file
  echo "file.close()" >> $DEVICE; sleep $SLEEPTIME
  echo "========================="
  echo "now login on ESP and call"
  echo "node.restart()"
fi