mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
esptesting framework
This commit is contained in:
@@ -1 +1,2 @@
|
||||
wifi.txt
|
||||
__pycache__
|
||||
|
||||
+34
-1
@@ -1,6 +1,8 @@
|
||||
import serial
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
import wificonfig
|
||||
|
||||
def log(txt):
|
||||
print(txt, end="", flush=True)
|
||||
@@ -15,7 +17,7 @@ class Esp():
|
||||
|
||||
|
||||
def pingserial(self, timeout=60):
|
||||
"""send enters until espeasy responds"""
|
||||
"""waits until espeasy reponds via serial"""
|
||||
self.serial.reset_input_buffer();
|
||||
log("Waiting for serial response: ")
|
||||
start_time=time.time()
|
||||
@@ -32,3 +34,34 @@ class Esp():
|
||||
log(".")
|
||||
|
||||
raise(Exception("Timeout!"))
|
||||
|
||||
|
||||
def reboot(self):
|
||||
'''reboot the esp via the serial DTR line'''
|
||||
self.serial.setDTR(0)
|
||||
time.sleep(0.1)
|
||||
self.serial.setDTR(1)
|
||||
|
||||
|
||||
def pingwifi(self, timeout=60):
|
||||
"""waits until espeasy reponds via wifi"""
|
||||
|
||||
log("Waiting for wifi response: ")
|
||||
start_time=time.time()
|
||||
|
||||
while (time.time()-start_time)< int(timeout):
|
||||
log(".")
|
||||
if not subprocess.call(["ping", "-w", "1", "-c", "1", self.config['ip']], stdout=subprocess.DEVNULL):
|
||||
log("OK\n")
|
||||
return
|
||||
|
||||
raise(Exception("Timeout!"))
|
||||
|
||||
|
||||
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'));
|
||||
self.pingwifi(timeout=timeout)
|
||||
|
||||
+3
-2
@@ -5,8 +5,9 @@ import json
|
||||
import sys
|
||||
import config
|
||||
import esp
|
||||
import pydoc
|
||||
|
||||
parser = argparse.ArgumentParser(description='ESPEasy testing framework')
|
||||
parser = argparse.ArgumentParser(description='ESPEasy testing framework', epilog=pydoc.render_doc(esp.Esp), formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
|
||||
# parser.add_argument('--url', default='http://localhost:8080/rpc', help='url of rpc server to connect to. default: %(default)s')
|
||||
# parser.add_argument('--user', default=None, help='user to login.')
|
||||
@@ -17,7 +18,7 @@ parser = argparse.ArgumentParser(description='ESPEasy testing framework')
|
||||
# parser.add_argument('--short', action='store_true', help='return short single-line JSON output (for scripting)')
|
||||
# parser.add_argument('--verbose', action='store_true', help='request verbose mode (module help output)')
|
||||
# parser.add_argument('--insecure', action='store_true', help='dont verify SSL certificates. (use with self-signed certificates)')
|
||||
parser.add_argument('command', nargs=1, help='esptest command to run')
|
||||
parser.add_argument('command', nargs=1, help='Function from the Esp class to run (help below)')
|
||||
parser.add_argument('unit', type=int,nargs=1, help='Unit number (from config)')
|
||||
parser.add_argument('params', default=[], nargs='*', help='command parameters. in foo=bar form ')
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
source configlib
|
||||
|
||||
./reboot.py $SERIAL
|
||||
@@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import serial
|
||||
import sys
|
||||
import time
|
||||
|
||||
p=serial.Serial(sys.argv[1])
|
||||
|
||||
p.setDTR(0)
|
||||
time.sleep(0.1)
|
||||
p.setDTR(1)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ssid="yourssid"
|
||||
password="yourpassword"
|
||||
Reference in New Issue
Block a user