Commit c8ac5cfb authored by Arnim Läuger's avatar Arnim Läuger Committed by GitHub
Browse files

Merge pull request #1980 from nodemcu/dev

2.1.0 master drop
parents 22e1adc4 787379f0
require("ds3231")
-- ESP-01 GPIO Mapping
gpio0, gpio2 = 3, 4
i2c.setup(gpio0, gpio2, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231.init(gpio0, gpio2)
require("ds3231")
second, minute, hour, day, date, month, year = ds3231.getTime();
......
require('ds3231')
port = 80
-- ESP-01 GPIO Mapping
gpio0, gpio2 = 3, 4
i2c.setup(gpio0, gpio2, scl, i2c.SLOW) -- call i2c.setup() only once
require('ds3231')
port = 80
days = {
[1] = "Sunday",
......@@ -30,8 +32,6 @@ months = {
[12] = "December"
}
ds3231.init(gpio0, gpio2)
srv=net.createServer(net.TCP)
srv:listen(port,
function(conn)
......
#DS3231 Module
##Require
# 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
#### Description
Sets the current date and time.
if _disableOscillator_ is set to 1 the oscillator will **stop** on battery.
If _disableOscillator_ is set to 1 the oscillator will **stop** on battery.
####Syntax
setTime(second, minute, hour, day, date, month, year, disableOscillator)
#### Syntax
`ds3231.setTime(second, minute, hour, day, date, month, year[, disableOscillator])`
####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
disableOscillator: (optional) 0-1
#### 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
- `disableOscillator`: (optional) 0-1, defaults to 0 if omitted
####Returns
nil
#### Returns
`nil`
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
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);
......@@ -71,34 +47,31 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_getTime"></a>
## getTime()
####Description
#### Description
Get the current date and time.
####Syntax
getTime()
#### Syntax
`ds3231.getTime()`
####Parameters
nil
#### Parameters
None
####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
#### 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
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
-- Get date and time
second, minute, hour, day, date, month, year = ds3231.getTime();
......@@ -112,13 +85,12 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_setAlarm"></a>
## setAlarm()
####Description
#### Description
Set an alarm to be triggered on SQW pin:
_alarm1_ has a precision of **seconds**; _alarm2_ has a precision of **minutes** (`second` parameter will be ignored).
Alarms sets gpio.LOW over the SQW pin and let it unchanged until reloaded. When reloaded sets gpio.HIGH.
......@@ -133,24 +105,25 @@ Alarm type set the alarm match conditions:
- `ds3231.DAY` triggers when time match given `seconds`, `minutes`, and `hours` on week day `date/day` parameters;
- `ds3231.DATE` triggers when time match given `seconds`, `minutes`, and `hours` on date (day of the month) `date/day` parameters;
####Syntax
setAlarm(alarmId, alarmType, seconds, minutes, hours, date/day)
#### Syntax
`ds3231.setAlarm(alarmId, alarmType, seconds, minutes, hours, date/day)`
####Parameters
alarmId: 1-2
alarmType: 1-7
seconds: 00-59
minutes: 00-59
hours: 00-23
date/day: 01-31 or 1-7 (Sunday = 1, Saturday = 7)
#### Parameters
- `alarmId`: 1-2
- `alarmType`: 1-7
- `seconds`: 00-59
- `minutes`: 00-59
- `hours`: 00-23
- `date/day`: 01-31 or 1-7 (Sunday = 1, Saturday = 7)
####Returns
nil
#### Returns
`nil`
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
-- Setting PIN1 to triggers on interrupt when alarm triggers
gpio.mode(1,gpio.INT)
......@@ -167,28 +140,26 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_reloadAlarms"></a>
## reloadAlarms()
####Description
#### Description
Reload an already triggered alarm. Otherwise it will never be triggered again.
There are two different alarms and they have to be reloaded both to let, even only one, to be triggered again. So there isn't a param to select which alarm to reload.
####Syntax
reloadAlarms()
#### Syntax
`ds3231.reloadAlarms()`
####Parameters
nil
#### Parameters
None
####Returns
nil
#### Returns
`nil`
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
-- Setting PIN1 to triggers on interrupt when alarm triggers
gpio.mode(1,gpio.INT)
......@@ -205,27 +176,25 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_enableAlarm"></a>
## enableAlarm()
####Description
#### Description
Enable an already setted alarm with the previous matching conditions. It reloads alarms internally.
####Syntax
enableAlarm(alarmId)
#### Syntax
`ds3231.enableAlarm(alarmId)`
####Parameters
alarmId: 1-2
#### Parameters
`alarmId`: 1-2
####Returns
nil
#### Returns
`nil`
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
-- Trigger on x:20:15
ds3231.setAlarm(1,ds3231.MINUTE,15,20)
......@@ -243,29 +212,29 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_disableAlarm"></a>
## disableAlarm()
####Description
#### Description
Disable an already setted alarm with the previous matching conditions.
if _alarmId_ is not 1 or 2 it disables both alarms.
**Warning**: `disableAlarm()` prevent alarms to trigger interrupt over SQW pin but alarm itself will triggers at the matching conditions as it could be seen on _status byte_.
####Syntax
disableAlarm(alarmId)
#### Syntax
`ds3231.disableAlarm(alarmId)`
####Parameters
alarmId: 0-2
#### Parameters
`alarmId: 0-2`
####Returns
nil
#### Returns
`nil`
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
-- Trigger on x:20:15
ds3231.setAlarm(1,ds3231.MINUTE,15,20)
......@@ -283,28 +252,26 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_getBytes"></a>
## getBytes()
####Description
#### Description
Get bytes of control, for debug purpose, and status of DS3231. To see what they means check the [Datasheet](http://datasheets.maximintegrated.com/en/ds/DS3231.pdf)
####Syntax
getBytes()
#### Syntax
`ds3231.getBytes()`
####Parameters
nil
#### Parameters
None
####Returns
control: integer. Control 0-255
status: integer. Status 0-143 (bit 6-5-4 unused)
#### Returns
- `control`: integer. Control 0-255
- `status`: integer. Status 0-143 (bit 6-5-4 unused)
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
control,status = ds3231.getBytes()
print('Control byte: '..control)
......@@ -315,29 +282,27 @@ ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
<a id="ds3231_resetStopFlag"></a>
## resetStopFlag()
####Description
Stop flag on status byte means that the oscillator either is stopped or was stopped for some period and may be used to judge the validity of the timekeeping data.
When setted to 1 this flag keeps that values until changed to 0.
#### Description
Stop flag on status byte means that the oscillator either is stopped or was stopped for some period and may be used to judge the validity of the timekeeping data. When set to 1 this flag keeps that values until changed to 0.
Call `resetStopFlag()` if you need to check validity of time data after that.
####Syntax
resetStopFlag()
#### Syntax
`ds3231.resetStopFlag()`
####Parameters
nil
#### Parameters
None
####Returns
nil
#### Returns
`nil`
####Example
#### Example
```lua
i2c.setup(3, 4, scl, i2c.SLOW) -- call i2c.setup() only once
ds3231=require("ds3231")
ds3231.init(3, 4)
control,status = ds3231.getBytes()
if bit.band(bit.rshift(status, 7),1) == 1 then
......@@ -349,6 +314,3 @@ end
ds3231 = nil
package.loaded["ds3231"]=nil
```
####See also
**-** []()
\ No newline at end of file
......@@ -5,6 +5,9 @@
-- Tobie Booth <tbooth@hindbra.in>
--------------------------------------------------------------------------------
require("bit")
require("i2c")
local moduleName = ...
local M = {}
_G[moduleName] = M
......@@ -39,21 +42,6 @@ local function addAlarmBit(val,day)
return bit.bor(val,128)
end
-- initialize i2c
--parameters:
--d: sda
--l: scl
function M.init(d, l)
if (d ~= nil) and (l ~= nil) and (d >= 0) and (d <= 11) and (l >= 0) and ( l <= 11) and (d ~= l) then
sda = d
scl = l
else
print("[ERROR] i2c config failed!") return nil
end
print("[LOG] DS3231 init done")
i2c.setup(id, sda, scl, i2c.SLOW)
end
--get time from DS3231
function M.getTime()
i2c.start(id)
......
Support for this Lua module has been discontinued.
Equivalent functionality is available from the si7021 module in the NodeMCU
firmware code base. Refer to `docs/en/modules/si7021.md` for API documentation.
The original Lua code can be found in the [git repository](https://github.com/nodemcu/nodemcu-firmware/tree/3e24b1c75b4b4fd469be784fd5d596f0eb3871ff/lua_modules/si7021).
tmr.alarm(0, 60000, 1, function()
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
si7021 = require("si7021")
si7021.init(SDA_PIN, SCL_PIN)
si7021.read(OSS)
h = si7021.getHumidity()
t = si7021.getTemperature()
-- pressure in differents units
print("Humidity: "..(h / 100).."."..(h % 100).." %")
-- temperature in degrees Celsius and Farenheit
print("Temperature: "..(t/100).."."..(t%100).." deg C")
print("Temperature: "..(9 * t / 500 + 32).."."..(9 * t / 50 % 10).." deg F")
-- release module
si7021 = nil
package.loaded["si7021"]=nil
end)
--创建一个定时器
tmr.alarm(0, 60000, 1, function()
SDA_PIN = 6 -- sda pin, GPIO12
SCL_PIN = 5 -- scl pin, GPIO14
si7021 = require("si7021")
si7021.init(SDA_PIN, SCL_PIN)
si7021.read(OSS)
Hum = si7021.getHumidity()
Temp = si7021.getTemperature()
--定义数据变量格式
PostData = "[{\"Name\":\"T\",\"Value\":\"" .. (Temp/100).."."..(Temp%100) .. "\"},{\"Name\":\"H\",\"Value\":\"" .. (Hum/100).."."..(Hum%100) .. "\"}]"
--创建一个TCP连接
socket=net.createConnection(net.TCP, 0)
--域名解析IP地址并赋值
socket:dns("www.lewei50.com", function(conn, ip)
ServerIP = ip
print("Connection IP:" .. ServerIP)
end)
--开始连接服务器
socket:connect(80, ServerIP)
socket:on("connection", function(sck) end)
--HTTP请求头定义
socket:send("POST /api/V1/gateway/UpdateSensors/yourID HTTP/1.1\r\n" ..
"Host: www.lewei50.com\r\n" ..
"Content-Length: " .. string.len(PostData) .. "\r\n" ..
"userkey: yourKEY\r\n\r\n" ..
PostData .. "\r\n")
--HTTP响应内容
socket:on("receive", function(sck, response)
print(response)
end)
-- release module
si7021 = nil
package.loaded["si7021"]=nil
end)
# si7021 module
##Require
```lua
si7021 = require("si7021")
```
## Release
```lua
si7021 = nil
package.loaded["si7021"]=nil
```
<a id="si7021_init"></a>
##init()
####Description
Setting the i2c pin of si7021.<br />
####Syntax
init(sda, scl)
####Parameters
sda: 1~12, IO index.<br />
scl: 1~12, IO index.<br />
####Returns
nil
####Example
```lua
si7021 = require("si7021")
gpio5 = 1
gpio4 = 2
sda = gpio5
scl = gpio4
si7021.init(sda, scl)
-- Don't forget to release it after use
si7021 = nil
package.loaded["si7021"]=nil
```
####See also
**-** []()
<a id="si7021_read"></a>
##read()
####Description
Read temperature and humidity from si7021.<br />
####Syntax
read()
####Parameters
nil.<br />
####Returns
nil(Why?).<br />
####Example
```lua
si7021 = require("si7021")
sda = 1
scl = 2
si7021.init(sda, scl)
r = si7021.read()
print(r)
-- Don't forget to release it after use
si7021 = nil
package.loaded["si7021"]=nil
```
####See also
**-** []()
<a id="si7021_getHumidity"></a>
##getHumidity()
####Description
Get humidity from si7021.<br />
####Syntax
getHumidity()
####Parameters
nil.<br />
####Returns
h: Integer, humidity from si7021.
####Example
```lua
si7021 = require("si7021")
sda = 1
scl = 2
si7021.init(sda, scl)
h = si7021.getHumidity()
print(h)
-- Don't forget to release it after use
si7021 = nil
package.loaded["si7021"]=nil
```
####See also
**-** []()
<a id="si7021_getTemperature"></a>
##getTemperature()
####Description
Get temperature from si7021.<br />
####Syntax
getTemperature()
####Parameters
nil.<br />
####Returns
t: Integer, temperature from si7021.
####Example
```lua
si7021 = require("si7021")
sda = 1
scl = 2
si7021.init(sda, scl)
t = si7021.getTemperature()
print(t)
-- Don't forget to release it after use
si7021 = nil
package.loaded["si7021"]=nil
```
####See also
**-** []()
-- ***************************************************************************
-- SI7021 module for ESP8266 with nodeMCU
-- Si7021 compatible tested 2015-1-22
--
-- Written by VIP6
--
-- MIT license, http://opensource.org/licenses/MIT
-- ***************************************************************************
local moduleName = ...
local M = {}
_G[moduleName] = M
--I2C slave address of Si70xx
local Si7021_ADDR = 0x40
--Commands
local CMD_MEASURE_HUMIDITY_HOLD = 0xE5
local CMD_MEASURE_HUMIDITY_NO_HOLD = 0xF5
local CMD_MEASURE_TEMPERATURE_HOLD = 0xE3
local CMD_MEASURE_TEMPERATURE_NO_HOLD = 0xF3
-- temperature and pressure
local t,h
local init = false
-- i2c interface ID
local id = 0
-- 16-bit two's complement
-- value: 16-bit integer
local function twoCompl(value)
if value > 32767 then value = -(65535 - value + 1)
end
return value
end
-- read data from si7021
-- ADDR: slave address
-- commands: Commands of si7021
-- length: bytes to read
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(20000)
c = i2c.read(id, length)
i2c.stop(id)
return c
end
-- initialize module
-- sda: SDA pin
-- scl SCL pin
function M.init(sda, scl)
i2c.setup(id, sda, scl, i2c.SLOW)
--print("i2c ok..")
init = true
end
-- read humidity from si7021
local function read_humi()
dataH = read_data(Si7021_ADDR, CMD_MEASURE_HUMIDITY_HOLD, 2)
UH = string.byte(dataH, 1) * 256 + string.byte(dataH, 2)
h = ((UH*12500+65536/2)/65536 - 600)
return(h)
end
-- read temperature from si7021
local function read_temp()
dataT = read_data(Si7021_ADDR, CMD_MEASURE_TEMPERATURE_HOLD, 2)
UT = string.byte(dataT, 1) * 256 + string.byte(dataT, 2)
t = ((UT*17572+65536/2)/65536 - 4685)
return(t)
end
-- read temperature and humidity from si7021
function M.read()
if (not init) then
print("init() must be called before read.")
else
read_humi()
read_temp()
end
end;
-- get humidity
function M.getHumidity()
return h
end
-- get temperature
function M.getTemperature()
return t
end
return M
......@@ -36,6 +36,7 @@ pages:
- Support: 'en/support.md'
- Modules:
- 'adc': 'en/modules/adc.md'
- 'ads1115' : 'en/modules/ads1115.md'
- 'adxl345': 'en/modules/adxl345.md'
- 'am2320': 'en/modules/am2320.md'
- 'apa102': 'en/modules/apa102.md'
......@@ -52,6 +53,7 @@ pages:
- 'file': 'en/modules/file.md'
- 'gdbstub': 'en/modules/gdbstub.md'
- 'gpio': 'en/modules/gpio.md'
- 'hdc1080': 'en/modules/hdc1080.md'
- 'hmc5883l': 'en/modules/hmc5883l.md'
- 'http': 'en/modules/http.md'
- 'hx711' : 'en/modules/hx711.md'
......@@ -71,12 +73,15 @@ pages:
- 'rtcfifo': 'en/modules/rtcfifo.md'
- 'rtcmem': 'en/modules/rtcmem.md'
- 'rtctime': 'en/modules/rtctime.md'
- 'si7021' : 'en/modules/si7021.md'
- 'sigma delta': 'en/modules/sigma-delta.md'
- 'sjson': 'en/modules/sjson.md'
- 'sntp': 'en/modules/sntp.md'
- 'somfy': 'en/modules/somfy.md'
- 'spi': 'en/modules/spi.md'
- 'struct': 'en/modules/struct.md'
- 'switec': 'en/modules/switec.md'
- 'tcs34725': 'en/modules/tcs34725.md'
- 'tls': 'en/modules/tls.md'
- 'tm1829': 'en/modules/tm1829.md'
- 'tmr': 'en/modules/tmr.md'
......@@ -89,5 +94,6 @@ pages:
- 'wps': 'en/modules/wps.md'
- 'ws2801': 'en/modules/ws2801.md'
- 'ws2812': 'en/modules/ws2812.md'
- 'xpt2046': 'en/modules/xpt2046.md'
#- Deutsch:
# - Home: 'de/index.md'
......@@ -9,4 +9,6 @@ int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (pri
int ets_vsprintf (char *d, const char *s, va_list ap);
extern ETSTimer *timer_list;
#endif /* SDK_OVERRIDES_INCLUDE_ETS_SYS_H_ */
......@@ -2,7 +2,6 @@
#define _SDK_OVERRIDE_OSAPI_H_
#include "rom.h"
void ets_timer_arm_new (ETSTimer *a, int b, int c, int isMstimer);
int atoi(const char *nptr);
int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
......@@ -16,4 +15,15 @@ void call_user_start(void);
#include_next "osapi.h"
#ifdef ENABLE_TIMER_SUSPEND
extern void swtmr_register(void* timer_ptr);
#undef os_timer_arm
#define os_timer_arm(timer_ptr, duration, mode) do{swtmr_register(timer_ptr); \
ets_timer_arm_new(timer_ptr, duration, mode, 1);}while(0);
extern void swtmr_unregister(void* timer_ptr);
#undef os_timer_disarm
#define os_timer_disarm(timer_ptr) do{swtmr_unregister(timer_ptr); ets_timer_disarm(timer_ptr);}while(0);
#endif
#endif
......@@ -6,11 +6,13 @@
bool wifi_softap_deauth(uint8 mac[6]);
uint8 get_fpm_auto_sleep_flag(void);
enum ext_flash_size_map {
FLASH_SIZE_32M_MAP_2048_2048 = 7,
FLASH_SIZE_64M_MAP = 8,
FLASH_SIZE_128M_MAP = 9
};
//force sleep API
#define FPM_SLEEP_MAX_TIME 268435455 //0xFFFFFFF
void wifi_fpm_set_wakeup_cb(void (*fpm_wakeup_cb_func)(void));
bool fpm_is_open(void);
bool fpm_rf_is_closed(void);
uint8 get_fpm_auto_sleep_flag(void);
#endif /* SDK_OVERRIDES_INCLUDE_USER_INTERFACE_H_ */
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