mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
converted all commands to python
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
wifi.txt
|
||||
__pycache__
|
||||
wificonfig.py
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source configlib
|
||||
|
||||
cd ..
|
||||
$BUILDCMD
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
./build $1
|
||||
./flash $1
|
||||
./serial $1
|
||||
+1
-1
@@ -3,7 +3,7 @@ units=[
|
||||
'type' : 'wemos d1 mini v2.2.0',
|
||||
'port' : '/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.4.4:1.0-port0',
|
||||
'ip' : '192.168.13.91',
|
||||
'flash_cmd' : 'esptool.py --port $SERIAL1 -b 1500000 write_flash 0x0 .pioenvs/dev_4096/firmware.bin --flash_size=32m -p',
|
||||
'flash_cmd' : 'esptool.py --port {port} -b 1500000 write_flash 0x0 .pioenvs/dev_4096/firmware.bin --flash_size=32m -p',
|
||||
'build_cmd' : 'platformio run --environment dev_4096'
|
||||
},
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
TYPE1="wemos d1 mini v2.2.0"
|
||||
SERIAL1=/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.4.4:1.0-port0
|
||||
IP1=192.168.13.91
|
||||
FLASHCMD1="esptool.py --port $SERIAL1 -b 1500000 write_flash 0x0 .pioenvs/dev_4096/firmware.bin --flash_size=32m -p"
|
||||
BUILDCMD1="platformio run --environment dev_4096"
|
||||
|
||||
TYPE2="geekcreit ESP12E devkit v2"
|
||||
SERIAL2=/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.4.3:1.0-port0
|
||||
IP2=192.168.13.92
|
||||
FLASHCMD2="esptool.py --port $SERIAL2 -b 1500000 write_flash 0x0 .pioenvs/dev_4096/firmware.bin --flash_size=32m -p"
|
||||
#FLASHCMD2="platformio run --environment dev_4096 -t upload --upload-port $SERIAL2"
|
||||
BUILDCMD2="platformio run --environment dev_4096"
|
||||
|
||||
|
||||
TYPE3="esp-12-f"
|
||||
SERIAL3=/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.4.2:1.0-port0
|
||||
IP3=192.168.13.93
|
||||
FLASHCMD3="esptool.py --port $SERIAL3 -b 1500000 write_flash 0x0 .pioenvs/dev_4096/firmware.bin --flash_size=32m -p"
|
||||
BUILDCMD3="platformio run --environment dev_4096"
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
source config.txt
|
||||
|
||||
#auto assign specified unit number to default variables
|
||||
|
||||
UNIT=$1
|
||||
|
||||
if [ "$UNIT" ]; then
|
||||
V="TYPE$UNIT"
|
||||
TYPE=${!V}
|
||||
|
||||
V="SERIAL$UNIT"
|
||||
SERIAL=${!V}
|
||||
|
||||
V="IP$UNIT"
|
||||
IP=${!V}
|
||||
|
||||
V="FLASHCMD$UNIT"
|
||||
FLASHCMD="${!V}"
|
||||
|
||||
V="BUILDCMD$UNIT"
|
||||
BUILDCMD="${!V}"
|
||||
|
||||
echo "Using unit $UNIT at $IP ($TYPE)"
|
||||
else
|
||||
echo "Please specify unit number"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source configlib
|
||||
|
||||
esptool.py --port $SERIAL -b 1500000 erase_flash
|
||||
|
||||
+40
-11
@@ -11,25 +11,25 @@ def log(txt):
|
||||
class Esp():
|
||||
def __init__(self, config):
|
||||
print("Using unit {unit} ({type}) with ip {ip}".format(**config))
|
||||
self.config=config
|
||||
self.serial=serial.Serial(port=config['port'], baudrate=115200, timeout=1, write_timeout=1)
|
||||
self._config=config
|
||||
self._serial=serial.Serial(port=config['port'], baudrate=115200, timeout=1, write_timeout=1)
|
||||
|
||||
|
||||
|
||||
def pingserial(self, timeout=60):
|
||||
"""waits until espeasy reponds via serial"""
|
||||
self.serial.reset_input_buffer();
|
||||
self._serial.reset_input_buffer();
|
||||
log("Waiting for serial response: ")
|
||||
start_time=time.time()
|
||||
|
||||
while (time.time()-start_time)< int(timeout):
|
||||
self.serial.write(bytes('\n', 'ascii'));
|
||||
self._serial.write(bytes('\n', 'ascii'));
|
||||
a=True
|
||||
while a!=b'':
|
||||
a=self.serial.readline()
|
||||
a=self._serial.readline()
|
||||
if a==b"Unknown command!\r\n":
|
||||
log("OK\n")
|
||||
self.serial.reset_input_buffer();
|
||||
self._serial.reset_input_buffer();
|
||||
return
|
||||
log(".")
|
||||
|
||||
@@ -38,9 +38,9 @@ class Esp():
|
||||
|
||||
def reboot(self):
|
||||
'''reboot the esp via the serial DTR line'''
|
||||
self.serial.setDTR(0)
|
||||
self._serial.setDTR(0)
|
||||
time.sleep(0.1)
|
||||
self.serial.setDTR(1)
|
||||
self._serial.setDTR(1)
|
||||
|
||||
|
||||
def pingwifi(self, timeout=60):
|
||||
@@ -51,7 +51,7 @@ class Esp():
|
||||
|
||||
while (time.time()-start_time)< int(timeout):
|
||||
log(".")
|
||||
if not subprocess.call(["ping", "-w", "1", "-c", "1", self.config['ip']], stdout=subprocess.DEVNULL):
|
||||
if not subprocess.call(["ping", "-w", "1", "-c", "1", self._config['ip']], stdout=subprocess.DEVNULL):
|
||||
log("OK\n")
|
||||
return
|
||||
|
||||
@@ -60,8 +60,37 @@ class Esp():
|
||||
|
||||
def wificonfig(self, timeout=60):
|
||||
"""configure wifi via serial and make sure esp is online and pingable."""
|
||||
|
||||
self.pingserial(timeout=timeout)
|
||||
|
||||
serial_str="wifissid {ssid}\nwifikey {password}\nip {ip}\nsave\nreboot\n".format(ssid=wificonfig.ssid, password=wificonfig.password, ip=self.config['ip'])
|
||||
self.serial.write(bytes(serial_str, 'ascii'));
|
||||
serial_str="wifissid {ssid}\nwifikey {password}\nip {ip}\nsave\nreboot\n".format(ssid=wificonfig.ssid, password=wificonfig.password, ip=self._config['ip'])
|
||||
self._serial.write(bytes(serial_str, 'ascii'));
|
||||
|
||||
self.pingwifi(timeout=timeout)
|
||||
|
||||
|
||||
def build(self):
|
||||
"""compile binary"""
|
||||
|
||||
subprocess.check_call(self._config['build_cmd'].format(**self._config), shell=True, cwd='..')
|
||||
|
||||
|
||||
def flashserial(self):
|
||||
"""flash binary to esp via serial"""
|
||||
|
||||
self.pingserial()
|
||||
|
||||
subprocess.check_call(self._config['flash_cmd'].format(**self._config), shell=True, cwd='..')
|
||||
|
||||
#to prevent hangs when ESPEasy tries to reboot via ESP.reboot (due to an ESP/lib bug)
|
||||
self.reboot()
|
||||
|
||||
|
||||
def serial(self):
|
||||
"""open serial terminal to esp"""
|
||||
subprocess.check_call("platformio serialports monitor --baud 115200 --port {port} --echo".format(**self._config), shell=True, cwd='..')
|
||||
|
||||
|
||||
def erase(self):
|
||||
"""erase flash"""
|
||||
subprocess.check_call("esptool.py --port {port} -b 1500000 erase_flash".format(**self._config), shell=True, cwd='..')
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source configlib
|
||||
|
||||
pushd .. >/dev/null
|
||||
$FLASHCMD
|
||||
popd > /dev/null
|
||||
|
||||
#to prevent hangs when ESPEasy tries to reboot (due to an ESP/lib bug)
|
||||
./reboot $UNIT
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source configlib
|
||||
|
||||
./pingserial.py $SERIAL
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# from __future__ import print_function
|
||||
|
||||
import serial
|
||||
import sys
|
||||
import time
|
||||
|
||||
#wait until ESPEasy is booted and ready
|
||||
|
||||
s=serial.Serial(port=sys.argv[1], baudrate=115200, timeout=1, write_timeout=1)
|
||||
|
||||
s.reset_input_buffer();
|
||||
sys.stdout.write("Waiting for serial response from ESPEASY: ")
|
||||
sys.stdout.flush()
|
||||
|
||||
while 1:
|
||||
s.write("\n");
|
||||
a=True
|
||||
while a!="":
|
||||
a=s.readline()
|
||||
if a=="Unknown command!\r\n":
|
||||
print("OK")
|
||||
s.reset_input_buffer();
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.stdout.write(".")
|
||||
sys.stdout.flush()
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source configlib
|
||||
|
||||
platformio serialports monitor --baud 115200 --port $SERIAL --echo;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
|
||||
|
||||
source configlib
|
||||
source wifi.txt
|
||||
|
||||
./pingserial $UNIT
|
||||
|
||||
echo "
|
||||
wifissid $WIFI_SSID
|
||||
wifikey $WIFI_PASS
|
||||
ip $IP
|
||||
save
|
||||
reboot
|
||||
" > $SERIAL
|
||||
|
||||
echo -n "Waiting for unit $UNIT to connect: "
|
||||
sleep 1
|
||||
trap "exit 1" SIGINT
|
||||
|
||||
while ! ping -w 1 -c 1 $IP &>/dev/null; do
|
||||
echo -n "."
|
||||
done
|
||||
|
||||
echo "ONLINE"
|
||||
Reference in New Issue
Block a user