Commit d77666c0 authored by sergio's avatar sergio Committed by Terry Ellison
Browse files

trailing spaces cleanup (#2659)

parent d7583040
...@@ -8,11 +8,11 @@ function M.run() ...@@ -8,11 +8,11 @@ function M.run()
print("Running component triangle...") print("Running component triangle...")
local m local m
disp:setColor(0, 0, 80, 20) disp:setColor(0, 0, 80, 20)
disp:setColor(1, 60, 80, 20) disp:setColor(1, 60, 80, 20)
disp:setColor(2, 60, 120, 0) disp:setColor(2, 60, 120, 0)
disp:setColor(3, 0, 140, 30) disp:setColor(3, 0, 140, 30)
disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight()) disp:drawGradientBox(0, 0, disp:getWidth(), disp:getHeight())
disp:setColor(255, 255, 255) disp:setColor(255, 255, 255)
...@@ -23,7 +23,7 @@ function M.run() ...@@ -23,7 +23,7 @@ function M.run()
while millis() < m do while millis() < m do
disp:setColor(bit.band(lcg_rnd(), 127)+127, bit.band(lcg_rnd(), 31), bit.band(lcg_rnd(), 127)+64) disp:setColor(bit.band(lcg_rnd(), 127)+127, bit.band(lcg_rnd(), 31), bit.band(lcg_rnd(), 127)+64)
disp:drawTriangle( disp:drawTriangle(
bit.rshift(lcg_rnd() * (disp:getWidth()), 8), bit.rshift(lcg_rnd() * (disp:getWidth()), 8),
bit.rshift(lcg_rnd() * (disp:getHeight()-20), 8) + 20, bit.rshift(lcg_rnd() * (disp:getHeight()-20), 8) + 20,
......
...@@ -67,7 +67,7 @@ function set_clip_range() ...@@ -67,7 +67,7 @@ function set_clip_range()
h = h + 25 h = h + 25
x = bit.rshift(lcg_rnd() * (disp:getWidth() - w), 8) x = bit.rshift(lcg_rnd() * (disp:getWidth() - w), 8)
y = bit.rshift(lcg_rnd() * (disp:getHeight() - h), 8) y = bit.rshift(lcg_rnd() * (disp:getHeight() - h), 8)
disp:setClipRange(x, y, w, h) disp:setClipRange(x, y, w, h)
end end
......
...@@ -64,7 +64,7 @@ function ic_body(x, y) ...@@ -64,7 +64,7 @@ function ic_body(x, y)
disp:setColor(2, 48, 48, 48) disp:setColor(2, 48, 48, 48)
disp:setColor(3, 30, 30, 30) disp:setColor(3, 30, 30, 30)
disp:drawGradientBox(x, y, w, h) disp:drawGradientBox(x, y, w, h)
disp:setColor(0, 255, 168, 0) disp:setColor(0, 255, 168, 0)
--disp:setColor(0, 225, 168, 30) --disp:setColor(0, 225, 168, 30)
disp:drawDisc(x+w-1, y+h/2-1, 7, bit.bor(ucg.DRAW_UPPER_LEFT, ucg.DRAW_LOWER_LEFT)) disp:drawDisc(x+w-1, y+h/2-1, 7, bit.bor(ucg.DRAW_UPPER_LEFT, ucg.DRAW_LOWER_LEFT))
...@@ -79,16 +79,16 @@ end ...@@ -79,16 +79,16 @@ end
function draw_ucg_logo() function draw_ucg_logo()
local a, b local a, b
--ucg_Init(ucg, ucg_sdl_dev_cb, ucg_ext_none, (ucg_com_fnptr)0) --ucg_Init(ucg, ucg_sdl_dev_cb, ucg_ext_none, (ucg_com_fnptr)0)
disp:setFont(ucg.font_ncenB24_tr) disp:setFont(ucg.font_ncenB24_tr)
--disp:setRotate270() --disp:setRotate270()
--disp:setClipRange(10,5,40,20) --disp:setClipRange(10,5,40,20)
a = 2 a = 2
b = 3 b = 3
disp:setColor(0, 135*a/b,206*a/b,250*a/b) disp:setColor(0, 135*a/b,206*a/b,250*a/b)
disp:setColor(1, 176*a/b,226*a/b,255*a/b) disp:setColor(1, 176*a/b,226*a/b,255*a/b)
disp:setColor(2, 25*a/b,25*a/b,112*a/b) disp:setColor(2, 25*a/b,25*a/b,112*a/b)
...@@ -118,7 +118,7 @@ function draw_ucg_logo() ...@@ -118,7 +118,7 @@ function draw_ucg_logo()
upper_pin(7+1*14, 4) upper_pin(7+1*14, 4)
upper_pin(7+2*14, 4) upper_pin(7+2*14, 4)
upper_pin(7+3*14, 4) upper_pin(7+3*14, 4)
ic_body(2, 10) ic_body(2, 10)
lower_pin(7+0*14, 41) lower_pin(7+0*14, 41)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- --
-- MIT license, http://opensource.org/licenses/MIT -- MIT license, http://opensource.org/licenses/MIT
-- *************************************************************************** -- ***************************************************************************
local moduleName = ... local moduleName = ...
local M = {} local M = {}
_G[moduleName] = M _G[moduleName] = M
--I2C slave address of GY-30 --I2C slave address of GY-30
......
...@@ -24,7 +24,7 @@ tmr.alarm(0, 60000, 1, function() ...@@ -24,7 +24,7 @@ tmr.alarm(0, 60000, 1, function()
PostData = "[{\"Name\":\"T\",\"Value\":\"" ..(l / 100).."."..(l % 100).."\"}]" PostData = "[{\"Name\":\"T\",\"Value\":\"" ..(l / 100).."."..(l % 100).."\"}]"
--创建一个TCP连接 Create a TCP Connection --创建一个TCP连接 Create a TCP Connection
socket=net.createConnection(net.TCP, 0) socket=net.createConnection(net.TCP, 0)
--域名解析IP地址并赋值 DNS...it --域名解析IP地址并赋值 DNS...it
socket:dns("www.lewei50.com", function(conn, ip) socket:dns("www.lewei50.com", function(conn, ip)
ServerIP = ip ServerIP = ip
print("Connection IP:" .. ServerIP) print("Connection IP:" .. ServerIP)
......
...@@ -21,24 +21,24 @@ t:enable_debug() ...@@ -21,24 +21,24 @@ t:enable_debug()
file.remove("ds18b20_save.lc") -- remove saved addresses file.remove("ds18b20_save.lc") -- remove saved addresses
print("=============================================", node.heap()) print("=============================================", node.heap())
print("first call, no addresses in flash, search is performed") print("first call, no addresses in flash, search is performed")
t:read_temp(readout, pin, t.C) t:read_temp(readout, pin, t.C)
tmr.create():alarm(2000, tmr.ALARM_SINGLE, function() tmr.create():alarm(2000, tmr.ALARM_SINGLE, function()
print("=============================================", node.heap()) print("=============================================", node.heap())
print("second readout, no new search, found addresses are used") print("second readout, no new search, found addresses are used")
t:read_temp(readout, pin) t:read_temp(readout, pin)
tmr.create():alarm(2000, tmr.ALARM_SINGLE, function() tmr.create():alarm(2000, tmr.ALARM_SINGLE, function()
print("=============================================", node.heap()) print("=============================================", node.heap())
print("force search again") print("force search again")
t:read_temp(readout, pin, nil, true) t:read_temp(readout, pin, nil, true)
tmr.create():alarm(2000, tmr.ALARM_SINGLE, function() tmr.create():alarm(2000, tmr.ALARM_SINGLE, function()
print("=============================================", node.heap()) print("=============================================", node.heap())
print("save search results") print("save search results")
t:read_temp(readout, pin, nil, false, true) t:read_temp(readout, pin, nil, false, true)
tmr.create():alarm(2000, tmr.ALARM_SINGLE, function() tmr.create():alarm(2000, tmr.ALARM_SINGLE, function()
print("=============================================", node.heap()) print("=============================================", node.heap())
print("use saved addresses") print("use saved addresses")
t.sens={} t.sens={}
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
local modname = ... local modname = ...
-- Used modules and functions -- Used modules and functions
local table, string, ow, tmr, print, type, tostring, pcall, ipairs = local table, string, ow, tmr, print, type, tostring, pcall, ipairs =
table, string, ow, tmr, print, type, tostring, pcall, ipairs table, string, ow, tmr, print, type, tostring, pcall, ipairs
-- Local functions -- Local functions
local ow_setup, ow_search, ow_select, ow_read, ow_read_bytes, ow_write, ow_crc8, ow_reset, ow_reset_search, ow_skip, ow_depower = local ow_setup, ow_search, ow_select, ow_read, ow_read_bytes, ow_write, ow_crc8, ow_reset, ow_reset_search, ow_skip, ow_depower =
ow.setup, ow.search, ow.select, ow.read, ow.read_bytes, ow.write, ow.crc8, ow.reset, ow.reset_search, ow.skip, ow.depower ow.setup, ow.search, ow.select, ow.read, ow.read_bytes, ow.write, ow.crc8, ow.reset, ow.reset_search, ow.skip, ow.depower
local node_task_post, node_task_LOW_PRIORITY = node.task.post, node.task.LOW_PRIORITY local node_task_post, node_task_LOW_PRIORITY = node.task.post, node.task.LOW_PRIORITY
local string_char, string_dump = string.char, string.dump local string_char, string_dump = string.char, string.dump
...@@ -44,7 +44,7 @@ local function to_string(addr, esc) ...@@ -44,7 +44,7 @@ local function to_string(addr, esc)
if type(addr) == 'string' and #addr == 8 then if type(addr) == 'string' and #addr == 8 then
return ( esc == true and return ( esc == true and
'"\\%u\\%u\\%u\\%u\\%u\\%u\\%u\\%u"' or '"\\%u\\%u\\%u\\%u\\%u\\%u\\%u\\%u"' or
'%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X '):format(addr:byte(1,8)) '%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X '):format(addr:byte(1,8))
else else
return tostring(addr) return tostring(addr)
end end
...@@ -65,21 +65,21 @@ local function readout(self) ...@@ -65,21 +65,21 @@ local function readout(self)
local t=(data:byte(1)+data:byte(2)*256) local t=(data:byte(1)+data:byte(2)*256)
-- t is actually signed so process the sign bit and adjust for fractional bits -- t is actually signed so process the sign bit and adjust for fractional bits
-- the DS18B20 family has 4 fractional bits and the DS18S20s, 1 fractional bit -- the DS18B20 family has 4 fractional bits and the DS18S20s, 1 fractional bit
t = ((t <= 32767) and t or t - 65536) * t = ((t <= 32767) and t or t - 65536) *
((addr:byte(1) == DS18B20FAMILY) and 625 or 5000) ((addr:byte(1) == DS18B20FAMILY) and 625 or 5000)
if 1/2 == 0 then if 1/2 == 0 then
-- integer version -- integer version
if unit == 'F' then if unit == 'F' then
t = (t * 18)/10 + 320000 t = (t * 18)/10 + 320000
elseif unit == 'K' then elseif unit == 'K' then
t = t + 2731500 t = t + 2731500
end end
local sgn = t<0 and -1 or 1 local sgn = t<0 and -1 or 1
local tA = sgn*t local tA = sgn*t
local tH=tA/10000 local tH=tA/10000
local tL=(tA%10000)/1000 + ((tA%1000)/100 >= 5 and 1 or 0) local tL=(tA%10000)/1000 + ((tA%1000)/100 >= 5 and 1 or 0)
if tH and (t~=850000) then if tH and (t~=850000) then
temp[addr]=(sgn<0 and "-" or "")..tH.."."..tL temp[addr]=(sgn<0 and "-" or "")..tH.."."..tL
debugPrint(to_string(addr),(sgn<0 and "-" or "")..tH.."."..tL) debugPrint(to_string(addr),(sgn<0 and "-" or "")..tH.."."..tL)
...@@ -94,7 +94,7 @@ local function readout(self) ...@@ -94,7 +94,7 @@ local function readout(self)
t = t * 18/10 + 32 t = t * 18/10 + 32
elseif unit == 'K' then elseif unit == 'K' then
t = t + 27315/100 t = t + 27315/100
end end
self.temp[addr]=t self.temp[addr]=t
debugPrint(to_string(addr), t) debugPrint(to_string(addr), t)
status[i] = 2 status[i] = 2
...@@ -104,12 +104,12 @@ local function readout(self) ...@@ -104,12 +104,12 @@ local function readout(self)
end end
next = next or status[i] == 0 next = next or status[i] == 0
end end
if next then if next then
node_task_post(node_task_LOW_PRIORITY, function() return conversion(self) end) node_task_post(node_task_LOW_PRIORITY, function() return conversion(self) end)
else else
--sens = {} --sens = {}
if cb then if cb then
node_task_post(node_task_LOW_PRIORITY, function() return cb(temp) end) node_task_post(node_task_LOW_PRIORITY, function() return cb(temp) end)
end end
end end
end end
...@@ -144,20 +144,20 @@ local function _search(self, lcb, lpin, search, save) ...@@ -144,20 +144,20 @@ local function _search(self, lcb, lpin, search, save)
self.temp = {} self.temp = {}
if search then self.sens = {}; status = {} end if search then self.sens = {}; status = {} end
local temp = self.temp local temp = self.temp
local sens = self.sens local sens = self.sens
pin = lpin or pin pin = lpin or pin
local addr local addr
if not search and #sens == 0 then if not search and #sens == 0 then
-- load addreses if available -- load addreses if available
debugPrint ("geting addreses from flash") debugPrint ("geting addreses from flash")
local s,check,a = pcall(dofile, "ds18b20_save.lc") local s,check,a = pcall(dofile, "ds18b20_save.lc")
if s and check == "ds18b20" then if s and check == "ds18b20" then
for i = 1, #a do sens[i] = a[i] end for i = 1, #a do sens[i] = a[i] end
end end
debugPrint (#sens, "addreses found") debugPrint (#sens, "addreses found")
end end
ow_setup(pin) ow_setup(pin)
if search or #sens == 0 then if search or #sens == 0 then
ow_reset_search(pin) ow_reset_search(pin)
...@@ -188,13 +188,13 @@ local function _search(self, lcb, lpin, search, save) ...@@ -188,13 +188,13 @@ local function _search(self, lcb, lpin, search, save)
-- save sensor addreses -- save sensor addreses
if save then if save then
debugPrint ("saving addreses to flash") debugPrint ("saving addreses to flash")
local addr_list = {} local addr_list = {}
for i =1, #sens do for i =1, #sens do
local s = sens[i] local s = sens[i]
addr_list[i] = to_string(s:sub(1,8), true)..('.."\\%u"'):format(s:byte(9)) addr_list[i] = to_string(s:sub(1,8), true)..('.."\\%u"'):format(s:byte(9))
end end
local save_statement = 'return "ds18b20", {' .. table_concat(addr_list, ',') .. '}' local save_statement = 'return "ds18b20", {' .. table_concat(addr_list, ',') .. '}'
debugPrint (save_statement) debugPrint (save_statement)
local save_file = file_open("ds18b20_save.lc","w") local save_file = file_open("ds18b20_save.lc","w")
save_file:write(string_dump(loadstring(save_statement))) save_file:write(string_dump(loadstring(save_statement)))
...@@ -211,7 +211,7 @@ local function read_temp(self, lcb, lpin, lunit, force_search, save_search) ...@@ -211,7 +211,7 @@ local function read_temp(self, lcb, lpin, lunit, force_search, save_search)
cb, unit = lcb, lunit or unit cb, unit = lcb, lunit or unit
_search(self, function() return conversion(self) end, lpin, force_search, save_search) _search(self, function() return conversion(self) end, lpin, force_search, save_search)
end end
-- Set module name as parameter of require and return module table -- Set module name as parameter of require and return module table
local M = { local M = {
sens = {}, sens = {},
......
--- ---
-- Working Example: https://www.youtube.com/watch?v=PDxTR_KJLhc -- Working Example: https://www.youtube.com/watch?v=PDxTR_KJLhc
-- IMPORTANT: run node.compile("imap.lua") after uploading this script -- IMPORTANT: run node.compile("imap.lua") after uploading this script
-- to create a compiled module. Then run file.remove("imap.lua") -- to create a compiled module. Then run file.remove("imap.lua")
-- @name imap -- @name imap
-- @description An IMAP 4rev1 module that can be used to read email. -- @description An IMAP 4rev1 module that can be used to read email.
-- Tested on NodeMCU 0.9.5 build 20150213. -- Tested on NodeMCU 0.9.5 build 20150213.
-- @date March 12, 2015 -- @date March 12, 2015
-- @author Miguel -- @author Miguel
-- GitHub: https://github.com/AllAboutEE -- GitHub: https://github.com/AllAboutEE
-- YouTube: https://www.youtube.com/user/AllAboutEE -- YouTube: https://www.youtube.com/user/AllAboutEE
-- Website: http://AllAboutEE.com -- Website: http://AllAboutEE.com
-- --
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
-- "How to test an IMAP server by using telnet" http://www.anta.net/misc/telnet-troubleshooting/imap.shtml -- "How to test an IMAP server by using telnet" http://www.anta.net/misc/telnet-troubleshooting/imap.shtml
-- "RFC 2060 - Internet Message Access Protocol - Version 4rev1" http://www.faqs.org/rfcs/rfc2060.html -- "RFC 2060 - Internet Message Access Protocol - Version 4rev1" http://www.faqs.org/rfcs/rfc2060.html
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
local moduleName = ... local moduleName = ...
local M = {} local M = {}
_G[moduleName] = M _G[moduleName] = M
local USERNAME = "" local USERNAME = ""
local PASSWORD = "" local PASSWORD = ""
local SERVER = "" local SERVER = ""
...@@ -44,7 +44,7 @@ end ...@@ -44,7 +44,7 @@ end
--- ---
-- @name display -- @name display
-- @description A generic IMAP response processing function. -- @description A generic IMAP response processing function.
-- Can disply the IMAP response if DEBUG is set to true. -- Can disply the IMAP response if DEBUG is set to true.
-- Sets the reponse processed variable to true when the string "complete" -- Sets the reponse processed variable to true when the string "complete"
-- is found in the IMAP reply/response -- is found in the IMAP reply/response
...@@ -55,7 +55,7 @@ local function display(socket, response) ...@@ -55,7 +55,7 @@ local function display(socket, response)
print(response) print(response)
end end
-- Some IMAP responses are long enough that they will cause the display -- Some IMAP responses are long enough that they will cause the display
-- function to be called several times. One thing is certain, IMAP will replay with -- function to be called several times. One thing is certain, IMAP will replay with
-- "<tag> OK <command> complete" when it's done sending data back. -- "<tag> OK <command> complete" when it's done sending data back.
if(string.match(response,'complete') ~= nil) then if(string.match(response,'complete') ~= nil) then
...@@ -64,7 +64,7 @@ local function display(socket, response) ...@@ -64,7 +64,7 @@ local function display(socket, response)
end end
--- ---
-- @name config -- @name config
-- @description Initiates the IMAP settings -- @description Initiates the IMAP settings
function M.config(username,password,tag,debug) function M.config(username,password,tag,debug)
...@@ -78,7 +78,7 @@ end ...@@ -78,7 +78,7 @@ end
-- @name login -- @name login
-- @descrpiton Logs into a new email session -- @descrpiton Logs into a new email session
function M.login(socket) function M.login(socket)
response_processed = false -- we are sending a new command response_processed = false -- we are sending a new command
-- which means that the response for it has not been processed -- which means that the response for it has not been processed
socket:send(TAG .. " LOGIN " .. USERNAME .. " " .. PASSWORD .. "\r\n") socket:send(TAG .. " LOGIN " .. USERNAME .. " " .. PASSWORD .. "\r\n")
socket:on("receive",display) socket:on("receive",display)
...@@ -92,7 +92,7 @@ function M.get_most_recent_num() ...@@ -92,7 +92,7 @@ function M.get_most_recent_num()
end end
--- ---
-- @name set_most_recent_num -- @name set_most_recent_num
-- @description Gets the most recent email number from the EXAMINE command. -- @description Gets the most recent email number from the EXAMINE command.
-- i.e. if EXAMINE returns "* 4 EXISTS" this means that there are 4 emails, -- i.e. if EXAMINE returns "* 4 EXISTS" this means that there are 4 emails,
-- so the latest/newest will be identified by the number 4 -- so the latest/newest will be identified by the number 4
...@@ -105,7 +105,7 @@ local function set_most_recent_num(socket,response) ...@@ -105,7 +105,7 @@ local function set_most_recent_num(socket,response)
local _, _, num = string.find(response,"([0-9]+) EXISTS(\.)") -- the _ and _ keep the index of the string found local _, _, num = string.find(response,"([0-9]+) EXISTS(\.)") -- the _ and _ keep the index of the string found
-- but we don't care about that. -- but we don't care about that.
if(num~=nil) then if(num~=nil) then
most_recent_num = num most_recent_num = num
end end
...@@ -133,7 +133,7 @@ end ...@@ -133,7 +133,7 @@ end
--- ---
-- @name set_header -- @name set_header
-- @description Records the IMAP header field response in a variable -- @description Records the IMAP header field response in a variable
-- so that it may be read later -- so that it may be read later
local function set_header(socket,response) local function set_header(socket,response)
if(DEBUG) then if(DEBUG) then
...@@ -162,14 +162,14 @@ end ...@@ -162,14 +162,14 @@ end
--- ---
-- @name get_body -- @name get_body
-- @return The last email read's body -- @return The last email read's body
function M.get_body() function M.get_body()
return body return body
end end
--- ---
-- @name set_body -- @name set_body
-- @description Records the IMAP body response in a variable -- @description Records the IMAP body response in a variable
-- so that it may be read later -- so that it may be read later
local function set_body(socket,response) local function set_body(socket,response)
......
...@@ -7,19 +7,19 @@ ...@@ -7,19 +7,19 @@
me to bias towards clarity of coding over brevity. It includes extra logic me to bias towards clarity of coding over brevity. It includes extra logic
to handle some of the edge case issues more robustly. It also uses a to handle some of the edge case issues more robustly. It also uses a
standard forward reference coding pattern to allow the code to be laid out standard forward reference coding pattern to allow the code to be laid out
in main routine, subroutine order. in main routine, subroutine order.
The app will only call one FTP.open() or FTP.createServer() at any time, The app will only call one FTP.open() or FTP.createServer() at any time,
with any multiple calls requected, so FTP is a singleton static object. with any multiple calls requected, so FTP is a singleton static object.
However there is nothing to stop multiple clients connecting to the FTP However there is nothing to stop multiple clients connecting to the FTP
listener at the same time, and indeed some FTP clients do use multiple listener at the same time, and indeed some FTP clients do use multiple
connections, so this server can accept and create multiple CON objects. connections, so this server can accept and create multiple CON objects.
Each CON object can also have a single DATA connection. Each CON object can also have a single DATA connection.
Note that FTP also exposes a number of really private properties (which Note that FTP also exposes a number of really private properties (which
could be stores in local / upvals) as FTP properties for debug purposes. could be stores in local / upvals) as FTP properties for debug purposes.
]] ]]
local file,net,wifi,node,string,table,tmr,pairs,print,pcall, tostring = local file,net,wifi,node,string,table,tmr,pairs,print,pcall, tostring =
file,net,wifi,node,string,table,tmr,pairs,print,pcall, tostring file,net,wifi,node,string,table,tmr,pairs,print,pcall, tostring
local post = node.task.post local post = node.task.post
local FTP, cnt = {client = {}}, 0 local FTP, cnt = {client = {}}, 0
...@@ -33,13 +33,13 @@ local processDataCmds -- function(cxt, cmd, arg) ...@@ -33,13 +33,13 @@ local processDataCmds -- function(cxt, cmd, arg)
local dataServer -- function(cxt, n) local dataServer -- function(cxt, n)
local ftpDataOpen -- function(dataSocket) local ftpDataOpen -- function(dataSocket)
-- Note these routines all used hoisted locals such as table and debug as -- Note these routines all used hoisted locals such as table and debug as
-- upvals for performance (ROTable lookup is slow on NodeMCU Lua), but -- upvals for performance (ROTable lookup is slow on NodeMCU Lua), but
-- data upvals (e.g. FTP) are explicitly list is -- "upval:" comments. -- data upvals (e.g. FTP) are explicitly list is -- "upval:" comments.
-- Note that the space between debug and the arglist is there for a reason -- Note that the space between debug and the arglist is there for a reason
-- so that a simple global edit " debug(" -> "-- debug(" or v.v. to -- so that a simple global edit " debug(" -> "-- debug(" or v.v. to
-- toggle debug compiled into the module. -- toggle debug compiled into the module.
local function debug (fmt, ...) -- upval: cnt (, print, node, tmr) local function debug (fmt, ...) -- upval: cnt (, print, node, tmr)
if not FTP.debug then return end if not FTP.debug then return end
...@@ -50,7 +50,7 @@ local function debug (fmt, ...) -- upval: cnt (, print, node, tmr) ...@@ -50,7 +50,7 @@ local function debug (fmt, ...) -- upval: cnt (, print, node, tmr)
end end
--------------------------- Set up the FTP object ---------------------------- --------------------------- Set up the FTP object ----------------------------
-- FTP has three static methods: open, createServer and close -- FTP has three static methods: open, createServer and close
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- optional wrapper around createServer() which also starts the wifi session -- optional wrapper around createServer() which also starts the wifi session
...@@ -82,9 +82,9 @@ function FTP.createServer(user, pass, dbgFlag) -- upval: FTP (, debug, tostring ...@@ -82,9 +82,9 @@ function FTP.createServer(user, pass, dbgFlag) -- upval: FTP (, debug, tostring
FTP.server:listen(21, function(sock) -- upval: FTP (, debug, pcall, type, processCommand) FTP.server:listen(21, function(sock) -- upval: FTP (, debug, pcall, type, processCommand)
-- since a server can have multiple connections, each connection -- since a server can have multiple connections, each connection
-- has a CNX table to store connection-wide globals. -- has a CNX table to store connection-wide globals.
local client = FTP.client local client = FTP.client
local CNX; CNX = { local CNX; CNX = {
validUser = false, validUser = false,
cmdSocket = sock, cmdSocket = sock,
send = function(rec, cb) -- upval: CNX (,debug) send = function(rec, cb) -- upval: CNX (,debug)
-- debug("Sending: %s", rec) -- debug("Sending: %s", rec)
...@@ -107,11 +107,11 @@ function FTP.createServer(user, pass, dbgFlag) -- upval: FTP (, debug, tostring ...@@ -107,11 +107,11 @@ function FTP.createServer(user, pass, dbgFlag) -- upval: FTP (, debug, tostring
-- debug("Authorising: %s", data) -- debug("Authorising: %s", data)
local cmd, arg = data:match('([A-Za-z]+) *([^\r\n]*)') local cmd, arg = data:match('([A-Za-z]+) *([^\r\n]*)')
local msg = "530 Not logged in, authorization required" local msg = "530 Not logged in, authorization required"
cmd = cmd:upper() cmd = cmd:upper()
if cmd == 'USER' then if cmd == 'USER' then
CNX.validUser = (arg == FTP.user) CNX.validUser = (arg == FTP.user)
msg = CNX.validUser and msg = CNX.validUser and
"331 OK. Password required" or "331 OK. Password required" or
"530 user not found" "530 user not found"
...@@ -133,7 +133,7 @@ function FTP.createServer(user, pass, dbgFlag) -- upval: FTP (, debug, tostring ...@@ -133,7 +133,7 @@ function FTP.createServer(user, pass, dbgFlag) -- upval: FTP (, debug, tostring
return CNX.send(msg) return CNX.send(msg)
end end
local port,ip = sock:getpeer() local port,ip = sock:getpeer()
-- debug("Connection accepted: (userdata) %s client %s:%u", tostring(sock), ip, port) -- debug("Connection accepted: (userdata) %s client %s:%u", tostring(sock), ip, port)
sock:on("receive", validateUser) sock:on("receive", validateUser)
...@@ -162,17 +162,17 @@ function FTP.close() -- upval: FTP (, debug, post, tostring) ...@@ -162,17 +162,17 @@ function FTP.close() -- upval: FTP (, debug, post, tostring)
FTP,_G.FTP = nil, nil -- the upval FTP can only be zeroed once FTP.client is cleared. FTP,_G.FTP = nil, nil -- the upval FTP can only be zeroed once FTP.client is cleared.
end end
end end
if svr then rollupClients(FTP.client, svr) end if svr then rollupClients(FTP.client, svr) end
package.loaded.ftpserver=nil package.loaded.ftpserver=nil
end -- FTP.close() end -- FTP.close()
----------------------------- Process Command -------------------------------- ----------------------------- Process Command --------------------------------
-- This splits the valid commands into one of three categories: -- This splits the valid commands into one of three categories:
-- * bare commands (which take no arg) -- * bare commands (which take no arg)
-- * simple commands (which take) a single arg; and -- * simple commands (which take) a single arg; and
-- * data commands which initiate data transfer to or from the client and -- * data commands which initiate data transfer to or from the client and
-- hence need to use CBs. -- hence need to use CBs.
-- --
-- Find strings are used do this lookup and minimise long if chains. -- Find strings are used do this lookup and minimise long if chains.
...@@ -184,9 +184,9 @@ processCommand = function(cxt, sock, data) -- upvals: (, debug, processBareCmds, ...@@ -184,9 +184,9 @@ processCommand = function(cxt, sock, data) -- upvals: (, debug, processBareCmds,
local cmd, arg = data:match('([a-zA-Z]+) *(.*)') local cmd, arg = data:match('([a-zA-Z]+) *(.*)')
cmd = cmd:upper() cmd = cmd:upper()
local _cmd_ = '_'..cmd..'_' local _cmd_ = '_'..cmd..'_'
if ('_CDUP_NOOP_PASV_PWD_QUIT_SYST_'):find(_cmd_) then if ('_CDUP_NOOP_PASV_PWD_QUIT_SYST_'):find(_cmd_) then
processBareCmds(cxt, cmd) processBareCmds(cxt, cmd)
elseif ('_CWD_DELE_MODE_PORT_RNFR_RNTO_SIZE_TYPE_'):find(_cmd_) then elseif ('_CWD_DELE_MODE_PORT_RNFR_RNTO_SIZE_TYPE_'):find(_cmd_) then
processSimpleCmds(cxt, cmd, arg) processSimpleCmds(cxt, cmd, arg)
elseif ('_LIST_NLST_RETR_STOR_'):find(_cmd_) then elseif ('_LIST_NLST_RETR_STOR_'):find(_cmd_) then
...@@ -212,15 +212,15 @@ processBareCmds = function(cxt, cmd) -- upval: (dataServer) ...@@ -212,15 +212,15 @@ processBareCmds = function(cxt, cmd) -- upval: (dataServer)
-- This FTP implementation ONLY supports PASV mode, and the passive port -- This FTP implementation ONLY supports PASV mode, and the passive port
-- listener is opened on receipt of the PASV command. If any data xfer -- listener is opened on receipt of the PASV command. If any data xfer
-- commands return an error if the PASV command hasn't been received. -- commands return an error if the PASV command hasn't been received.
-- Note the listener service is closed on receipt of the next PASV or -- Note the listener service is closed on receipt of the next PASV or
-- quit. -- quit.
local ip, port, pphi, pplo, i1, i2, i3, i4, _ local ip, port, pphi, pplo, i1, i2, i3, i4, _
_,ip = cxt.cmdSocket:getaddr() _,ip = cxt.cmdSocket:getaddr()
port = 2121 port = 2121
pplo = port % 256 pplo = port % 256
pphi = (port-pplo)/256 pphi = (port-pplo)/256
i1,i2,i3,i4 = ip:match("(%d+).(%d+).(%d+).(%d+)") i1,i2,i3,i4 = ip:match("(%d+).(%d+).(%d+).(%d+)")
dataServer(cxt, port) dataServer(cxt, port)
return send( return send(
('227 Entering Passive Mode(%d,%d,%d,%d,%d,%d)'):format( ('227 Entering Passive Mode(%d,%d,%d,%d,%d,%d)'):format(
i1,i2,i3,i4,pphi,pplo)) i1,i2,i3,i4,pphi,pplo))
...@@ -230,16 +230,16 @@ processBareCmds = function(cxt, cmd) -- upval: (dataServer) ...@@ -230,16 +230,16 @@ processBareCmds = function(cxt, cmd) -- upval: (dataServer)
elseif cmd == 'QUIT' then elseif cmd == 'QUIT' then
send("221 Goodbye", function() cxt.close(cxt.cmdSocket) end) send("221 Goodbye", function() cxt.close(cxt.cmdSocket) end)
return return
elseif cmd == 'SYST' then elseif cmd == 'SYST' then
-- return send("215 UNKNOWN") -- return send("215 UNKNOWN")
return send("215 UNIX Type: L8") -- must be Unix so ls is parsed correctly return send("215 UNIX Type: L8") -- must be Unix so ls is parsed correctly
else else
error('Oops. Missed '..cmd) error('Oops. Missed '..cmd)
end end
end -- processBareCmds(cmd, send) end -- processBareCmds(cmd, send)
------------------------- Process Simple Commands ---------------------------- ------------------------- Process Simple Commands ----------------------------
local from -- needs to persist between simple commands local from -- needs to persist between simple commands
...@@ -264,11 +264,11 @@ processSimpleCmds = function(cxt, cmd, arg) -- upval: from (, file, tostring, d ...@@ -264,11 +264,11 @@ processSimpleCmds = function(cxt, cmd, arg) -- upval: from (, file, tostring, d
return send("200 TYPE is now 8-bit binary") return send("200 TYPE is now 8-bit binary")
else else
return send("504 Unknown TYPE") return send("504 Unknown TYPE")
end end
end end
-- The remaining commands take a filename as an arg. Strip off leading / and ./ -- The remaining commands take a filename as an arg. Strip off leading / and ./
arg = arg:gsub('^%.?/',''):gsub('^%.?/','') arg = arg:gsub('^%.?/',''):gsub('^%.?/','')
debug("Filename is %s",arg) debug("Filename is %s",arg)
if cmd == 'CWD' then if cmd == 'CWD' then
...@@ -279,7 +279,7 @@ processSimpleCmds = function(cxt, cmd, arg) -- upval: from (, file, tostring, d ...@@ -279,7 +279,7 @@ processSimpleCmds = function(cxt, cmd, arg) -- upval: from (, file, tostring, d
elseif cmd == 'DELE' then elseif cmd == 'DELE' then
if file.exists(arg) then if file.exists(arg) then
file.remove(arg) file.remove(arg)
if not file.exists(arg) then return send("250 Deleted "..arg) end if not file.exists(arg) then return send("250 Deleted "..arg) end
end end
return send("550 Requested action not taken") return send("550 Requested action not taken")
...@@ -297,11 +297,11 @@ processSimpleCmds = function(cxt, cmd, arg) -- upval: from (, file, tostring, d ...@@ -297,11 +297,11 @@ processSimpleCmds = function(cxt, cmd, arg) -- upval: from (, file, tostring, d
"550 Requested action not taken") "550 Requested action not taken")
elseif cmd == "SIZE" then elseif cmd == "SIZE" then
local st = file.stat(arg) local st = file.stat(arg)
return send(st and ("213 "..st.size) or return send(st and ("213 "..st.size) or
"550 Could not get file size.") "550 Could not get file size.")
else else
error('Oops. Missed '..cmd) error('Oops. Missed '..cmd)
end end
end -- processSimpleCmds(cmd, arg, send) end -- processSimpleCmds(cmd, arg, send)
...@@ -318,12 +318,12 @@ processDataCmds = function(cxt, cmd, arg) -- upval: FTP (, pairs, file, tostrin ...@@ -318,12 +318,12 @@ processDataCmds = function(cxt, cmd, arg) -- upval: FTP (, pairs, file, tostrin
cxt.getData, cxt.setData = nil, nil cxt.getData, cxt.setData = nil, nil
arg = arg:gsub('^%.?/',''):gsub('^%.?/','') arg = arg:gsub('^%.?/',''):gsub('^%.?/','')
if cmd == "LIST" or cmd == "NLST" then if cmd == "LIST" or cmd == "NLST" then
-- There are -- There are
local fileSize, nameList, pattern = file.list(), {}, '.' local fileSize, nameList, pattern = file.list(), {}, '.'
arg = arg:gsub('^-[a-z]* *', '') -- ignore any Unix style command parameters arg = arg:gsub('^-[a-z]* *', '') -- ignore any Unix style command parameters
arg = arg:gsub('^/','') -- ignore any leading / arg = arg:gsub('^/','') -- ignore any leading /
...@@ -332,26 +332,26 @@ processDataCmds = function(cxt, cmd, arg) -- upval: FTP (, pairs, file, tostrin ...@@ -332,26 +332,26 @@ processDataCmds = function(cxt, cmd, arg) -- upval: FTP (, pairs, file, tostrin
end end
for k,v in pairs(fileSize) do for k,v in pairs(fileSize) do
if k:match(pattern) then if k:match(pattern) then
nameList[#nameList+1] = k nameList[#nameList+1] = k
else else
fileSize[k] = nil fileSize[k] = nil
end end
end end
table.sort(nameList) table.sort(nameList)
function cxt.getData() -- upval: cmd, fileSize, nameList (, table) function cxt.getData() -- upval: cmd, fileSize, nameList (, table)
local list, user, v = {}, FTP.user local list, user, v = {}, FTP.user
for i = 1,10 do for i = 1,10 do
if #nameList == 0 then break end if #nameList == 0 then break end
local f = table.remove(nameList, 1) local f = table.remove(nameList, 1)
list[#list+1] = (cmd == "LIST") and list[#list+1] = (cmd == "LIST") and
("-rw-r--r-- 1 %s %s %6u Jan 1 00:00 %s\r\n"):format(user, user, fileSize[f], f) or ("-rw-r--r-- 1 %s %s %6u Jan 1 00:00 %s\r\n"):format(user, user, fileSize[f], f) or
(f.."\r\n") (f.."\r\n")
end end
return table.concat(list) return table.concat(list)
end end
elseif cmd == "RETR" then elseif cmd == "RETR" then
local f = file.open(arg, "r") local f = file.open(arg, "r")
if f then -- define a getter to read the file if f then -- define a getter to read the file
...@@ -379,7 +379,7 @@ processDataCmds = function(cxt, cmd, arg) -- upval: FTP (, pairs, file, tostrin ...@@ -379,7 +379,7 @@ processDataCmds = function(cxt, cmd, arg) -- upval: FTP (, pairs, file, tostrin
send((cxt.getData or cxt.setData) and "150 Accepted data connection" or send((cxt.getData or cxt.setData) and "150 Accepted data connection" or
"451 Can't open/create "..arg) "451 Can't open/create "..arg)
if cxt.getData and cxt.dataSocket then if cxt.getData and cxt.dataSocket then
debug ("poking sender to initiate first xfer") debug ("poking sender to initiate first xfer")
post(function() cxt.sender(cxt.dataSocket) end) post(function() cxt.sender(cxt.dataSocket) end)
end end
...@@ -389,17 +389,17 @@ end -- processDataCmds(cmd, arg, send) ...@@ -389,17 +389,17 @@ end -- processDataCmds(cmd, arg, send)
----------------------------- Data Port Routines ----------------------------- ----------------------------- Data Port Routines -----------------------------
-- These are used to manage the data transfer over the data port. This is -- These are used to manage the data transfer over the data port. This is
-- set up lazily either by a PASV or by the first LIST NLST RETR or STOR -- set up lazily either by a PASV or by the first LIST NLST RETR or STOR
-- command that uses it. These also provide a sendData / receiveData cb to -- command that uses it. These also provide a sendData / receiveData cb to
-- handle the actual xfer. Also note that the sending process can be primed in -- handle the actual xfer. Also note that the sending process can be primed in
-- --
---------------- Open a new data server and port --------------------------- ---------------- Open a new data server and port ---------------------------
dataServer = function(cxt, n) -- upval: (pcall, net, ftpDataOpen, debug, tostring) dataServer = function(cxt, n) -- upval: (pcall, net, ftpDataOpen, debug, tostring)
local dataServer = cxt.dataServer local dataServer = cxt.dataServer
if dataServer then -- close any existing listener if dataServer then -- close any existing listener
pcall(dataServer.close, dataServer) pcall(dataServer.close, dataServer)
end end
if n then if n then
-- Open a new listener if needed. Note that this is only used to establish -- Open a new listener if needed. Note that this is only used to establish
-- a single connection, so ftpDataOpen closes the server socket -- a single connection, so ftpDataOpen closes the server socket
cxt.dataServer = net.createServer(net.TCP, 300) cxt.dataServer = net.createServer(net.TCP, 300)
...@@ -423,7 +423,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall) ...@@ -423,7 +423,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall)
cxt.dataServer:close() cxt.dataServer:close()
cxt.dataServer = nil cxt.dataServer = nil
local function cleardown(skt,type) -- upval: cxt (, debug, tostring, post, pcall) local function cleardown(skt,type) -- upval: cxt (, debug, tostring, post, pcall)
type = type==1 and "disconnection" or "reconnection" type = type==1 and "disconnection" or "reconnection"
local which = cxt.setData and "setData" or (cxt.getData and cxt.getData or "neither") local which = cxt.setData and "setData" or (cxt.getData and cxt.getData or "neither")
...@@ -431,7 +431,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall) ...@@ -431,7 +431,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall)
if cxt.setData then if cxt.setData then
cxt.fileClose() cxt.fileClose()
cxt.setData = nil cxt.setData = nil
cxt.send("226 Transfer complete.") cxt.send("226 Transfer complete.")
else else
cxt.getData, cxt.sender = nil, nil cxt.getData, cxt.sender = nil, nil
...@@ -453,12 +453,12 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall) ...@@ -453,12 +453,12 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall)
if not on_hold then if not on_hold then
-- Cludge to stop the client flooding the ESP SPIFFS on an upload of a -- Cludge to stop the client flooding the ESP SPIFFS on an upload of a
-- large file. As soon as a record arrives assert a flow control hold. -- large file. As soon as a record arrives assert a flow control hold.
-- This can take up to 5 packets to come into effect at which point the -- This can take up to 5 packets to come into effect at which point the
-- low priority unhold task is executed releasing the flow again. -- low priority unhold task is executed releasing the flow again.
-- debug("Issuing hold on data socket %s", tostring(skt)) -- debug("Issuing hold on data socket %s", tostring(skt))
skt:hold(); on_hold = true skt:hold(); on_hold = true
post(node.task.LOW_PRIORITY, post(node.task.LOW_PRIORITY,
function() -- upval: skt, on_hold (, debug, tostring)) function() -- upval: skt, on_hold (, debug, tostring))
-- debug("Issuing unhold on data socket %s", tostring(skt)) -- debug("Issuing unhold on data socket %s", tostring(skt))
pcall(skt.unhold, skt); on_hold = false pcall(skt.unhold, skt); on_hold = false
...@@ -484,7 +484,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall) ...@@ -484,7 +484,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall)
-- debug("Send of data completed") -- debug("Send of data completed")
skt:close() skt:close()
cxt.send("226 Transfer complete.") cxt.send("226 Transfer complete.")
cxt.getData, cxt.dataSocket = nil, nil cxt.getData, cxt.dataSocket = nil, nil
end end
end end
...@@ -496,7 +496,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall) ...@@ -496,7 +496,7 @@ ftpDataOpen = function(cxt, dataSocket) -- upval: (debug, tostring, post, pcall)
if cxt.getData then cxt.sender(cxt.dataSocket) end if cxt.getData then cxt.sender(cxt.dataSocket) end
end -- ftpDataOpen(socket) end -- ftpDataOpen(socket)
------------------------------------------------ ----------------------------- ------------------------------------------------ -----------------------------
return FTP return FTP
------------------------------------------------------- -------------------------------------------------------
-- This library was written for the Texas Instruments -- This library was written for the Texas Instruments
-- HDC1000 temperature and humidity sensor. -- HDC1000 temperature and humidity sensor.
-- It should work for the HDC1008 too. -- It should work for the HDC1008 too.
-- Written by Francesco Truzzi (francesco@truzzi.me) -- Written by Francesco Truzzi (francesco@truzzi.me)
-- Released under GNU GPL v2.0 license. -- Released under GNU GPL v2.0 license.
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
-- --
-- Written by Levente Tamas <levente.tamas@navicron.com> -- Written by Levente Tamas <levente.tamas@navicron.com>
-- --
-- modify by Garberoglio Leonardo <leogarberoglio@gmail.com> -- modify by Garberoglio Leonardo <leogarberoglio@gmail.com>
-- --
-- GNU LGPL, see https://www.gnu.org/copyleft/lesser.html -- GNU LGPL, see https://www.gnu.org/copyleft/lesser.html
-- ****************************************************** -- ******************************************************
...@@ -38,7 +38,7 @@ local function read_reg(reg_addr, len) ...@@ -38,7 +38,7 @@ local function read_reg(reg_addr, len)
end end
i2c.stop(id) i2c.stop(id)
return ret return ret
end end
--write reg with data table --write reg with data table
local function write_reg(reg_addr, data) local function write_reg(reg_addr, data)
...@@ -47,7 +47,7 @@ local function write_reg(reg_addr, data) ...@@ -47,7 +47,7 @@ local function write_reg(reg_addr, data)
i2c.write(id, reg_addr) i2c.write(id, reg_addr)
i2c.write(id, data) i2c.write(id, data)
i2c.stop(id) i2c.stop(id)
end end
--write comparison reg with 2 bytes --write comparison reg with 2 bytes
local function write_comp_reg(reg_addr, msb, lsb) local function write_comp_reg(reg_addr, msb, lsb)
...@@ -55,9 +55,9 @@ local function write_comp_reg(reg_addr, msb, lsb) ...@@ -55,9 +55,9 @@ local function write_comp_reg(reg_addr, msb, lsb)
i2c.address(id, address, i2c.TRANSMITTER) i2c.address(id, address, i2c.TRANSMITTER)
i2c.write(id, reg_addr) i2c.write(id, reg_addr)
i2c.write(id, msb) i2c.write(id, msb)
i2c.write(id, lsb) i2c.write(id, lsb)
i2c.stop(id) i2c.stop(id)
end end
-- initialize i2c -- initialize i2c
-- a: i2c addr 0x48|A1<<1|A0 (A0-A1: chip pins) -- a: i2c addr 0x48|A1<<1|A0 (A0-A1: chip pins)
function M.setup(a) function M.setup(a)
...@@ -70,7 +70,7 @@ function M.setup(a) ...@@ -70,7 +70,7 @@ function M.setup(a)
print("device not found") print("device not found")
return nil return nil
end end
else else
print("wrong i2c address") return nil print("wrong i2c address") return nil
end end
end end
......
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
-- MCP23008 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf -- MCP23008 Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf
-- Tested on NodeMCU 0.9.5 build 20150213. -- Tested on NodeMCU 0.9.5 build 20150213.
-- @date March 02, 2015 -- @date March 02, 2015
-- @author Miguel -- @author Miguel
-- GitHub: https://github.com/AllAboutEE -- GitHub: https://github.com/AllAboutEE
-- YouTube: https://www.youtube.com/user/AllAboutEE -- YouTube: https://www.youtube.com/user/AllAboutEE
-- Website: http://AllAboutEE.com -- Website: http://AllAboutEE.com
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local moduleName = ... local moduleName = ...
local M = {} local M = {}
_G[moduleName] = M _G[moduleName] = M
-- Constant device address. -- Constant device address.
local MCP23008_ADDRESS = 0x20 local MCP23008_ADDRESS = 0x20
...@@ -84,10 +84,10 @@ end ...@@ -84,10 +84,10 @@ end
--- ---
--! @name begin --! @name begin
--! @description Sets the MCP23008 device address's last three bits. --! @description Sets the MCP23008 device address's last three bits.
-- Note: The address is defined as binary 0100[A2][A1][A0] where -- Note: The address is defined as binary 0100[A2][A1][A0] where
-- A2, A1, and A0 are defined by the connection of the pins, -- A2, A1, and A0 are defined by the connection of the pins,
-- e.g. if the pins are connected all to GND then the paramter address -- e.g. if the pins are connected all to GND then the paramter address
-- will need to be 0x0. -- will need to be 0x0.
-- @param address The 3 least significant bits (LSB) of the address -- @param address The 3 least significant bits (LSB) of the address
-- @param pinSDA The pin to use for SDA -- @param pinSDA The pin to use for SDA
...@@ -140,8 +140,8 @@ end ...@@ -140,8 +140,8 @@ end
--- ---
-- @name writeGPPU The byte to write to the GPPU -- @name writeGPPU The byte to write to the GPPU
-- @description Writes a byte of data to the -- @description Writes a byte of data to the
-- PULL-UP RESISTOR CONFIGURATION (GPPU)REGISTER -- PULL-UP RESISTOR CONFIGURATION (GPPU)REGISTER
-- @param databyte the value to write to the GPPU register. -- @param databyte the value to write to the GPPU register.
-- each bit in this byte is assigned to an individual GPIO pin -- each bit in this byte is assigned to an individual GPIO pin
-- @return void -- @return void
......
...@@ -17,9 +17,9 @@ yeelink.init(23333,23333,"You api-key",function() --Step3: Register the callbac ...@@ -17,9 +17,9 @@ yeelink.init(23333,23333,"You api-key",function() --Step3: Register the callbac
print("Yeelink Init OK...") print("Yeelink Init OK...")
tmr.alarm(1,60000,1,function() --Step4: Have fun~ (Update your data) tmr.alarm(1,60000,1,function() --Step4: Have fun~ (Update your data)
dht.read(4) dht.read(4)
yeelink.update(dht.getTemperature()) yeelink.update(dht.getTemperature())
end) end)
end) end)
...@@ -34,7 +34,7 @@ if wifi.sta.getip() == nil then ...@@ -34,7 +34,7 @@ if wifi.sta.getip() == nil then
tmr.alarm(1,1000,1,function () tmr.alarm(1,1000,1,function ()
if wifi.sta.getip() ~= nil then if wifi.sta.getip() ~= nil then
tmr.stop(1) tmr.stop(1)
sk:dns("api.yeelink.net",function(conn,ip) sk:dns("api.yeelink.net",function(conn,ip)
dns=ip dns=ip
print("DNS YEELINK OK... IP: "..dns) print("DNS YEELINK OK... IP: "..dns)
end) end)
...@@ -42,7 +42,7 @@ if wifi.sta.getip() == nil then ...@@ -42,7 +42,7 @@ if wifi.sta.getip() == nil then
end) end)
end end
sk:dns("api.yeelink.net",function(conn,ip) sk:dns("api.yeelink.net",function(conn,ip)
dns=ip dns=ip
...@@ -74,8 +74,8 @@ end ...@@ -74,8 +74,8 @@ end
--========Check the DNS Status=========== --========Check the DNS Status===========
--if DNS success, return the address(string) --if DNS success, return the address(string)
--if DNS fail(or processing), return nil --if DNS fail(or processing), return nil
-- --
-- --
--======================================== --========================================
function M.getDNS() function M.getDNS()
...@@ -96,11 +96,11 @@ function M.update(_datapoint) ...@@ -96,11 +96,11 @@ function M.update(_datapoint)
datapoint = tostring(_datapoint) datapoint = tostring(_datapoint)
sk:on("connection", function(conn) sk:on("connection", function(conn)
print("connect OK...")
print("connect OK...")
local a=[[{"value":]] local a=[[{"value":]]
local b=[[}]] local b=[[}]]
...@@ -116,10 +116,10 @@ function M.update(_datapoint) ...@@ -116,10 +116,10 @@ function M.update(_datapoint)
end) end)
sk:on("receive", function(sck, content) sk:on("receive", function(sck, content)
if debug then if debug then
print("\r\n"..content.."\r\n") print("\r\n"..content.."\r\n")
else else
print("Date Receive") print("Date Receive")
end end
......
################################################################# #################################################################
# This file is configured in RTD -> Admin -> Advanced Settings! # # This file is configured in RTD -> Admin -> Advanced Settings! #
################################################################# #################################################################
# Enforce a specific MkDocs version by using the standard pip requirements.txt syntax # Enforce a specific MkDocs version by using the standard pip requirements.txt syntax
# mkdocs >= 0.16.3, < 0.17 # mkdocs >= 0.16.3, < 0.17
...@@ -6,7 +6,7 @@ FSSOURCE ?= ../local/fs ...@@ -6,7 +6,7 @@ FSSOURCE ?= ../local/fs
LUASOURCE ?= ../local/lua LUASOURCE ?= ../local/lua
FLASHSIZE ?= 4mb 32mb 8mb FLASHSIZE ?= 4mb 32mb 8mb
FLASH_SW = -S FLASH_SW = -S
SUBDIRS = SUBDIRS =
OBJDUMP = $(or $(shell which objdump),xtensa-lx106-elf-objdump) OBJDUMP = $(or $(shell which objdump),xtensa-lx106-elf-objdump)
...@@ -25,14 +25,14 @@ FLASH_FS_SIZE := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPI ...@@ -25,14 +25,14 @@ FLASH_FS_SIZE := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPI
ifneq ($(strip $(FLASH_FS_SIZE)),) ifneq ($(strip $(FLASH_FS_SIZE)),)
FLASHSIZE = $(shell printf "0x%x" $(FLASH_FS_SIZE)) FLASHSIZE = $(shell printf "0x%x" $(FLASH_FS_SIZE))
FLASH_SW = -c FLASH_SW = -c
endif endif
FLASH_FS_LOC := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPIFFS_FIXED_LOCATION| cut -d ' ' -f 3) FLASH_FS_LOC := $(shell $(CC) -E -dM - <../app/include/user_config.h | grep SPIFFS_FIXED_LOCATION| cut -d ' ' -f 3)
ifeq ($(strip $(FLASH_FS_LOC)),) ifeq ($(strip $(FLASH_FS_LOC)),)
FLASH_FS_LOC := $(shell printf "0x%x" $$((0x$(shell $(OBJDUMP) -t ../app/.output/eagle/debug/image/eagle.app.v6.out |grep " _flash_used_end" |cut -f1 -d" ") - 0x40200000))) FLASH_FS_LOC := $(shell printf "0x%x" $$((0x$(shell $(OBJDUMP) -t ../app/.output/eagle/debug/image/eagle.app.v6.out |grep " _flash_used_end" |cut -f1 -d" ") - 0x40200000)))
else else
FLASH_FS_LOC := $(shell printf "0x%x" $(FLASH_FS_LOC)) FLASH_FS_LOC := $(shell printf "0x%x" $(FLASH_FS_LOC))
endif endif
LFSSOURCES := $(wildcard $(LUASOURCE)/*.lua) LFSSOURCES := $(wildcard $(LUASOURCE)/*.lua)
...@@ -58,7 +58,7 @@ TEST: ...@@ -58,7 +58,7 @@ TEST:
@echo $(FLASH_FS_LOC) @echo $(FLASH_FS_LOC)
@echo $(FLASH_USED_END) @echo $(FLASH_USED_END)
spiffsimg/spiffsimg: spiffsimg/spiffsimg:
.PHONY: spiffsimg .PHONY: spiffsimg
...@@ -67,8 +67,8 @@ spiffsimg/spiffsimg: ...@@ -67,8 +67,8 @@ spiffsimg/spiffsimg:
spiffsimg: spiffsimg/spiffsimg spiffsimg: spiffsimg/spiffsimg
@echo Built spiffsimg in spiffsimg/spiffsimg @echo Built spiffsimg in spiffsimg/spiffsimg
spiffsimg/spiffsimg: spiffsimg/spiffsimg:
@$(MAKE) -C spiffsimg @$(MAKE) -C spiffsimg
spiffsscript: remove-image LFSimage spiffsimg/spiffsimg spiffsscript: remove-image LFSimage spiffsimg/spiffsimg
rm -f ./spiffsimg/spiffs.lst rm -f ./spiffsimg/spiffs.lst
...@@ -81,7 +81,7 @@ ifneq ($(LFSSOURCES),) ...@@ -81,7 +81,7 @@ ifneq ($(LFSSOURCES),)
LFSimage: $(LFSSOURCES) LFSimage: $(LFSSOURCES)
$(LUAC_CROSS) -f -o $(FSSOURCE)/LFS.img $(LFSSOURCES) $(LUAC_CROSS) -f -o $(FSSOURCE)/LFS.img $(LFSSOURCES)
else else
LFSimage: LFSimage:
rm -f $(FSSOURCE)/LFS.img rm -f $(FSSOURCE)/LFS.img
endif endif
......
...@@ -7,7 +7,7 @@ class Cert(object): ...@@ -7,7 +7,7 @@ class Cert(object):
self.len = len(buff) self.len = len(buff)
self.buff = buff self.buff = buff
pass pass
def __str__(self): def __str__(self):
out_str = ['\0']*32 out_str = ['\0']*32
for i in range(len(self.name)): for i in range(len(self.name)):
......
...@@ -11,7 +11,7 @@ class Cert(object): ...@@ -11,7 +11,7 @@ class Cert(object):
self.len = len(buff) self.len = len(buff)
self.buff = buff self.buff = buff
pass pass
def __str__(self): def __str__(self):
out_str = ['\0']*32 out_str = ['\0']*32
for i in range(len(self.name)): for i in range(len(self.name)):
...@@ -26,11 +26,11 @@ class Cert(object): ...@@ -26,11 +26,11 @@ class Cert(object):
def main(): def main():
parser = argparse.ArgumentParser(description='Convert PEM file(s) into C source file.') parser = argparse.ArgumentParser(description='Convert PEM file(s) into C source file.')
parser.add_argument('--section', parser.add_argument('--section',
default='.servercert.flash', default='.servercert.flash',
help='specify the section for the data (default is .servercert.flash)') help='specify the section for the data (default is .servercert.flash)')
parser.add_argument('--name', parser.add_argument('--name',
default='tls_server_cert_area', default='tls_server_cert_area',
help='specify the variable name for the data (default is tls_server_cert_area)') help='specify the variable name for the data (default is tls_server_cert_area)')
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
PROJECT_NAME="Nodemcu Project" PROJECT_NAME="Nodemcu Project"
# Generate the openssl configuration files. # Generate the openssl configuration files.
cat > ca_cert.conf << EOF cat > ca_cert.conf << EOF
[ req ] [ req ]
distinguished_name = req_distinguished_name distinguished_name = req_distinguished_name
prompt = no prompt = no
...@@ -31,7 +31,7 @@ prompt = no ...@@ -31,7 +31,7 @@ prompt = no
O = $PROJECT_NAME Dodgy Certificate Authority O = $PROJECT_NAME Dodgy Certificate Authority
EOF EOF
cat > certs.conf << EOF cat > certs.conf << EOF
[ req ] [ req ]
distinguished_name = req_distinguished_name distinguished_name = req_distinguished_name
prompt = no prompt = no
...@@ -41,7 +41,7 @@ prompt = no ...@@ -41,7 +41,7 @@ prompt = no
CN = Nodemcu Client cert CN = Nodemcu Client cert
EOF EOF
cat > device_cert.conf << EOF cat > device_cert.conf << EOF
[ req ] [ req ]
distinguished_name = req_distinguished_name distinguished_name = req_distinguished_name
prompt = no prompt = no
...@@ -61,7 +61,7 @@ openssl rsa -in TLS.key_2048.pem -out TLS.key_2048 -outform DER ...@@ -61,7 +61,7 @@ openssl rsa -in TLS.key_2048.pem -out TLS.key_2048 -outform DER
openssl req -out TLS.ca_x509.req -sha256 -key TLS.ca_key.pem -new \ openssl req -out TLS.ca_x509.req -sha256 -key TLS.ca_key.pem -new \
-config ./ca_cert.conf -config ./ca_cert.conf
openssl req -out TLS.x509_2048.req -sha256 -key TLS.key_2048.pem -new \ openssl req -out TLS.x509_2048.req -sha256 -key TLS.key_2048.pem -new \
-config ./certs.conf -config ./certs.conf
# generate the actual certs. # generate the actual certs.
openssl x509 -req -in TLS.ca_x509.req -sha256 -out TLS.ca_x509.pem \ openssl x509 -req -in TLS.ca_x509.req -sha256 -out TLS.ca_x509.pem \
......
...@@ -143,7 +143,7 @@ static void import (char *src, char *dst) ...@@ -143,7 +143,7 @@ static void import (char *src, char *dst)
if (SPIFFS_write (&fs, fh, buff, n) < 0) if (SPIFFS_write (&fs, fh, buff, n) < 0)
die ("spiffs_write"); die ("spiffs_write");
if (SPIFFS_close (&fs, fh) < 0) if (SPIFFS_close (&fs, fh) < 0)
die("spiffs_close"); die("spiffs_close");
close (fd); close (fd);
} }
...@@ -199,7 +199,7 @@ void syntax (void) ...@@ -199,7 +199,7 @@ void syntax (void)
exit (1); exit (1);
} }
static size_t getsize(const char *s) static size_t getsize(const char *s)
{ {
char *end = 0; char *end = 0;
size_t val = strtoul(s, &end, 0); size_t val = strtoul(s, &end, 0);
......
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