ready
This commit is contained in:
parent
b1ac19f887
commit
e437ae17de
73
init.lua
73
init.lua
@ -1,11 +1,11 @@
|
|||||||
local t = require("DS1820")
|
local t = require("ds18b20")
|
||||||
timing = 60000 -- Sending timer
|
local timing = 60000 -- Sending timer
|
||||||
srv = nil -- TCP client
|
local srv = nil -- TCP client
|
||||||
uid = '' -- MAC UID
|
local uid = '' -- MAC UID
|
||||||
dhtpin_room = 1 -- DHT11 room pin
|
local dhtpin_room = 1 -- DHT11 room pin
|
||||||
dhtpin_cellar = 2 -- DHT11 cellar pin
|
local dhtpin_cellar = 2 -- DHT11 cellar pin
|
||||||
dhtpin_weather = 5 -- DHT11 weather pin
|
local dhtpin_weather = 5 -- DHT11 weather pin
|
||||||
ds_pin = 6
|
local ds_pin = 6
|
||||||
|
|
||||||
local results = {} -- DS1822 results
|
local results = {} -- DS1822 results
|
||||||
|
|
||||||
@ -64,44 +64,39 @@ local function send()
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- On Internet connect
|
local function connect_wifi()
|
||||||
|
if wifi.sta.getip() == nil then
|
||||||
function on_connect()
|
print("Connect to Wi-fi.")
|
||||||
-- Generate UID from MAC address
|
else
|
||||||
uid = string.gsub(wifi.ap.getmac(),':','')
|
print("Success")
|
||||||
print("Connected to wifi as: " .. wifi.sta.getip())
|
print("IP: " .. wifi.sta.getip())
|
||||||
ssid,password,bssid_set,bssid = wifi.sta.getconfig()
|
wifitimer:stop()
|
||||||
sensor_start()
|
uid = string.gsub(wifi.ap.getmac(),':','')
|
||||||
print(
|
srv = net.createConnection(net.TCP, 0)
|
||||||
"\nCurrent Station configuration:"
|
if srv then
|
||||||
.."\nSSID : "..ssid
|
print('TCP Connection start')
|
||||||
.."\nPassword : "..password
|
tcptimer:start()
|
||||||
.."\nBSSID_set : "..bssid_set
|
else
|
||||||
.."\nBSSID: "..bssid
|
print('Error connect to TCP')
|
||||||
.."\nUID:"..uid
|
end
|
||||||
.."\nClient IP:"..wifi.sta.getip().."\n"
|
|
||||||
)
|
|
||||||
srv = net.createConnection(net.TCP, 0)
|
|
||||||
if srv then
|
|
||||||
print('TCP Connection start')
|
|
||||||
tcptimer:start()
|
|
||||||
else
|
|
||||||
print('Error connect to TCP')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Setup sensors
|
wifi.setmode(wifi.STATION)
|
||||||
|
|
||||||
bme280.setup()
|
station_cfg = {}
|
||||||
|
station_cfg.ssid = "ASUS"
|
||||||
|
station_cfg.pwd = "0"
|
||||||
|
station_cfg.save = true
|
||||||
|
|
||||||
|
wifi.sta.config(station_cfg)
|
||||||
|
|
||||||
-- Setup timers
|
-- Setup timers
|
||||||
|
|
||||||
tcptimer = tmr.create()
|
tcptimer = tmr.create()
|
||||||
tcptimer:register(timing, tmr.ALARM_AUTO,send)
|
tcptimer:register(timing, tmr.ALARM_AUTO,send)
|
||||||
|
|
||||||
inittimer = tmr.create()
|
|
||||||
inittimer:register(5000, tmr.ALARM_SINGLE, function()
|
|
||||||
enduser_setup.start('chan',on_connect)
|
|
||||||
end)
|
|
||||||
|
|
||||||
inittimer:start()
|
wifitimer = tmr.create()
|
||||||
|
wifitimer:register(1000, tmr.ALARM_AUTO,connect_wifi)
|
||||||
|
|
||||||
|
wifitimer:start()
|
||||||
|
|||||||
BIN
nodemcu-release-11-modules-2026-03-12-15-31-50-integer.bin
Normal file
BIN
nodemcu-release-11-modules-2026-03-12-15-31-50-integer.bin
Normal file
Binary file not shown.
@ -8,12 +8,14 @@ tcp:connect(host, port);
|
|||||||
|
|
||||||
local pack = {}
|
local pack = {}
|
||||||
pack['id'] = 'test'
|
pack['id'] = 'test'
|
||||||
pack['room'] = {['temp'] = 12,['humi'] = 67}
|
pack['room'] = {['temp'] = 12,['warm'] = 67}
|
||||||
pack['cellar'] = {['temp'] = 14,['humi'] = 77}
|
pack['cellar'] = {['temp'] = 14,['warm'] = 77}
|
||||||
pack['weather'] = {['temp'] = 0,['humi'] = 57}
|
pack['weather'] = {['temp'] = 0,['warm'] = 57}
|
||||||
pack['sensors'] = {['28:61:64:34:80:10:F4:39'] = 18,['28:61:64:35:18:1E:74:EB'] = 17,['28:61:64:35:18:3C:3D:61'] = 19}
|
pack['sensors'] = {['28:61:64:34:80:10:F4:39'] = 18,['28:61:64:35:18:1E:74:EB'] = 17,['28:61:64:35:18:3C:3D:61'] = 19}
|
||||||
|
|
||||||
--tcp:send(base64.encode(json.encode(pack)))
|
print(base64.encode(json.encode(pack)))
|
||||||
|
|
||||||
|
tcp:send(base64.encode(json.encode(pack)))
|
||||||
|
|
||||||
tcp:send('test')
|
tcp:send('test')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user