Commit 9cab7513 authored by Vowstar's avatar Vowstar
Browse files

Merge pull request #1 from MarsTechHAN/master

Update to MarsTechHAN's nodemcu-firmware
parents a2d1e5ff ad1ec8fb
No preview for this file type
No preview for this file type
------------------------------------------------------------------------------
-- IR send module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- require("irsend").nec(4, 0x00ff00ff)
------------------------------------------------------------------------------
local M
do
-- const
local NEC_PULSE_US = 1000000 / 38000
local NEC_HDR_MARK = 9000
local NEC_HDR_SPACE = 4500
local NEC_BIT_MARK = 560
local NEC_ONE_SPACE = 1600
local NEC_ZERO_SPACE = 560
local NEC_RPT_SPACE = 2250
-- cache
local gpio, bit = gpio, bit
local mode, write = gpio.mode, gpio.write
local waitus = tmr.delay
local isset = bit.isset
-- NB: poorman 38kHz PWM with 1/3 duty. Touch with care! )
local carrier = function(pin, c)
c = c / NEC_PULSE_US
while c > 0 do
write(pin, 1)
write(pin, 0)
c = c + 0
c = c + 0
c = c + 0
c = c + 0
c = c + 0
c = c + 0
c = c * 1
c = c * 1
c = c * 1
c = c - 1
end
end
-- tsop signal simulator
local pull = function(pin, c)
write(pin, 0)
waitus(c)
write(pin, 1)
end
-- NB: tsop mode allows to directly connect pin
-- inplace of TSOP input
local nec = function(pin, code, tsop)
local pulse = tsop and pull or carrier
-- setup transmitter
mode(pin, 1)
write(pin, tsop and 1 or 0)
-- header
pulse(pin, NEC_HDR_MARK)
waitus(NEC_HDR_SPACE)
-- sequence, lsb first
for i = 0, 31 do
pulse(pin, NEC_BIT_MARK)
waitus(isset(code, i) and NEC_ONE_SPACE or NEC_ZERO_SPACE)
end
-- trailer
pulse(pin, NEC_BIT_MARK)
-- done transmitter
--mode(pin, 0, tsop and 1 or 0)
end
-- expose
M = {
nec = nec,
}
end
return M
uart.setup(0,9600,8,0,1,0)
sv=net.createServer(net.TCP, 60)
global_c = nil
sv:listen(9999, function(c)
if global_c~=nil then
global_c:close()
end
global_c=c
c:on("receive",function(sck,pl) uart.write(0,pl) end)
end)
uart.on("data",4, function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)
------------------------------------------------------------------------------
-- DHT11/22 query module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- print("DHT11", require("dht22").read(4))
-- print("DHT22", require("dht22").read(4, true))
-- NB: the very first read sometimes fails
------------------------------------------------------------------------------
local M
do
-- cache
local gpio = gpio
local val = gpio.read
local waitus = tmr.delay
--
local read = function(pin, dht22)
-- wait for pin value
local w = function(v)
local c = 255
while c > 0 and val(pin) ~= v do c = c - 1 end
return c
end
-- NB: we preallocate incoming data buffer
-- or precise timing in reader gets broken
local b = { 0, 0, 0, 0, 0 }
-- kick the device
gpio.mode(pin, gpio.INPUT, gpio.PULLUP)
gpio.write(pin, 1)
waitus(10)
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, 0)
waitus(20000)
gpio.write(pin, 1)
gpio.mode(pin, gpio.INPUT, gpio.PULLUP)
-- wait for device presense
if w(0) == 0 or w(1) == 0 or w(0) == 0 then
return nil, 0
end
-- receive 5 octets of data, msb first
for i = 1, 5 do
local x = 0
for j = 1, 8 do
x = x + x
if w(1) == 0 then return nil, 1 end
-- 70us for 1, 27 us for 0
waitus(30)
if val(pin) == 1 then
x = x + 1
if w(0) == 0 then return nil, 2 end
end
end
b[i] = x
end
-- check crc. NB: calculating in receiver loop breaks timings
local crc = 0
for i = 1, 4 do
crc = (crc + b[i]) % 256
end
if crc ~= b[5] then return nil, 3 end
-- convert
local t, h
-- DHT22: values in tenths of unit, temperature can be negative
if dht22 then
h = b[1] * 256 + b[2]
t = b[3] * 256 + b[4]
if t > 0x8000 then t = -(t - 0x8000) end
-- DHT11: no negative temperatures, only integers
-- NB: return in 0.1 Celsius
else
h = 10 * b[1]
t = 10 * b[3]
end
return t, h
end
-- expose interface
M = {
read = read,
}
end
return M
------------------------------------------------------------------------------
-- DS18B20 query module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- for k, v in pairs(require("ds18b20").read(4)) do print(k, v) end
------------------------------------------------------------------------------
local M
do
local format_addr = function(a)
return ("%02x-%02x%02x%02x%02x%02x%02x"):format(
a:byte(1),
a:byte(7), a:byte(6), a:byte(5),
a:byte(4), a:byte(3), a:byte(2)
)
end
local read = function(pin, delay)
local ow = require("ow")
-- get list of relevant devices
local d = { }
ow.setup(pin)
ow.reset_search(pin)
while true do
tmr.wdclr()
local a = ow.search(pin)
if not a then break end
if ow.crc8(a) == 0 and
(a:byte(1) == 0x10 or a:byte(1) == 0x28)
then
d[#d + 1] = a
end
end
-- conversion command for all
ow.reset(pin)
ow.skip(pin)
ow.write(pin, 0x44, 1)
-- wait a bit
tmr.delay(delay or 100000)
-- iterate over devices
local r = { }
for i = 1, #d do
tmr.wdclr()
-- read rom command
ow.reset(pin)
ow.select(pin, d[i])
ow.write(pin, 0xBE, 1)
-- read data
local x = ow.read_bytes(pin, 9)
if ow.crc8(x) == 0 then
local t = (x:byte(1) + x:byte(2) * 256) * 625
-- NB: temperature in Celcius * 10^4
r[format_addr(d[i])] = t
d[i] = nil
end
end
return r
end
-- expose
M = {
read = read,
}
end
return M
-- ***************************************************************************
-- BH1750 module for ESP8266 with nodeMCU
-- BH1750 compatible tested 2015-1-22
--
-- Written by xiaohu
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
local moduleName = ...
local M = {}
_G[moduleName] = M
--I2C slave address of GY-30
local GY_30_address = 0X23
-- i2c interface ID
local id = 0
--LUX
local l
--CMD
local CMD = 0x10
local init = false
function M.init(sda, scl)
i2c.setup(id, sda, scl, i2c.SLOW)
--print("i2c ok..")
init = true
end
local function read_data(ADDR, commands, length)
i2c.start(id)
i2c.address(id, ADDR, i2c.TRANSMITTER)
i2c.write(id, commands)
i2c.stop(id)
i2c.start(id)
i2c.address(id, ADDR,i2c.RECEIVER)
tmr.delay(200000)
c = i2c.read(id, length)
i2c.stop(id)
return c
end
local function read_lux()
dataT = read_data(GY_30_address, CMD, 2)
UT = string.byte(dataT, 1) * 256 + string.byte(dataT, 2)
l = (UT*1000/12)
return(l)
end
function M.read()
if (not init) then
print("init() must be called before read.")
else
read_lux()
end
end
function M.getlux()
return l
end
return M
# BH1750 模块
##引用
```lua
bh1750 = require("bh1750")
```
## 释放
```lua
bh1750 = nil
package.loaded["bh1750"]=nil
```
<a id="bh1750_init"></a>
##init()
####描述
设置BH1750所在的I2C引脚<br />
####语法
init(sda, scl)
####参数
sda: 1~12, IO index.<br />
scl: 1~12, IO index.<br />
####返回值
nil
####示例
```lua
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
```
####参见
**-** []()
<a id="bh1750_read"></a>
##read()
####描述
从bh1750中读取光线传感器数据(Lux勒克斯).<br />
####语法
read()
####参数
nil.<br />
####返回值
nil.<br />
####示例
```lua
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read()
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
```
####参见
**-** []()
<a id="bh1750_getlux"></a>
##getlux()
####描述
从BH1750中提取数据.<br />
####语法
getlux()
####参数
nil.<br />
####返回值
l: 整数,Lux计数
####示例
```lua
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read()
l = bh1750.getlux()
print("lux: "..(l / 100).."."..(l % 100).." lx")
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
```
####参见
**-** []()
# bh1750 Module
##Require
```lua
bh1750 = require("bh1750")
```
## Release
```lua
bh1750 = nil
package.loaded["bh1750"]=nil
```
<a id="bh1750_init"></a>
##init()
####Description
Setting the I2C pin of bh1750.<br />
####Syntax
init(sda, scl)
####Parameters
sda: 1~12, IO index.<br />
scl: 1~12, IO index.<br />
####Returns
nil
####Example
```lua
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
```
####See also
**-** []()
<a id="bh1750_read"></a>
##read()
####Description
Read Lux data from bh1750.<br />
####Syntax
read()
####Parameters
nil.<br />
####Returns
nil.<br />
####Example
```lua
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read()
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
```
####See also
**-** []()
<a id="bh1750_getlux"></a>
##getlux()
####Description
Get lux from bh1750.<br />
####Syntax
getlux()
####Parameters
nil.<br />
####Returns
l: Integer, getlux from bh1750.
####Example
```lua
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read()
l = bh1750.getlux()
print("lux: "..(l / 100).."."..(l % 100).." lx")
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
```
####See also
**-** []()
-- ***************************************************************************
-- BH1750 Example Program for ESP8266 with nodeMCU
-- BH1750 compatible tested 2015-1-30
--
-- Written by xiaohu
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
tmr.alarm(0, 10000, 1, function()
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
bh1750 = require("bh1750")
bh1750.init(SDA_PIN, SCL_PIN)
bh1750.read(OSS)
l = bh1750.getlux()
print("lux: "..(l / 100).."."..(l % 100).." lx")
-- release module
bh1750 = nil
package.loaded["bh1750"]=nil
end)
-- ***************************************************************************
-- BH1750 Example Program for ESP8266 with nodeMCU
-- BH1750 compatible tested 2015-1-30
--
-- Written by xiaohu
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
--Updata to Lelian
--Ps 需要改动的地方LW_GATEWAY(乐联的设备标示),USERKEY(乐联userkey)
--Ps You nees to rewrite the LW_GATEWAY(Lelian's Device ID),USERKEY(Lelian's userkey)
tmr.alarm(0, 60000, 1, function()
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
BH1750 = require("BH1750")
BH1750.init(SDA_PIN, SCL_PIN)
BH1750.read(OSS)
l = BH1750.getlux()
--定义数据变量格式 Define the veriables formate
PostData = "[{\"Name\":\"T\",\"Value\":\"" ..(l / 100).."."..(l % 100).."\"}]"
--创建一个TCP连接 Create a TCP Connection
socket=net.createConnection(net.TCP, 0)
--域名解析IP地址并赋值 DNS...it
socket:dns("www.lewei50.com", function(conn, ip)
ServerIP = ip
print("Connection IP:" .. ServerIP)
end)
--开始连接服务器 Connect the sever
socket:connect(80, ServerIP)
socket:on("connection", function(sck) end)
--HTTP请求头定义 HTTP Head
socket:send("POST /api/V1/gateway/UpdateSensors/LW_GATEWAY HTTP/1.1\r\n" ..
"Host: www.lewei50.com\r\n" ..
"Content-Length: " .. string.len(PostData) .. "\r\n" ..
"userkey: USERKEY\r\n\r\n" ..
PostData .. "\r\n")
--HTTP响应内容 Print the HTTP response
socket:on("receive", function(sck, response)
print(response)
end)
end)
# BMP085 module
##Require
```lua
bmp085 = require("bmp085")
```
## Release
```lua
bmp085 = nil
package.loaded["bmp085"]=nil
```
<a id="bmp085_init"></a>
##init()
####Description
Setting the i2c pin of bmp085.<br />
####Syntax
init(sda, scl)
####Parameters
sda: 1~12, IO index.<br />
scl: 1~12, IO index.<br />
####Returns
nil
####Example
```lua
bmp085 = require("bmp085")
gpio5 = 1
gpio4 = 2
sda = gpio5
scl = gpio4
bmp085.init(sda, scl)
-- Don't forget to release it after use
bmp085 = nil
package.loaded["bmp085"]=nil
```
####See also
**-** []()
<a id="bmp085_getUP"></a>
##getUP()
####Description
Get calibrated data of pressure from bmp085.<br />
####Syntax
getUP(oss)
####Parameters
oss: Over sampling setting, which is 0,1,2,3. Default value is 0.<br />
####Returns
p: Integer, calibrated data of pressure from bmp085.
####Example
```lua
bmp085 = require("bmp085")
sda = 1
scl = 2
bmp085.init(sda, scl)
p = bmp085.getUP(oss)
print(p)
-- Don't forget to release it after use
bmp085 = nil
package.loaded["bmp085"]=nil
```
####See also
**-** []()
<a id="bmp085_getUP_raw"></a>
##getUP_raw()
####Description
Get raw data of pressure from bmp085.<br />
####Syntax
getUP_raw(oss)
####Parameters
oss: Over sampling setting, which is 0,1,2,3. Default value is 0.<br />
####Returns
up_raw: Integer, raw data of pressure from bmp085.
####Example
```lua
bmp085 = require("bmp085")
sda = 1
scl = 2
bmp085.init(sda, scl)
up = bmp085.getUP_raw(oss)
print(up)
-- Don't forget to release it after use
bmp085 = nil
package.loaded["bmp085"]=nil
```
####See also
**-** []()
<a id="bmp085_getUT"></a>
##getUT()
####Description
Get temperature from bmp085.<br />
####Syntax
getUT(num_10x)
####Parameters
num_10x: num_10x: bool value, if true, return number of 0.1 centi-degree. Default value is false, which return a string , eg: 16.7.<br />
####Returns
t: Integer or String, if num_10x is true, return number of 0.1 centi-degree, otherwise return a string.The temperature from bmp085.<br />
####Example
```lua
bmp085 = require("bmp085")
sda = 1
scl = 2
bmp085.init(sda, scl)
-- Get string of temperature.
p = bmp085.getUT(false)
print(p)
-- Get number of temperature.
p = bmp085.getUT(true)
print(p)
-- Don't forget to release it after use
bmp085 = nil
package.loaded["bmp085"]=nil
```
####See also
**-** []()
<a id="bmp085_getAL"></a>
##getAL()
####Description
Get estimated data of altitude from bmp085.<br />
####Syntax
getAL(oss)
####Parameters
oss: over sampling setting, which is 0,1,2,3. Default value is 0.<br />
####Returns
e: Integer, estimated data of altitude. Altitudi can be calculated by pressure refer to sea level pressure, which is 101325. Pressure changes 100pa corresponds to 8.43m at sea level<br />
####Example
```lua
bmp085 = require("bmp085")
sda = 1
scl = 2
bmp085.init(sda, scl)
-- Get string of temperature.
e = bmp085.getAL()
print(p)
-- Don't forget to release it after use
bmp085 = nil
package.loaded["bmp085"]=nil
```
####See also
**-** []()
# DHT22 module
This module is compatible with DHT22 and DHT21.
No need to use a resistor to connect the pin data of DHT22 to ESP8266.
## Example
```lua
PIN = 4 -- data pin, GPIO2
dht22 = require("dht22")
dht22.read(PIN)
t = dht22.getTemperature()
h = dht22.getHumidity()
if h == -1 then
print("Error reading from DHT22")
else
-- temperature in degrees Celsius and Farenheit
print("Temperature: "..(t / 10).."."..(t % 10).." deg C")
print("Temperature: "..(9 * t / 50 + 32).."."..(9 * t / 5 % 10).." deg F")
-- humidity
print("Humidity: "..(h/10).."."..(h%10).."%")
end
-- release module
dht22 = nil
package.loaded["dht22"]=nil
```
## Functions
### read
read(pin)
Read humidity and temperature from DHT22.
**Parameters:**
* pin - ESP8266 pin connect to data pin in DHT22
### getHumidity
getHumidity()
Returns the humidity of the last reading.
**Returns:**
* last humidity reading in per thousand
### getTemperature
getTemperature()
Returns the temperature of the last reading.
**Returns:**
* last temperature reading in 0.1ºC
-- ***************************************************************************
-- DHT22 module for ESP8266 with nodeMCU
--
-- Written by Javier Yanez
-- but based on a script of Pigs Fly from ESP8266.com forum
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
local moduleName = ...
local M = {}
_G[moduleName] = M
local humidity
local temperature
function M.read(pin)
local checksum
local checksumTest
humidity = 0
temperature = 0
checksum = 0
-- Use Markus Gritsch trick to speed up read/write on GPIO
local gpio_read = gpio.read
local bitStream = {}
for j = 1, 40, 1 do
bitStream[j] = 0
end
local bitlength = 0
-- Step 1: send out start signal to DHT22
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.HIGH)
tmr.delay(100)
gpio.write(pin, gpio.LOW)
tmr.delay(20000)
gpio.write(pin, gpio.HIGH)
gpio.mode(pin, gpio.INPUT)
-- Step 2: DHT22 send response signal
-- bus will always let up eventually, don't bother with timeout
while (gpio_read(pin) == 0 ) do end
local c=0
while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
-- bus will always let up eventually, don't bother with timeout
while (gpio_read(pin) == 0 ) do end
c=0
while (gpio_read(pin) == 1 and c < 500) do c = c + 1 end
-- Step 3: DHT22 send data
for j = 1, 40, 1 do
while (gpio_read(pin) == 1 and bitlength < 10 ) do
bitlength = bitlength + 1
end
bitStream[j] = bitlength
bitlength = 0
-- bus will always let up eventually, don't bother with timeout
while (gpio_read(pin) == 0) do end
end
--DHT data acquired, process.
for i = 1, 16, 1 do
if (bitStream[i] > 4) then
humidity = humidity + 2 ^ (16 - i)
end
end
for i = 1, 16, 1 do
if (bitStream[i + 16] > 4) then
temperature = temperature + 2 ^ (16 - i)
end
end
for i = 1, 8, 1 do
if (bitStream[i + 32] > 4) then
checksum = checksum + 2 ^ (8 - i)
end
end
checksumTest=((humidity / 256) + (humidity % 256) + (temperature / 256) + (temperature % 256)) % 256
if temperature > 0x8000 then
-- convert to negative format
temperature = -(temperature - 0x8000)
end
if checksum ~= checksumTest then
humidity = -1
end
end
function M.getTemperature()
return temperature
end
function M.getHumidity()
return humidity
end
return M
require("ds3231")
-- ESP-01 GPIO Mapping
gpio0, gpio2 = 3, 4
ds3231.init(gpio0, gpio2)
second, minute, hour, day, date, month, year = ds3231.getTime();
-- Get current time
print(string.format("Time & Date: %s:%s:%s %s/%s/%s", hour, minute, second, date, month, year))
-- Don't forget to release it after use
ds3231 = nil
package.loaded["ds3231"]=nil
require('ds3231')
port = 80
-- ESP-01 GPIO Mapping
gpio0, gpio2 = 3, 4
days = {
[1] = "Sunday",
[2] = "Monday",
[3] = "Tuesday",
[4] = "Wednesday",
[5] = "Thursday",
[6] = "Friday",
[7] = "Saturday"
}
months = {
[1] = "January",
[2] = "Febuary",
[3] = "March",
[4] = "April",
[5] = "May",
[6] = "June",
[7] = "July",
[8] = "August",
[9] = "September",
[10] = "October",
[11] = "November",
[12] = "December"
}
ds3231.init(gpio0, gpio2)
srv=net.createServer(net.TCP)
srv:listen(port,
function(conn)
second, minute, hour, day, date, month, year = ds3231.getTime()
prettyTime = string.format("%s, %s %s %s %s:%s:%s", days[day], date, months[month], year, hour, minute, second)
conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
"<!DOCTYPE HTML>" ..
"<html><body>" ..
"<b>ESP8266</b></br>" ..
"Time and Date: " .. prettyTime .. "<br>" ..
"Node ChipID : " .. node.chipid() .. "<br>" ..
"Node MAC : " .. wifi.sta.getmac() .. "<br>" ..
"Node Heap : " .. node.heap() .. "<br>" ..
"Timer Ticks : " .. tmr.now() .. "<br>" ..
"</html></body>")
conn:on("sent",function(conn) conn:close() end)
end
)
\ No newline at end of file
#DS3231 Module
##Require
```lua
ds3231 = require("ds3231")
```
## Release
```lua
ds3231 = nil
package.loaded["ds3231"]=nil
```
<a id="ds3231_init"></a>
##init()
####Description
Setting the pins of DS3231.
####Syntax
init(sda, scl)
####Parameters
sda: 1~10, IO index.
scl: 1~10, IO index.
####Returns
nil
####Example
```lua
ds3231 = require("ds3231")
ds3231.init(3, 4)
-- Don't forget to release it after use
ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_settime"></a>
## setTime()
####Description
Sets the current date and time.
####Syntax
setTime(second, minute, hour, day, date, month, year)
####Parameters
second: 00-59
minute: 00-59
hour: 00-23
day: 1-7 (Sunday = 1, Saturday = 7)
date: 01-31
month: 01-12
year: 00-99
####Returns
nil
####Example
```lua
ds3231 = require("ds3231")
ds3231.init(3, 4)
-- Set date and time to Sunday, January 18th 2015 6:30PM
ds3231.setTime(0, 30, 18, 1, 18, 1, 15);
-- Don't forget to release it after use
ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_getTime"></a>
## getTime()
####Description
Get the current date and time.
####Syntax
getTime()
####Parameters
nil
####Returns
second: integer. Second 00-59
minute: integer. Minute 00-59
hour: integer. Hour 00-23
day: integer. Day 1-7 (Sunday = 1, Saturday = 7)
date: integer. Date 01-31
month: integer. Month 01-12
year: integer. Year 00-99
####Example
```lua
ds3231=require("ds3231")
ds3231.init(3, 4)
-- Get date and time
second, minute, hour, day, date, month, year = ds3231.getTime();
-- Print date and time
print(string.format("Time & Date: %s:%s:%s %s/%s/%s",
hour, minute, second, date, month, year))
-- Don't forget to release it after use
ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment