limbo
Published © Apache-2.0

ESP8266 Easy (END USER) WiFi Setup

A complete and easy way for end users to setup WiFi parameters to a device with ESP8266 / Wemos.

BeginnerProtip12 minutes1,595
ESP8266 Easy (END USER) WiFi Setup

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1

Software apps and online services

NodeMCU firmware
NodeMCU firmware

Story

Read more

Code

readconfig.lua

Lua
The lua file for NodeMCU firmware to read WiFi parameters
--Read the variables mySSID,myPASS,myDEVICEID
--from "Config.txt" if file exists
--Created by Nikos Georgousis DEC 2018
--######################################################################################################
--HOW TO USE 
--developer must copy this code to his init.lua file or run a dofile('readconfig.lua') at startup 
--then the mySSID, myPASS, myDEVICEID variables can be used to his/her code to setup the WiFi parameters 
--e.g. using the command: wifi.sta.config {ssid=mySSID, pwd=myPASS}
--######################################################################################################
configfile = 'Config.txt' 
if file.open(configfile, 'r') then
	--script = '' 
	repeat
	line = file.readline() 
	if (line~=nil) then 
		--script = script .. line 
		line=string.gsub(line, "\n", " ", 20) --replace end of line with space
		--print(line)
 		if string.find(line, "SSID") ~=nil then --set variable mySSID
			mySSID=string.gsub(line, "SSID:", "", 2)
			mySSID=string.gsub(mySSID, " ", "", 20)
			print("Wifi name: "..mySSID)	--optional for serial debugging, can be removed
		end 
	 	if string.find(line, "PASS") ~=nil then --set variable myPASS
			myPASS=string.gsub(line, "PASS:", "", 2)
			myPASS=string.gsub(myPASS, " ", "", 20)
			print("Wifi password: "..myPASS)	 --optional for serial debugging, can be removed
		end 
		if string.find(line, "DeviceID") ~=nil then --set variable myDEVICEID
			myDEVICEID=string.gsub(line, "DeviceID:", "", 2)
			myDEVICEID=string.gsub(myDEVICEID, " ", "", 20)
			print("Module ID: "..myDEVICEID)	--optional for serial debugging, can be removed
		end 
	end 
	until line == nil 
	file.close() 
else
print("no config file") --optional for serial debugging, can be removed
end 
configfile= nil
--print(script)

Credits

limbo
2 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.