import network
import picoweb
import logging
logger = logging.getLogger(__name__)

class STA:
  def __init__(self):
    self.interface = network.WLAN(network.STA_IF)
    self.interface.active()

  def get(self):
    return self.interface.ifconfig()

  def set(self, opts):
    self.interface.connect(opts.ssid, opts.passwd)

  def scan(self):
    wlan = network.WLAN(mode=network.WLAN.STA)
    nets = wlan.scan()
    return nets

sta = STA()
app = picoweb.WebApp(__name__)

def get(req, res):
  yield from picoweb.jsonify(res, sta.get())

def set(req, res):
  data = req.read_form_data()
  logging.info(data)
  sta.set(data)
  yield from get(req, res)

def notFound(req, res):
  yield from picoweb.start_response(res, status='404')
  yield from res.awrite('404\r\n')

def method(req, res):
  ret = {
    'GET': get,
    'PUT': set
  }
  logger.info('{0} {1}'.format(req.method, req.path))
  yield from ret.get(req.method, notFound)(req, res)

app.route('/sta')(method)

@@ -1,12 +1,25 @@
+import ujson%0A
 import netwo
@@ -21,16 +21,16 @@
 network%0A
-
 import p
@@ -315,16 +315,19 @@
 pts.ssid
+%5B0%5D
 , opts.p
@@ -331,16 +331,19 @@
 s.passwd
+%5B0%5D
 )%0A%0A  def
@@ -576,14 +576,18 @@
 :%0A  
-data =
+yield from
  req
@@ -610,41 +610,24 @@
 )%0A  
-logging.info(data)%0A  sta.set(data
+sta.set(req.form
 )%0A  

remove debug msg