enable method in get/post data

This commit is contained in:
Michaël Ricart 2018-03-09 00:09:59 +01:00
parent 4ca6158807
commit 15a27bc8ff
2 changed files with 32 additions and 5 deletions

View file

@ -1,7 +1,16 @@
[DEFAULT]
ssid = MIPS
ssid = HODOR
key = importthis
key = holdthedoor
webrepl_passwd = totocaca
webrepl_passwd = HODOR
[DOOR_WS]
url = http://hold.the.door/hodor
method = POST
param1 = HODOR
param2 = HoldTheDoor

View file

@ -1,13 +1,31 @@
from machine import Pin
from urequests import get
from urequests import get, post
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:
get('http://192.168.44.174:6543/value/%s' % 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) if not 'url' in option or not "method" in option}
if method == "POST":
post(url, **data)
elif method == "GET":
get(url, **data)
pin_value = current_value
collect()