from machine import Pin import urequests as requests 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") pin_value = current_value collect()