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
fdc71a80
Commit
fdc71a80
authored
Feb 07, 2015
by
Vowstar
Browse files
Merge pull request #188 from dvv/master
Redis client module started
parents
1740841e
edc7eaf3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
fdc71a80
...
...
@@ -75,7 +75,7 @@ else
endif
endif
#############################################################
ESPTOOL
=
../tools/esptool.py
ESPTOOL
?
=
../tools/esptool.py
CSRCS
?=
$(
wildcard
*
.c
)
...
...
lua_examples/irsend.lua
View file @
fdc71a80
...
...
@@ -5,7 +5,7 @@
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
--
requir
e("irsend").nec(4, 0x00ff00ff)
--
dofil
e("irsend
.lua
").nec(4, 0x00ff00ff)
------------------------------------------------------------------------------
local
M
do
...
...
lua_examples/yet-another-bmp085.lua
View file @
fdc71a80
...
...
@@ -6,7 +6,7 @@
-- Heavily based on work of Christee <Christee@nodemcu.com>
--
-- Example:
--
requir
e("bmp085").read(sda, scl)
--
dofil
e("bmp085
.lua
").read(sda, scl)
------------------------------------------------------------------------------
local
M
do
...
...
@@ -59,20 +59,13 @@ do
MD
=
r16
(
0xBE
)
end
-- get raw P
local
p
-- NB: optimize for oss = 0
if
not
oss
then
oss
=
0
end
if
oss
==
0
then
oss
=
0
w8
(
0xF4
,
0x34
)
tmr
.
delay
(
5000
)
p
=
r8
(
0xF6
)
*
256
+
r8
(
0xF7
)
else
w8
(
0xF4
,
0x34
+
64
*
oss
)
tmr
.
delay
(
30000
)
p
=
r8
(
0xF6
)
*
65536
+
r8
(
0xF7
)
*
256
+
r8
(
0xF8
)
p
=
p
/
2
^
(
8
-
oss
)
end
if
oss
<=
0
then
oss
=
0
end
if
oss
>
3
then
oss
=
3
end
w8
(
0xF4
,
0x34
+
64
*
oss
)
tmr
.
delay
((
4
+
3
^
oss
)
*
1000
)
local
p
=
r8
(
0xF6
)
*
65536
+
r8
(
0xF7
)
*
256
+
r8
(
0xF8
)
p
=
p
/
2
^
(
8
-
oss
)
-- get T
w8
(
0xF4
,
0x2E
)
tmr
.
delay
(
5000
)
...
...
@@ -86,14 +79,14 @@ do
local
X1
=
B2
*
(
B6
*
B6
/
4096
)
/
2048
local
X2
=
AC2
*
B6
/
2048
local
X3
=
X1
+
X2
local
B3
=
((
AC1
*
4
+
X3
)
*
2
^
oss
+
2
)
/
4
local
B3
=
((
AC1
*
4
+
X3
)
*
2
^
oss
+
2
)
/
4
X1
=
AC3
*
B6
/
8192
X2
=
(
B1
*
(
B6
*
B6
/
4096
))
/
65536
X3
=
(
X1
+
X2
+
2
)
/
4
local
B4
=
AC4
*
(
X3
+
32768
)
/
32768
local
B7
=
(
p
-
B3
)
*
(
50000
/
2
^
oss
)
local
B7
=
(
p
-
B3
)
*
(
50000
/
2
^
oss
)
p
=
B7
/
B4
*
2
X1
=
(
p
/
256
)
^
2
X1
=
(
p
/
256
)
^
2
X1
=
(
X1
*
3038
)
/
65536
X2
=
(
-
7357
*
p
)
/
65536
p
=
p
+
(
X1
+
X2
+
3791
)
/
16
...
...
lua_examples/yet-another-dht22.lua
View file @
fdc71a80
...
...
@@ -5,8 +5,8 @@
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- print("DHT11",
requir
e("dht22").read(4))
-- print("DHT22",
requir
e("dht22").read(4, true))
-- print("DHT11",
dofil
e("dht22
.lua
").read(4))
-- print("DHT22",
dofil
e("dht22
.lua
").read(4, true))
-- NB: the very first read sometimes fails
------------------------------------------------------------------------------
local
M
...
...
lua_examples/yet-another-ds18b20.lua
View file @
fdc71a80
...
...
@@ -5,7 +5,7 @@
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
--
requir
e("ds18b20").read(4, function(r) for k, v in pairs(r) do print(k, v) end end)
--
dofil
e("ds18b20
.lua
").read(4, function(r) for k, v in pairs(r) do print(k, v) end end)
------------------------------------------------------------------------------
local
M
do
...
...
lua_modules/redis/redis.lua
0 → 100644
View file @
fdc71a80
------------------------------------------------------------------------------
-- Redis client module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- local redis = dofile("redis.lua").connect(host, port)
-- redis:publish("chan1", foo")
-- redis:subscribe("chan1", function(channel, msg) print(channel, msg) end)
------------------------------------------------------------------------------
local
M
do
-- const
local
REDIS_PORT
=
6379
-- cache
local
pairs
,
tonumber
=
pairs
,
tonumber
--
local
publish
=
function
(
self
,
chn
,
s
)
self
.
_fd
:
send
((
"*3\r\n$7\r\npublish\r\n$%d\r\n%s\r\n$%d\r\n%s\r\n"
):
format
(
#
chn
,
chn
,
#
s
,
s
))
-- TODO: confirmation? then queue of answers needed
end
local
subscribe
=
function
(
self
,
chn
,
handler
)
-- TODO: subscription to all channels, with single handler
self
.
_fd
:
send
((
"*2\r\n$9\r\nsubscribe\r\n$%d\r\n%s\r\n"
):
format
(
#
chn
,
chn
))
self
.
_handlers
[
chn
]
=
handler
-- TODO: confirmation? then queue of answers needed
end
local
unsubscribe
=
function
(
self
,
chn
)
self
.
_handlers
[
chn
]
=
false
end
-- NB: pity we can not just augment what net.createConnection returns
local
close
=
function
(
self
)
self
.
_fd
:
close
()
end
local
connect
=
function
(
host
,
port
)
local
_fd
=
net
.
createConnection
(
net
.
TCP
,
0
)
local
self
=
{
_fd
=
_fd
,
_handlers
=
{
},
-- TODO: consider metatables?
close
=
close
,
publish
=
publish
,
subscribe
=
subscribe
,
unsubscribe
=
unsubscribe
,
}
_fd
:
on
(
"connection"
,
function
()
--print("+FD")
end
)
_fd
:
on
(
"disconnection"
,
function
()
-- FIXME: this suddenly occurs. timeout?
--print("-FD")
end
)
_fd
:
on
(
"receive"
,
function
(
fd
,
s
)
--print("IN", s)
-- TODO: subscription to all channels
-- lookup message pattern to determine channel and payload
-- NB: pairs() iteration gives no fixed order!
for
chn
,
handler
in
pairs
(
self
.
_handlers
)
do
local
p
=
(
"*3\r\n$7\r\nmessage\r\n$%d\r\n%s\r\n$"
):
format
(
#
chn
,
chn
)
if
s
:
find
(
p
,
1
,
true
)
then
-- extract and check message length
-- NB: only the first TCP packet considered!
local
_
,
start
,
len
=
s
:
find
(
"(%d-)\r\n"
,
#
p
)
if
start
and
tonumber
(
len
)
==
#
s
-
start
-
2
and
handler
then
handler
(
chn
,
s
:
sub
(
start
+
1
,
-
2
))
-- ends with \r\n
end
end
end
end
)
_fd
:
connect
(
port
or
REDIS_PORT
,
host
)
return
self
end
-- expose
M
=
{
connect
=
connect
,
}
end
return
M
tools/esptool.py
View file @
fdc71a80
#!/usr/bin/env python
#!/usr/bin/env python
2
#
# ESP8266 ROM Bootloader Utility
# https://github.com/themadinventor/esptool
...
...
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