Commit 6926c66b authored by galjonsfigur's avatar galjonsfigur Committed by Marcel Stör
Browse files

Polish Lua examples (#2846)

* Add missing globals from luacheck config

* Fix luacheck warnings in all lua files

* Re-enable luacheck in Travis

* Speed up Travis by using preinstalled LuaRocks

* Fix more luacheck warnings in httpserver lua module

* Fix DCC module and add appropriate definitions to luacheck config.

* Change inline comments from ignoring block to only ignore specific line

* Add Luacheck for Windows and enable it for both Windows and Linux

* Change luacheck exceptions and fix errors from 1st round of polishing

* Add retry and timeout params to wget
parent 36df8d00
......@@ -10,13 +10,13 @@
wifi.setmode(wifi.STATION) --Step1: Connect to Wifi
wifi.sta.config("SSID","Password")
dht = require("dht_lib") --Step2: "Require" the libs
yeelink = require("yeelink_lib")
local dht = require("dht_lib") --Step2: "Require" the libs
local yeelink = require("yeelink_lib")
yeelink.init(23333,23333,"You api-key",function() --Step3: Register the callback function
print("Yeelink Init OK...")
tmr.alarm(1,60000,1,function() --Step4: Have fun~ (Update your data)
tmr.create():alarm(60000, tmr.ALARM_AUTO, function() --Step4: Have fun~ (Update your data)
dht.read(4)
yeelink.update(dht.getTemperature())
......
......@@ -22,7 +22,7 @@ local apikey = ""
--================================
local debug = true --<<<<<<<<<<<<< Don't forget to "false" it before using
--================================
local sk=net.createConnection(net.TCP, 0)
local sk = net.createConnection(net.TCP, 0)
local datapoint = 0
......@@ -31,10 +31,11 @@ local datapoint = 0
if wifi.sta.getip() == nil then
print("Please Connect WIFI First")
tmr.alarm(1,1000,1,function ()
local wifiTimer = tmr.create()
wifiTimer:alarm(1000, tmr.ALARM_AUTO,function ()
if wifi.sta.getip() ~= nil then
tmr.stop(1)
sk:dns("api.yeelink.net",function(conn,ip)
wifiTimer:stop()
sk:dns("api.yeelink.net",function(_,ip)
dns=ip
print("DNS YEELINK OK... IP: "..dns)
end)
......@@ -42,12 +43,9 @@ if wifi.sta.getip() == nil then
end)
end
sk:dns("api.yeelink.net",function(conn,ip)
dns=ip
print("DNS YEELINK OK... IP: "..dns)
sk:dns("api.yeelink.net",function(conn, ip) -- luacheck: no unused
dns = ip
print("DNS YEELINK OK... IP: "..dns)
end)
--========Set the init function===========
......@@ -61,7 +59,7 @@ function M.init(_device, _sensor, _apikey)
sensor = tostring(_sensor)
apikey = _apikey
if dns == "0.0.0.0" then
tmr.alarm(2,5000,1,function ()
tmr.create():alarm(5000,tmr.ALARM_AUTO,function ()
if dns == "0.0.0.0" then
print("Waiting for DNS...")
end
......@@ -96,7 +94,7 @@ function M.update(_datapoint)
datapoint = tostring(_datapoint)
sk:on("connection", function(conn)
sk:on("connection", function()
print("connect OK...")
......@@ -116,7 +114,7 @@ function M.update(_datapoint)
end)
sk:on("receive", function(sck, content)
sk:on("receive", function(conn, content) -- luacheck: no unused
if debug then
print("\r\n"..content.."\r\n")
......
......@@ -173,6 +173,32 @@ stds.nodemcu_libs = {
toHex = empty
}
},
dcc = {
fields = {
CV_READ = empty,
CV_RESET = empty,
CV_VALID = empty,
CV_WRITE = empty,
DCC_ACCESSORY = empty,
DCC_FUNC = empty,
DCC_IDLE = empty,
DCC_RAW = empty,
DCC_RESET = empty,
DCC_SERVICEMODE = empty,
DCC_SPEED = empty,
DCC_SPEED_RAW = empty,
DCC_TURNOUT = empty,
FLAGS_AUTO_FACTORY_DEFAULT = empty,
FLAGS_DCC_ACCESSORY_DECODER = empty,
FLAGS_MY_ADDRESS_ONLY = empty,
FLAGS_OUTPUT_ADDRESS_MODE = empty,
MAN_ID_DIY = empty,
MAN_ID_JMRI = empty,
MAN_ID_SILICON_RAILWAY = empty,
close = empty,
setup = empty
}
},
dht = {
fields = {
ERROR_CHECKSUM = empty,
......@@ -200,12 +226,17 @@ stds.nodemcu_libs = {
},
file = {
fields = {
chdir = empty,
close = empty,
exists = empty,
flush = empty,
format = empty,
fscfg = empty,
fsinfo = empty,
getcontents = empty,
list = empty,
mount = empty,
n = empty,
on = empty,
open = empty,
putcontents = empty,
......@@ -393,7 +424,10 @@ stds.nodemcu_libs = {
},
task = {
fields = {
post = empty
post = empty,
LOW_PRIORITY = empty,
MEDIUM_PRIORITY = empty,
HIGH_PRIORITY = empty
}
}
}
......@@ -576,6 +610,13 @@ stds.nodemcu_libs = {
transaction = empty
}
},
struct = {
fields = {
pack = empty,
size = empty,
unpack = empty
}
},
switec = {
fields = {
close = empty,
......@@ -876,7 +917,8 @@ stds.nodemcu_libs = {
},
pack = empty,
unpack = empty,
size = empty
size = empty,
package = {fields = {seeall = read_write}}
}
}
......
......@@ -114,6 +114,12 @@ local function printTables(fileName)
if not findBegin then
findBegin, _, field = string.find(line, "LROT_TABENTRY%(%s?(%g+),")
end
if not findBegin then
findBegin, _, field = string.find(line, "LROT_FUNCENTRY_S%(%s?(%g+),")
end
if not findBegin then
findBegin, _, field = string.find(line, "LROT_FUNCENTRY_F%(%s?(%g+),")
end
if findBegin then
if not string.find(field, "__") then
......
#!/bin/bash
set -e
exists() {
if command -v "$1" >/dev/null 2>&1
then
return 0
else
return 1
fi
}
usage() {
echo "
usage: bash tools/travis/run-luacheck.sh [-s]
Avarible options are:
-s: Standalone mode: Lua, LuaRocks and luacheck
will be installed in nodemcu-firmare/cache folder.
By default script will use luarocks installed in host system.
"
}
install_tools() {
if ! exists luarocks; then
echo "LuaRocks not found!"
exit 1
fi
eval "`luarocks path --bin`" #Set PATH for luacheck
#In Travis Path it's not changed by LuaRocks for some unknown reason
if [ "${TRAVIS}" = "true" ]; then
export PATH=$PATH:/home/travis/.luarocks/bin
fi
if ! exists luacheck; then
echo "Installing luacheck"
luarocks install --local luacheck || exit
fi
}
install_tools_standalone() {
if ! [ -x cache/localua/bin/luarocks ]; then
echo "Installing Lua 5.3 and LuaRocks"
bash tools/travis/localua.sh cache/localua || exit
fi
if ! [ -x cache/localua/bin/luacheck ]; then
echo "Installing luacheck"
cache/localua/bin/luarocks install luacheck || exit
fi
}
if [[ $1 == "" ]]; then
install_tools
else
while getopts "s" opt
do
case $opt in
(s) install_tools_standalone ;;
(*) usage; exit 1 ;;
esac
done
fi
echo "Static analysys of"
find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo
(find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 luacheck --config tools/luacheck_config.lua) || exit
#!/bin/bash
set -e
#Download luacheck binary if nessesary
if ! [ -x "cache/luacheck.exe" ]; then
wget --tries=5 --timeout=10 --waitretry=10 --read-timeout=10 --retry-connrefused -O cache/luacheck.exe https://github.com/mpeterv/luacheck/releases/download/0.23.0/luacheck.exe
fi
echo "Static analysys of"
find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo
(find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 cache/luacheck.exe --config tools/luacheck_config.lua) || exit
#!/bin/bash
set -e
echo "Installing Lua 5.3, LuaRocks and Luacheck"
(
cd "$TRAVIS_BUILD_DIR" || exit
bash tools/travis/localua.sh cache/localua || exit
cache/localua/bin/luarocks install luacheck || exit
)
(
echo "Static analysys of:"
find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo
)
(find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 cache/localua/bin/luacheck --config tools/luacheck_config.lua) || exit
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