Compare commits
No commits in common. "master" and "4-enable-comments-feature" have entirely different histories.
master
...
4-enable-c
5 changed files with 11 additions and 87 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
*.pyc
|
|
|
@ -1,32 +1,19 @@
|
||||||
import uConfigParser
|
def do_connect():
|
||||||
import gc
|
|
||||||
import webrepl
|
|
||||||
|
|
||||||
def do_connect(ssid, key):
|
|
||||||
import network
|
import network
|
||||||
import gc
|
|
||||||
wlan = network.WLAN(network.STA_IF)
|
wlan = network.WLAN(network.STA_IF)
|
||||||
wlan.active(True)
|
wlan.active(True)
|
||||||
if not wlan.isconnected():
|
if not wlan.isconnected():
|
||||||
print('connecting to network...')
|
print('connecting to network...')
|
||||||
wlan.connect(ssid, key)
|
wlan.connect("MIPS", "importthis")
|
||||||
while not wlan.isconnected():
|
while not wlan.isconnected():
|
||||||
pass
|
pass
|
||||||
print('network config:', wlan.ifconfig())
|
print('network config:', wlan.ifconfig())
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
|
do_connect()
|
||||||
|
|
||||||
config_obj = uConfigParser.ConfigParser()
|
import gc
|
||||||
config_obj.read('config.ini')
|
import webrepl
|
||||||
config = config_obj.config_dict
|
webrepl.start()
|
||||||
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()
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
|
@ -1,52 +1,13 @@
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
import urequests as requests
|
from urequests import get
|
||||||
from time import sleep_ms
|
from time import sleep_ms
|
||||||
from gc import collect
|
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 = Pin(2, Pin.IN)
|
||||||
pin_value = pin.value()
|
pin_value = pin.value()
|
||||||
while True:
|
while True:
|
||||||
current_value = pin.value()
|
current_value = pin.value()
|
||||||
if pin_value != current_value:
|
if pin_value != current_value:
|
||||||
for section in config_obj.sections():
|
get('http://192.168.44.174:6543/value/%s' % current_value)
|
||||||
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")
|
|
||||||
pin_value = current_value
|
pin_value = current_value
|
||||||
collect()
|
collect()
|
||||||
|
|
|
@ -4,8 +4,8 @@ class ConfigParser:
|
||||||
|
|
||||||
def sections(self):
|
def sections(self):
|
||||||
"""Return a list of section names, excluding [DEFAULT]"""
|
"""Return a list of section names, excluding [DEFAULT]"""
|
||||||
to_return = [section for section in self.config_dict.keys() if not section in "DEFAULT"]
|
dict_to_return = [section for section in self.config_dict.keys() if not section in "DEFAULT"]
|
||||||
return to_return
|
return dict_to_return
|
||||||
|
|
||||||
def add_section(self, section):
|
def add_section(self, section):
|
||||||
"""Create a new section in the configuration."""
|
"""Create a new section in the configuration."""
|
||||||
|
@ -18,13 +18,6 @@ class ConfigParser:
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
def options(self, section):
|
||||||
"""Return a list of option names for the given section name."""
|
"""Return a list of option names for the given section name."""
|
||||||
if not section in self.config_dict:
|
if not section in self.config_dict:
|
||||||
|
@ -63,7 +56,7 @@ class ConfigParser:
|
||||||
end_index = None
|
end_index = None
|
||||||
else:
|
else:
|
||||||
end_index = block.index(end_flag[0])
|
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:
|
if not values:
|
||||||
values = None
|
values = None
|
||||||
elif len(values) == 1:
|
elif len(values) == 1:
|
||||||
|
|
Loading…
Reference in a new issue