def __init__(self, config_file):
     self.sta_if = network.WLAN(network.STA_IF)
     print('network is active: ', self.sta_if.active())
     self.sta_if.active(True)
     self.ini = uini()
     self.config_file = config_file
     self.load_config()
 def __init__(self, ipaddr, conn):
     """
     TODO minor: 0 duty after reset becomes 1
     """
     self.ipaddr = ipaddr
     self.sdata = socket_data()
     self.duty0 = p0.duty() * 100 // 1024 + 1  # 10
     self.duty1 = p1.duty() * 100 // 1024 + 1  # 10
     self.conn = conn
     self.last_conn_check = 0
     self.ini = uini()
 def __init__(self, ipaddr, conn):
     """
     TODO_: after reset duties change, are actually lower than should be
     """
     self.ipaddr = ipaddr
     self.sdata = socket_data()
     self.duty0 = 0  # p0.duty() * 100 // 1024 + 1  # 10
     self.duty1 = 0  # p1.duty() * 100 // 1024 + 1  # 10
     self.conn = conn
     self.last_conn_check = 0
     self.ini = uini()
def main():
    """runs main script"""
    # loads config
    ini = uini()
    startup_config = {
        'duties': [5, 5, 0, 0],
    }
    startup_config.update(ini.read("startup.json"))
    print(' using config: ', startup_config)

    # returns LEDs to previous state
    print(' returning LEDs to previous state')
    # p0.duty(startup_config['duties'][0] * 1023 // 100)
    # p1.duty(startup_config['duties'][1] * 1023 // 100)

    # p0.duty(math.trunc((math.pow(10, (startup_config['duties'][0] / 50 - 1)) * 10 / 9.9 - 0.1) * 102.3))
    # p1.duty(math.trunc((math.pow(10, (startup_config['duties'][1] / 50 - 1)) * 10 / 9.9 - 0.1) * 102.3))

    p0.duty(
        math.trunc((math.pow(math.e, (startup_config['duties'][0] / 50 - 1))) *
                   435.2 - 160.3))
    p1.duty(
        math.trunc((math.pow(math.e, (startup_config['duties'][1] / 50 - 1))) *
                   435.2 - 160.3))

    # touch_reset check timer
    # timer1 = machine.Timer(-1)
    # timer1.init(period=1000, mode=machine.Timer.PERIODIC, callback=cb_reset_check)

    # starts server
    print('initiating network connection')
    global conn
    conn = network_conn('conf.json')
    conn.connect2()
    global server1
    # server1 = socket_server(conn.ipaddr, conn)
    server1 = SocketServerNonblocking(conn.ipaddr, conn)
    server1.write_duties(startup_config['duties'])
    server1.start(config['timeout'])
    server1.listen_indef()
        return conn_status

    def close(self):
        print('disconnecting network...')
        self.sta_if.disconnect()
        print('network connected: ', self.check_conn())
        psig.duty(0)


# global variables:
config = {
    'rst_threshold': 200,
    'pwm_freq': 5000,
    'timeout': 20,
}
config.update(uini().read("conf.json"))

pwm_freq = config['pwm_freq']
psig = machine.PWM(machine.Pin(2), freq=pwm_freq)
psig.duty(100)
p0 = machine.PWM(machine.Pin(12), freq=pwm_freq)
p1 = machine.PWM(machine.Pin(14), freq=pwm_freq)
p0.duty(10 * 1023 // 100)
p1.duty(10 * 1023 // 100)
touch_reset = machine.TouchPad(machine.Pin(32))
watchdog = machine.WDT(timeout=config['timeout'] * 2 * 1000)


def net_conn():
    """
    connect to network function