# Path: mqtt_as/config.py
# def ledfunc(pin):
#     def func(v):
# def ledfunc(led, init):
#     def func(v):


import gc
import ubinascii
import uasyncio as asyncio
import usocket as socket
import ustruct as struct
from mqtt_as import MQTTClient, config
from machine import Pin, unique_id, freq
from network import WLAN, STA_IF, AP_IF
from syncom import SynCom
from status_values import *  # Numeric status values shared with user code.
            elif command == SUBSCRIBE:
                await client.subscribe(s[1], int(s[2]))
                client.subscriptions[s[1]] = int(s[2])  # re-subscribe after outage
            elif command == MEM:
                gc.collect()
                gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
                self.send(argformat(MEM, gc.mem_free(), gc.mem_alloc()))
            elif command == TIME:
                t = await client.get_time()
                self.send(argformat(TIME, t))
            else:
                self.send(argformat(STATUS, UNKNOWN, 'Unknown command:', istr))

# Runs when channel has synchronised. No return: Pyboard resets ESP on fail.
# Get parameters from Pyboard. Process them. Connect. Instantiate client. Start
# from_pyboard() task. Wait forever, updating connected status.
    async def main_task(self, _):
        got_params = False
        # Await connection parameters (init record)
        while not got_params:
            istr = await self.await_obj(100)
            ilst = istr.split(SEP)
            command = ilst[0]
            if command == 'init':
                got_params = True
                ssid, pw, broker, mqtt_user, mqtt_pw, ssl_params = ilst[1:7]
                use_default = bool(int(ilst[7]))
                fast = bool(int(ilst[10]))
                debug = bool(int(ilst[12]))
                config['server'] = broker

# Path: mqtt_as/config.py
# def ledfunc(pin):
#     def func(v):
# def ledfunc(led, init):
#     def func(v):


# Path: bridge/esp8266/mqtt.py
import gc
import ubinascii
import uasyncio as asyncio
import usocket as socket
import ustruct as struct
from mqtt_as import MQTTClient, config
from machine import Pin, unique_id, freq
from network import WLAN, STA_IF, AP_IF
from syncom import SynCom
from status_values import *  # Numeric status values shared with user code.

            elif command == SUBSCRIBE:
                await client.subscribe(s[1], int(s[2]))
                client.subscriptions[s[1]] = int(s[2])  # re-subscribe after outage
            elif command == MEM:
                gc.collect()
                gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
                self.send(argformat(MEM, gc.mem_free(), gc.mem_alloc()))
            elif command == TIME:
                t = await client.get_time()
                self.send(argformat(TIME, t))
            else:
                self.send(argformat(STATUS, UNKNOWN, 'Unknown command:', istr))

# Runs when channel has synchronised. No return: Pyboard resets ESP on fail.
# Get parameters from Pyboard. Process them. Connect. Instantiate client. Start
# from_pyboard() task. Wait forever, updating connected status.
    async def main_task(self, _):
        got_params = False
        # Await connection parameters (init record)
        while not got_params:
            istr = await self.await_obj(100)
            ilst = istr.split(SEP)
            command = ilst[0]
            if command == 'init':
                got_params = True
                ssid, pw, broker, mqtt_user, mqtt_pw, ssl_params = ilst[1:7]
                use_default = bool(int(ilst[7]))
                fast = bool(int(ilst[10]))
                debug = bool(int(ilst[12]))
                config['server'] = broker

                config['port'] = int(ilst[8])