ready
This commit is contained in:
parent
b1ac19f887
commit
e437ae17de
73
init.lua
73
init.lua
@ -1,11 +1,11 @@
|
||||
local t = require("DS1820")
|
||||
timing = 60000 -- Sending timer
|
||||
srv = nil -- TCP client
|
||||
uid = '' -- MAC UID
|
||||
dhtpin_room = 1 -- DHT11 room pin
|
||||
dhtpin_cellar = 2 -- DHT11 cellar pin
|
||||
dhtpin_weather = 5 -- DHT11 weather pin
|
||||
ds_pin = 6
|
||||
local t = require("ds18b20")
|
||||
local timing = 60000 -- Sending timer
|
||||
local srv = nil -- TCP client
|
||||
local uid = '' -- MAC UID
|
||||
local dhtpin_room = 1 -- DHT11 room pin
|
||||
local dhtpin_cellar = 2 -- DHT11 cellar pin
|
||||
local dhtpin_weather = 5 -- DHT11 weather pin
|
||||
local ds_pin = 6
|
||||
|
||||
local results = {} -- DS1822 results
|
||||
|
||||
@ -64,44 +64,39 @@ local function send()
|
||||
end)
|
||||
end
|
||||
|
||||
-- On Internet connect
|
||||
|
||||
function on_connect()
|
||||
-- Generate UID from MAC address
|
||||
uid = string.gsub(wifi.ap.getmac(),':','')
|
||||
print("Connected to wifi as: " .. wifi.sta.getip())
|
||||
ssid,password,bssid_set,bssid = wifi.sta.getconfig()
|
||||
sensor_start()
|
||||
print(
|
||||
"\nCurrent Station configuration:"
|
||||
.."\nSSID : "..ssid
|
||||
.."\nPassword : "..password
|
||||
.."\nBSSID_set : "..bssid_set
|
||||
.."\nBSSID: "..bssid
|
||||
.."\nUID:"..uid
|
||||
.."\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')
|
||||
local function connect_wifi()
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connect to Wi-fi.")
|
||||
else
|
||||
print("Success")
|
||||
print("IP: " .. wifi.sta.getip())
|
||||
wifitimer:stop()
|
||||
uid = string.gsub(wifi.ap.getmac(),':','')
|
||||
srv = net.createConnection(net.TCP, 0)
|
||||
if srv then
|
||||
print('TCP Connection start')
|
||||
tcptimer:start()
|
||||
else
|
||||
print('Error connect to TCP')
|
||||
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
|
||||
|
||||
tcptimer = tmr.create()
|
||||
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 = {}
|
||||
pack['id'] = 'test'
|
||||
pack['room'] = {['temp'] = 12,['humi'] = 67}
|
||||
pack['cellar'] = {['temp'] = 14,['humi'] = 77}
|
||||
pack['weather'] = {['temp'] = 0,['humi'] = 57}
|
||||
pack['room'] = {['temp'] = 12,['warm'] = 67}
|
||||
pack['cellar'] = {['temp'] = 14,['warm'] = 77}
|
||||
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}
|
||||
|
||||
--tcp:send(base64.encode(json.encode(pack)))
|
||||
print(base64.encode(json.encode(pack)))
|
||||
|
||||
tcp:send(base64.encode(json.encode(pack)))
|
||||
|
||||
tcp:send('test')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user