ソースを参照

add hostname config

moononournation 7 年 前
コミット
1acb798dfc
2 ファイル変更5 行追加2 行削除
  1. 1 0
      bin/config.lua
  2. 4 2
      bin/init.lua

+ 1 - 0
bin/config.lua

@@ -18,6 +18,7 @@ conf.wifi = {}
 conf.wifi.mode = wifi.SOFTAP -- default: SOFTAP (avoid try to connect an invalid AP)
 
 -- STATION config
+--conf.wifi.stahostname = "NODEMCU-WEBIDE" -- DNS host name send to DHCP server (don't use underscore)
 --conf.wifi.stassid = "YourSSID" -- Name of the WiFi network you want to join
 --conf.wifi.stapwd = "PleaseInputYourPasswordHere" -- Password for the WiFi network
 

+ 4 - 2
bin/init.lua

@@ -22,6 +22,7 @@ if (conf.wifi.mode == wifi.SOFTAP) or (conf.wifi.mode == wifi.STATIONAP) then
 end
 if (conf.wifi.mode == wifi.STATION) or (conf.wifi.mode == wifi.STATIONAP) then
     print('Client MAC: ', wifi.sta.getmac())
+    wifi.sta.sethostname(conf.wifi.stahostname)
     wifi.sta.config(conf.wifi.stassid, conf.wifi.stapwd, 1)
 end
 
@@ -62,12 +63,12 @@ i = nil
 f = nil
 collectgarbage()
 
--- pre compile other lua files
+-- pre-compile other lua files
 local l, f, s
 l = file.list();
 for f, s in pairs(l) do
   if ((string.sub(f, -4) == '.lua') and (f ~= 'config.lua') and (f ~= 'init.lua')) then
-    print('Compiling:', f)
+    print('Pre-compiling:', f)
     node.compile(f)
     collectgarbage()
   end
@@ -103,5 +104,6 @@ end
 -- start the nodemcu-httpserver in port 80
 if (not not wifi.sta.getip()) or (not not wifi.ap.getip()) then
     dofile("httpserver.lc")(80)
+    mdns.register("nodemcu-webide", { description="NodeMCU WebIDE", service="http", port=80, location='In your ESP board' })
     collectgarbage()
 end