Skip to content

Commit 031e30e

Browse files
committed
update
1 parent ff94ce9 commit 031e30e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+757
-31
lines changed

ap.lua

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
print("set up wifi AP mode")
2+
wifi.setmode(wifi.SOFTAP)
3+
cfg = {}
4+
cfg.ssid = 'ESP8266-'..node.chipid()
5+
cfg.pwd = '1234567890'
6+
wifi.ap.config(cfg)
7+
8+
tmr.alarm(0, 2000, 0, function()
9+
print ('Start HTTP Server')
10+
dofile('sample_http3.lc')
11+
end)

calculator.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<html lang="zh-Hans">
2+
<head><meta charset="utf-8"><title>calculator</title></head>
3+
<body>
4+
<form method="post">
5+
<input name="num1" value='1'>
6+
<select name="sign">
7+
<option value="+">+</option>
8+
<option value="-">-</option>
9+
<option value="*">*</option>
10+
<option value="/">/</option>
11+
</select>
12+
<input name="num2" value='1'>
13+
<button type="submit">Submit</button>
14+
</form>
15+
{{result}}
16+
</body>
17+
</html>

coms.lua

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ssid = 'Comscicafe'
2+
pwd = 'ArteTalento'
3+
print("set up wifi mode")
4+
wifi.setmode(wifi.STATION)
5+
wifi.sta.config(ssid, pwd)
6+
wifi.sta.connect()
7+
cnt = 0
8+
tmr.alarm(0, 1000, 1, function()
9+
if (wifi.sta.getip() == nil) and (cnt < 200) then
10+
print("IP unavaiable, Waiting...")
11+
cnt = cnt + 1
12+
else
13+
tmr.stop(0)
14+
if (cnt < 20) then
15+
print("Config done, IP is "..wifi.sta.getip())
16+
tmr.alarm(0, 2000, 1, function()
17+
tmr.stop(0)
18+
print("WIFI connected...")
19+
dofile('tcp_client_temp.lc')
20+
--dofile("iothink_relay.lc")
21+
-- dofile("sample_http3.lua")
22+
--dofile("iothink_weather.lc")
23+
end)
24+
else
25+
print("Wifi setup time more than 10s, Please verify wifi.sta.config() function. Then re-download the file.")
26+
end
27+
end
28+
end)

dht22.lua

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
------------------------------------------------------------------------------
2+
-- DHT11/22 query module
3+
--
4+
-- LICENCE: http://opensource.org/licenses/MIT
5+
-- Vladimir Dronnikov <[email protected]>
6+
--
7+
-- Example:
8+
-- print("DHT11", dofile("dht22.lua").read(4))
9+
-- print("DHT22", dofile("dht22.lua").read(4, true))
10+
-- NB: the very first read sometimes fails
11+
------------------------------------------------------------------------------
12+
local M
13+
do
14+
-- cache
15+
local gpio = gpio
16+
local val = gpio.read
17+
local waitus = tmr.delay
18+
--
19+
local read = function(pin, dht22)
20+
-- wait for pin value
21+
local w = function(v)
22+
local c = 255
23+
while c > 0 and val(pin) ~= v do c = c - 1 end
24+
return c
25+
end
26+
-- NB: we preallocate incoming data buffer
27+
-- or precise timing in reader gets broken
28+
local b = { 0, 0, 0, 0, 0 }
29+
30+
-- kick the device
31+
gpio.mode(pin, gpio.INPUT, gpio.PULLUP)
32+
gpio.write(pin, 1)
33+
waitus(10)
34+
gpio.mode(pin, gpio.OUTPUT)
35+
gpio.write(pin, 0)
36+
waitus(20000)
37+
gpio.write(pin, 1)
38+
gpio.mode(pin, gpio.INPUT, gpio.PULLUP)
39+
-- wait for device presense
40+
if w(0) == 0 or w(1) == 0 or w(0) == 0 then
41+
return nil, 0
42+
end
43+
-- receive 5 octets of data, msb first
44+
for i = 1, 5 do
45+
local x = 0
46+
for j = 1, 8 do
47+
x = x + x
48+
if w(1) == 0 then return nil, 1 end
49+
-- 70us for 1, 27 us for 0
50+
waitus(30)
51+
if val(pin) == 1 then
52+
x = x + 1
53+
if w(0) == 0 then return nil, 2 end
54+
end
55+
end
56+
b[i] = x
57+
end
58+
-- check crc. NB: calculating in receiver loop breaks timings
59+
local crc = 0
60+
for i = 1, 4 do
61+
crc = (crc + b[i]) % 256
62+
end
63+
if crc ~= b[5] then return nil, 3 end
64+
-- convert
65+
local t, h
66+
-- DHT22: values in tenths of unit, temperature can be negative
67+
if dht22 then
68+
h = b[1] * 256 + b[2]
69+
t = b[3] * 256 + b[4]
70+
if t > 0x8000 then t = -(t - 0x8000) end
71+
-- DHT11: no negative temperatures, only integers
72+
-- NB: return in 0.1 Celsius
73+
else
74+
h = 10 * b[1]
75+
t = 10 * b[3]
76+
end
77+
return t, h
78+
end
79+
-- expose interface
80+
M = {
81+
read = read,
82+
}
83+
end
84+
return M

dht_lib.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local moduleName = 'dht'
1+
local moduleName = 'dht_lib'
22
local M = {}
33
_G[moduleName] = M
44
local humidity
@@ -101,4 +101,4 @@ function M.getHumidity()
101101
return humidity
102102
end
103103

104-
return M
104+
return M

ds3231-example.lua

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require("ds3231")
2+
3+
-- ESP-01 GPIO Mapping
4+
gpio0, gpio2 = 3, 4
5+
6+
ds3231.init(gpio0, gpio2)
7+
8+
second, minute, hour, day, date, month, year = ds3231.getTime();
9+
10+
-- Get current time
11+
print(string.format("Time & Date: %s:%s:%s %s/%s/%s", hour, minute, second, date, month, year))
12+
13+
-- Don't forget to release it after use
14+
ds3231 = nil
15+
package.loaded["ds3231"]=nil

ds3231-web.lua

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require('ds3231')
2+
3+
port = 80
4+
5+
-- ESP-01 GPIO Mapping
6+
gpio0, gpio2 = 3, 4
7+
8+
days = {
9+
[1] = "Sunday",
10+
[2] = "Monday",
11+
[3] = "Tuesday",
12+
[4] = "Wednesday",
13+
[5] = "Thursday",
14+
[6] = "Friday",
15+
[7] = "Saturday"
16+
}
17+
18+
months = {
19+
[1] = "January",
20+
[2] = "Febuary",
21+
[3] = "March",
22+
[4] = "April",
23+
[5] = "May",
24+
[6] = "June",
25+
[7] = "July",
26+
[8] = "August",
27+
[9] = "September",
28+
[10] = "October",
29+
[11] = "November",
30+
[12] = "December"
31+
}
32+
33+
ds3231.init(gpio0, gpio2)
34+
35+
srv=net.createServer(net.TCP)
36+
srv:listen(port,
37+
function(conn)
38+
39+
second, minute, hour, day, date, month, year = ds3231.getTime()
40+
prettyTime = string.format("%s, %s %s %s %s:%s:%s", days[day], date, months[month], year, hour, minute, second)
41+
42+
conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
43+
"<!DOCTYPE HTML>" ..
44+
"<html><body>" ..
45+
"<b>ESP8266</b></br>" ..
46+
"Time and Date: " .. prettyTime .. "<br>" ..
47+
"Node ChipID : " .. node.chipid() .. "<br>" ..
48+
"Node MAC : " .. wifi.sta.getmac() .. "<br>" ..
49+
"Node Heap : " .. node.heap() .. "<br>" ..
50+
"Timer Ticks : " .. tmr.now() .. "<br>" ..
51+
"</html></body>")
52+
conn:on("sent",function(conn) conn:close() end)
53+
end
54+
)

ds3231.lua

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--------------------------------------------------------------------------------
2+
-- DS3231 I2C module for NODEMCU
3+
-- NODEMCU TEAM
4+
-- LICENCE: http://opensource.org/licenses/MIT
5+
-- Tobie Booth <[email protected]>
6+
--------------------------------------------------------------------------------
7+
8+
local moduleName = 'ds3231'
9+
local M = {}
10+
_G[moduleName] = M
11+
12+
-- Default value for i2c communication
13+
local id = 0
14+
15+
--device address
16+
local dev_addr = 0x68
17+
18+
local function decToBcd(val)
19+
return((((val/10) - ((val/10)%1)) *16) + (val%10))
20+
end
21+
22+
local function bcdToDec(val)
23+
return((((val/16) - ((val/16)%1)) *10) + (val%16))
24+
end
25+
26+
-- initialize i2c
27+
--parameters:
28+
--d: sda
29+
--l: scl
30+
function M.init(d, l)
31+
if (d ~= nil) and (l ~= nil) and (d >= 0) and (d <= 11) and (l >= 0) and ( l <= 11) and (d ~= l) then
32+
sda = d
33+
scl = l
34+
else
35+
print("iic config failed!") return nil
36+
end
37+
print("init done")
38+
i2c.setup(id, sda, scl, i2c.SLOW)
39+
end
40+
41+
--get time from DS3231
42+
function M.getTime()
43+
i2c.start(id)
44+
i2c.address(id, dev_addr, i2c.TRANSMITTER)
45+
i2c.write(id, 0x00)
46+
i2c.stop(id)
47+
i2c.start(id)
48+
i2c.address(id, dev_addr, i2c.RECEIVER)
49+
local c=i2c.read(id, 7)
50+
i2c.stop(id)
51+
return bcdToDec(tonumber(string.byte(c, 1))),
52+
bcdToDec(tonumber(string.byte(c, 2))),
53+
bcdToDec(tonumber(string.byte(c, 3))),
54+
bcdToDec(tonumber(string.byte(c, 4))),
55+
bcdToDec(tonumber(string.byte(c, 5))),
56+
bcdToDec(tonumber(string.byte(c, 6))),
57+
bcdToDec(tonumber(string.byte(c, 7)))
58+
end
59+
60+
--set time for DS3231
61+
function M.setTime(second, minute, hour, day, date, month, year)
62+
i2c.start(id)
63+
i2c.address(id, dev_addr, i2c.TRANSMITTER)
64+
i2c.write(id, 0x00)
65+
i2c.write(id, decToBcd(second))
66+
i2c.write(id, decToBcd(minute))
67+
i2c.write(id, decToBcd(hour))
68+
i2c.write(id, decToBcd(day))
69+
i2c.write(id, decToBcd(date))
70+
i2c.write(id, decToBcd(month))
71+
i2c.write(id, decToBcd(year))
72+
i2c.stop(id)
73+
end
74+
75+
return M

esp8266-projects-master.zip

1.02 MB
Binary file not shown.

esp8266-projects-master/01d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/02d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/03d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/04d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/09d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/10d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/11d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/13d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/50d.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# esp8266-projects
2+
3+
Collection of projects for the ESP8266. Have a look at the projects for more detailed instructions or go to http://blog.squix.ch
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#define clouds_width 60
2+
#define clouds_height 60
3+
static unsigned short clouds_bits[] = {
4+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
5+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
6+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
7+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf000, 0x000f, 0x0000,
8+
0x0000, 0xfe00, 0x007f, 0x0000, 0x0000, 0xff80, 0x01ff, 0x0000, 0x0000,
9+
0xffc0, 0x07ff, 0x0000, 0x0000, 0xffe0, 0x0fff, 0x0000, 0x0000, 0x1ff0,
10+
0x1ff8, 0x0000, 0x0000, 0x07f8, 0x3fc0, 0x0000, 0x0000, 0x01fc, 0x7f00,
11+
0x0000, 0x0000, 0x00fe, 0x7e00, 0x0000, 0x0000, 0x007e, 0xfc00, 0x0000,
12+
0xe000, 0x003f, 0xf800, 0x0001, 0xfc00, 0x001f, 0xf800, 0x0001, 0xff00,
13+
0x001f, 0xf000, 0x0001, 0xff80, 0x000f, 0xf000, 0x0003, 0xffc0, 0x000f,
14+
0xe000, 0x0003, 0x3fe0, 0x000c, 0xe000, 0x0003, 0x07f0, 0x0000, 0xe000,
15+
0x000f, 0x03f0, 0x0000, 0xe000, 0x001f, 0x01f8, 0x0000, 0xe000, 0x003f,
16+
0x00f8, 0x0000, 0xe000, 0x007f, 0x00fc, 0x0000, 0xa000, 0x00ff, 0x007c,
17+
0x0000, 0x0000, 0x01fc, 0x007c, 0x0000, 0x0000, 0x01f8, 0x007c, 0x0000,
18+
0x0000, 0x01f0, 0x007c, 0x0000, 0x0000, 0x03f0, 0x007c, 0x0000, 0x0000,
19+
0x03e0, 0x007c, 0x0000, 0x0000, 0x03e0, 0x00fc, 0x0000, 0x0000, 0x03e0,
20+
0x00f8, 0x0000, 0x0000, 0x03e0, 0x01f8, 0x0000, 0x0000, 0x03f0, 0x03f8,
21+
0x0000, 0x0000, 0x01f0, 0x07f0, 0x01c0, 0x0703, 0x01f8, 0x1fe0, 0x81c0,
22+
0x0703, 0x00fe, 0xffc0, 0xc0e3, 0xe383, 0x00ff, 0xff80, 0xc0f1, 0xe3c1,
23+
0x007f, 0xff00, 0xe0f0, 0xe3c1, 0x003f, 0xfe00, 0xe0f8, 0xe1e1, 0x000f,
24+
0x7000, 0xf078, 0xf1f0, 0x0003, 0x0000, 0xf87c, 0x01f0, 0x0000, 0x0000,
25+
0xf87e, 0x00f8, 0x0000, 0x0000, 0x7c3e, 0x00f8, 0x0000, 0x0000, 0x7e3e,
26+
0x00f8, 0x0000, 0x0000, 0x3e1c, 0x0070, 0x0000, 0x0000, 0x3e00, 0x0000,
27+
0x0000, 0x0000, 0x3e00, 0x0000, 0x0000, 0x0000, 0x0c00, 0x0000, 0x0000,
28+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
29+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
30+
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
-- setup I2c and connect display
3+
function init_i2c_display()
4+
-- SDA and SCL can be assigned freely to available GPIOs
5+
sda = 3 -- GPIO14
6+
scl = 4 -- GPIO12
7+
sla = 0x3c
8+
i2c.setup(0, sda, scl, i2c.SLOW)
9+
disp = u8g.ssd1306_128x64_i2c(sla)
10+
end
11+
12+
function xbm_picture()
13+
disp:setFont(u8g.font_6x10)
14+
disp:drawStr( 0, 62, "Rainy 8C")
15+
disp:drawXBM( 0, -5, 60, 60, xbm_data )
16+
end
17+
18+
function bitmap_test(delay)
19+
file.open("13d.MONO", "r")
20+
xbm_data = file.read()
21+
file.close()
22+
23+
disp:firstPage()
24+
repeat
25+
xbm_picture()
26+
until disp:nextPage() == false
27+
28+
tmr.wdclr()
29+
end
30+
31+
init_i2c_display()
32+
bitmap_test()
Binary file not shown.
Loading

esp8266-projects-master/temp.MONO

480 Bytes
Binary file not shown.

esp8266-projects-master/temp.gif

1.15 KB
Loading

esp8266-projects-master/temp.png

2 KB
Loading
647 Bytes
Binary file not shown.
647 Bytes
Binary file not shown.
676 Bytes
Binary file not shown.
663 Bytes
Binary file not shown.
663 Bytes
Binary file not shown.
647 Bytes
Binary file not shown.
673 Bytes
Binary file not shown.
697 Bytes
Binary file not shown.
674 Bytes
Binary file not shown.
733 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)