diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0d20b64..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pyc diff --git a/esp8266/boot.py b/esp8266/boot.py index f5a6c1a..abe5771 100644 --- a/esp8266/boot.py +++ b/esp8266/boot.py @@ -1,32 +1,19 @@ -import uConfigParser -import gc -import webrepl - -def do_connect(ssid, key): +def do_connect(): import network - import gc wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') - wlan.connect(ssid, key) + wlan.connect("MIPS", "importthis") while not wlan.isconnected(): pass print('network config:', wlan.ifconfig()) - gc.collect() +do_connect() -config_obj = uConfigParser.ConfigParser() -config_obj.read('config.ini') -config = config_obj.config_dict -if config_obj.has_option('DEFAULT','ssid') and config_obj.has_option('DEFAULT','key'): - do_connect(config['DEFAULT']['ssid'], config['DEFAULT']['key']) -else: - do_connect() -if config_obj.has_option('DEFAULT','webrepl_passwd'): - webrepl.start(password=config['DEFAULT']['webrepl_passwd']) -else: - webrepl.start() +import gc +import webrepl +webrepl.start() gc.collect() diff --git a/esp8266/config.ini b/esp8266/config.ini index ff30337..e69de29 100644 --- a/esp8266/config.ini +++ b/esp8266/config.ini @@ -1,16 +0,0 @@ -[DEFAULT] - -ssid = HODOR - -key = holdthedoor - -webrepl_passwd = HODOR - -[DOOR_WS] - -url = http://hold.the.door/hodor - -method = POST - -param1 = HODOR -param2 = HoldTheDoor diff --git a/esp8266/main.py b/esp8266/main.py index eeb35a5..aefe102 100644 --- a/esp8266/main.py +++ b/esp8266/main.py @@ -1,52 +1,13 @@ from machine import Pin -import urequests as requests +from urequests import get from time import sleep_ms from gc import collect -from uConfigParser import ConfigParser - -config_obj = ConfigParser() -config_obj.read('config.ini') -config = config_obj.config_dict pin = Pin(2, Pin.IN) pin_value = pin.value() while True: current_value = pin.value() if pin_value != current_value: - for section in config_obj.sections(): - if config_obj.has_option(section, 'url'): - try: - url = config[section]['url'] - method = config[section]['method'] - - except: - print("error when read section %s in config file" % section) - else: - continue - data = {option:config[section][option] for option in config_obj.options(section)} - del data['url'] - del data['method'] - print(data) - try: - if method == "GET": - print('GET') - if data : - r = requests.get(url, data=data) - else: - r = requests.get(url) - elif method == "POST": - print('POST') - if data: - r = requests.post(url, data=data) - else: - r = requests.post(url) - except: - print(url) - requests.get(url) - print("UNKNOWN ERROR") - continue - print("close") - r.close() - print("closed") + get('http://192.168.44.174:6543/value/%s' % current_value) pin_value = current_value collect() diff --git a/esp8266/uConfigParser.py b/esp8266/uConfigParser.py index 9f3e889..e44a337 100644 --- a/esp8266/uConfigParser.py +++ b/esp8266/uConfigParser.py @@ -4,8 +4,8 @@ class ConfigParser: def sections(self): """Return a list of section names, excluding [DEFAULT]""" - to_return = [section for section in self.config_dict.keys() if not section in "DEFAULT"] - return to_return + dict_to_return = [section for section in self.config_dict.keys() if not section in "DEFAULT"] + return dict_to_return def add_section(self, section): """Create a new section in the configuration.""" @@ -18,13 +18,6 @@ class ConfigParser: else: return False - def add_option(self, section, option): - """Create a new option in the configuration.""" - if self.has_section(section) and not option in self.config_dict[section]: - self.config_dict[section][option] = None - else: - raise - def options(self, section): """Return a list of option names for the given section name.""" if not section in self.config_dict: @@ -63,7 +56,7 @@ class ConfigParser: end_index = None else: end_index = block.index(end_flag[0]) - values = [value.split('=',1)[-1].strip() for value in block[start_index:end_index] if value] + values = [value.split('=')[-1].strip() for value in block[start_index:end_index] if value] if not values: values = None elif len(values) == 1: