Explorar o código

impl write interface

etisab %!s(int64=10) %!d(string=hai) anos
pai
achega
59a55f093f
Modificáronse 2 ficheiros con 29 adicións e 6 borrados
  1. 1 6
      rebuild/server.lua
  2. 28 0
      rebuild/write.lua

+ 1 - 6
rebuild/server.lua

@@ -1,8 +1,6 @@
 local read = require('read')
 local net = net
 local string = string
-local assert = assert
-local type = type
 local srv = nil
 local debug_message = debug_message
 
@@ -62,9 +60,6 @@ function send_index(conn)
   index = read.index()
 
   local settings = read.current_settings()
-  assert(type(settings.ssid) == 'string', 'ssid must be a string')
-  assert(type(settings.status) == 'string', 'status must be a string')
-  assert(type(settings.yo_to) == 'string', 'yo_to must be a string')
 
   index = string.gsub(index, 'S_', settings.ssid)
   index = string.gsub(index, 'T_', settings.status)
@@ -97,4 +92,4 @@ function stop()
     srv = nil
   end
   debug_message(srv)
-end
+end

+ 28 - 0
rebuild/write.lua

@@ -0,0 +1,28 @@
+local wifi = wifi
+local file = file
+local assert = assert
+local type = type
+local yo_file = 'yo_recipient.txt'
+local debug_message = debug_message
+
+--TODO: validate ALL THE THINGS!
+module(...)
+
+function yo_recipient(value)
+  --TODO strip all non-alphanumeric
+  assert(type(value) == 'string')
+  file.open(yo_file, 'w+')
+  file.write(value)
+  file.close()
+end
+
+function new_settings(settings)
+  --TODO 1-7 length passwords --> ''
+  --TODO strip all invalid SSID,pw chars
+  assert(type(settings.ssid) == 'string', 'ssid must be a string')
+  assert(type(settings.password) == 'string', 'password must be a string')
+  assert(type(settings.yo_to) == 'string', 'yo_to must be a string')
+
+  yo_recipient(settings.yo_to)
+  wifi.sta.config(settings.ssid, settings.password)
+end