enable method in get/post data
This commit is contained in:
parent
4ca6158807
commit
15a27bc8ff
2 changed files with 32 additions and 5 deletions
|
@ -1,7 +1,16 @@
|
||||||
[DEFAULT]
|
[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
|
||||||
|
|
|
@ -1,13 +1,31 @@
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
from urequests import get
|
from urequests import get, post
|
||||||
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:
|
||||||
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
|
pin_value = current_value
|
||||||
collect()
|
collect()
|
||||||
|
|
Loading…
Reference in a new issue