Commit 0b01f28c authored by HuangRui's avatar HuangRui
Browse files

Merge branch 'dev' of https://github.com/nodemcu/nodemcu-firmware

Conflicts:
	app/include/user_modules.h
	app/include/user_version.h
parents e3c31d06 6c6d0d0e
......@@ -355,11 +355,29 @@ cs:listen(5683)
myvar=1
cs:var("myvar") -- get coap://192.168.18.103:5683/v1/v/myvar will return the value of myvar: 1
function myfun()
-- function should tack one string, return one string.
function myfun(payload)
print("myfun called")
respond = "hello"
return respond
end
cs:func("myfun") -- post coap://192.168.18.103:5683/v1/f/myfun will call myfun
cc = coap.Client()
cc:get(coap.CON, "coap://192.168.18.100:5683/.well-known/core")
cc:post(coap.NON, "coap://192.168.18.100:5683/", "Hello")
file.open("test1.txt", "a+") for i = 1, 100*1000 do file.write("x") end file.close() print("Done.")
for n,s in pairs(file.list()) do print(n.." size: "..s) end
file.remove("test1.txt")
for n,s in pairs(file.list()) do print(n.." size: "..s) end
file.open("test2.txt", "a+") for i = 1, 1*1000 do file.write("x") end file.close() print("Done.")
function TestDNSLeak()
c=net.createConnection(net.TCP, 0)
c:connect(80, "bad-name.tlddfdf")
tmr.alarm(1, 3000, 0, function() print("hack socket close, MEM: "..node.heap()) c:close() end) -- socket timeout hack
print("MEM: "..node.heap())
end
......@@ -3,6 +3,7 @@
-- NODEMCU TEAM
-- LICENCE: http://opensource.org/licenses/MIT
-- Vowstar <vowstar@nodemcu.com>
-- 2015/02/14 sza2 <sza2trash@gmail.com> Fix for negative values
--------------------------------------------------------------------------------
-- Set module name as parameter of require
......@@ -96,12 +97,16 @@ function readNumber(addr, unit)
crc = ow.crc8(string.sub(data,1,8))
-- print("CRC="..crc)
if (crc == data:byte(9)) then
t = (data:byte(1) + data:byte(2) * 256)
if (t > 32767) then
t = t - 65536
end
if(unit == nil or unit == C) then
t = (data:byte(1) + data:byte(2) * 256) * 625
t = t * 625
elseif(unit == F) then
t = (data:byte(1) + data:byte(2) * 256) * 1125 + 320000
t = t * 1125 + 320000
elseif(unit == K) then
t = (data:byte(1) + data:byte(2) * 256) * 625 + 2731500
t = t * 625 + 2731500
else
return nil
end
......
HDC1000 = require("HDC1000")
sda = 1
scl = 2
drdyn = false
HDC1000.init(sda, scl, drdyn)
HDC1000.config() -- default values are used if called with no arguments. prototype is config(address, resolution, heater)
print(string.format("Temperature: %.2f °C\nHumidity: %.2f %%", HDC1000.getTemp(), HDC1000.getHumi()))
HDC1000 = nil
package.loaded["HDC1000"]=nil
\ No newline at end of file
-------------------------------------------------------
-- This library was written for the Texas Instruments
-- HDC1000 temperature and humidity sensor.
-- It should work for the HDC1008 too.
-- Written by Francesco Truzzi (francesco@truzzi.me)
-- Released under GNU GPL v2.0 license.
-------------------------------------------------------
-------------- NON-DEFAULT CONFIG VALUES --------------
------------- config() optional arguments -------------
-- HDC1000_HEAT_OFF 0x00 (heater)
-- HDC1000_TEMP_11BIT 0x40 (resolution)
-- HDC1000_HUMI_11BIT 0x01 (resolution)
-- HDC1000_HUMI_8BIT 0x20 (resolution)
-------------------------------------------------------
local modname = ...
local M = {}
_G[modname] = M
local id = 0
local i2c = i2c
local delay = 20000
local _drdyn_pin
local HDC1000_ADDR = 0x40
local HDC1000_TEMP = 0x00
local HDC1000_HUMI = 0x01
local HDC1000_CONFIG = 0x02
local HDC1000_HEAT_ON = 0x20
local HDC1000_TEMP_HUMI_14BIT = 0x00
-- reads 16bits from the sensor
local function read16()
i2c.start(id)
i2c.address(id, HDC1000_ADDR, i2c.RECEIVER)
data_temp = i2c.read(0, 2)
i2c.stop(id)
data = bit.lshift(string.byte(data_temp, 1, 1), 8) + string.byte(data_temp, 2, 2)
return data
end
-- sets the register to read next
local function setReadRegister(register)
i2c.start(id)
i2c.address(id, HDC1000_ADDR, i2c.TRANSMITTER)
i2c.write(id, register)
i2c.stop(id)
end
-- writes the 2 configuration bytes
local function writeConfig(config)
i2c.start(id)
i2c.address(id, HDC1000_ADDR, i2c.TRANSMITTER)
i2c.write(id, HDC1000_CONFIG, config, 0x00)
i2c.stop(id)
end
-- returns true if battery voltage is < 2.7V, false otherwise
function M.batteryDead()
setReadRegister(HDC1000_CONFIG)
return(bit.isset(read16(), 11))
end
-- initalize i2c
function M.init(sda, scl, drdyn_pin)
_drdyn_pin = drdyn_pin
i2c.setup(id, sda, scl, i2c.SLOW)
end
function M.config(addr, resolution, heater)
-- default values are set if the function is called with no arguments
HDC1000_ADDR = addr or HDC1000_ADDR
resolution = resolution or HDC1000_TEMP_HUMI_14BIT
heater = heater or HDC1000_HEAT_ON
writeConfig(bit.bor(resolution, heater))
end
-- outputs temperature in Celsius degrees
function M.getHumi()
setReadRegister(HDC1000_HUMI)
if(_drdyn_pin ~= false) then
gpio.mode(_drdyn_pin, gpio.INPUT)
while(gpio.read(_drdyn_pin)==1) do
end
else tmr.delay(delay) end
return(read16()/65535.0*100)
end
-- outputs humidity in %RH
function M.getTemp()
setReadRegister(HDC1000_TEMP)
if(_drdyn_pin ~= false) then
gpio.mode(_drdyn_pin, gpio.INPUT)
while(gpio.read(_drdyn_pin)==1) do
end
else tmr.delay(delay) end
return(read16()/65535.0*165-40)
end
return M
HDC1000 NodeMCU module
=======================
Here's my NodeMCU module for the TI HDC1000 temperature and humidity sensor. It should work with the HDC1008 too but I haven't tested it.
### Setup your sensor:
First, require it:
`HDC1000 = require("HDC1000")`
Then, initialize it:
`HDC1000.init(sda, scl, drdyn)`
If you don't want to use the DRDYn pin, set it to false: a 20ms delay will be automatically set after each read request.
`HDC1000.init(sda, scl, false)`
Configure it:
`HDC1000.config()`
Default options set the address to 0x40 and enable both temperature and humidity readings at 14-bit resolution, with the integrated heater on. You can change them by initializing your sensor like this:
`HDC1000.config(address, resolution, heater);`
"resolution" can be set to 14 bits for both temperature and humidity (0x00 - default) 11 bits for temperature (0x40), 11 bits for humidity (0x01), 8 bits for humidity (0x20)
"heater" can be set to ON (0x20 - default) or OFF (0x00)
### Read some values
You can read temperature and humidity by using the following commands:
`temperature = HDC1000.getTemp()` in Celsius degrees.
`humidity = HDC1000.getHumi()` in %
### Check your battery
The following code returns true if the battery voltage is <2.8V, false otherwise.
`isDead = HDC1000.batteryDead();`
Happy making! Also, check out my Breakout Board and Arduino library for this chip: http://b.truzzi.me/hdc1000-temperature-and-humidity-sensor-breakout-with-arduino-library/.
[Downloads](https://github.com/nodemcu/nodemcu-firmware/releases/latest)
\ 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