To get access to your access point, to your email account or cloud services you need very often credentials (username, password, API keys etc.).
It is a good idea to hide these private information from code to be published. For this purpose I modified my init.lua for example.
Before the Wifi initialization I load the file credentials.lua which hold all this private information.
--load credentials
dofile("credentials.lua")
--init.lua
print("set up wifi mode")
wifi.setmode(wifi.STATION)
wifi.sta.config(SSID,PASSWORD)
--here SSID and PassWord should be modified according your wireless router
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("myfile.lua")
end
end)
For the Wifi initialization above the credential file contains only two items. But if there is more information required then this file can be modified.
-- Credentials
SSID = "yourSSID"
PASSWORD = "yourPassword"