Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
0f40adf4
Commit
0f40adf4
authored
May 01, 2015
by
Vowstar
Browse files
Merge pull request #377 from MarsTechHAN/patch-4
Update the Yeelink lib, add example
parents
6c080c9d
effb5724
Changes
2
Hide whitespace changes
Inline
Side-by-side
lua_modules/yeelink/Example_for_Yeelink_Lib.lua
0 → 100644
View file @
0f40adf4
-- ***************************************************************************
-- Example for Yeelink Lib
--
-- Written by Martin
--
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
wifi
.
setmode
(
wifi
.
STATION
)
--Step1: Connect to Wifi
wifi
.
sta
.
config
(
"SSID"
,
"Password"
)
dht
=
require
(
"dht_lib"
)
--Step2: "Require" the libs
yeelink
=
require
(
"yeelink_lib"
)
yeelink
.
init
(
23333
,
23333
,
"You api-key"
,
function
()
--Step3: Register the callback function
print
(
"Yeelink Init OK..."
)
tmr
.
alarm
(
1
,
60000
,
1
,
function
()
--Step4: Have fun~ (Update your data)
dht
.
read
(
4
)
yeelink
.
update
(
dht
.
getTemperature
())
end
)
end
)
lua_modules/yeelink/yeelink_lib.lua
View file @
0f40adf4
-- ***************************************************************************
-- ***************************************************************************
-- Yeelink Updata Libiary
-- Yeelink Updata Libiary
Version 0.1.2 r1
--
--
-- Written by Martin
-- Written by Martin
-- but based on a script of zhouxu_o from bbs.nodemcu.com
-- but based on a script of zhouxu_o from bbs.nodemcu.com
--
--
-- MIT license, http://opensource.org/licenses/MIT
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
-- ***************************************************************************
if
wifi
.
sta
.
getip
()
==
nil
then
print
(
"Please Connect WIFI First"
)
return
nil
end
--==========================Module Part======================
--==========================Module Part======================
local
moduleName
=
...
local
moduleName
=
...
...
@@ -30,7 +25,23 @@ local debug = true --<<<<<<<<<<<<< Don't forget to "false" it before using
...
@@ -30,7 +25,23 @@ local debug = true --<<<<<<<<<<<<< Don't forget to "false" it before using
local
sk
=
net
.
createConnection
(
net
.
TCP
,
0
)
local
sk
=
net
.
createConnection
(
net
.
TCP
,
0
)
local
datapoint
=
0
local
datapoint
=
0
--====DNS the yeelink ip advance(in order to save RAM)=====
--====DNS the yeelink ip advance(in order to save RAM)=====
if
wifi
.
sta
.
getip
()
==
nil
then
print
(
"Please Connect WIFI First"
)
tmr
.
alarm
(
1
,
1000
,
1
,
function
()
if
wifi
.
sta
.
getip
()
~=
nil
then
tmr
.
stop
(
1
)
sk
:
dns
(
"api.yeelink.net"
,
function
(
conn
,
ip
)
dns
=
ip
print
(
"DNS YEELINK OK... IP: "
..
dns
)
end
)
end
end
)
end
sk
:
dns
(
"api.yeelink.net"
,
function
(
conn
,
ip
)
sk
:
dns
(
"api.yeelink.net"
,
function
(
conn
,
ip
)
dns
=
ip
dns
=
ip
...
@@ -50,13 +61,31 @@ function M.init(_device, _sensor, _apikey)
...
@@ -50,13 +61,31 @@ function M.init(_device, _sensor, _apikey)
sensor
=
tostring
(
_sensor
)
sensor
=
tostring
(
_sensor
)
apikey
=
_apikey
apikey
=
_apikey
if
dns
==
"0.0.0.0"
then
if
dns
==
"0.0.0.0"
then
tmr
.
alarm
(
2
,
5000
,
1
,
function
()
if
dns
==
"0.0.0.0"
then
print
(
"Waiting for DNS..."
)
end
end
)
return
false
return
false
else
else
return
dns
return
dns
end
end
end
end
--========Check the DNS Status===========
--if DNS success, return the address(string)
--if DNS fail(or processing), return nil
--
--
--========================================
function
M
.
getDNS
()
if
dns
==
"0.0.0.0"
then
return
nil
else
return
dns
end
end
--=====Update to Yeelink Sever(At least 10s per sencods))=====
--=====Update to Yeelink Sever(At least 10s per sencods))=====
-- datapoint->number
-- datapoint->number
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment