mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-11-16 18:47:57 +01:00
Compare commits
No commits in common. "master" and "0.10.6-rc2" have entirely different histories.
master
...
0.10.6-rc2
23
Makefile
23
Makefile
@ -66,13 +66,6 @@ define Build/Compile directives
|
|||||||
# no compilation necessary (although possible with luac?)
|
# no compilation necessary (although possible with luac?)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# This information is contained within the ipk file and (at least) used by
|
|
||||||
# sysupgrade to determine which files to keep (see `opkg list-changed-conffiles`).
|
|
||||||
define Package/wifibox/conffiles
|
|
||||||
/etc/config/wifibox
|
|
||||||
/etc/logrotate.d/wifibox.conf
|
|
||||||
endef
|
|
||||||
|
|
||||||
# The $(1) variable represents the root directory on the router running
|
# The $(1) variable represents the root directory on the router running
|
||||||
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
|
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
|
||||||
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
|
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
|
||||||
@ -95,16 +88,9 @@ define Package/wifibox/install
|
|||||||
#$(INSTALL_DIR) $(1)/etc
|
#$(INSTALL_DIR) $(1)/etc
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_DIR) $(1)/etc/config
|
$(INSTALL_DIR) $(1)/etc/config
|
||||||
$(INSTALL_DIR) $(1)/etc/logrotate.d
|
|
||||||
$(INSTALL_DIR) $(1)/root/
|
|
||||||
$(INSTALL_DIR) $(1)/root/sketches
|
|
||||||
#$(INSTALL_DIR) $(1)/www
|
#$(INSTALL_DIR) $(1)/www
|
||||||
$(INSTALL_DIR) $(1)/www/cgi-bin
|
$(INSTALL_DIR) $(1)/www/cgi-bin
|
||||||
|
|
||||||
#copy wps button script to procd folder
|
|
||||||
$(INSTALL_DIR) $(1)/etc/rc.button/
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifi-switch-netconfig.sh $(1)/etc/rc.button/wps
|
|
||||||
|
|
||||||
### create all files in /usr/share/lua/autowifi (autowifi)
|
### create all files in /usr/share/lua/autowifi (autowifi)
|
||||||
|
|
||||||
$(CP) $(WIFIBOX_BASE_DIR)/opkg.conf $(1)/$(TGT_LUA_DIR_SUFFIX)/
|
$(CP) $(WIFIBOX_BASE_DIR)/opkg.conf $(1)/$(TGT_LUA_DIR_SUFFIX)/
|
||||||
@ -116,19 +102,10 @@ define Package/wifibox/install
|
|||||||
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3d-updater.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3d-updater.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3d-updater.lua $(1)/bin/d3d-updater
|
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3d-updater.lua $(1)/bin/d3d-updater
|
||||||
$(CP) $(WIFIBOX_BASE_DIR)/script/loglite-filters.lua $(1)/root/
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/loglite.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
|
||||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/loglite.lua $(1)/bin/loglite
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/dhcpcheck_init $(1)/etc/init.d/dhcpcheck
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/dhcpcheck_init $(1)/etc/init.d/dhcpcheck
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3dapi $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3dapi $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/d3dapi $(1)/bin/d3dapi
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/signin.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/signin.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||||
$(CP) $(WIFIBOX_BASE_DIR)/script/logrotate-wifibox.conf $(1)/etc/logrotate.d/wifibox.conf
|
|
||||||
|
|
||||||
|
|
||||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/print-fetch.lua $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
|
||||||
$(LN) -s /$(TGT_LUA_DIR_SUFFIX)/script/print-fetch.lua $(1)/bin/print-fetch
|
|
||||||
|
|
||||||
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
||||||
$(CP) $(WIFIBOX_BASE_DIR)/FIRMWARE-VERSION $(1)/etc/wifibox-version
|
$(CP) $(WIFIBOX_BASE_DIR)/FIRMWARE-VERSION $(1)/etc/wifibox-version
|
||||||
|
27
README.md
27
README.md
@ -3,7 +3,6 @@ WiFi box OpenWRT firmware package
|
|||||||
|
|
||||||
General documentation can be found on the wiki: <http://doodle3d.com/help/wiki>. Source code documentation can be generated, see below.
|
General documentation can be found on the wiki: <http://doodle3d.com/help/wiki>. Source code documentation can be generated, see below.
|
||||||
|
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@ -11,29 +10,3 @@ The script 'doxify.sh' generates HTML documentation of the source code in the di
|
|||||||
Make sure the 'ldoc' program is installed on your machine and the LDOC variable in the script points there.
|
Make sure the 'ldoc' program is installed on your machine and the LDOC variable in the script points there.
|
||||||
|
|
||||||
On OSX, this can be accomplished by installing it through luarocks (run `sudo luarocks install ldoc`). Luarocks can be installed using [MacPorts](http://www.macports.org/). After installing that, the command would be `sudo port install luarocks`.
|
On OSX, this can be accomplished by installing it through luarocks (run `sudo luarocks install ldoc`). Luarocks can be installed using [MacPorts](http://www.macports.org/). After installing that, the command would be `sudo port install luarocks`.
|
||||||
|
|
||||||
Command line interface
|
|
||||||
----------------------
|
|
||||||
The Doodle3D API can be called using a terminal:
|
|
||||||
|
|
||||||
```d3dapi p=/network/scan r=GET```
|
|
||||||
|
|
||||||
Where the p parameter is the module you want to call and r is the method.
|
|
||||||
Post request can be send using the same method:
|
|
||||||
|
|
||||||
```d3dapi p=/printer/print r=POST```
|
|
||||||
|
|
||||||
Parameters: TODO
|
|
||||||
|
|
||||||
Debugging Lua
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Syntax errors in Lua can lead to tricky issues since they might only surface when the faulty code is actually being run.
|
|
||||||
|
|
||||||
One countermeasure for this is to use [pcall](http://www.lua.org/pil/8.4.html) instead of regular calls in many cases. To let the error 'happen' (which in turn gives information in the form of stack traces), tell the code to use regular calls by setting 'M.DEBUG_PCALLS' to 'true' in `conf_defaults.lua`.
|
|
||||||
|
|
||||||
Additionally, when the pcall setting is not enough, a second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'.
|
|
||||||
|
|
||||||
Note that because stack traces are sent to `stderr`, this script redirects output streams to a separate log file: `/tmp/wifibox.stdout.log`; apart from these traces, the file should not contain any data.
|
|
||||||
|
|
||||||
Finally, the `CGI` gateway of uhttpd also uses this script, so the API can also be used to obtain stack traces by calling it as `<wifibox-ip>/cgi-bin/d3dapi/<endpoint>` (note the extra `cgi-bin`).
|
|
||||||
|
@ -1,93 +1,5 @@
|
|||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
# 0.11.0 (12 jul 2017)
|
|
||||||
# 0.11.0-c (10 jul 2017)
|
|
||||||
- fix: Also closing file descriptor after removing current print file (commit 550e151)
|
|
||||||
|
|
||||||
# 0.11.0-b (6 jul 2017)
|
|
||||||
- show id of current print in d3dapi/info/status when printing in 'fetch' mode.
|
|
||||||
- code reuse and cleanup for control, kill and status
|
|
||||||
|
|
||||||
# 0.11.0-a (23 jun 2017)
|
|
||||||
- Added 'fetch' functionality to let the WiFi-Box print from a remote server. This enables the WiFi-Box to print large g-code files. (yeah!)
|
|
||||||
- Added support for the Renkforce RF100 printer.
|
|
||||||
- Changed 'default startcode' to prevent Ultimaker 2 series to bump into platform [#21](https://github.com/Doodle3D/WiFi-Box/issues/21) when Ultimaker (original) is selected.
|
|
||||||
- Changed default nozzle temperature from 230 to 210 °C.
|
|
||||||
- Fixed corrupted endcode for delta printers.
|
|
||||||
- Changed default endcode to cooldown to 0 after print instead of cooling down to preheat temperature.
|
|
||||||
|
|
||||||
# 0.10.12
|
|
||||||
# 0.10.12-b (12 jan 2017)
|
|
||||||
- Post install update to config for changes in 0.10.10 (fixes print3d logging)
|
|
||||||
|
|
||||||
# 0.10.12-a (26 jul 2016)
|
|
||||||
- Added Ultimaker Original Plus (Thanks Remco)
|
|
||||||
- Added extra usb drivers
|
|
||||||
|
|
||||||
# 0.10.11
|
|
||||||
# 0.10.11-a (25 may 2016)
|
|
||||||
- After pressing the reset button for about 4 seconds the WiFi-Box will go to access point mode. Useful for when you can't reach it.
|
|
||||||
- Becomes access point when it can't connect to WiFi network.
|
|
||||||
- Handles more clients by tweaking the uhttpd config.
|
|
||||||
- Print3D isn't killed when there is no memory available.
|
|
||||||
- New banner (shown after ssh login)
|
|
||||||
- Ultimaker 2 type printers show status information on display.
|
|
||||||
|
|
||||||
# 0.10.10 (11 may 2016)
|
|
||||||
- Logging client version info to console.
|
|
||||||
- Logging less when printing to makerbot/wanhao
|
|
||||||
- Logging API time info
|
|
||||||
- Included version number file in logfiles
|
|
||||||
- Fixed stopping while sending
|
|
||||||
|
|
||||||
# 0.10.10-e (21 apr 2016)
|
|
||||||
- Fixed Makerbot end gcode that prevented prints or stopping prints to finish.
|
|
||||||
|
|
||||||
# 0.10.10-d (20 apr 2016)
|
|
||||||
- Allow print part sequence numbers to be retrieved
|
|
||||||
- Sequence numbers are send back when sending print parts
|
|
||||||
- When WiFi-Box responds that print part was already received the client will send the next part.
|
|
||||||
|
|
||||||
# 0.10.10-c (1 apr 2016)
|
|
||||||
- Quicker log rotation
|
|
||||||
|
|
||||||
# 0.10.10-b (21 mrt 2016)
|
|
||||||
- Logrotation (making sure older logs are removed)
|
|
||||||
- Improved logging.
|
|
||||||
- Always log initial printer communication
|
|
||||||
- loglite improvements, added readme
|
|
||||||
|
|
||||||
# 0.10.10-a (24 feb 2016)
|
|
||||||
- Max buffer size check: the WiFi-Box can now indicate through the API that its buffer is full and it won't accept new gcode.
|
|
||||||
- Buffer information is communicated through the API so all clients can handle this properly. The Doodle3D client will stop sending and waits until it drops below 75%. It will check this every 30 seconds.
|
|
||||||
- Improved progress indication: when sending a print the total number of lines can be added, causing the total lines reported through the API to be correct, instead of being approximated to be total lines in buffer, which keeps increasing while a print is still being sent.
|
|
||||||
- When sending print parts, sequence numbers can be added which will be checked for correctness.
|
|
||||||
- The stop button now stays enabled while still sending a print.
|
|
||||||
- Made firmware log format consistent with print3d's.
|
|
||||||
- Fixed local IP parsing pattern in firmware.
|
|
||||||
- Improved log messages and log messages formatting.
|
|
||||||
- Added loglite utility which enables filtering and coloring of logs.
|
|
||||||
- Won't attempt sign-in when in access point mode.
|
|
||||||
- More consistent error reporting from API.
|
|
||||||
- API d3dapi/printer/print's 'first' parameter has been deprecated in favor of a more descriptive 'clear' parameter.
|
|
||||||
- Support for CraftBot PLUS printer.
|
|
||||||
|
|
||||||
# 0.10.9 (11 jan 2016)
|
|
||||||
# 0.10.8 (11 jan 2016)
|
|
||||||
# 0.10.8-b (7 jan 2016)
|
|
||||||
Logging less by default, fixing some pretty serious memory issues, which could cause the WiFi-box to 'crash' while printing bigger files.
|
|
||||||
Log level setting, enabling users to log more if they run into problems.
|
|
||||||
For better adhesion we extruded even while traveling on the bottom layers, we now made it configurable and turned it off by default.
|
|
||||||
Fixed month display of releases in settings screen.
|
|
||||||
|
|
||||||
# 0.10.8-a (11 nov 2015)
|
|
||||||
Added ch341 and cp210x usb-serial drivers to diffconfig
|
|
||||||
|
|
||||||
# 0.10.7 (21 aug 2015)
|
|
||||||
Added ColiDo printer profiles
|
|
||||||
|
|
||||||
# 0.10.6 (17 jun 2015)
|
|
||||||
# 0.10.6-rc3 (17 jun 2015)
|
|
||||||
# 0.10.6-rc2 (16 jun 2015)
|
# 0.10.6-rc2 (16 jun 2015)
|
||||||
# 0.10.6-rc1 (16 jun 2015)
|
# 0.10.6-rc1 (16 jun 2015)
|
||||||
This release sees several connectivity bugs resolved as we continue to look to
|
This release sees several connectivity bugs resolved as we continue to look to
|
||||||
|
@ -22,10 +22,8 @@ CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
|||||||
# CONFIG_PACKAGE_libip6tc is not set
|
# CONFIG_PACKAGE_libip6tc is not set
|
||||||
CONFIG_PACKAGE_libiwinfo=y
|
CONFIG_PACKAGE_libiwinfo=y
|
||||||
CONFIG_PACKAGE_libiwinfo-lua=y
|
CONFIG_PACKAGE_libiwinfo-lua=y
|
||||||
CONFIG_PACKAGE_libpopt=y
|
|
||||||
CONFIG_PACKAGE_liblua=y
|
CONFIG_PACKAGE_liblua=y
|
||||||
CONFIG_PACKAGE_libuci-lua=y
|
CONFIG_PACKAGE_libuci-lua=y
|
||||||
CONFIG_PACKAGE_logrotate=y
|
|
||||||
CONFIG_PACKAGE_lua=y
|
CONFIG_PACKAGE_lua=y
|
||||||
CONFIG_PACKAGE_luafilesystem=y
|
CONFIG_PACKAGE_luafilesystem=y
|
||||||
# CONFIG_PACKAGE_odhcp6c is not set
|
# CONFIG_PACKAGE_odhcp6c is not set
|
||||||
|
@ -20,10 +20,8 @@ CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
|||||||
# CONFIG_PACKAGE_libip6tc is not set
|
# CONFIG_PACKAGE_libip6tc is not set
|
||||||
CONFIG_PACKAGE_libiwinfo=y
|
CONFIG_PACKAGE_libiwinfo=y
|
||||||
CONFIG_PACKAGE_libiwinfo-lua=y
|
CONFIG_PACKAGE_libiwinfo-lua=y
|
||||||
CONFIG_PACKAGE_libpopt=y
|
|
||||||
CONFIG_PACKAGE_liblua=y
|
CONFIG_PACKAGE_liblua=y
|
||||||
CONFIG_PACKAGE_libuci-lua=y
|
CONFIG_PACKAGE_libuci-lua=y
|
||||||
CONFIG_PACKAGE_logrotate=y
|
|
||||||
CONFIG_PACKAGE_lua=y
|
CONFIG_PACKAGE_lua=y
|
||||||
CONFIG_PACKAGE_luafilesystem=y
|
CONFIG_PACKAGE_luafilesystem=y
|
||||||
# CONFIG_PACKAGE_odhcp6c is not set
|
# CONFIG_PACKAGE_odhcp6c is not set
|
||||||
|
@ -9,10 +9,8 @@ CONFIG_PACKAGE_kmod-usb-serial=y
|
|||||||
CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
CONFIG_PACKAGE_kmod-usb-serial-ftdi=y
|
||||||
CONFIG_PACKAGE_libiwinfo=y
|
CONFIG_PACKAGE_libiwinfo=y
|
||||||
CONFIG_PACKAGE_libiwinfo-lua=y
|
CONFIG_PACKAGE_libiwinfo-lua=y
|
||||||
CONFIG_PACKAGE_libpopt=y
|
|
||||||
CONFIG_PACKAGE_liblua=y
|
CONFIG_PACKAGE_liblua=y
|
||||||
CONFIG_PACKAGE_libuci-lua=y
|
CONFIG_PACKAGE_libuci-lua=y
|
||||||
CONFIG_PACKAGE_logrotate=y
|
|
||||||
CONFIG_PACKAGE_lua=y
|
CONFIG_PACKAGE_lua=y
|
||||||
CONFIG_PACKAGE_luafilesystem=y
|
CONFIG_PACKAGE_luafilesystem=y
|
||||||
CONFIG_PACKAGE_print3d=y
|
CONFIG_PACKAGE_print3d=y
|
||||||
|
@ -254,8 +254,6 @@ local function main()
|
|||||||
else
|
else
|
||||||
print("error: file '" .. f .. "' has uncommitted changes in git, refusing to process")
|
print("error: file '" .. f .. "' has uncommitted changes in git, refusing to process")
|
||||||
end
|
end
|
||||||
elseif processType == false then
|
|
||||||
print("Skipping excluded file '" .. f .. "'")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,21 +8,12 @@
|
|||||||
-- USAGE:
|
-- USAGE:
|
||||||
-- The only dependency of this script are the penlight and luafilesystem libraries, which can be installed using
|
-- The only dependency of this script are the penlight and luafilesystem libraries, which can be installed using
|
||||||
-- LuaRocks (http://luarocks.org/) as follows:
|
-- LuaRocks (http://luarocks.org/) as follows:
|
||||||
-- $ sudo luarocks install penlight
|
-- sudo luarocks install penlight
|
||||||
-- If the penlight libary is not found you might need to add the following to /etc/launchd.conf
|
-- If the penlight libary is not found you might need to add the following to /etc/launchd.conf
|
||||||
-- setenv LUA_CPATH /opt/local/share/luarocks/lib/lua/5.2/?.so
|
-- setenv LUA_CPATH /opt/local/share/luarocks/lib/lua/5.2/?.so
|
||||||
-- setenv LUA_PATH /opt/local/share/luarocks/share/lua/5.2/?.lua
|
-- setenv LUA_PATH /opt/local/share/luarocks/share/lua/5.2/?.lua
|
||||||
-- Reboot
|
-- Reboot
|
||||||
-- Also see: https://github.com/keplerproject/luarocks/wiki/Using-LuaRocks#rocks-trees-and-the-lua-libraries-path
|
|
||||||
--
|
--
|
||||||
-- Lua + Luarocks installation on Linux:
|
|
||||||
-- $ sudo apt-get install lua5.2 liblua5.2-dev
|
|
||||||
-- # Build Luarocks from source, configured for lua 5.2:
|
|
||||||
-- $ wget http://luarocks.org/releases/luarocks-2.2.2.tar.gz
|
|
||||||
-- $ tar zxpf luarocks-2.2.2.tar.gz
|
|
||||||
-- $ cd luarocks-2.2.2
|
|
||||||
-- $ ./configure --lua-version=5.2
|
|
||||||
-- $ sudo make bootstrap
|
|
||||||
-- This script will automatically locate the Doodle3D repo's.
|
-- This script will automatically locate the Doodle3D repo's.
|
||||||
-- Index files are fetched from the online repository.
|
-- Index files are fetched from the online repository.
|
||||||
-- For synchronizing, rsync must have passwordless SSH access to the server, for a
|
-- For synchronizing, rsync must have passwordless SSH access to the server, for a
|
||||||
@ -75,11 +66,8 @@ end
|
|||||||
pl = pl()
|
pl = pl()
|
||||||
local um --- update manager module, will be loaded later through @{loadUpdateManager}
|
local um --- update manager module, will be loaded later through @{loadUpdateManager}
|
||||||
|
|
||||||
local ok, lfs = pcall(require, 'lfs')
|
local lfs = require('lfs') -- assume this exists since it's required by penlight as well
|
||||||
if not ok then
|
|
||||||
ERR('This script requires the LuaFileSystem library')
|
|
||||||
os.exit(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
-----------------------------
|
-----------------------------
|
||||||
-- CONSTANTS AND VARIABLES --
|
-- CONSTANTS AND VARIABLES --
|
||||||
@ -129,15 +117,9 @@ local function quit(ev)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function md5sum(file)
|
local function md5sum(file)
|
||||||
-- try OS X specific md5 utility
|
|
||||||
local rv,_,sum = pl.utils.executeex('md5 -q "' .. file .. '"')
|
local rv,_,sum = pl.utils.executeex('md5 -q "' .. file .. '"')
|
||||||
if rv then
|
|
||||||
return rv and sum:sub(1, -2) or nil
|
return rv and sum:sub(1, -2) or nil
|
||||||
end
|
|
||||||
-- try Linux md5sum utility
|
|
||||||
local rv,_,output = pl.utils.executeex('md5sum "' .. file .. '"')
|
|
||||||
local md5 = string.match(output, "[^%s]+")
|
|
||||||
return md5
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getYesNo(question)
|
local function getYesNo(question)
|
||||||
@ -166,17 +148,13 @@ local function findInFile(needle, file)
|
|||||||
return not not t:find(needle, 1, true)
|
return not not t:find(needle, 1, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fileExists(path)
|
local function detectOpenWrtRoot()
|
||||||
local attr = lfs.attributes (path)
|
local f = io.open('Makefile', 'r')
|
||||||
return attr ~= nil
|
local line = f and f:read('*line')
|
||||||
end
|
local rv = (line and line:find('# Makefile for OpenWrt') == 1) and true or false
|
||||||
|
|
||||||
local function detectBuildroot()
|
if f then f:close() end
|
||||||
if not fileExists("customfeeds") or not fileExists("bin") then
|
return rv
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- returns uri (file path) of the wifibox feed, nil if not found or nil+msg on error
|
-- returns uri (file path) of the wifibox feed, nil if not found or nil+msg on error
|
||||||
@ -266,15 +244,24 @@ end
|
|||||||
local function prepare()
|
local function prepare()
|
||||||
local msg = nil
|
local msg = nil
|
||||||
|
|
||||||
|
io.write("* Checking if working directory is the OpenWrt root... ")
|
||||||
|
local isOpenWrtRoot = detectOpenWrtRoot()
|
||||||
|
if isOpenWrtRoot then
|
||||||
|
paths.wrt = pl.path.currentdir()
|
||||||
|
print("found " .. paths.wrt)
|
||||||
|
else
|
||||||
|
print("unrecognized directory, try changing directories or using -wrt-root")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
io.write("* Looking for Doodle3D feed path... ")
|
io.write("* Looking for Doodle3D feed path... ")
|
||||||
-- local d3dFeed,msg = getWifiboxFeedRoot('feeds.conf')
|
local d3dFeed,msg = getWifiboxFeedRoot('feeds.conf')
|
||||||
-- if d3dFeed then
|
if d3dFeed then
|
||||||
-- print("found " .. d3dFeed)
|
print("found " .. d3dFeed)
|
||||||
-- else
|
else
|
||||||
-- if msg then print("not found: " .. msg) else print("not found.") end
|
if msg then print("not found: " .. msg) else print("not found.") end
|
||||||
-- return nil
|
return nil
|
||||||
-- end
|
end
|
||||||
local d3dFeed = "customfeeds"
|
|
||||||
|
|
||||||
paths.firmware = pl.path.join(d3dFeed, D3D_REPO_FIRMWARE_NAME)
|
paths.firmware = pl.path.join(d3dFeed, D3D_REPO_FIRMWARE_NAME)
|
||||||
paths.client = pl.path.join(d3dFeed, D3D_REPO_CLIENT_NAME)
|
paths.client = pl.path.join(d3dFeed, D3D_REPO_CLIENT_NAME)
|
||||||
@ -328,8 +315,8 @@ local function collectLocalInfo()
|
|||||||
local info = {}
|
local info = {}
|
||||||
|
|
||||||
-- temporary fields required for copying image files
|
-- temporary fields required for copying image files
|
||||||
info.factoryImgPath = pl.path.join(paths.root, 'bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-factory.bin')
|
info.factoryImgPath = pl.path.join(paths.wrt, 'bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-factory.bin')
|
||||||
info.sysupgradeImgPath = pl.path.join(paths.root, 'bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-sysupgrade.bin')
|
info.sysupgradeImgPath = pl.path.join(paths.wrt, 'bin/ar71xx/openwrt-ar71xx-generic-' .. deviceType .. '-v1-squashfs-sysupgrade.bin')
|
||||||
|
|
||||||
info.version = um.parseVersion(pl.file.read(pl.path.join(paths.firmware, 'src/FIRMWARE-VERSION')))
|
info.version = um.parseVersion(pl.file.read(pl.path.join(paths.firmware, 'src/FIRMWARE-VERSION')))
|
||||||
if not info.version then return nil,"could not determine current firmware version" end
|
if not info.version then return nil,"could not determine current firmware version" end
|
||||||
@ -423,7 +410,7 @@ end
|
|||||||
-- TODO: the packages are not really used and the openwrt script to generate the
|
-- TODO: the packages are not really used and the openwrt script to generate the
|
||||||
-- package index requires all packages to be present so this has been skipped for now
|
-- package index requires all packages to be present so this has been skipped for now
|
||||||
local function buildFeedDir()
|
local function buildFeedDir()
|
||||||
local scriptPath = pl.path.join(paths.root, 'scripts/ipkg-make-index.sh')
|
local scriptPath = pl.path.join(paths.wrt, 'scripts/ipkg-make-index.sh')
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -437,6 +424,26 @@ local function uploadFiles()
|
|||||||
return rv and true or nil,("rsync failed, exit status: " .. ev)
|
return rv and true or nil,("rsync failed, exit status: " .. ev)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function checkWrtConfig()
|
||||||
|
local goodConfigPath = pl.path.join(paths.firmware, "extra/openwrt-build/openwrt-diffconfig-extramini")
|
||||||
|
local wrtConfigPath = pl.path.tmpname()
|
||||||
|
--print("diffonfig output file: " .. wrtConfigPath)
|
||||||
|
|
||||||
|
local rv,ev = pl.utils.execute('./scripts/diffconfig.sh > "' .. wrtConfigPath .. '" 2> /dev/null')
|
||||||
|
if not rv then return nil,"could not run diffconfig script (exit status: " .. ev .. ")" end
|
||||||
|
|
||||||
|
local _,rv,output = pl.utils.executeex('diff "' .. wrtConfigPath .. '" "' .. goodConfigPath .. '"')
|
||||||
|
|
||||||
|
if rv == 0 then
|
||||||
|
return true
|
||||||
|
elseif rv == 1 then
|
||||||
|
print("configurations differ:\n-----------------------\n" .. output .. "\n-----------------------")
|
||||||
|
--ask for confirmation?
|
||||||
|
else
|
||||||
|
return nil,"unexpected exit status from diff (" .. rv .. ")"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function main()
|
local function main()
|
||||||
print("\nDoodle3D release script")
|
print("\nDoodle3D release script")
|
||||||
if detectRootPrivileges() then
|
if detectRootPrivileges() then
|
||||||
@ -450,16 +457,6 @@ local function main()
|
|||||||
-- if opts['cache-dir'] then paths.cache = opts['cache-dir'] end
|
-- if opts['cache-dir'] then paths.cache = opts['cache-dir'] end
|
||||||
-- more options: clear cache, rebuild (download all and generate index from actual files), dry-run, force
|
-- more options: clear cache, rebuild (download all and generate index from actual files), dry-run, force
|
||||||
|
|
||||||
io.write("* Checking if working directory is the Buildroot... ")
|
|
||||||
local isBuildroot = detectBuildroot()
|
|
||||||
if isBuildroot then
|
|
||||||
paths.root = pl.path.currentdir()
|
|
||||||
print("found " .. paths.root)
|
|
||||||
else
|
|
||||||
print("unrecognized directory, try changing directories or using -wrt-root")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if not prepare() then quit(1) end
|
if not prepare() then quit(1) end
|
||||||
|
|
||||||
|
|
||||||
@ -477,6 +474,7 @@ local function main()
|
|||||||
|
|
||||||
--TODO: if requested, fetch images and packages (i.e., mirror whole directory)
|
--TODO: if requested, fetch images and packages (i.e., mirror whole directory)
|
||||||
|
|
||||||
|
|
||||||
-- pl.pretty.dump(newVersion)
|
-- pl.pretty.dump(newVersion)
|
||||||
-- print("stables: "); pl.pretty.dump(stables)
|
-- print("stables: "); pl.pretty.dump(stables)
|
||||||
-- print("===========================");
|
-- print("===========================");
|
||||||
@ -490,6 +488,8 @@ local function main()
|
|||||||
return not (um.findVersion(newVersion.version, nil, stables) or um.findVersion(newVersion.version, nil, betas)) and true or nil
|
return not (um.findVersion(newVersion.version, nil, stables) or um.findVersion(newVersion.version, nil, betas)) and true or nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
runAction("Checking OpenWrt config", "failed", 3, checkWrtConfig)
|
||||||
|
|
||||||
--TODO: check git repos (`git log -n 1 --pretty=format:%ct` gives commit date of last commit (not author date))
|
--TODO: check git repos (`git log -n 1 --pretty=format:%ct` gives commit date of last commit (not author date))
|
||||||
|
|
||||||
local isStable = (newVersion.version.suffix == nil)
|
local isStable = (newVersion.version.suffix == nil)
|
||||||
@ -516,7 +516,8 @@ local function main()
|
|||||||
print("skipped - not implemented")
|
print("skipped - not implemented")
|
||||||
-- runAction("Building package feed directory", "failed", 5, buildFeedDir)
|
-- runAction("Building package feed directory", "failed", 5, buildFeedDir)
|
||||||
|
|
||||||
local answer = getYesNo("? Are you SURE you want to publish? (y/n) ")
|
|
||||||
|
local answer = getYesNo("? Local updates cache will be synced to remote server, proceed? (y/n) ")
|
||||||
if answer ~= true then
|
if answer ~= true then
|
||||||
print("Did not get green light, quitting.")
|
print("Did not get green light, quitting.")
|
||||||
quit(5)
|
quit(5)
|
||||||
@ -524,7 +525,7 @@ local function main()
|
|||||||
|
|
||||||
runAction("About to sync files to server", "could not upload files", 6, uploadFiles)
|
runAction("About to sync files to server", "could not upload files", 6, uploadFiles)
|
||||||
|
|
||||||
print("Released version " .. um.formatVersion(newVersion.version) .. "!")
|
print("Done.")
|
||||||
quit()
|
quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
local M = {
|
local M = {
|
||||||
BASE_PATH = 'src',
|
BASE_PATH = 'src',
|
||||||
EXCLUDE_FILES = { 'src/util/JSON.lua', 'src/util/urlcode.lua', 'src/script/loglite%-filters.lua' },
|
EXCLUDE_FILES = { 'src/util/JSON.lua', 'src/util/urlcode.lua' },
|
||||||
PROCESS_FILES = {
|
PROCESS_FILES = {
|
||||||
['src/[^/]*%.lua'] = 'lua',
|
['src/[^/]*%.lua'] = 'lua',
|
||||||
['src/network/[^/]*%.lua'] = 'lua',
|
['src/network/[^/]*%.lua'] = 'lua',
|
||||||
|
@ -36,18 +36,15 @@ addFirewallNet() {
|
|||||||
### Replace the banner with a custom one
|
### Replace the banner with a custom one
|
||||||
if [ ! -f $IPKG_INSTROOT/etc/banner.default ]; then
|
if [ ! -f $IPKG_INSTROOT/etc/banner.default ]; then
|
||||||
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
|
mv $IPKG_INSTROOT/etc/banner $IPKG_INSTROOT/etc/banner.default
|
||||||
cat <<-\EOM > $IPKG_INSTROOT/etc/banner
|
cat <<-'EOM' > $IPKG_INSTROOT/etc/banner
|
||||||
,------. ,--.,--. ,----. ,------.
|
........D o o d l e 3 D
|
||||||
| .-. \ ,---. ,---. ,-| || | ,---. '.-. || .-. \
|
.......________ _____ _____ v \$(PACKAGE_VERSION)
|
||||||
| | \ :| .-. || .-. |' .-. || || .-. : .' < | | \ :
|
....../ / / |__ / __/ / - /___ __
|
||||||
| '--' /' '-' '' '-' '\ `-' || |\ --./'-' || '--' /
|
...../ / / /--// _|-// --| . /v /
|
||||||
`-------' `---' `---' `---' `--' `----'`----' `-------'
|
..../________/__//__/__//____/___/_^_\
|
||||||
__ ___ ______ _ ____
|
...
|
||||||
\ \ / (_) ____(_) | _ \
|
..A cad in a box.
|
||||||
\ \ /\ / / _| |__ _ ______| |_) | _____ __
|
.
|
||||||
\ \/ \/ / | | __| | |______| _ < / _ \ \/ /
|
|
||||||
\ /\ / | | | | | | |_) | (_) > <
|
|
||||||
\/ \/ |_|_| |_| |____/ \___/_/\_\
|
|
||||||
EOM
|
EOM
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -55,22 +52,17 @@ fi
|
|||||||
mkdir -p $IPKG_INSTROOT/root
|
mkdir -p $IPKG_INSTROOT/root
|
||||||
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
|
grep '^# DO NOT MODIFY.*wifibox package.$' $IPKG_INSTROOT/root/.profile >/dev/null 2>&1
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
cat <<-\EOM >> $IPKG_INSTROOT/root/.profile
|
cat <<-EOM >> $IPKG_INSTROOT/root/.profile
|
||||||
|
|
||||||
# DO NOT MODIFY - this block of lines has been added by the wifibox package.
|
# DO NOT MODIFY - this block of lines has been added by the wifibox package.
|
||||||
alias d='ls -la'
|
alias d='ls -la'
|
||||||
|
alias d3dapi='/usr/share/lua/wifibox/script/d3dapi'
|
||||||
alias encore='ulimit -c unlimited'
|
alias encore='ulimit -c unlimited'
|
||||||
alias wopkg='opkg -f /usr/share/lua/wifibox/opkg.conf'
|
alias wopkg='opkg -f /usr/share/lua/wifibox/opkg.conf'
|
||||||
|
|
||||||
alias tailfw='loglite /tmp/wifibox.log firmware'
|
|
||||||
tailp3d() {
|
|
||||||
logfile=/tmp/print3d-ttyACM0.log
|
|
||||||
if [ $# -gt 0 ]; then logfile=$1; fi
|
|
||||||
loglite "$logfile" print3d
|
|
||||||
}
|
|
||||||
|
|
||||||
loop() {
|
loop() {
|
||||||
if [ $# -lt 2 ]; then echo "Please supply a delay and a command."; return 1; fi
|
if [ \$# -lt 2 ]; then echo "Please supply a delay and a command."; return 1; fi
|
||||||
DELAY=$1; shift; while true; do $@; sleep $DELAY; done
|
DELAY=\$1; shift; while true; do \$@; sleep \$DELAY; done
|
||||||
}
|
}
|
||||||
EOM
|
EOM
|
||||||
fi
|
fi
|
||||||
@ -78,15 +70,13 @@ fi
|
|||||||
#preserve saved sketches during firmware update
|
#preserve saved sketches during firmware update
|
||||||
echo "/root/sketches" >> $IPKG_INSTROOT/etc/sysupgrade.conf
|
echo "/root/sketches" >> $IPKG_INSTROOT/etc/sysupgrade.conf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Finally make sure basic configuration is set correctly
|
### Finally make sure basic configuration is set correctly
|
||||||
|
|
||||||
LOGROTATE_CRON_LINE="*/2 * * * * /usr/sbin/logrotate /etc/logrotate.conf"
|
$IPKG_INSTROOT/etc/init.d/wifibox enable
|
||||||
|
$IPKG_INSTROOT/etc/init.d/wifibox start
|
||||||
|
$IPKG_INSTROOT/etc/init.d/dhcpcheck enable
|
||||||
|
|
||||||
if [ -z "$IPKG_INSTROOT" ]; then
|
if [ -z "$IPKG_INSTROOT" ]; then
|
||||||
# No installation root, we are being installed on a live box so run uci commands directly.
|
|
||||||
|
|
||||||
echo "Enabling and configuring wifi device..."
|
echo "Enabling and configuring wifi device..."
|
||||||
uci set wireless.@wifi-device[0].disabled=0
|
uci set wireless.@wifi-device[0].disabled=0
|
||||||
uci delete wireless.radio0.channel
|
uci delete wireless.radio0.channel
|
||||||
@ -102,31 +92,16 @@ if [ -z "$IPKG_INSTROOT" ]; then
|
|||||||
uci set network.wlan=interface
|
uci set network.wlan=interface
|
||||||
uci commit network; /etc/init.d/network reload
|
uci commit network; /etc/init.d/network reload
|
||||||
|
|
||||||
echo "Setting default wifibox log level..."
|
|
||||||
uci set wifibox.general.system_log_level='info'
|
|
||||||
uci -q delete wifibox.system.loglevel # remove key used in older versions (<=0.10.8a) if it exists
|
|
||||||
uci commit wifibox
|
|
||||||
|
|
||||||
crontab -l 2> /dev/null | grep logrotate\.conf > /dev/null
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
# add line, method from http://askubuntu.com/a/58582
|
|
||||||
# Note: `crontab -l` will throw an error to stderr because the file does not exist, but that does not matter
|
|
||||||
(crontab -l 2> /dev/null; echo "$LOGROTATE_CRON_LINE" ) | crontab -
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
else
|
||||||
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0.
|
# Create a script to setup the system as wifibox, it will be deleted after it has been run, except if it returns > 0
|
||||||
|
|
||||||
cat <<-EOM >> $IPKG_INSTROOT/etc/uci-defaults/setup-wifibox.sh
|
cat <<-EOM >> $IPKG_INSTROOT/etc/uci-defaults/setup-wifibox.sh
|
||||||
uci set system.@system[0].hostname=wifibox
|
uci set system.@system[0].hostname=wifibox
|
||||||
uci set system.@system[0].log_size=64
|
uci set system.@system[0].log_size=64
|
||||||
uci set network.lan.ipaddr=192.168.5.1
|
uci set network.lan.ipaddr=192.168.5.1
|
||||||
echo -e "beta\nbeta" | passwd root
|
echo -e "beta\nbeta" | passwd root
|
||||||
|
|
||||||
# uhttpd config: https://wiki.openwrt.org/doc/uci/uhttpd#server_settings
|
|
||||||
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
|
uci set uhttpd.main.lua_handler='/usr/share/lua/wifibox/main.lua'
|
||||||
uci set uhttpd.main.lua_prefix='/d3dapi'
|
uci set uhttpd.main.lua_prefix='/d3dapi'
|
||||||
uci set uhttpd.main.max_requests='10'
|
|
||||||
|
|
||||||
uci set wireless.@wifi-device[0].disabled=0
|
uci set wireless.@wifi-device[0].disabled=0
|
||||||
uci delete wireless.radio0.channel
|
uci delete wireless.radio0.channel
|
||||||
@ -134,32 +109,9 @@ else
|
|||||||
uci set network.wlan=interface
|
uci set network.wlan=interface
|
||||||
|
|
||||||
uci set dhcp.lan.dhcp_option='3 6'
|
uci set dhcp.lan.dhcp_option='3 6'
|
||||||
|
|
||||||
uci set wifibox.general.system_log_level='info'
|
|
||||||
uci -q delete wifibox.system.loglevel # remove key used in older versions (<=0.10.8a) if it exists
|
|
||||||
|
|
||||||
# update wifibox's config for config changes in 0.10.10
|
|
||||||
uci set wifibox.system.log_path='/tmp'
|
|
||||||
uci set wifibox.system.api_log_filename='wifibox.log'
|
|
||||||
uci set wifibox.system.p3d_log_basename='print3d'
|
|
||||||
|
|
||||||
crontab -l 2> /dev/null | grep logrotate\.conf > /dev/null
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
# add line, method from http://askubuntu.com/a/58582
|
|
||||||
# Note: `crontab -l` will throw an error to stderr because the file does not exist, but that does not matter
|
|
||||||
(crontab -l 2> /dev/null; echo "$LOGROTATE_CRON_LINE" ) | crontab -
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
|
echo "WARNING: WiFiBox network configuration can only be fully prepared when installing on real device"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$IPKG_INSTROOT/etc/init.d/wifibox enable
|
|
||||||
$IPKG_INSTROOT/etc/init.d/wifibox start
|
|
||||||
$IPKG_INSTROOT/etc/init.d/dhcpcheck enable
|
|
||||||
$IPKG_INSTROOT/etc/init.d/cron enable
|
|
||||||
$IPKG_INSTROOT/etc/init.d/cron start
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -1 +1 @@
|
|||||||
0.11.0
|
0.10.6-rc2
|
@ -36,8 +36,6 @@ M.DEBUG_PCALLS = false
|
|||||||
|
|
||||||
--- This constant enables debugging of the REST API from the command-line by emulating GET/POST requests.
|
--- This constant enables debugging of the REST API from the command-line by emulating GET/POST requests.
|
||||||
-- Specify the path and optionally the request method as follows: `d3dapi p=/mod/func r=POST`.
|
-- Specify the path and optionally the request method as follows: `d3dapi p=/mod/func r=POST`.
|
||||||
-- Note that the command-line script redirects the output streams to '/tmp/wifibox.stdout.log',
|
|
||||||
-- meaning that any stack traces can be found there.
|
|
||||||
M.DEBUG_API = true
|
M.DEBUG_API = true
|
||||||
|
|
||||||
--- If enabled, REST responses will contain 'module' and 'function' keys describing what was requested.
|
--- If enabled, REST responses will contain 'module' and 'function' keys describing what was requested.
|
||||||
@ -46,22 +44,6 @@ M.API_INCLUDE_ENDPOINT_INFO = false
|
|||||||
--- This base path is used in @{rest.response}. It includes any base path if necessary (e.g. 'localhost/~user').
|
--- This base path is used in @{rest.response}. It includes any base path if necessary (e.g. 'localhost/~user').
|
||||||
M.API_BASE_URL_PATH = 'doodle3d.com'
|
M.API_BASE_URL_PATH = 'doodle3d.com'
|
||||||
|
|
||||||
M.system_log_level = {
|
|
||||||
default = 'info',
|
|
||||||
type = 'string',
|
|
||||||
description = 'Log level for firmware and print server',
|
|
||||||
isValid = function(value)
|
|
||||||
-- Note: level names mimic those in print3d
|
|
||||||
levelNames = { 'quiet', 'error', 'warning', 'info', 'verbose', 'bulk' }
|
|
||||||
for i,v in ipairs(levelNames) do
|
|
||||||
if value == v then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false, 'not one of '..table.concat(levelNames, ',')
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
M.network_ap_ssid = {
|
M.network_ap_ssid = {
|
||||||
default = 'Doodle3D-%%MAC_ADDR_TAIL%%',
|
default = 'Doodle3D-%%MAC_ADDR_TAIL%%',
|
||||||
type = 'string',
|
type = 'string',
|
||||||
@ -128,13 +110,8 @@ M.printer_dimensions_x = {
|
|||||||
default_minifactory = 150,
|
default_minifactory = 150,
|
||||||
default_lulzbot_taz_4 = 298,
|
default_lulzbot_taz_4 = 298,
|
||||||
default_ultimaker2go = 120,
|
default_ultimaker2go = 120,
|
||||||
default_renkforce_rf100 = 100,
|
|
||||||
default_doodle_dream = 120,
|
default_doodle_dream = 120,
|
||||||
default_wanhao_duplicator4 = 210,
|
default_wanhao_duplicator4 = 210,
|
||||||
default_colido_2_0_plus = 230,
|
|
||||||
default_colido_x3045 = 300,
|
|
||||||
default_colido_compact = 130,
|
|
||||||
default_craftbot_plus = 250,
|
|
||||||
subSection = 'printer_type',
|
subSection = 'printer_type',
|
||||||
type = 'int',
|
type = 'int',
|
||||||
description = '',
|
description = '',
|
||||||
@ -149,12 +126,8 @@ M.printer_dimensions_y = {
|
|||||||
default_minifactory = 150,
|
default_minifactory = 150,
|
||||||
default_lulzbot_taz_4 = 275,
|
default_lulzbot_taz_4 = 275,
|
||||||
default_ultimaker2go = 120,
|
default_ultimaker2go = 120,
|
||||||
default_renkforce_rf100 = 100,
|
|
||||||
default_doodle_dream = 120,
|
default_doodle_dream = 120,
|
||||||
default_wanhao_duplicator4 = 140,
|
default_wanhao_duplicator4 = 140,
|
||||||
default_colido_2_0_plus = 150,
|
|
||||||
default_colido_x3045 = 300,
|
|
||||||
default_colido_compact = 130,
|
|
||||||
subSection = 'printer_type',
|
subSection = 'printer_type',
|
||||||
type = 'int',
|
type = 'int',
|
||||||
description = '',
|
description = '',
|
||||||
@ -166,13 +139,8 @@ M.printer_dimensions_z = {
|
|||||||
default__3Dison_plus = 150,
|
default__3Dison_plus = 150,
|
||||||
default_lulzbot_taz_4 = 250,
|
default_lulzbot_taz_4 = 250,
|
||||||
default_ultimaker2go = 112,
|
default_ultimaker2go = 112,
|
||||||
default_renkforce_rf100 = 100,
|
|
||||||
default_doodle_dream = 80,
|
default_doodle_dream = 80,
|
||||||
default_wanhao_duplicator4 = 140,
|
default_wanhao_duplicator4 = 140,
|
||||||
default_colido_2_0_plus = 140,
|
|
||||||
default_colido_x3045 = 450,
|
|
||||||
default_colido_compact = 115,
|
|
||||||
default_colido_diy = 170,
|
|
||||||
subSection = 'printer_type',
|
subSection = 'printer_type',
|
||||||
type = 'int',
|
type = 'int',
|
||||||
description = '',
|
description = '',
|
||||||
@ -185,11 +153,6 @@ M.printer_heatedbed = {
|
|||||||
default_minifactory = true,
|
default_minifactory = true,
|
||||||
default_lulzbot_taz_4 = true,
|
default_lulzbot_taz_4 = true,
|
||||||
default_wanhao_duplicator4 = true,
|
default_wanhao_duplicator4 = true,
|
||||||
default_colido_2_0_plus = true,
|
|
||||||
default_colido_m2020 = true,
|
|
||||||
default_colido_x3045 = true,
|
|
||||||
default_craftbot_plus = true,
|
|
||||||
default_ultimaker_original_plus = true,
|
|
||||||
subSection = 'printer_type',
|
subSection = 'printer_type',
|
||||||
type = 'bool',
|
type = 'bool',
|
||||||
description = 'Printer has heated bed',
|
description = 'Printer has heated bed',
|
||||||
@ -197,9 +160,7 @@ M.printer_heatedbed = {
|
|||||||
M.printer_filamentThickness = {
|
M.printer_filamentThickness = {
|
||||||
default = 2.89,
|
default = 2.89,
|
||||||
default_doodle_dream = 1.75,
|
default_doodle_dream = 1.75,
|
||||||
default_renkforce_rf100 = 1.75,
|
|
||||||
default_wanhao_duplicator4 = 1.75,
|
default_wanhao_duplicator4 = 1.75,
|
||||||
default_craftbot_plus = 1.75,
|
|
||||||
type = 'float',
|
type = 'float',
|
||||||
description = '',
|
description = '',
|
||||||
min = 0.0,
|
min = 0.0,
|
||||||
@ -208,10 +169,9 @@ M.printer_filamentThickness = {
|
|||||||
|
|
||||||
local default_makerbot_startcode = ';@printer {printerType}\nM136 (enable build)\nM73 P0 (Set build percentage to 0)\nG162 X Y F2000 (home XY axes to maximum)\nG161 Z F900 (home Z axis to minimum quick)\nG92 X0 Y0 Z0 A0 B0 (set axis positions to 0)\nG1 Z5.0 F900 (move Z axis down)\nG161 Z F100 (home Z axis to minimum more precise)\nG92 X0 Y0 Z0 A0 B0 (set axis positions to 0)\nG1 Z2.0 F900 (move Z axis to safety height)\nG1 X-264 Y-145 Z0 F3300.0 (move XY to start position)\nG92 X0 Y0 Z0 A0 B0 (set axis position to 0)\nG130 X20 Y20 A20 B20 (Lower stepper Vrefs while heating)\n{if heatedBed}M140 S{printingBedTemp} T0 (Set bed temp)\nM135 T0 (use first extruder)\nM104 S{printingTemp} T0 (set extruder temp)\nM133 T0 (Wait for extruder)\nG130 X127 Y127 A127 B127 (Set Stepper motor Vref to defaults)\nG1 F100 A10 (extrude 10mm)\nG92 A0 (reset extruder)\nG0 Z20 (move up, to lose filament)'
|
local default_makerbot_startcode = ';@printer {printerType}\nM136 (enable build)\nM73 P0 (Set build percentage to 0)\nG162 X Y F2000 (home XY axes to maximum)\nG161 Z F900 (home Z axis to minimum quick)\nG92 X0 Y0 Z0 A0 B0 (set axis positions to 0)\nG1 Z5.0 F900 (move Z axis down)\nG161 Z F100 (home Z axis to minimum more precise)\nG92 X0 Y0 Z0 A0 B0 (set axis positions to 0)\nG1 Z2.0 F900 (move Z axis to safety height)\nG1 X-264 Y-145 Z0 F3300.0 (move XY to start position)\nG92 X0 Y0 Z0 A0 B0 (set axis position to 0)\nG130 X20 Y20 A20 B20 (Lower stepper Vrefs while heating)\n{if heatedBed}M140 S{printingBedTemp} T0 (Set bed temp)\nM135 T0 (use first extruder)\nM104 S{printingTemp} T0 (set extruder temp)\nM133 T0 (Wait for extruder)\nG130 X127 Y127 A127 B127 (Set Stepper motor Vref to defaults)\nG1 F100 A10 (extrude 10mm)\nG92 A0 (reset extruder)\nG0 Z20 (move up, to lose filament)'
|
||||||
local default_deltabot_startcode = ';Generated with Doodle3D (deltabot)\nM109 S{printingTemp} ;set target temperature\n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 ; move to home\nG92 E0 ;zero the extruded length\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)'
|
local default_deltabot_startcode = ';Generated with Doodle3D (deltabot)\nM109 S{printingTemp} ;set target temperature\n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 ; move to home\nG92 E0 ;zero the extruded length\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)'
|
||||||
local default_ultimaker2_startcode = ';Generated with Doodle3D (ultimaker2)\nM10000\nM10000\nM10001 X8 Y28 SDoodle3D heat up...\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM10000\nM10000\nM10001 X8 Y28 SDoodle3D printing...\n'
|
local default_ultimaker2_startcode = ';Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)\n'
|
||||||
local default_ultimaker_original_plus_startcode = ';Generated with Doodle3D (Ultimaker Original Plus)\n{if heatedBed}M190 S{printingBedTemp}\nM109 S{printingTemp}\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)'
|
|
||||||
M.printer_startcode = {
|
M.printer_startcode = {
|
||||||
default = ';Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG91 ;relative positioning\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)',
|
default = ';Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)',
|
||||||
default_ultimaker2 = default_ultimaker2_startcode,
|
default_ultimaker2 = default_ultimaker2_startcode,
|
||||||
default_ultimaker2go = default_ultimaker2_startcode,
|
default_ultimaker2go = default_ultimaker2_startcode,
|
||||||
default__3Dison_plus = ';@printer {printerType}\nM136 (enable build)\nM73 P0\nG21\nG90\nM103\n;M109 S50 T0\nM140 S50 T0\nM104 S{printingTemp} T0\n;M134 T0\nM135 T0\nM104 S{printingTemp} T0\nG162 X Y F2000(home XY axes maximum)\nG161 Z F900(home Z axis minimum)\nG92 X113.5 Y74 Z-5 A0 B0 (set Z to -5)\nG1 Z0.0 F900(move Z to 0)\nG161 Z F100(home Z axis minimum)\nM132 X Y Z A B (Recall stored home offsets for XYZAB axis)\nG1 Z50 F3300\nG130 X20 Y20 A20 B20 (Lower stepper Vrefs while heating)\nM133 T0\nM6 T0\nG130 X127 Y127 A127 B127 (Set Stepper motor Vref to defaults)\nG0 Z0.2 F3000\nG1 Z0 F100 A10 ;extrude 10mm\nG92 X227 Y148 Z0 A0 ;reset again\nG1 X227 Y148 Z0',
|
default__3Dison_plus = ';@printer {printerType}\nM136 (enable build)\nM73 P0\nG21\nG90\nM103\n;M109 S50 T0\nM140 S50 T0\nM104 S{printingTemp} T0\n;M134 T0\nM135 T0\nM104 S{printingTemp} T0\nG162 X Y F2000(home XY axes maximum)\nG161 Z F900(home Z axis minimum)\nG92 X113.5 Y74 Z-5 A0 B0 (set Z to -5)\nG1 Z0.0 F900(move Z to 0)\nG161 Z F100(home Z axis minimum)\nM132 X Y Z A B (Recall stored home offsets for XYZAB axis)\nG1 Z50 F3300\nG130 X20 Y20 A20 B20 (Lower stepper Vrefs while heating)\nM133 T0\nM6 T0\nG130 X127 Y127 A127 B127 (Set Stepper motor Vref to defaults)\nG0 Z0.2 F3000\nG1 Z0 F100 A10 ;extrude 10mm\nG92 X227 Y148 Z0 A0 ;reset again\nG1 X227 Y148 Z0',
|
||||||
@ -223,20 +183,19 @@ M.printer_startcode = {
|
|||||||
default_delta_rostockmax = default_deltabot_startcode,
|
default_delta_rostockmax = default_deltabot_startcode,
|
||||||
default_deltamaker = default_deltabot_startcode,
|
default_deltamaker = default_deltabot_startcode,
|
||||||
default_kossel = default_deltabot_startcode,
|
default_kossel = default_deltabot_startcode,
|
||||||
default_ultimaker_original_plus = default_ultimaker_original_plus_startcode,
|
|
||||||
type = 'string',
|
type = 'string',
|
||||||
subSection = 'printer_type',
|
subSection = 'printer_type',
|
||||||
description = ''
|
description = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
local default_makerbot_endcode = 'G92 A0 B0 ;reset extruder position to prevent retraction\nM18 A B(Turn off A and B Steppers)\nG162 Z F900\nG162 X Y F2000\nM18 X Y Z(Turn off steppers after a build)\n{if heatedBed}M140 S0 T0\nM104 S0 T0\nM72 P1 ( Play Ta-Da song )\nM137 (build end notification)'
|
local default_makerbot_endcode = 'M73 P100\nG92 A0 B0 ;reset extruder position to prevent retraction\nM18 A B(Turn off A and B Steppers)\nG162 Z F900\nG162 X Y F2000\nM18 X Y Z(Turn off steppers after a build)\n{if heatedBed}M140 S{preheatBedTemp} T0\nM104 S{preheatTemp} T0\nM73 P100 (end build progress )\nM72 P1 ( Play Ta-Da song )\nM137 (build end notification)'
|
||||||
local default_deltabot_endcode = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;move to home\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM109 S0 ; hot end off\n{if heatedBed}M140 S0\nM117 Done ;display message (20 characters to clear whole screen)'
|
local default_deltabot_endcode = 'M107 ;fan offG91 ;relative positioningG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressureG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even moreG28 ;move to homeM84 ;disable axes / steppersG90 ;absolute positioningM109 S0 ; hot end off{if heatedBed}M140 S{preheatBedTemp}M117 Done ;display message (20 characters to clear whole screen)'
|
||||||
local default_ultimaker2_endcode = 'M10000\nM10000\nM10001 X20 Y28 SDoodle3D done!\nM107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S0\n{if heatedBed}M140 S0\n'
|
local default_ultimaker2_endcode = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)'
|
||||||
M.printer_endcode = {
|
M.printer_endcode = {
|
||||||
default = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S0\n{if heatedBed}M140 S0\nM117 Done ;display message (20 characters to clear whole screen)',
|
default = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)',
|
||||||
default_ultimaker2 = default_ultimaker2_endcode,
|
default_ultimaker2 = default_ultimaker2_endcode,
|
||||||
default_ultimaker2go = default_ultimaker2_endcode,
|
default_ultimaker2go = default_ultimaker2_endcode,
|
||||||
default__3Dison_plus = 'M73 P100\nG92 A0 B0 ;reset extruder position to prevent retraction\nM18 A B(Turn off A and B Steppers)\nG1 Z155 F900\nG162 X Y F2000\nM18 X Y Z(Turn off steppers after a build)\nM140 S0 T0\nM104 S0 T0\nM73 P100 (end build progress )\nM72 P1 ( Play Ta-Da song )\nM137 (build end notification)\n',
|
default__3Dison_plus = 'M73 P100\nG92 A0 B0 ;reset extruder position to prevent retraction\nM18 A B(Turn off A and B Steppers)\nG1 Z155 F900\nG162 X Y F2000\nM18 X Y Z(Turn off steppers after a build)\nM140 S35 T0\nM104 S180 T0\nM73 P100 (end build progress )\nM72 P1 ( Play Ta-Da song )\nM137 (build end notification)\n',
|
||||||
default_makerbot_generic = default_makerbot_endcode,
|
default_makerbot_generic = default_makerbot_endcode,
|
||||||
default_makerbot_replicator2 = default_makerbot_endcode,
|
default_makerbot_replicator2 = default_makerbot_endcode,
|
||||||
default_makerbot_replicator2x = default_makerbot_endcode,
|
default_makerbot_replicator2x = default_makerbot_endcode,
|
||||||
@ -245,7 +204,6 @@ M.printer_endcode = {
|
|||||||
default_delta_rostockmax = default_deltabot_endcode,
|
default_delta_rostockmax = default_deltabot_endcode,
|
||||||
default_deltamaker = default_deltabot_endcode,
|
default_deltamaker = default_deltabot_endcode,
|
||||||
default_kossel = default_deltabot_endcode,
|
default_kossel = default_deltabot_endcode,
|
||||||
default_craftbot_plus = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM109 S0\n{if heatedBed}M140 S0\nM117 Done ;display message (20 characters to clear whole screen)',
|
|
||||||
type = 'string',
|
type = 'string',
|
||||||
subSection = 'printer_type',
|
subSection = 'printer_type',
|
||||||
description = ''
|
description = ''
|
||||||
@ -262,7 +220,7 @@ M.printer_baudrate = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
M.printer_temperature = {
|
M.printer_temperature = {
|
||||||
default = 210,
|
default = 230,
|
||||||
type = 'int',
|
type = 'int',
|
||||||
description = 'printing temperature',
|
description = 'printing temperature',
|
||||||
min = 0
|
min = 0
|
||||||
@ -327,26 +285,20 @@ M.printer_bottomFlowRate = {
|
|||||||
description = 'Multiplication factor for filament flow rate in first few layers'
|
description = 'Multiplication factor for filament flow rate in first few layers'
|
||||||
}
|
}
|
||||||
|
|
||||||
M.printer_bottomEnableTraveling = {
|
|
||||||
default = true,
|
|
||||||
type = 'bool',
|
|
||||||
description = 'Enable traveling on bottom layers, disabling this might improve adhesion on some printers'
|
|
||||||
}
|
|
||||||
|
|
||||||
M.printer_heatup_enabled = {
|
M.printer_heatup_enabled = {
|
||||||
default = false,
|
default = true,
|
||||||
type = 'bool',
|
type = 'bool',
|
||||||
description = ''
|
description = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
M.printer_heatup_temperature = {
|
M.printer_heatup_temperature = {
|
||||||
default = 0,
|
default = 180,
|
||||||
type = 'int',
|
type = 'int',
|
||||||
description = ''
|
description = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
M.printer_heatup_bed_temperature = {
|
M.printer_heatup_bed_temperature = {
|
||||||
default = 0,
|
default = 70,
|
||||||
type = 'int',
|
type = 'int',
|
||||||
description = ''
|
description = ''
|
||||||
}
|
}
|
||||||
@ -422,10 +374,4 @@ M.doodle3d_update_baseUrl = {
|
|||||||
description = ''
|
description = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
M.gcode_server = {
|
|
||||||
default = 'http://gcodeserver.doodle3d.com',
|
|
||||||
type = 'string',
|
|
||||||
description =''
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
140
src/main.lua
140
src/main.lua
@ -22,8 +22,6 @@ local netconf = require('network.netconfig')
|
|||||||
local RequestClass = require('rest.request')
|
local RequestClass = require('rest.request')
|
||||||
local ResponseClass = require('rest.response')
|
local ResponseClass = require('rest.response')
|
||||||
local Signin = require('network.signin')
|
local Signin = require('network.signin')
|
||||||
local osUtils = require('os_utils')
|
|
||||||
|
|
||||||
|
|
||||||
-- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined.
|
-- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined.
|
||||||
argStash = arg
|
argStash = arg
|
||||||
@ -32,7 +30,6 @@ local updater = require('script.d3d-updater')
|
|||||||
arg = argStash
|
arg = argStash
|
||||||
|
|
||||||
local postData = nil
|
local postData = nil
|
||||||
local MOD_ABBR = "ENTR"
|
|
||||||
|
|
||||||
|
|
||||||
--- Switches to wifi client mode or to access point mode based on availability of known wifi networks.
|
--- Switches to wifi client mode or to access point mode based on availability of known wifi networks.
|
||||||
@ -51,11 +48,11 @@ local function setupAutoWifiMode()
|
|||||||
|
|
||||||
local wifiState = wifi.getDeviceState()
|
local wifiState = wifi.getDeviceState()
|
||||||
local netName, netMode = wifiState.ssid, wifiState.mode
|
local netName, netMode = wifiState.ssid, wifiState.mode
|
||||||
log:info(MOD_ABBR, "current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode)
|
log:info("current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode)
|
||||||
|
|
||||||
local apSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
local apSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
||||||
local apMode = (apSsid == netName) and (netMode == 'ap')
|
local apMode = (apSsid == netName) and (netMode == 'ap')
|
||||||
log:info(MOD_ABBR, "ssid of self: " .. apSsid)
|
log:info("ssid of self: " .. apSsid)
|
||||||
|
|
||||||
local scanList,msg = wifi.getScanInfo()
|
local scanList,msg = wifi.getScanInfo()
|
||||||
if not scanList then
|
if not scanList then
|
||||||
@ -63,7 +60,7 @@ local function setupAutoWifiMode()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local knownSsids = wifi.getConfigs()
|
local knownSsids = wifi.getConfigs()
|
||||||
-- log:info(MOD_ABBR, "current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode .. ", ssid of self: " .. apSsid)
|
-- log:info("current wifi name: " .. (netName or "<nil>") .. ", mode: " .. netMode .. ", ssid of self: " .. apSsid)
|
||||||
local visNet, knownNet = {}, {}
|
local visNet, knownNet = {}, {}
|
||||||
for _,sn in ipairs(scanList) do
|
for _,sn in ipairs(scanList) do
|
||||||
table.insert(visNet, sn.ssid)
|
table.insert(visNet, sn.ssid)
|
||||||
@ -71,17 +68,17 @@ local function setupAutoWifiMode()
|
|||||||
for _,kn in ipairs(knownSsids) do
|
for _,kn in ipairs(knownSsids) do
|
||||||
table.insert(knownNet, kn.ssid .. "/" .. kn.mode)
|
table.insert(knownNet, kn.ssid .. "/" .. kn.mode)
|
||||||
end
|
end
|
||||||
log:info(MOD_ABBR, "visible networks: " .. table.concat(visNet, ", "))
|
log:info("visible networks: " .. table.concat(visNet, ", "))
|
||||||
log:info(MOD_ABBR, "known networks: " .. table.concat(knownNet, ", "))
|
log:info("known networks: " .. table.concat(knownNet, ", "))
|
||||||
|
|
||||||
-- if the currently active network is client mode and is also visible, do nothing since it will connect automatically further along the boot process
|
-- if the currently active network is client mode and is also visible, do nothing since it will connect automatically further along the boot process
|
||||||
if netMode == 'sta' and netName ~= nil and netName ~= "" and findSsidInList(scanList, netName) then
|
if netMode == 'sta' and netName ~= nil and netName ~= "" and findSsidInList(scanList, netName) then
|
||||||
-- signin to connect.doodle3d.com
|
-- signin to connect.doodle3d.com
|
||||||
local success, output = Signin.signin()
|
local success, output = Signin.signin()
|
||||||
if success then
|
if success then
|
||||||
log:info(MOD_ABBR, "Signed in")
|
log:info("Signed in")
|
||||||
else
|
else
|
||||||
log:info(MOD_ABBR, "Signing in failed")
|
log:info("Signing in failed")
|
||||||
end
|
end
|
||||||
-- report we are connected after signin attempt
|
-- report we are connected after signin attempt
|
||||||
netconf.setStatus(netconf.CONNECTED,"Connected");
|
netconf.setStatus(netconf.CONNECTED,"Connected");
|
||||||
@ -122,57 +119,36 @@ local function setupAutoWifiMode()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Initializes the logging system to use the file and level defined in the system settings.
|
--- Initializes the logging system to use the file and level defined in the system settings.
|
||||||
-- The settings used are `log_path`, `api_log_filename` from the system section and
|
-- The settings used are `logfile` and `loglevel`. The former may either be a
|
||||||
-- `system_log_level` from the general section. The filename may either be a regular filename
|
-- reular file path, or `<stdout>` or `<stderr>`.
|
||||||
-- (with an absolute log_path), or `<stdout>` or `<stderr>`.
|
|
||||||
-- TODO: also support backticks (see Logger.cpp in print3d)--
|
|
||||||
-- @see util.settings.getSystemKey
|
-- @see util.settings.getSystemKey
|
||||||
-- @treturn bool True on success, false on error.
|
-- @treturn bool True on success, false on error.
|
||||||
local function setupLogger()
|
local function setupLogger()
|
||||||
local logStream = io.stderr -- use stderr as hard-coded default target
|
local logStream = io.stderr -- use stderr as hard-coded default target
|
||||||
local logLevel = log.LEVEL.verbose -- use verbose logging as hard-coded default level
|
local logLevel = log.LEVEL.debug -- use debug logging as hard-coded default level
|
||||||
|
|
||||||
local logPathSetting = settings.getSystemKey('log_path')
|
local logTargetSetting = settings.getSystemKey('logfile')
|
||||||
local logTargetSetting = settings.getSystemKey('api_log_filename')
|
local logLevelSetting = settings.getSystemKey('loglevel')
|
||||||
local logLevelSetting = settings.get('system_log_level')
|
|
||||||
local logTargetError, logLevelError = nil, nil
|
local logTargetError, logLevelError = nil, nil
|
||||||
|
|
||||||
if type(logTargetSetting) == 'string' then
|
if type(logTargetSetting) == 'string' then
|
||||||
local streamTarget = logTargetSetting:match('^<(.*)>$')
|
local specialTarget = logTargetSetting:match('^<(.*)>$')
|
||||||
local popenTarget = logTargetSetting:match('^`(.*)`$')
|
if specialTarget then
|
||||||
if streamTarget then
|
if specialTarget == 'stdout' then logStream = io.stdout
|
||||||
if streamTarget:lower() == 'stdout' then logStream = io.stdout
|
elseif specialTarget == 'stderr' then logStream = io.stderr
|
||||||
elseif streamTarget:lower() == 'stderr' then logStream = io.stderr
|
|
||||||
end
|
end
|
||||||
elseif popenTarget then
|
elseif logTargetSetting:sub(1, 1) == '/' then
|
||||||
local f,msg = io.popen(popenTarget, 'w')
|
local f,msg = io.open(logTargetSetting, 'a+')
|
||||||
|
|
||||||
if f then logStream = f
|
if f then logStream = f
|
||||||
else logTargetError = msg
|
else logTargetError = msg
|
||||||
end
|
end
|
||||||
elseif logPathSetting:sub(1, 1) == '/' then
|
|
||||||
local path = logPathSetting .. '/' .. logTargetSetting
|
|
||||||
local f,msg = io.open(path, 'a+')
|
|
||||||
|
|
||||||
if f then
|
|
||||||
logStream = f
|
|
||||||
log:setLogFilePath(path)
|
|
||||||
else
|
|
||||||
logTargetError = msg
|
|
||||||
end
|
|
||||||
else
|
|
||||||
logTargetError = "log file path is not absolute"
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- if uci config not available, fallback to /tmp/wifibox.log
|
-- if uci config not available, fallback to /tmp/wifibox.log
|
||||||
local path = '/tmp/wifibox.log'
|
local f,msg = io.open('/tmp/wifibox.log', 'a+')
|
||||||
local f,msg = io.open(path, 'a+')
|
if f then logStream = f
|
||||||
|
else logTargetError = msg
|
||||||
if f then
|
|
||||||
logStream = f
|
|
||||||
log:setLogFilePath(path)
|
|
||||||
else
|
|
||||||
logTargetError = msg
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -192,12 +168,12 @@ local function setupLogger()
|
|||||||
|
|
||||||
local rv = true
|
local rv = true
|
||||||
if logTargetError then
|
if logTargetError then
|
||||||
log:error(MOD_ABBR, "could not open logfile '" .. logPathSetting .. '/' .. logTargetSetting .. "', using stderr as fallback (" .. logTargetError .. ")")
|
log:error("could not open logfile '" .. logTargetSetting .. "', using stderr as fallback (" .. logTargetError .. ")")
|
||||||
rv = false
|
rv = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if logLevelError then
|
if logLevelError then
|
||||||
log:error(MOD_ABBR, "uci config specifies invalid log level '" .. logLevelSetting .. "', using verbose level as fallback")
|
log:error("uci config specifies invalid log level '" .. logLevelSetting .. "', using debug level as fallback")
|
||||||
rv = false
|
rv = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -208,6 +184,17 @@ end
|
|||||||
-- The logger is set up, any POST data is read and several other subsystems are initialized.
|
-- The logger is set up, any POST data is read and several other subsystems are initialized.
|
||||||
-- @tparam table environment The 'shell' environment containing all CGI variables. Note that @{cmdmain} simulates this.
|
-- @tparam table environment The 'shell' environment containing all CGI variables. Note that @{cmdmain} simulates this.
|
||||||
local function init(environment)
|
local function init(environment)
|
||||||
|
setupLogger()
|
||||||
|
|
||||||
|
local dbgText = ""
|
||||||
|
if confDefaults.DEBUG_API and confDefaults.DEBUG_PCALLS then dbgText = "pcall+api"
|
||||||
|
elseif confDefaults.DEBUG_API then dbgText = "api"
|
||||||
|
elseif confDefaults.DEBUG_PCALL then dbgText = "pcall"
|
||||||
|
end
|
||||||
|
|
||||||
|
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end
|
||||||
|
log:info("=======rest api" .. dbgText .. "=======")
|
||||||
|
|
||||||
if (environment['REQUEST_METHOD'] == 'POST') then
|
if (environment['REQUEST_METHOD'] == 'POST') then
|
||||||
local n = tonumber(environment['CONTENT_LENGTH'])
|
local n = tonumber(environment['CONTENT_LENGTH'])
|
||||||
postData = io.read(n)
|
postData = io.read(n)
|
||||||
@ -232,45 +219,48 @@ local function main(environment)
|
|||||||
if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then
|
if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then
|
||||||
|
|
||||||
local version = updater.formatVersion(updater.getCurrentVersion());
|
local version = updater.formatVersion(updater.getCurrentVersion());
|
||||||
log:info(MOD_ABBR, "Doodle3D version: "..util.dump(version))
|
log:info("Doodle3D version: "..util.dump(version))
|
||||||
|
|
||||||
log:info(MOD_ABBR, "Running in autowifi mode")
|
log:info("running in autowifi mode")
|
||||||
local rv,msg = setupAutoWifiMode()
|
local rv,msg = setupAutoWifiMode()
|
||||||
|
|
||||||
if rv then
|
if rv then
|
||||||
log:info(MOD_ABBR, "Autowifi setup done (" .. msg .. ")")
|
log:info("autowifi setup done (" .. msg .. ")")
|
||||||
else
|
else
|
||||||
log:error(MOD_ABBR, "Autowifi setup failed (" .. msg .. ")")
|
log:error("autowifi setup failed (" .. msg .. ")")
|
||||||
end
|
end
|
||||||
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
||||||
log:info(MOD_ABBR, "Running in signin mode")
|
log:info("running in signin mode")
|
||||||
|
|
||||||
log:info(MOD_ABBR, " attempting signin")
|
local ds = wifi.getDeviceState()
|
||||||
|
log:info(" ds.mode: "..util.dump(ds.mode))
|
||||||
|
if ds.mode == "sta" then
|
||||||
|
log:info(" attempting signin")
|
||||||
local success,msg = Signin.signin()
|
local success,msg = Signin.signin()
|
||||||
if success then
|
if success then
|
||||||
log:info(MOD_ABBR, "Signin successful")
|
log:info("Signin successful")
|
||||||
else
|
else
|
||||||
log:warning(MOD_ABBR, "Signin failed: "..util.dump(msg))
|
log:info("Signin failed: "..util.dump(msg))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
|
elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
|
||||||
-- Note: the commented log message will print too many data if it's for instance dumping a gcode add request
|
-- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||||
--logMessage = "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))
|
||||||
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll())
|
log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
|
||||||
logMessage = rq:getRequestMethod() .. " request for " .. (rq:getRequestedApiModule() or "<unknown>")
|
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
|
||||||
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>")
|
|
||||||
if rq:getRequestMethod() ~= 'CMDLINE' then
|
if rq:getRequestMethod() ~= 'CMDLINE' then
|
||||||
logMessage = logMessage .. " (remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort() .. ")"
|
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
|
||||||
--logMessage = logMessage .. " (user agent: " .. rq:getUserAgent() .. ")"
|
--log:debug("user agent: " .. rq:getUserAgent())
|
||||||
end
|
end
|
||||||
log:info(MOD_ABBR, logMessage)
|
|
||||||
|
|
||||||
local response, err = rq:handle()
|
local response, err = rq:handle()
|
||||||
|
|
||||||
if err ~= nil then log:error(MOD_ABBR, err) end
|
if err ~= nil then log:error(err) end
|
||||||
response:send()
|
response:send()
|
||||||
|
|
||||||
response:executePostResponseQueue()
|
response:executePostResponseQueue()
|
||||||
else
|
else
|
||||||
log:info(MOD_ABBR, "Nothing to do...bye.\n")
|
log:info("Nothing to do...bye.\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -283,22 +273,6 @@ end
|
|||||||
-- @tparam table env The CGI environment table.
|
-- @tparam table env The CGI environment table.
|
||||||
-- @treturn number A Z+ return value suitable to return from wrapper script. Note that this value is ignored by uhttpd-mod-lua.
|
-- @treturn number A Z+ return value suitable to return from wrapper script. Note that this value is ignored by uhttpd-mod-lua.
|
||||||
function handle_request(env)
|
function handle_request(env)
|
||||||
local function constructDebugText()
|
|
||||||
local dbgText = ""
|
|
||||||
if confDefaults.DEBUG_API and confDefaults.DEBUG_PCALLS then dbgText = "pcall+api"
|
|
||||||
elseif confDefaults.DEBUG_API then dbgText = "api"
|
|
||||||
elseif confDefaults.DEBUG_PCALL then dbgText = "pcall"
|
|
||||||
end
|
|
||||||
if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end
|
|
||||||
return dbgText
|
|
||||||
end
|
|
||||||
|
|
||||||
setupLogger()
|
|
||||||
|
|
||||||
local pid = osUtils.getPID()
|
|
||||||
local beginSecs, beginUSecs = osUtils.getTime()
|
|
||||||
|
|
||||||
log:verbose(MOD_ABBR, "START-RQ with PID=" .. pid .. constructDebugText())
|
|
||||||
local s, msg = init(env)
|
local s, msg = init(env)
|
||||||
|
|
||||||
if s == false then
|
if s == false then
|
||||||
@ -307,13 +281,11 @@ function handle_request(env)
|
|||||||
|
|
||||||
resp:setError("initialization failed" .. errSuffix)
|
resp:setError("initialization failed" .. errSuffix)
|
||||||
resp:send()
|
resp:send()
|
||||||
log:error(MOD_ABBR, "Initialization failed" .. errSuffix)
|
log:error("initialization failed" .. errSuffix) --NOTE: this assumes the logger has been initialized properly, despite init() having failed
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
main(env)
|
main(env)
|
||||||
local elapsed,msg = osUtils.getElapsedTime(beginSecs, beginUSecs)
|
|
||||||
log:bulk(MOD_ABBR, "END-RQ with PID=" .. pid .. " completed in " .. elapsed .. " msec")
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,8 +18,6 @@ local reconf = {}
|
|||||||
local wifi
|
local wifi
|
||||||
local reloadSilent
|
local reloadSilent
|
||||||
|
|
||||||
local MOD_ABBR = "NTCF"
|
|
||||||
|
|
||||||
M.WWW_CAPTIVE_PATH = '/usr/share/lua/wifibox/www'
|
M.WWW_CAPTIVE_PATH = '/usr/share/lua/wifibox/www'
|
||||||
M.WWW_CAPTIVE_INDICATOR = '/www/.wifibox-inplace'
|
M.WWW_CAPTIVE_INDICATOR = '/www/.wifibox-inplace'
|
||||||
M.WWW_RENAME_NAME = '/www-regular'
|
M.WWW_RENAME_NAME = '/www-regular'
|
||||||
@ -64,10 +62,10 @@ function M.switchConfiguration(components)
|
|||||||
for k,v in pairs(components) do
|
for k,v in pairs(components) do
|
||||||
local fname = k .. '_' .. v
|
local fname = k .. '_' .. v
|
||||||
if type(reconf[fname]) == 'function' then
|
if type(reconf[fname]) == 'function' then
|
||||||
log:verbose(MOD_ABBR, "reconfiguring component '" .. k .. "' (" .. v .. ")")
|
log:debug("reconfiguring component '" .. k .. "' (" .. v .. ")")
|
||||||
reconf[fname](dirtyList)
|
reconf[fname](dirtyList)
|
||||||
else
|
else
|
||||||
log:warning(MOD_ABBR, "unknown component or action '" .. fname .. "' skipped")
|
log:warn("unknown component or action '" .. fname .. "' skipped")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -81,12 +79,12 @@ function M.switchConfiguration(components)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.commitComponent(c)
|
function M.commitComponent(c)
|
||||||
log:verbose(MOD_ABBR, "committing component '" .. c .. "'")
|
log:info("committing component '" .. c .. "'")
|
||||||
uci:commit(c)
|
uci:commit(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.reloadComponent(c, silent)
|
function M.reloadComponent(c, silent)
|
||||||
log:verbose(MOD_ABBR, "reloading component '" .. c .. "'")
|
log:info("reloading component '" .. c .. "'")
|
||||||
local command = 'reload'
|
local command = 'reload'
|
||||||
local cmd = '/etc/init.d/' .. c .. ' '..command
|
local cmd = '/etc/init.d/' .. c .. ' '..command
|
||||||
if silent ~= nil and silent then
|
if silent ~= nil and silent then
|
||||||
@ -94,7 +92,7 @@ function M.reloadComponent(c, silent)
|
|||||||
os.execute(cmd)
|
os.execute(cmd)
|
||||||
else
|
else
|
||||||
rv = utils.captureCommandOutput(cmd)
|
rv = utils.captureCommandOutput(cmd)
|
||||||
log:verbose(MOD_ABBR, " result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
log:debug(" result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -149,7 +147,7 @@ function reconf.apnet_rm(dirtyList)
|
|||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
if s.ssid == wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) then sname = s['.name']; return false end
|
if s.ssid == wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) then sname = s['.name']; return false end
|
||||||
end)
|
end)
|
||||||
if sname == nil then return log:info(MOD_ABBR, "AP network configuration does not exist, nothing to remove") end
|
if sname == nil then return log:info("AP network configuration does not exist, nothing to remove") end
|
||||||
uci:delete('wireless', sname)
|
uci:delete('wireless', sname)
|
||||||
reloadBit(dirtyList, 'network'); commitBit(dirtyList, 'wireless')
|
reloadBit(dirtyList, 'network'); commitBit(dirtyList, 'wireless')
|
||||||
end
|
end
|
||||||
@ -214,15 +212,15 @@ end
|
|||||||
function reconf.dnsredir_add(dirtyList)
|
function reconf.dnsredir_add(dirtyList)
|
||||||
local redirText = '/#/' .. settings.get('network.ap.address')
|
local redirText = '/#/' .. settings.get('network.ap.address')
|
||||||
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
||||||
if sname == nil then return log:error(MOD_ABBR, "dhcp config does not contain a dnsmasq section") end
|
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
||||||
if uci:get('dhcp', sname, 'address') ~= nil then return log:info(MOD_ABBR, "DNS address redirection already in place, not re-adding", false) end
|
if uci:get('dhcp', sname, 'address') ~= nil then return log:debug("DNS address redirection already in place, not re-adding", false) end
|
||||||
|
|
||||||
uci:set('dhcp', sname, 'address', {redirText})
|
uci:set('dhcp', sname, 'address', {redirText})
|
||||||
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
||||||
end
|
end
|
||||||
function reconf.dnsredir_rm(dirtyList)
|
function reconf.dnsredir_rm(dirtyList)
|
||||||
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
||||||
if sname == nil then return log:error(MOD_ABBR, "dhcp config does not contain a dnsmasq section") end
|
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
||||||
|
|
||||||
uci:delete('dhcp', sname, 'address')
|
uci:delete('dhcp', sname, 'address')
|
||||||
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
||||||
@ -232,21 +230,21 @@ end
|
|||||||
--TODO: handle os.rename() return values (nil+msg on error)
|
--TODO: handle os.rename() return values (nil+msg on error)
|
||||||
function reconf.wwwcaptive_add(dirtyList)
|
function reconf.wwwcaptive_add(dirtyList)
|
||||||
if utils.exists(M.WWW_CAPTIVE_INDICATOR) then
|
if utils.exists(M.WWW_CAPTIVE_INDICATOR) then
|
||||||
return log:info(MOD_ABBR, "WWW captive directory already in place, not redoing", false)
|
return log:debug("WWW captive directory already in place, not redoing", false)
|
||||||
end
|
end
|
||||||
local rv,reason = os.rename('/www', M.WWW_RENAME_NAME)
|
local rv,reason = os.rename('/www', M.WWW_RENAME_NAME)
|
||||||
if rv == true then
|
if rv == true then
|
||||||
utils.symlink(M.WWW_CAPTIVE_PATH, '/www')
|
utils.symlink(M.WWW_CAPTIVE_PATH, '/www')
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return log:error(MOD_ABBR, "Could not rename /www to " .. M.WWW_RENAME_NAME .. "(" .. reason .. ")")
|
return log:error("Could not rename /www to " .. M.WWW_RENAME_NAME .. "(" .. reason .. ")")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function reconf.wwwcaptive_rm(dirtyList)
|
function reconf.wwwcaptive_rm(dirtyList)
|
||||||
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:info(MOD_ABBR, "WWW captive directory not in place, not undoing", false) end
|
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:debug("WWW captive directory not in place, not undoing", false) end
|
||||||
os.remove('/www')
|
os.remove('/www')
|
||||||
if os.rename(M.WWW_RENAME_NAME, '/www') ~= true then
|
if os.rename(M.WWW_RENAME_NAME, '/www') ~= true then
|
||||||
return log:error(MOD_ABBR, "Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
|
return log:error("Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -288,23 +286,21 @@ function M.setupAccessPoint(ssid)
|
|||||||
M.setStatus(M.CREATED,"Access point created");
|
M.setStatus(M.CREATED,"Access point created");
|
||||||
|
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
--log:info(MOD_ABBR, " network/status: ")
|
--log:info(" network/status: ")
|
||||||
log:info(MOD_ABBR, " ssid: ".. utils.dump(ds.ssid))
|
log:info(" ssid: ".. utils.dump(ds.ssid))
|
||||||
--[[
|
--[[log:info(" bssid: ".. utils.dump(ds.bssid))
|
||||||
log:info(MOD_ABBR, " bssid: ".. utils.dump(ds.bssid))
|
log:info(" channel: ".. utils.dump(ds.channel))
|
||||||
log:info(MOD_ABBR, " channel: ".. utils.dump(ds.channel))
|
log:info(" mode: ".. utils.dump(ds.mode))
|
||||||
log:info(MOD_ABBR, " mode: ".. utils.dump(ds.mode))
|
log:info(" encryption: ".. utils.dump(ds.encryption))
|
||||||
log:info(MOD_ABBR, " encryption: ".. utils.dump(ds.encryption))
|
log:info(" quality: ".. utils.dump(ds.quality))
|
||||||
log:info(MOD_ABBR, " quality: ".. utils.dump(ds.quality))
|
log:info(" quality_max: ".. utils.dump(ds.quality_max))
|
||||||
log:info(MOD_ABBR, " quality_max: ".. utils.dump(ds.quality_max))
|
log:info(" txpower: ".. utils.dump(ds.txpower))
|
||||||
log:info(MOD_ABBR, " txpower: ".. utils.dump(ds.txpower))
|
log:info(" signal: ".. utils.dump(ds.signal))
|
||||||
log:info(MOD_ABBR, " signal: ".. utils.dump(ds.signal))
|
log:info(" noise: ".. utils.dump(ds.noise))
|
||||||
log:info(MOD_ABBR, " noise: ".. utils.dump(ds.noise))
|
log:info(" raw: ".. utils.dump(ds))
|
||||||
log:info(MOD_ABBR, " raw: ".. utils.dump(ds))
|
|
||||||
|
|
||||||
local localip = wifi.getLocalIP()
|
local localip = wifi.getLocalIP()
|
||||||
log:info(MOD_ABBR, " localip: "..utils.dump(localip))
|
log:info(" localip: "..utils.dump(localip))]]--
|
||||||
--]]
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -315,13 +311,13 @@ end
|
|||||||
-- @tparam string ssid The SSID to use for the access point.
|
-- @tparam string ssid The SSID to use for the access point.
|
||||||
-- @return True on success or nil+msg on error.
|
-- @return True on success or nil+msg on error.
|
||||||
function M.enableAccessPoint(ssid)
|
function M.enableAccessPoint(ssid)
|
||||||
log:info(MOD_ABBR, "enableAccessPoint ssid: ".. utils.dump(ssid))
|
log:debug("enableAccessPoint ssid: ".. utils.dump(ssid))
|
||||||
|
|
||||||
M.switchConfiguration{apnet="add_noreload"}
|
M.switchConfiguration{apnet="add_noreload"}
|
||||||
wifi.activateConfig(ssid)
|
wifi.activateConfig(ssid)
|
||||||
|
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
log:info(MOD_ABBR, " deviceState.ssid: ".. utils.dump(ds.ssid))
|
log:debug(" ssid: ".. utils.dump(ds.ssid))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -334,7 +330,7 @@ end
|
|||||||
-- @tparam boolean recreate If true, a new UCI configuration based on scan data will always be created, otherwise an attempt will be made to use an existing configuration.
|
-- @tparam boolean recreate If true, a new UCI configuration based on scan data will always be created, otherwise an attempt will be made to use an existing configuration.
|
||||||
-- @return True on success or nil+msg on error.
|
-- @return True on success or nil+msg on error.
|
||||||
function M.associateSsid(ssid, passphrase, recreate)
|
function M.associateSsid(ssid, passphrase, recreate)
|
||||||
log:info(MOD_ABBR, "netconfig:associateSsid: "..(ssid or "<nil>")..", "..(recreate or "<nil>"))
|
log:info("netconfig:associateSsid: "..(ssid or "<nil>")..", "..(recreate or "<nil>"))
|
||||||
M.setStatus(M.CONNECTING,"Connecting...");
|
M.setStatus(M.CONNECTING,"Connecting...");
|
||||||
|
|
||||||
-- see if previously configured network for given ssid exists
|
-- see if previously configured network for given ssid exists
|
||||||
@ -378,7 +374,7 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
local nextAttemptTime = os.time()
|
local nextAttemptTime = os.time()
|
||||||
while true do
|
while true do
|
||||||
if os.time() > nextAttemptTime then
|
if os.time() > nextAttemptTime then
|
||||||
log:verbose(MOD_ABBR, "associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
log:debug("associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||||
if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then
|
if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
@ -394,14 +390,13 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
log:info(MOD_ABBR, "Network associated")
|
|
||||||
|
|
||||||
-- signin to connect.doodle3d.com
|
-- signin to connect.doodle3d.com
|
||||||
local success, output = signin.signin()
|
local success, output = signin.signin()
|
||||||
if success then
|
if success then
|
||||||
log:info(MOD_ABBR, "Signed in")
|
log:info("Signed in")
|
||||||
else
|
else
|
||||||
log:info(MOD_ABBR, "Signing in failed")
|
log:info("Signing in failed")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- report we are connected after signin attempt
|
-- report we are connected after signin attempt
|
||||||
@ -409,7 +404,6 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Disassociate wlan device as client from all SSID's.
|
--- Disassociate wlan device as client from all SSID's.
|
||||||
-- Note: this function might belong in the wlanconfig module but that would introduce
|
-- Note: this function might belong in the wlanconfig module but that would introduce
|
||||||
-- a circular dependency, easiest solution is to place the function here.
|
-- a circular dependency, easiest solution is to place the function here.
|
||||||
@ -423,22 +417,24 @@ function M.disassociate()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.getStatus()
|
function M.getStatus()
|
||||||
log:verbose(MOD_ABBR, "network:getStatus")
|
log:info("network:getStatus")
|
||||||
local file, error = io.open('/tmp/networkstatus.txt','r')
|
local file, error = io.open('/tmp/networkstatus.txt','r')
|
||||||
if file == nil then
|
if file == nil then
|
||||||
--log:error(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error)
|
--log:error("Util:Access:Can't read controller file. Error: "..error)
|
||||||
return "",""
|
return "",""
|
||||||
else
|
else
|
||||||
local status = file:read('*a')
|
local status = file:read('*a')
|
||||||
|
--log:info(" status: "..utils.dump(status))
|
||||||
file:close()
|
file:close()
|
||||||
local code, msg = string.match(status, '([^|]+)|+(.*)')
|
local code, msg = string.match(status, '([^|]+)|+(.*)')
|
||||||
log:verbose(MOD_ABBR, " raw status: "..utils.dump(status).." (code: "..utils.dump(code)..", msg: "..utils.dump(msg)..")")
|
--log:info(" code: "..utils.dump(code))
|
||||||
|
--log:info(" msg: "..utils.dump(msg))
|
||||||
return code,msg
|
return code,msg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setStatus(code,msg)
|
function M.setStatus(code,msg)
|
||||||
log:info(MOD_ABBR, "network:setStatus: "..code.." | "..msg)
|
log:info("network:setStatus: "..code.." | "..msg)
|
||||||
local file = io.open('/tmp/networkstatus.txt','w')
|
local file = io.open('/tmp/networkstatus.txt','w')
|
||||||
file:write(code.."|"..msg)
|
file:write(code.."|"..msg)
|
||||||
file:flush()
|
file:flush()
|
||||||
|
@ -20,7 +20,6 @@ local status = require('util.status')
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local STATUS_FILE = "signinstatus"
|
local STATUS_FILE = "signinstatus"
|
||||||
local MOD_ABBR = "NTSI"
|
|
||||||
|
|
||||||
local IDLE_STATUS = 1
|
local IDLE_STATUS = 1
|
||||||
local SIGNING_IN_STATUS = 2
|
local SIGNING_IN_STATUS = 2
|
||||||
@ -28,21 +27,15 @@ local SIGNING_IN_STATUS = 2
|
|||||||
--- Signin to connect.doodle3d.com server
|
--- Signin to connect.doodle3d.com server
|
||||||
--
|
--
|
||||||
function M.signin()
|
function M.signin()
|
||||||
log:verbose(MOD_ABBR, "signin:signin");
|
|
||||||
|
--log:debug("signin:signin");
|
||||||
|
|
||||||
local code, msg = M.getStatus()
|
local code, msg = M.getStatus()
|
||||||
--log:verbose(MOD_ABBR, " status: "..utils.dump(code).." "..utils.dump(msg));
|
--log:debug(" status: "..utils.dump(code).." "..utils.dump(msg));
|
||||||
|
|
||||||
-- if we are already signin in, skip
|
-- if we are already signin in, skip
|
||||||
if(code == SIGNING_IN_STATUS) then
|
if(code == SIGNING_IN_STATUS) then
|
||||||
log:verbose(MOD_ABBR, " already signing in, skipping")
|
log:debug(" skipping signin")
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local ds = wifi.getDeviceState()
|
|
||||||
log:verbose(MOD_ABBR, " wifi deviceState.mode: "..utils.dump(ds.mode))
|
|
||||||
if ds.mode ~= "sta" then
|
|
||||||
log:verbose(MOD_ABBR, " wifi not in station mode, skipping signin")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,10 +53,10 @@ function M.signin()
|
|||||||
local signinResponse = ""
|
local signinResponse = ""
|
||||||
while true do
|
while true do
|
||||||
if os.time() > nextAttemptTime then
|
if os.time() > nextAttemptTime then
|
||||||
log:verbose(MOD_ABBR, " signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
log:debug("signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||||
local signedin = false
|
local signedin = false
|
||||||
local localip = wifi.getLocalIP();
|
local localip = wifi.getLocalIP();
|
||||||
--log:verbose(MOD_ABBR, " localip: "..utils.dump(localip))
|
--log:debug(" localip: "..utils.dump(localip))
|
||||||
if localip ~= nil then
|
if localip ~= nil then
|
||||||
|
|
||||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||||
@ -71,16 +64,16 @@ function M.signin()
|
|||||||
|
|
||||||
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||||
signinResponse = utils.captureCommandOutput(cmd);
|
signinResponse = utils.captureCommandOutput(cmd);
|
||||||
log:verbose(MOD_ABBR, " signin response: \n"..utils.dump(signinResponse))
|
log:debug(" signin response: \n"..utils.dump(signinResponse))
|
||||||
local success = signinResponse:match('"status":"success"')
|
local success = signinResponse:match('"status":"success"')
|
||||||
log:verbose(MOD_ABBR, " success: "..utils.dump(success))
|
log:debug(" success: "..utils.dump(success))
|
||||||
if success ~= nil then
|
if success ~= nil then
|
||||||
signedin = true
|
signedin = true
|
||||||
else
|
else
|
||||||
log:warning(MOD_ABBR, "signin failed, request failed (response: "..utils.dump(signinResponse)..")")
|
log:warn("signin failed request failed (response: "..utils.dump(signinResponse)..")")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log:warning(MOD_ABBR, "signin failed, no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")")
|
log:warn("signin failed no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")")
|
||||||
end
|
end
|
||||||
|
|
||||||
if signedin then
|
if signedin then
|
||||||
@ -107,7 +100,7 @@ function M.getStatus()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.setStatus(code,msg)
|
function M.setStatus(code,msg)
|
||||||
log:verbose(MOD_ABBR, "signin:setStatus: " .. code .. " (" .. msg .. ")")
|
log:info("signin:setStatus: "..code.." | "..msg)
|
||||||
status.set(STATUS_FILE,code,msg);
|
status.set(STATUS_FILE,code,msg);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,8 +13,6 @@ local iwinfo = require('iwinfo')
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local MOD_ABBR = "NTWL"
|
|
||||||
|
|
||||||
-- NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears
|
-- NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears
|
||||||
M.DFL_DEVICE = 'wlan0'
|
M.DFL_DEVICE = 'wlan0'
|
||||||
M.DFL_DEVICE_FALLBACK = 'radio0'
|
M.DFL_DEVICE_FALLBACK = 'radio0'
|
||||||
@ -27,12 +25,12 @@ local deviceName, deviceApi
|
|||||||
local cachedApSsid, baseApSsid = nil, nil
|
local cachedApSsid, baseApSsid = nil, nil
|
||||||
|
|
||||||
function M.getSubstitutedSsid(unformattedSsid)
|
function M.getSubstitutedSsid(unformattedSsid)
|
||||||
log:verbose(MOD_ABBR, "getSubstitutedSsid unformattedSsid:'" .. (unformattedSsid or "nil") .. "' baseApSsid:'" .. (baseApSsid or "nil") .. "' cachedApSsid:'" .. (cachedApSsid or "nil"))
|
log:debug("getSubstitutedSsid unformattedSsid:'" .. (unformattedSsid or "nil") .. "' baseApSsid:'" .. (baseApSsid or "nil") .. "' cachedApSsid:'" .. (cachedApSsid or "nil"))
|
||||||
if unformattedSsid == baseApSsid and cachedApSsid ~= nil then return cachedApSsid end
|
if unformattedSsid == baseApSsid and cachedApSsid ~= nil then return cachedApSsid end
|
||||||
if not unformattedSsid or type(unformattedSsid) ~= 'string' then return nil end
|
if not unformattedSsid or type(unformattedSsid) ~= 'string' then return nil end
|
||||||
|
|
||||||
local macTail = M.getMacAddress():sub(7)
|
local macTail = M.getMacAddress():sub(7)
|
||||||
log:verbose(MOD_ABBR, " macTail:'" .. macTail)
|
log:debug(" macTail:'" .. macTail)
|
||||||
baseApSsid = unformattedSsid
|
baseApSsid = unformattedSsid
|
||||||
cachedApSsid = unformattedSsid:gsub('%%%%MAC_ADDR_TAIL%%%%', macTail)
|
cachedApSsid = unformattedSsid:gsub('%%%%MAC_ADDR_TAIL%%%%', macTail)
|
||||||
return cachedApSsid
|
return cachedApSsid
|
||||||
@ -77,7 +75,7 @@ function M.init(device)
|
|||||||
deviceName = M.DFL_DEVICE_FALLBACK
|
deviceName = M.DFL_DEVICE_FALLBACK
|
||||||
deviceApi = iwinfo.type(deviceName)
|
deviceApi = iwinfo.type(deviceName)
|
||||||
|
|
||||||
log:info(MOD_ABBR, "wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'")
|
||||||
|
|
||||||
if not deviceApi then
|
if not deviceApi then
|
||||||
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
|
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)"
|
||||||
@ -109,9 +107,9 @@ end
|
|||||||
--returns the wireless device's MAC address (as string, without colons)
|
--returns the wireless device's MAC address (as string, without colons)
|
||||||
--(lua numbers on openWrt seem to be 32bit so they cannot represent a MAC address as one number)
|
--(lua numbers on openWrt seem to be 32bit so they cannot represent a MAC address as one number)
|
||||||
function M.getMacAddress()
|
function M.getMacAddress()
|
||||||
log:verbose(MOD_ABBR, "getMacAddress")
|
log:debug("getMacAddress")
|
||||||
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
|
local macText = utils.readFile('/sys/class/net/' .. deviceName .. '/address')
|
||||||
log:verbose(MOD_ABBR, " macText: '" .. (macText or "nil") .. "'")
|
log:debug(" macText: '" .. (macText or "nil") .. "'")
|
||||||
local out = ''
|
local out = ''
|
||||||
|
|
||||||
-- Hack to prevent failure in case the MAC address could not be obtained.
|
-- Hack to prevent failure in case the MAC address could not be obtained.
|
||||||
@ -128,10 +126,9 @@ end
|
|||||||
--returns the wireless local ip address
|
--returns the wireless local ip address
|
||||||
function M.getLocalIP()
|
function M.getLocalIP()
|
||||||
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
||||||
log:bulk(MOD_ABBR, " ifconfig: \n"..utils.dump(ifconfig));
|
--log:debug(" ifconfig: \n"..utils.dump(ifconfig));
|
||||||
|
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
||||||
local localip = ifconfig:match('inet addr:([%d%.]+)')
|
return localip;
|
||||||
return localip
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.getDeviceName()
|
function M.getDeviceName()
|
||||||
@ -143,9 +140,9 @@ end
|
|||||||
-- @return data for all or requested network; false+error on failure or nil when requested network not found
|
-- @return data for all or requested network; false+error on failure or nil when requested network not found
|
||||||
function M.getScanInfo(ssid)
|
function M.getScanInfo(ssid)
|
||||||
local iw = iwinfo[deviceApi]
|
local iw = iwinfo[deviceApi]
|
||||||
log:info(MOD_ABBR, "start wifi scan")
|
log:info("start wifi scan")
|
||||||
local sr = iw.scanlist(deviceName)
|
local sr = iw.scanlist(deviceName)
|
||||||
log:info(MOD_ABBR, "wifi scan done")
|
log:info("wifi scan done")
|
||||||
local si, se
|
local si, se
|
||||||
|
|
||||||
if ssid == nil then
|
if ssid == nil then
|
||||||
@ -177,13 +174,11 @@ end
|
|||||||
function M.removeConfig(ssid)
|
function M.removeConfig(ssid)
|
||||||
local rv = false
|
local rv = false
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
log:verbose(MOD_ABBR, utils.dump(s.ssid).."\n "..utils.dump(s))
|
|
||||||
if s.ssid == ssid then
|
if s.ssid == ssid then
|
||||||
log:verbose(MOD_ABBR, "deleting faulty ssid: "..utils.dump(s['.name']))
|
uci:delete('wireless', s['.name'])
|
||||||
rv = uci:delete('wireless', s['.name'])
|
rv = true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
uci:save('wireless')
|
|
||||||
uci:commit('wireless')
|
uci:commit('wireless')
|
||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
@ -191,12 +186,12 @@ end
|
|||||||
--- Activate wireless section for given SSID and disable all others
|
--- Activate wireless section for given SSID and disable all others
|
||||||
-- @param ssid SSID of config to enable, or nil to disable all network configs
|
-- @param ssid SSID of config to enable, or nil to disable all network configs
|
||||||
function M.activateConfig(ssid)
|
function M.activateConfig(ssid)
|
||||||
log:verbose(MOD_ABBR, "wlanconfig.activateConfig: "..ssid);
|
--log:info("wlanconfig.activateConfig: "..ssid);
|
||||||
|
|
||||||
-- make sure only one is enabled
|
-- make sure only one is enabled
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
local disabled = s.ssid ~= ssid and '1' or '0'
|
local disabled = s.ssid ~= ssid and '1' or '0'
|
||||||
log:verbose(MOD_ABBR, " ssid: "..utils.dump(s.ssid).." disabled: "..utils.dump(disabled))
|
--log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
|
||||||
uci:set('wireless', s['.name'], 'disabled', disabled)
|
uci:set('wireless', s['.name'], 'disabled', disabled)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -214,14 +209,11 @@ function M.activateConfig(ssid)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
--[[log:info(" result:");
|
||||||
--[[
|
|
||||||
log:verbose(MOD_ABBR, " wifi reorder result:");
|
|
||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
local disabled = s.ssid ~= ssid and '1' or '0'
|
local disabled = s.ssid ~= ssid and '1' or '0'
|
||||||
log:verbose(MOD_ABBR, " ssid: "..utils.dump(s.ssid).." disabled: "..utils.dump(disabled))
|
log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
|
||||||
end)
|
end)]]--
|
||||||
--]]
|
|
||||||
|
|
||||||
uci:commit('wireless')
|
uci:commit('wireless')
|
||||||
end
|
end
|
||||||
@ -249,7 +241,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
|||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
--if s.bssid == info.bssid then
|
--if s.bssid == info.bssid then
|
||||||
if s.ssid == info.ssid then
|
if s.ssid == info.ssid then
|
||||||
log:verbose(MOD_ABBR, "removing old wireless config for net '" .. s.ssid .. "'")
|
log:debug("removing old wireless config for net '" .. s.ssid .. "'")
|
||||||
uci:delete('wireless', s['.name'])
|
uci:delete('wireless', s['.name'])
|
||||||
-- return false --keep looking, just in case multiple entries with this bssid exist
|
-- return false --keep looking, just in case multiple entries with this bssid exist
|
||||||
end
|
end
|
||||||
|
@ -15,8 +15,6 @@ local wifi = require('network.wlanconfig')
|
|||||||
local accessManager = require('util.access')
|
local accessManager = require('util.access')
|
||||||
local printerAPI = require('rest.api.api_printer')
|
local printerAPI = require('rest.api.api_printer')
|
||||||
|
|
||||||
local MOD_ABBR = "ACFG"
|
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
isApi = true
|
isApi = true
|
||||||
}
|
}
|
||||||
@ -59,7 +57,7 @@ end
|
|||||||
-- returns substituted_wifiboxid (since version 0.10.2)
|
-- returns substituted_wifiboxid (since version 0.10.2)
|
||||||
-- returns substituted_ssid (since version 0.9.1)
|
-- returns substituted_ssid (since version 0.9.1)
|
||||||
function M._global_POST(request, response)
|
function M._global_POST(request, response)
|
||||||
log:verbose(MOD_ABBR, "API:config(set)")
|
--log:info("API:config:set")
|
||||||
|
|
||||||
if not operationsAccessOrFail(request, response) then return end
|
if not operationsAccessOrFail(request, response) then return end
|
||||||
|
|
||||||
@ -67,14 +65,14 @@ function M._global_POST(request, response)
|
|||||||
|
|
||||||
local validation = {}
|
local validation = {}
|
||||||
for k,v in pairs(request:getAll()) do
|
for k,v in pairs(request:getAll()) do
|
||||||
log:verbose(MOD_ABBR, " about to set '"..k.."' -> '"..v.."'");
|
--log:info(" "..k..": "..v);
|
||||||
local r,m = settings.set(k, v, true)
|
local r,m = settings.set(k, v, true)
|
||||||
|
|
||||||
if r then
|
if r then
|
||||||
validation[k] = "ok"
|
validation[k] = "ok"
|
||||||
elseif r == false then
|
elseif r == false then
|
||||||
validation[k] = "could not save setting ('" .. m .. "')"
|
validation[k] = "could not save setting ('" .. m .. "')"
|
||||||
log:info(MOD_ABBR, " failed to set '"..k.."' ("..utils.dump(m)..")")
|
log:info(" m: "..utils.dump(m))
|
||||||
elseif r == nil then
|
elseif r == nil then
|
||||||
settings.commit()
|
settings.commit()
|
||||||
response:setError(m)
|
response:setError(m)
|
||||||
@ -111,20 +109,18 @@ end
|
|||||||
-- and printer.type is set to 'ultimaker' then
|
-- and printer.type is set to 'ultimaker' then
|
||||||
-- only the printer.startcode under the ultimaker subsection is removed.
|
-- only the printer.startcode under the ultimaker subsection is removed.
|
||||||
function M.reset_POST(request, response)
|
function M.reset_POST(request, response)
|
||||||
--log:verbose(MOD_ABBR, "API:config/reset")
|
--log:info("API:reset");
|
||||||
if not operationsAccessOrFail(request, response) then return end
|
if not operationsAccessOrFail(request, response) then return end
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
|
|
||||||
for k,v in pairs(request:getAll()) do
|
for k,v in pairs(request:getAll()) do
|
||||||
--log:info(MOD_ABBR, " "..k..": "..v);
|
--log:info(" "..k..": "..v);
|
||||||
local r,m = settings.reset(k);
|
local r,m = settings.reset(k);
|
||||||
if r ~= nil then
|
if r ~= nil then
|
||||||
response:addData(k, "ok")
|
response:addData(k, "ok")
|
||||||
log:verbose(MOD_ABBR, " reset " .. k)
|
|
||||||
else
|
else
|
||||||
response:addData(k, "could not reset key ('" .. m .. "')")
|
response:addData(k, "could not reset key ('" .. m .. "')")
|
||||||
response:setError(m)
|
response:setError(m)
|
||||||
log:verbose(MOD_ABBR, " could not reset key " .. k .. "(" .. m .. ")")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,19 +16,11 @@ local printerAPI = require('rest.api.api_printer')
|
|||||||
local wifi = require('network.wlanconfig')
|
local wifi = require('network.wlanconfig')
|
||||||
local settings = require('util.settings')
|
local settings = require('util.settings')
|
||||||
|
|
||||||
local MOD_ABBR = "AINF"
|
|
||||||
|
|
||||||
local TMP_DIR = '/tmp'
|
local TMP_DIR = '/tmp'
|
||||||
local LOG_COLLECT_DIRNAME = 'wifibox-logs'
|
local LOG_COLLECT_DIRNAME = 'wifibox-logs'
|
||||||
local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME
|
local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME
|
||||||
local DEFAULT_WIFIBOX_LOG_FILENAME = 'wifibox.log'
|
local WIFIBOX_LOG_FILENAME = 'wifibox.log'
|
||||||
local DEFAULT_WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. DEFAULT_WIFIBOX_LOG_FILENAME
|
local WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_LOG_FILENAME
|
||||||
local WIFIBOX_STDOUT_LOG_FILENAME = 'wifibox.stdout.log'
|
|
||||||
local WIFIBOX_STDOUT_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME
|
|
||||||
local WIFIBOX_VERSION_FILENAME = 'wifibox-version'
|
|
||||||
local WIFIBOX_VERSION_FILE = '/etc/' .. WIFIBOX_VERSION_FILENAME
|
|
||||||
local ROTATED_LOGS_DIRNAME = 'wifibox-rotated'
|
|
||||||
local ROTATED_LOGS_DIR = TMP_DIR .. '/' .. ROTATED_LOGS_DIRNAME
|
|
||||||
|
|
||||||
local SYSLOG_FILENAME = 'syslog'
|
local SYSLOG_FILENAME = 'syslog'
|
||||||
local PROCESS_LIST_FILENAME = 'processes'
|
local PROCESS_LIST_FILENAME = 'processes'
|
||||||
@ -42,7 +34,7 @@ local USB_DIRTREE_COMMAND = "ls -R /sys/devices/platform/ehci-platform/usb1 | gr
|
|||||||
local USB_DIRTREE_FILENAME = 'sys_devices_platform_ehci-platform_usb1.tree'
|
local USB_DIRTREE_FILENAME = 'sys_devices_platform_ehci-platform_usb1.tree'
|
||||||
|
|
||||||
local PRINT3D_BASEPATH = '/tmp'
|
local PRINT3D_BASEPATH = '/tmp'
|
||||||
local PRINT3D_LOG_FILENAME_PREFIX = 'print3d.'
|
local PRINT3D_LOG_FILENAME_PREFIX = 'print3d-'
|
||||||
local PRINT3D_LOG_FILENAME_SUFFIX = '.log'
|
local PRINT3D_LOG_FILENAME_SUFFIX = '.log'
|
||||||
local LOG_COLLECT_ARCHIVE_FILENAME = LOG_COLLECT_DIRNAME .. '.tgz'
|
local LOG_COLLECT_ARCHIVE_FILENAME = LOG_COLLECT_DIRNAME .. '.tgz'
|
||||||
local LOG_COLLECT_ARCHIVE_FILE = TMP_DIR .. '/' .. LOG_COLLECT_ARCHIVE_FILENAME
|
local LOG_COLLECT_ARCHIVE_FILE = TMP_DIR .. '/' .. LOG_COLLECT_ARCHIVE_FILENAME
|
||||||
@ -71,34 +63,11 @@ function M.logfiles(request, response)
|
|||||||
rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
|
rv,msg = lfs.mkdir(LOG_COLLECT_DIR)
|
||||||
rv,msg = lfs.chdir(TMP_DIR)
|
rv,msg = lfs.chdir(TMP_DIR)
|
||||||
|
|
||||||
local wifiboxLogFilePath = log:getLogFilePath()
|
|
||||||
local wifiboxLogFileName = wifiboxLogFilePath and wifiboxLogFilePath:match('.*/(.*)')
|
|
||||||
|
|
||||||
|
|
||||||
--[[ create temporary files ]]--
|
--[[ create temporary files ]]--
|
||||||
|
|
||||||
-- copy wifibox API-script (firmware) log
|
-- copy wifibox API-script log
|
||||||
lfs.link(wifiboxLogFilePath, LOG_COLLECT_DIR .. '/' .. wifiboxLogFileName)
|
rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_LOG_FILE .. ' ' .. LOG_COLLECT_DIR)
|
||||||
|
|
||||||
-- copy d3dapi script stdout/stderr (fallback) log
|
|
||||||
lfs.link(WIFIBOX_STDOUT_LOG_FILE, LOG_COLLECT_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME)
|
|
||||||
|
|
||||||
-- collect and copy print3d server logs
|
|
||||||
for file in lfs.dir(PRINT3D_BASEPATH) do
|
|
||||||
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
|
|
||||||
local srcLogFile = PRINT3D_BASEPATH .. '/' .. file
|
|
||||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
|
|
||||||
lfs.link(srcLogFile, tgtLogFile)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- copy rotated firmware and print3d logs
|
|
||||||
rv,msg = lfs.mkdir(LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME)
|
|
||||||
for file in lfs.dir(ROTATED_LOGS_DIR) do
|
|
||||||
local srcLogFile = ROTATED_LOGS_DIR .. '/' .. file
|
|
||||||
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME .. '/' .. file
|
|
||||||
lfs.link(srcLogFile, tgtLogFile)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- capture syslog
|
-- capture syslog
|
||||||
rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||||
@ -118,10 +87,7 @@ function M.logfiles(request, response)
|
|||||||
-- list directory structure for primary USB controller
|
-- list directory structure for primary USB controller
|
||||||
rv,sig,code = os.execute(USB_DIRTREE_COMMAND .. ' > ' .. LOG_COLLECT_DIR .. '/' .. USB_DIRTREE_FILENAME)
|
rv,sig,code = os.execute(USB_DIRTREE_COMMAND .. ' > ' .. LOG_COLLECT_DIR .. '/' .. USB_DIRTREE_FILENAME)
|
||||||
|
|
||||||
rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_VERSION_FILE .. ' ' .. LOG_COLLECT_DIR)
|
|
||||||
|
|
||||||
-- copy relevant openwrt configuration files
|
-- copy relevant openwrt configuration files
|
||||||
-- Note: we cannot link them because that would require the link to span over filesystems
|
|
||||||
rv,msg = lfs.mkdir(LOG_COLLECT_DIR .. '/config')
|
rv,msg = lfs.mkdir(LOG_COLLECT_DIR .. '/config')
|
||||||
for _,v in pairs(UCI_CONFIG_FILES_TO_SAVE) do
|
for _,v in pairs(UCI_CONFIG_FILES_TO_SAVE) do
|
||||||
local srcFile = '/etc/config/' .. v
|
local srcFile = '/etc/config/' .. v
|
||||||
@ -129,12 +95,19 @@ function M.logfiles(request, response)
|
|||||||
if v ~= 'wireless' then
|
if v ~= 'wireless' then
|
||||||
rv,sig,code = redirectedExecute('cp ' .. srcFile .. ' ' .. tgtFile)
|
rv,sig,code = redirectedExecute('cp ' .. srcFile .. ' ' .. tgtFile)
|
||||||
else
|
else
|
||||||
-- replace WiFi passwords with '...'
|
|
||||||
rv,sig,code = os.execute("sed \"s/option key '.*'/option key '...'/g\" " .. srcFile .. " > " .. tgtFile)
|
rv,sig,code = os.execute("sed \"s/option key '.*'/option key '...'/g\" " .. srcFile .. " > " .. tgtFile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- create tar.gz archive of the files/data we collected
|
-- collect and copy print3d server logs
|
||||||
|
for file in lfs.dir(PRINT3D_BASEPATH) do
|
||||||
|
if file:find(PRINT3D_LOG_FILENAME_PREFIX) == 1 and file:find(PRINT3D_LOG_FILENAME_SUFFIX) ~= nil then
|
||||||
|
local srcLogFile = PRINT3D_BASEPATH .. '/' .. file
|
||||||
|
local tgtLogFile = LOG_COLLECT_DIR .. '/' .. file
|
||||||
|
rv,sig,code = redirectedExecute('cp ' .. srcLogFile .. ' ' .. tgtLogFile)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
|
rv,sig,code = redirectedExecute('tar czf ' .. LOG_COLLECT_ARCHIVE_FILE .. ' ' .. LOG_COLLECT_DIRNAME) --returns 0 success, 1 error
|
||||||
|
|
||||||
|
|
||||||
@ -160,19 +133,13 @@ function M.logfiles(request, response)
|
|||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/config/*')
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/config/*')
|
||||||
rv,msg = lfs.rmdir(LOG_COLLECT_DIR .. '/config')
|
rv,msg = lfs.rmdir(LOG_COLLECT_DIR .. '/config')
|
||||||
|
|
||||||
-- Note: this assumes the rotated logs directory does not contain subdirectories
|
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME .. '/*')
|
|
||||||
rv,msg = lfs.rmdir(LOG_COLLECT_DIR .. '/' .. ROTATED_LOGS_DIRNAME)
|
|
||||||
|
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_VERSION_FILENAME)
|
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. USB_DIRTREE_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. USB_DIRTREE_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. DISKFREE_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. DISKFREE_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. MOUNTS_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. MOUNTS_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. MEMINFO_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. MEMINFO_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. PROCESS_LIST_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. PROCESS_LIST_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME)
|
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. WIFIBOX_LOG_FILENAME)
|
||||||
rv,sig,code = redirectedExecute('rm ' .. LOG_COLLECT_DIR .. '/' .. wifiboxLogFileName)
|
|
||||||
|
|
||||||
rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
|
rv,msg = lfs.rmdir(LOG_COLLECT_DIR)
|
||||||
|
|
||||||
@ -180,16 +147,16 @@ function M.logfiles(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.access(request, response)
|
function M.access(request, response)
|
||||||
--log:info(MOD_ABBR, " remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
--log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|");
|
||||||
--log:info(MOD_ABBR, " controller: |"..utils.dump(accessManager.getController()).."|");
|
--log:info(" controller: |"..utils.dump(accessManager.getController()).."|");
|
||||||
|
|
||||||
local hasControl = accessManager.hasControl(request.remoteAddress)
|
local hasControl = accessManager.hasControl(request.remoteAddress)
|
||||||
-- if hasControl then log:info(MOD_ABBR, " hasControl: true")
|
-- if hasControl then log:info(" hasControl: true")
|
||||||
-- else log:info(MOD_ABBR, " hasControl: false") end
|
-- else log:info(" hasControl: false") end
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('has_control', hasControl)
|
response:addData('has_control', hasControl)
|
||||||
|
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.status(request, response)
|
function M.status(request, response)
|
||||||
|
@ -16,8 +16,6 @@ local signin = require('network.signin')
|
|||||||
local accessManager = require('util.access')
|
local accessManager = require('util.access')
|
||||||
local printerAPI = require('rest.api.api_printer')
|
local printerAPI = require('rest.api.api_printer')
|
||||||
|
|
||||||
local MOD_ABBR = "ANET"
|
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
isApi = true
|
isApi = true
|
||||||
}
|
}
|
||||||
@ -151,14 +149,9 @@ function M.associate_POST(request, response)
|
|||||||
|
|
||||||
local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate)
|
local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate)
|
||||||
if rv then
|
if rv then
|
||||||
log:info(MOD_ABBR, "associated to wifi: "..utils.dump(argSsid))
|
log:info("associated to wifi: "..utils.dump(argSsid))
|
||||||
else
|
else
|
||||||
log:info(MOD_ABBR, "failed to associate to wifi: "..utils.dump(argSsid).." ("..utils.dump(msg)..")")
|
log:info("failed to associate to wifi: "..utils.dump(argSsid).." ("..utils.dump(msg)..")")
|
||||||
wifi.removeConfig(argSsid)
|
|
||||||
local backupssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
|
||||||
netconf.setupAccessPoint(backupssid)
|
|
||||||
netconf.enableAccessPoint(backupssid)
|
|
||||||
wifi.removeConfig(argSsid)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -208,13 +201,14 @@ function M.remove_POST(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.signin(request, response)
|
function M.signin(request, response)
|
||||||
|
log:info("API:Network:signin")
|
||||||
local success, output = signin.signin()
|
local success, output = signin.signin()
|
||||||
if success then
|
if success then
|
||||||
log:info(MOD_ABBR, "signed in")
|
log:info("API:Network:signed in")
|
||||||
response:setSuccess("API:Network:signed in")
|
response:setSuccess("API:Network:signed in")
|
||||||
response:addData("response", output)
|
response:addData("response", output)
|
||||||
else
|
else
|
||||||
log:warning(MOD_ABBR, "signing in failed")
|
log:info("API:Network:Signing in failed")
|
||||||
response:setError("Signing in failed")
|
response:setError("Signing in failed")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -223,17 +217,4 @@ function M.alive(request, response)
|
|||||||
response:setSuccess("alive")
|
response:setSuccess("alive")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.reset_POST(request, response)
|
|
||||||
response:setSuccess("Resetting networks")
|
|
||||||
|
|
||||||
log:info(MOD_ABBR, "Resetting networks")
|
|
||||||
for _, net in ipairs(wifi.getConfigs()) do
|
|
||||||
wifi.removeConfig(net.ssid)
|
|
||||||
end
|
|
||||||
|
|
||||||
local ssid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid'))
|
|
||||||
netconf.setupAccessPoint(ssid)
|
|
||||||
netconf.enableAccessPoint(ssid)
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -5,17 +5,15 @@
|
|||||||
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
-- @license This software is licensed under the terms of the GNU GPL v2 or later.
|
||||||
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
-- See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
||||||
|
|
||||||
-- TODO: return errors like in print_POST (error message in a 'msg' key instead of directly in the response) if this does not break API compatibility
|
|
||||||
|
|
||||||
local lfs = require('lfs')
|
local lfs = require('lfs')
|
||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
local settings = require('util.settings')
|
local settings = require('util.settings')
|
||||||
|
local printDriver = require('print3d')
|
||||||
local printerUtils = require('util.printer')
|
local printerUtils = require('util.printer')
|
||||||
local accessManager = require('util.access')
|
local accessManager = require('util.access')
|
||||||
|
|
||||||
local MOD_ABBR = "APRN"
|
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
isApi = true
|
isApi = true
|
||||||
}
|
}
|
||||||
@ -29,7 +27,7 @@ end
|
|||||||
function M.temperature(request, response)
|
function M.temperature(request, response)
|
||||||
local argId = request:get("id")
|
local argId = request:get("id")
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||||
if not printer or not printer:hasSocket() then return end
|
if not printer or not printer:hasSocket() then return false end
|
||||||
|
|
||||||
local temperatures,msg = printer:getTemperatures()
|
local temperatures,msg = printer:getTemperatures()
|
||||||
|
|
||||||
@ -40,78 +38,37 @@ function M.temperature(request, response)
|
|||||||
response:addData('hotend_target', temperatures.hotend_target)
|
response:addData('hotend_target', temperatures.hotend_target)
|
||||||
response:addData('bed', temperatures.bed)
|
response:addData('bed', temperatures.bed)
|
||||||
response:addData('bed_target', temperatures.bed_target)
|
response:addData('bed_target', temperatures.bed_target)
|
||||||
elseif temperatures == false then
|
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not get temperature information (" .. msg .. ")")
|
|
||||||
else
|
else
|
||||||
response:setError(msg)
|
response:setError(msg)
|
||||||
end
|
return false;
|
||||||
end
|
|
||||||
|
|
||||||
local function setCurrentPrint(id)
|
|
||||||
local cpfileName = "/tmp/current-print"
|
|
||||||
if id == nil then
|
|
||||||
io.popen('rm ' .. cpfileName):close()
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local cpfile = io.open(cpfileName, 'w+')
|
return true;
|
||||||
if cpfile == nil then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
cpfile:write(id)
|
|
||||||
cpfile:close()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getCurrentPrint()
|
|
||||||
local idfile = io.open('/tmp/current-print')
|
|
||||||
if idfile ~= nil then
|
|
||||||
return idfile:read('*a')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function stopFetch()
|
|
||||||
log:verbose(MOD_ABBR, "stopping print-fetch and removing start/endgcode")
|
|
||||||
io.popen("killall print-fetch"):close()
|
|
||||||
io.popen("rm /tmp/startcode /tmp/endcode"):close()
|
|
||||||
setCurrentPrint(nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.progress(request, response)
|
function M.progress(request, response)
|
||||||
local argId = request:get("id")
|
local argId = request:get("id")
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||||
if not printer or not printer:hasSocket() then return end
|
if not printer or not printer:hasSocket() then return false end
|
||||||
|
|
||||||
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
||||||
local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress()
|
local currentLine,bufferedLines,totalLines = printer:getProgress()
|
||||||
|
|
||||||
local printId = getCurrentPrint()
|
|
||||||
|
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
if printId ~= nil then
|
|
||||||
response:addData('current_print', printId)
|
|
||||||
end
|
|
||||||
if currentLine then
|
if currentLine then
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('current_line', currentLine)
|
response:addData('current_line', currentLine)
|
||||||
response:addData('buffered_lines', bufferedLines)
|
response:addData('buffered_lines', bufferedLines)
|
||||||
response:addData('total_lines', totalLines)
|
response:addData('total_lines', totalLines)
|
||||||
response:addData('buffer_size', bufferSize)
|
|
||||||
response:addData('max_buffer_size', maxBufferSize)
|
|
||||||
response:addData('seq_number', seqNumber)
|
|
||||||
response:addData('seq_total', seqTotal)
|
|
||||||
elseif progress == false then
|
|
||||||
response:addData('status', bufferedLines)
|
|
||||||
response:setFail("could not get progress information (" .. bufferedLines .. ")")
|
|
||||||
else
|
else
|
||||||
response:setError(bufferedLines)
|
response:setError(bufferedLines)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Note: onlyReturnState is optional and prevents response from being modified, used when calling from within other api call
|
-- NOTE: onlyReturnState is optional and prevents response from being modified
|
||||||
-- Note: unlike regular API-functions, this one returns either true+state or false
|
|
||||||
function M.state(request, response, onlyReturnState)
|
function M.state(request, response, onlyReturnState)
|
||||||
local argId = request:get("id")
|
local argId = request:get("id")
|
||||||
if not onlyReturnState then response:addData('id', argId) end
|
if not onlyReturnState then response:addData('id', argId) end
|
||||||
@ -140,24 +97,25 @@ function M.state(request, response, onlyReturnState)
|
|||||||
response:addData('state', rv)
|
response:addData('state', rv)
|
||||||
end
|
end
|
||||||
return true, rv
|
return true, rv
|
||||||
else -- Note: do not differentiate between false and nil here, false should never be returned
|
else
|
||||||
if not onlyReturnState then response:setError(msg) end
|
if not onlyReturnState then response:setError(msg) end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
--this point cannot be reached, no return necessary
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- retrieve a list of 3D printers currently supported
|
-- retrieve a list of 3D printers currently supported
|
||||||
function M.listall(request, response)
|
function M.listall(request, response)
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('printers', printerUtils.supportedPrinters())
|
response:addData('printers', printerUtils.supportedPrinters())
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function M.heatup_POST(request, response)
|
function M.heatup_POST(request, response)
|
||||||
|
|
||||||
if not accessManager.hasControl(request.remoteAddress) then
|
if not accessManager.hasControl(request.remoteAddress) then
|
||||||
response:setFail("No control access")
|
response:setFail("No control access")
|
||||||
return
|
return
|
||||||
@ -171,17 +129,15 @@ function M.heatup_POST(request, response)
|
|||||||
local rv,msg = printer:heatup(temperature)
|
local rv,msg = printer:heatup(temperature)
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
if rv then
|
if rv then response:setSuccess()
|
||||||
response:setSuccess()
|
else response:setFail(msg)
|
||||||
elseif rv == false then
|
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not start heatup (" .. msg .. ")")
|
|
||||||
else
|
|
||||||
response:setError(msg)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.stop_POST(request, response)
|
function M.stop_POST(request, response)
|
||||||
|
|
||||||
|
log:info("API:printer/stop")
|
||||||
|
|
||||||
if not accessManager.hasControl(request.remoteAddress) then
|
if not accessManager.hasControl(request.remoteAddress) then
|
||||||
response:setFail("No control access")
|
response:setFail("No control access")
|
||||||
return
|
return
|
||||||
@ -190,149 +146,45 @@ function M.stop_POST(request, response)
|
|||||||
local argId = request:get("id")
|
local argId = request:get("id")
|
||||||
local argGcode = request:get("gcode")
|
local argGcode = request:get("gcode")
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||||
if not printer or not printer:hasSocket() then return end
|
if not printer or not printer:hasSocket() then return false end
|
||||||
|
|
||||||
stopFetch()
|
|
||||||
|
|
||||||
if(argGcode == nil) then
|
if(argGcode == nil) then
|
||||||
argGcode = ""
|
argGcode = ""
|
||||||
end
|
end
|
||||||
local rv,msg = printer:stopPrint(argGcode)
|
local rv,msg = printer:stopPrint(argGcode)
|
||||||
|
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
if rv then
|
if rv then response:setSuccess()
|
||||||
response:setSuccess()
|
else response:setError(msg)
|
||||||
elseif rv == false then
|
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not stop print (" .. msg .. ")")
|
|
||||||
else
|
|
||||||
response:setError(msg)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Used only in print_POST(); not nested for performance reasons
|
--accepts: first(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
||||||
local function addSequenceNumbering(printer, response)
|
|
||||||
-- NOTE: despite their names, `currentLine` is still the error indicator and `bufferedLines` the message in such case.
|
|
||||||
local currentLine,bufferedLines,totalLines,bufferSize,maxBufferSize,seqNumber,seqTotal = printer:getProgress()
|
|
||||||
if currentLine then
|
|
||||||
response:addData('seq_number', seqNumber)
|
|
||||||
response:addData('seq_total', seqTotal)
|
|
||||||
--else
|
|
||||||
--Note: getProgress failure is ignored (unlikely to happen if the other calls work, and also not really fatal here).
|
|
||||||
-- Alternatively, we could still add the fields with a special value (NaN is not supported by json, so perhaps -2?)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.fetch_POST(request, response)
|
|
||||||
if not accessManager.hasControl(request.remoteAddress) then
|
|
||||||
response:setFail("No control access")
|
|
||||||
return
|
|
||||||
else
|
|
||||||
accessManager.setController(request.remoteAddress)
|
|
||||||
end
|
|
||||||
|
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
|
||||||
if not printer or not printer:hasSocket() then return end
|
|
||||||
|
|
||||||
local state = printer:getState()
|
|
||||||
if state ~= "idle" then
|
|
||||||
response:setFail("printer is not idle")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
|
|
||||||
stopFetch()
|
|
||||||
local rv,msg = printer:clearGcode()
|
|
||||||
|
|
||||||
if rv == false then
|
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not clear gcode (" .. msg .. ")")
|
|
||||||
elseif rv == nil then
|
|
||||||
response:setError(msg)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local gcodeFiles = " "
|
|
||||||
local startCode = request:get("start_code")
|
|
||||||
if startCode ~= nil then
|
|
||||||
gcodeFiles = gcodeFiles .. '/tmp/startcode '
|
|
||||||
local startCodeFile = io.open('/tmp/startcode', 'w+')
|
|
||||||
if startCodeFile == nil then
|
|
||||||
response:setError("could not open startCode file for writing")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
startCodeFile:write(startCode)
|
|
||||||
end
|
|
||||||
|
|
||||||
local endCode = request:get("end_code")
|
|
||||||
if endCode ~= nil then
|
|
||||||
gcodeFiles = gcodeFiles .. '/tmp/endcode '
|
|
||||||
local endCodeFile = io.open('/tmp/endcode', 'w+')
|
|
||||||
if endCodeFile == nil then
|
|
||||||
response:setError("could not open endcode file for writing")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
endCodeFile:write(endCode)
|
|
||||||
end
|
|
||||||
|
|
||||||
local socket = printer:getId()
|
|
||||||
if socket == nil then
|
|
||||||
response:setError("no socket found")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local gcodeServer = settings.get('gcode.server')
|
|
||||||
if gcodeServer == nil then
|
|
||||||
response:setError("no gcode server configured")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local id = request:get("id")
|
|
||||||
if id == nil then
|
|
||||||
response:setError("no id supplied")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
setCurrentPrint(id)
|
|
||||||
|
|
||||||
log:info(MOD_ABBR, " starting fetch print. id: " .. id .. " server: " .. gcodeServer)
|
|
||||||
io.popen("print-fetch " .. socket .. " " .. gcodeServer .. " " .. id .. gcodeFiles)
|
|
||||||
|
|
||||||
response:setSuccess()
|
|
||||||
end
|
|
||||||
|
|
||||||
--requires: gcode(string) (the gcode to be appended)
|
|
||||||
--accepts: id(string) (the printer ID to append to)
|
|
||||||
--accepts: clear(bool) (chunks will be concatenated but output file will be cleared first if this argument is true)
|
|
||||||
--accepts: first(deprecated) (an alias for 'clear')
|
|
||||||
--accepts: start(bool) (only when this argument is true will printing be started)
|
--accepts: start(bool) (only when this argument is true will printing be started)
|
||||||
--accepts: total_lines(int) (the total number of lines that is going to be sent, will be used only for reporting progress)
|
|
||||||
--accepts: seq_number(int) (sequence number of the chunk, must be given until clear() after given once, and incremented each time)
|
|
||||||
--accepts: seq_total(int) (total number of gcode chunks to be appended, must be given until clear() after given once, and stay the same)
|
|
||||||
--returns: when the gcode buffer cannot accept the gcode, or the IPC transaction fails,
|
|
||||||
-- a fail with a (formal, i.e., parseable) status argument will be returned;
|
|
||||||
-- additionally, current sequence number and total will be returned (both are -1 if they have not been set)
|
|
||||||
function M.print_POST(request, response)
|
function M.print_POST(request, response)
|
||||||
if not accessManager.hasControl(request.remoteAddress) then
|
|
||||||
|
local controllerIP = accessManager.getController()
|
||||||
|
local hasControl = false
|
||||||
|
if controllerIP == "" then
|
||||||
|
accessManager.setController(request.remoteAddress)
|
||||||
|
hasControl = true
|
||||||
|
elseif controllerIP == request.remoteAddress then
|
||||||
|
hasControl = true
|
||||||
|
end
|
||||||
|
|
||||||
|
log:info(" hasControl: "..utils.dump(hasControl))
|
||||||
|
if not hasControl then
|
||||||
response:setFail("No control access")
|
response:setFail("No control access")
|
||||||
return
|
return
|
||||||
else
|
|
||||||
accessManager.setController(request.remoteAddress)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local argId = request:get("id")
|
local argId = request:get("id")
|
||||||
local argGcode = request:get("gcode")
|
local argGcode = request:get("gcode")
|
||||||
local argClear = utils.toboolean(request:get("clear"))
|
local argIsFirst = utils.toboolean(request:get("first"))
|
||||||
local argIsFirst = utils.toboolean(request:get("first")) -- deprecated
|
|
||||||
local argStart = utils.toboolean(request:get("start"))
|
local argStart = utils.toboolean(request:get("start"))
|
||||||
local argTotalLines = request:get("total_lines") or -1
|
|
||||||
local argSeqNumber = request:get("seq_number") or -1
|
|
||||||
local argSeqTotal = request:get("seq_total") or -1
|
|
||||||
local remoteHost = request:getRemoteHost()
|
|
||||||
|
|
||||||
log:info(MOD_ABBR, "print chunk metadata: total_lines=" .. argTotalLines .. ", seq_number=" .. argSeqNumber .. ", seq_total=" .. argSeqTotal)
|
|
||||||
|
|
||||||
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
local printer,msg = printerUtils.createPrinterOrFail(argId, response)
|
||||||
if not printer or not printer:hasSocket() then return end
|
if not printer or not printer:hasSocket() then return false end
|
||||||
|
|
||||||
stopFetch()
|
|
||||||
|
|
||||||
response:addData('id', argId)
|
response:addData('id', argId)
|
||||||
|
|
||||||
@ -341,15 +193,12 @@ function M.print_POST(request, response)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if argClear == true or argIsFirst == true then
|
if argIsFirst == true then
|
||||||
log:verbose(MOD_ABBR, " clearing all gcode for " .. printer:getId())
|
log:debug("clearing all gcode for " .. printer:getId())
|
||||||
response:addData('gcode_clear',true)
|
response:addData('gcode_clear',true)
|
||||||
local rv,msg = printer:clearGcode()
|
local rv,msg = printer:clearGcode()
|
||||||
|
|
||||||
if rv == false then
|
if not rv then
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not clear gcode (" .. msg .. ")")
|
|
||||||
elseif rv == nil then
|
|
||||||
response:setError(msg)
|
response:setError(msg)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -357,20 +206,14 @@ function M.print_POST(request, response)
|
|||||||
|
|
||||||
local rv,msg
|
local rv,msg
|
||||||
|
|
||||||
rv,msg = printer:appendGcode(argGcode, argTotalLines, { seq_number = argSeqNumber, seq_total = argSeqTotal, source = remoteHost })
|
-- TODO: return errors with a separate argument like here in the rest of the code (this is how we designed the API right?)
|
||||||
|
rv,msg = printer:appendGcode(argGcode)
|
||||||
if rv then
|
if rv then
|
||||||
addSequenceNumbering(printer, response)
|
|
||||||
--NOTE: this does not report the number of lines, but only the block which has just been added
|
--NOTE: this does not report the number of lines, but only the block which has just been added
|
||||||
response:addData('gcode_append',argGcode:len())
|
response:addData('gcode_append',argGcode:len())
|
||||||
elseif rv == false then
|
|
||||||
addSequenceNumbering(printer, response)
|
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not add gcode (" .. msg .. ")")
|
|
||||||
return
|
|
||||||
else
|
else
|
||||||
addSequenceNumbering(printer, response)
|
response:setError("could not add gcode")
|
||||||
response:addData('msg', msg)
|
response:addData('msg', msg)
|
||||||
response:setError("could not add gcode (" .. msg .. ")")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -380,14 +223,9 @@ function M.print_POST(request, response)
|
|||||||
if rv then
|
if rv then
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
response:addData('gcode_print',true)
|
response:addData('gcode_print',true)
|
||||||
elseif rv == false then
|
|
||||||
response:addData('status', msg)
|
|
||||||
response:setFail("could not send gcode (" .. msg .. ")")
|
|
||||||
return
|
|
||||||
else
|
else
|
||||||
|
response:setError("could not send gcode")
|
||||||
response:addData('msg', msg)
|
response:addData('msg', msg)
|
||||||
response:setError("could not send gcode (" .. msg .. ")")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
response:setSuccess()
|
response:setSuccess()
|
||||||
|
@ -16,8 +16,6 @@ local lfs = require('lfs')
|
|||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
|
|
||||||
local MOD_ABBR = "ASKE"
|
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
isApi = true,
|
isApi = true,
|
||||||
SKETCH_DIR = '/root/sketches',
|
SKETCH_DIR = '/root/sketches',
|
||||||
@ -31,7 +29,7 @@ local SKETCH_FILE_EXTENSION = 'svg'
|
|||||||
-- creates sketch directory, and sets response to error state on failure
|
-- creates sketch directory, and sets response to error state on failure
|
||||||
local function createSketchDirectory()
|
local function createSketchDirectory()
|
||||||
if os.execute('mkdir -p ' .. M.SKETCH_DIR) ~= 0 then
|
if os.execute('mkdir -p ' .. M.SKETCH_DIR) ~= 0 then
|
||||||
log:error(MOD_ABBR, "could not create sketch directory '" .. M.SKETCH_DIR .. "'")
|
log:error("Error: could not create sketch directory '" .. M.SKETCH_DIR .. "'")
|
||||||
response:setError("could not create sketch directory")
|
response:setError("could not create sketch directory")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -135,7 +133,7 @@ function M._global_POST(request, response)
|
|||||||
local sketchIdx = listSize > 0 and sketches[listSize] + 1 or 1
|
local sketchIdx = listSize > 0 and sketches[listSize] + 1 or 1
|
||||||
local sketchFile = M.SKETCH_DIR .. '/' .. constructSketchFilename(sketchIdx)
|
local sketchFile = M.SKETCH_DIR .. '/' .. constructSketchFilename(sketchIdx)
|
||||||
|
|
||||||
log:verbose(MOD_ABBR, "saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)")
|
log:debug("saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)")
|
||||||
local saveFile,msg = io.open(sketchFile, 'w')
|
local saveFile,msg = io.open(sketchFile, 'w')
|
||||||
|
|
||||||
if not saveFile then
|
if not saveFile then
|
||||||
|
@ -10,8 +10,6 @@ local wifi = require('network.wlanconfig')
|
|||||||
local netconf = require('network.netconfig')
|
local netconf = require('network.netconfig')
|
||||||
local settings = require('util.settings')
|
local settings = require('util.settings')
|
||||||
|
|
||||||
local MOD_ABBR = "AUPD"
|
|
||||||
|
|
||||||
-- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined.
|
-- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined.
|
||||||
argStash = arg
|
argStash = arg
|
||||||
arg = nil
|
arg = nil
|
||||||
@ -160,7 +158,7 @@ end
|
|||||||
function M.install_POST(request, response)
|
function M.install_POST(request, response)
|
||||||
local argVersion = request:get("version")
|
local argVersion = request:get("version")
|
||||||
local argNoRetain = request:get("no_retain")
|
local argNoRetain = request:get("no_retain")
|
||||||
log:info(MOD_ABBR, "API:update/install (noRetain: "..utils.dump(argNoRetain)..")")
|
log:info("API:update/install (noRetain: "..utils.dump(argNoRetain)..")")
|
||||||
local noRetain = argNoRetain == 'true'
|
local noRetain = argNoRetain == 'true'
|
||||||
|
|
||||||
if not operationsAccessOrFail(request, response) then return end
|
if not operationsAccessOrFail(request, response) then return end
|
||||||
|
@ -167,8 +167,7 @@ setmetatable(M, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
--This function initializes itself using various environment variables, the arg array and the given postData
|
--This function initializes itself using various environment variables, the arg array and the given postData
|
||||||
--NOTE: if debugging is enabled, commandline argument 'p' (path) overrides requested module and function and
|
--NOTE: if debugging is enabled, commandline arguments 'm' and 'f' override requested module and function
|
||||||
-- 'r' (rqType) overrides request method
|
|
||||||
function M.new(environment, postData, debugEnabled)
|
function M.new(environment, postData, debugEnabled)
|
||||||
local self = setmetatable({}, M)
|
local self = setmetatable({}, M)
|
||||||
|
|
||||||
@ -181,10 +180,6 @@ function M.new(environment, postData, debugEnabled)
|
|||||||
self.remoteAddress = environment['REMOTE_ADDR']
|
self.remoteAddress = environment['REMOTE_ADDR']
|
||||||
else
|
else
|
||||||
self.requestMethod = 'CMDLINE'
|
self.requestMethod = 'CMDLINE'
|
||||||
self.remoteHost = "cmdline"
|
|
||||||
self.remotePort = "0"
|
|
||||||
self.userAgent = "shell"
|
|
||||||
self.remoteAddress = "0.0.0.0"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.cmdLineArgs = kvTableFromArray(arg)
|
self.cmdLineArgs = kvTableFromArray(arg)
|
||||||
|
@ -20,7 +20,6 @@ local M = {}
|
|||||||
M.__index = M
|
M.__index = M
|
||||||
|
|
||||||
local REQUEST_ID_ARGUMENT = 'rq_id'
|
local REQUEST_ID_ARGUMENT = 'rq_id'
|
||||||
local MOD_ABBR = "HRSP"
|
|
||||||
|
|
||||||
M.httpStatusCode, M.httpStatusText, M.contentType = nil, nil, nil
|
M.httpStatusCode, M.httpStatusText, M.contentType = nil, nil, nil
|
||||||
M.binaryData, M.binarySavename = nil, nil
|
M.binaryData, M.binarySavename = nil, nil
|
||||||
@ -130,9 +129,9 @@ function M:addPostResponseFunction(fn)
|
|||||||
table.insert(self.postResponseQueue, fn)
|
table.insert(self.postResponseQueue, fn)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Call all functions on the post-response queue, see @{M:addPostResponseFunction} for details and a side-note.
|
--- Call all function on the post-response queue, see @{M:addPostResponseFunction} for details and a side-note.
|
||||||
function M:executePostResponseQueue()
|
function M:executePostResponseQueue()
|
||||||
if #self.postResponseQueue > 0 then log:verbose(MOD_ABBR, "Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue)) end
|
--log:info("Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue))
|
||||||
|
|
||||||
for i,fn in ipairs(self.postResponseQueue) do fn() end
|
for i,fn in ipairs(self.postResponseQueue) do fn() end
|
||||||
end
|
end
|
||||||
@ -153,7 +152,7 @@ function M:serializeAsJson()
|
|||||||
return JSON:encode(self.body)
|
return JSON:encode(self.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Writes HTTP headers to stdout, followed by an HTTP body containing either JSON data or a file attachment.
|
--- Writes HTTP headers, followed by an HTTP body containing JSON data to stdout.
|
||||||
function M:send()
|
function M:send()
|
||||||
printHeaderLine("Status", self.httpStatusCode .. " " .. self.httpStatusText)
|
printHeaderLine("Status", self.httpStatusCode .. " " .. self.httpStatusText)
|
||||||
printHeaderLine("Content-Type", self.contentType)
|
printHeaderLine("Content-Type", self.contentType)
|
||||||
@ -170,7 +169,7 @@ function M:send()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.body.status ~= "success" then
|
if self.body.status ~= "success" then
|
||||||
log:warning(MOD_ABBR, "Response status: "..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
|
log:debug("Response:"..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
## Loglite
|
|
||||||
|
|
||||||
The loglite script allows coloring and filtering of log files by specifying certain patterns and associating directives to them. These mainly specify colors but additionally, (non-)matched lines can be deleted from output and also all output lines can be numbered.
|
|
||||||
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
|
|
||||||
The script can follow an existing log file (comparable to `tail -f`), or it can follow its standard input. A file to follow is always specified as the first argument and a filter set name as the second (use '-' as file name to read from standard input). Details on filter sets can be found below. If no filter set is mentioned on the command-line, the script will attempt to use one named 'default'.
|
|
||||||
|
|
||||||
* Example following an existing log file using a filter set named 'example':
|
|
||||||
`./loglite.lua print3d.log example`.
|
|
||||||
* Example using standard input, to filter/view a whole log file, with a filter set named 'serial' (note the '-' as file name):
|
|
||||||
`cat print3d-ttyACM0.log | ./loglite.lua - serial`
|
|
||||||
* Example using standard input, to capture both output streams from `print3d`, with a filter set named 'example' (note the '-' as file name):
|
|
||||||
`./print3d -V 2>&1 | ./loglite.lua - example`.
|
|
||||||
|
|
||||||
#### On WiFi-Box
|
|
||||||
Loglite is already installed since version 0.10.10 as `loglite`.
|
|
||||||
Check `/root/.profile` for handy aliases like `tailfw` and `tailp3d`.
|
|
||||||
|
|
||||||
### Filter sets
|
|
||||||
|
|
||||||
The script looks for filter sets in the file '$HOME/loglite-filters.lua'. It looks like this:
|
|
||||||
|
|
||||||
``` lua
|
|
||||||
local M = {}
|
|
||||||
|
|
||||||
M.default = {
|
|
||||||
['options'] = { mode = 'keep', count = 'none' },
|
|
||||||
['patterns'] = {
|
|
||||||
['%(error%)'] = 'red',
|
|
||||||
['%(warning%)'] = 'yellow',
|
|
||||||
['%(bulk%)'] = 'bold,black'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
M.specialization = {
|
|
||||||
['parent'] = 'default',
|
|
||||||
['options'] = { mode = 'delete' }
|
|
||||||
['patterns'] = {
|
|
||||||
['setState%(%)'] = 'bblue,_nodelete'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
|
||||||
```
|
|
||||||
|
|
||||||
Here, the declaration and returning of `M` is required for the loglite script to be able to cleanly import the file. In `M.default`, 'default' is the name of a filter set being defined (similar for 'specialization'). Definitions can contain three so-called keys: 'parent' specifies a filter set to inherit from in order to reduce code duplication, 'options' and 'patterns' are described below.
|
|
||||||
|
|
||||||
Inheritance can be used to set new keys or to override keys from the parent set. Previously set keys cannot be removed, but they can be set to a non-existing directive (e.g., Lua's 'false' keyword) to achieve the same effect. Note that directives in inheriting sets are currently not combined with previous ones, so for instance overriding `['test'] = 'red, _delete'` with `['test'] = 'blue'` will result in only the directive 'blue' to be applied.
|
|
||||||
|
|
||||||
#### Options
|
|
||||||
|
|
||||||
Two options are currently available:
|
|
||||||
|
|
||||||
* `mode`, which specifies whether to keep log lines (`keep`, the default) or to drop them (`delete`). For specific lines this can then be overridden, see 'Patterns' below.
|
|
||||||
* `count`, which can be set to `all` to prefix log lines with a counter, or `none` (default) to leave them as is.
|
|
||||||
|
|
||||||
#### Patterns
|
|
||||||
|
|
||||||
Pattern specifications are patterns as used in Lua: [Lua documentation on patterns](http://www.lua.org/pil/20.2.html).
|
|
||||||
The following directives can be associated with a pattern:
|
|
||||||
|
|
||||||
* A foreground color, one of: black, red, green, yellow, blue, magenta, cyan or white.
|
|
||||||
* A background color, like foreground colors but prefixed with 'b'.
|
|
||||||
* `bold`, which usually has the effect of rendering a bright variant of the foreground color (note that `bold,black` renders as dark gray).
|
|
||||||
* `reverse` will reverse fore- and background colors.
|
|
||||||
* Also available are `blink` and `underscore` but they do currently not work in all terminal programs or might need to be enabled in the preferences.
|
|
||||||
* `_delete` or `_nodelete` to override the active mode specified in the 'options' above.
|
|
||||||
|
|
||||||
Directives can be combined with ',' (e.g.: `'red,_nodelete'`). Finally, in any filter set, pattern rules are matched from top to bottom, the last one encountered overriding any previous conflicting directive.
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
Note: Loglite is already installed on the WiFi-Box since version 0.10.10.
|
|
||||||
|
|
||||||
Install Lua. See:
|
|
||||||
http://lua-users.org/wiki/LuaBinaries
|
|
||||||
It's tested in Lua 5.1 and Lua 5.2.
|
|
||||||
|
|
||||||
Loglite will check for a `loglite-filters.lua` file in your home directory. It's recommended to create a symbolic link to the latest version.
|
|
||||||
On OS X / Linux:
|
|
||||||
```
|
|
||||||
cd
|
|
||||||
ln -s [absolute path to file]/loglite-filters.lua loglite-filters.lua
|
|
||||||
```
|
|
||||||
|
|
||||||
It's recommended to create a symbolic link in one of your PATH directories (`echo $PATH`) to the loglite.lua file. This allows you to run `loglite` from any directory.
|
|
||||||
On OS X / Linux:
|
|
||||||
```
|
|
||||||
cd /usr/local/bin
|
|
||||||
ln -s [absolute path to file]/loglite.lua loglite.lua
|
|
||||||
```
|
|
34
src/script/collect-code.sh
Executable file
34
src/script/collect-code.sh
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
BASE_NAME=d3d-wifibox-backup
|
||||||
|
SRC_PATHS="/etc /root /www/ /usr/share/lua"
|
||||||
|
TEMP_DIR=/tmp
|
||||||
|
TGT_FILE=$BASE_NAME.tar.gz
|
||||||
|
|
||||||
|
if [ -e /www-external ]; then
|
||||||
|
echo "ERROR: switch back /www-regular to /www before running this script"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $TEMP_DIR
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "ERROR: could not cd to temporary directory ($TEMP_DIR)"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
TGT_DIR=$TEMP_DIR/$BASE_NAME
|
||||||
|
rm -rf $TGT_DIR
|
||||||
|
mkdir -p $TGT_DIR
|
||||||
|
|
||||||
|
for path in $SRC_PATHS; do
|
||||||
|
echo "copying $path -> $TGT_DIR..."
|
||||||
|
cp -a $path $TGT_DIR
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "compressing $TGT_DIR into $BASE_NAME.tar.gz..."
|
||||||
|
tar czf $BASE_NAME.tar.gz $BASE_NAME
|
||||||
|
|
||||||
|
echo "removing staging dir..."
|
||||||
|
rm -rf $TGT_DIR
|
||||||
|
|
||||||
|
echo "done."
|
@ -24,8 +24,6 @@
|
|||||||
-- note: take care not to print any text in module functions, as this breaks http responses
|
-- note: take care not to print any text in module functions, as this breaks http responses
|
||||||
-- change representation of sysupgrade/factory info in versionInfo? (and also in image index?) <- create api call to get all info on all versions?
|
-- change representation of sysupgrade/factory info in versionInfo? (and also in image index?) <- create api call to get all info on all versions?
|
||||||
|
|
||||||
local MOD_ABBR = "UPDA"
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- Possible states the updater can be in, they are stored in @{STATE_FILE}.
|
--- Possible states the updater can be in, they are stored in @{STATE_FILE}.
|
||||||
@ -84,15 +82,15 @@ local baseUrl = M.DEFAULT_BASE_URL -- default, can be overwritten by M.setBaseUr
|
|||||||
-- @string msg The message to log.
|
-- @string msg The message to log.
|
||||||
local function P(lvl, msg)
|
local function P(lvl, msg)
|
||||||
if log then
|
if log then
|
||||||
if lvl == -1 then log:verbose(MOD_ABBR, msg)
|
if lvl == -1 then log:debug(msg)
|
||||||
elseif lvl == 0 or lvl == 1 then log:info(MOD_ABBR, msg)
|
elseif lvl == 0 or lvl == 1 then log:info(msg)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if (-lvl <= verbosity) then print(msg) end
|
if (-lvl <= verbosity) then print(msg) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Log a debug/verbose message, this function wraps @{P}.
|
--- Log a debug message, this function wraps @{P}.
|
||||||
-- The message will be logged with level -1 and be prefixed with '(DBG)'.
|
-- The message will be logged with level -1 and be prefixed with '(DBG)'.
|
||||||
-- @string msg The message to log.
|
-- @string msg The message to log.
|
||||||
local function D(msg) P(-1, (log and msg or "(DBG) " .. msg)) end
|
local function D(msg) P(-1, (log and msg or "(DBG) " .. msg)) end
|
||||||
@ -101,7 +99,7 @@ local function D(msg) P(-1, (log and msg or "(DBG) " .. msg)) end
|
|||||||
-- Messages will be written to [stderr](http://www.cplusplus.com/reference/cstdio/stderr/), or logged using the logger set with @{setLogger}.
|
-- Messages will be written to [stderr](http://www.cplusplus.com/reference/cstdio/stderr/), or logged using the logger set with @{setLogger}.
|
||||||
-- @string msg The message to log.
|
-- @string msg The message to log.
|
||||||
local function E(msg)
|
local function E(msg)
|
||||||
if log then log:error(MOD_ABBR, msg)
|
if log then log:error(msg)
|
||||||
else io.stderr:write(msg .. '\n')
|
else io.stderr:write(msg .. '\n')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -794,7 +792,7 @@ end
|
|||||||
-- @treturn bool|nil True on success (with the 'exception' as noted above) or nil on error.
|
-- @treturn bool|nil True on success (with the 'exception' as noted above) or nil on error.
|
||||||
-- @treturn ?string|number (optional) Descriptive message or sysupgrade exit status on error.
|
-- @treturn ?string|number (optional) Descriptive message or sysupgrade exit status on error.
|
||||||
function M.flashImageVersion(versionEntry, noRetain, devType, isFactory)
|
function M.flashImageVersion(versionEntry, noRetain, devType, isFactory)
|
||||||
if log then log:info(MOD_ABBR, "flashImageVersion") end
|
if log then log:info("flashImageVersion") end
|
||||||
local imgName = M.constructImageFilename(versionEntry.version, devType, isFactory)
|
local imgName = M.constructImageFilename(versionEntry.version, devType, isFactory)
|
||||||
local cmd = noRetain and 'sysupgrade -n ' or 'sysupgrade '
|
local cmd = noRetain and 'sysupgrade -n ' or 'sysupgrade '
|
||||||
cmd = cmd .. cachePath .. '/' .. imgName
|
cmd = cmd .. cachePath .. '/' .. imgName
|
||||||
|
@ -10,16 +10,15 @@
|
|||||||
|
|
||||||
LUA=lua
|
LUA=lua
|
||||||
SCRIPT_PATH=/usr/share/lua/wifibox
|
SCRIPT_PATH=/usr/share/lua/wifibox
|
||||||
LOG_FILE=/tmp/wifibox.stdout.log
|
LOG_FILE=/tmp/wifibox.log
|
||||||
|
|
||||||
cd $SCRIPT_PATH
|
cd $SCRIPT_PATH
|
||||||
#echo "CGI invocation" >> $LOG_FILE
|
echo "CGI invocation" >> $LOG_FILE
|
||||||
#strace -o /tmp/trace-$$.log -ff $LUA ./cmdmain.lua $@ 2>> $LOG_FILE
|
#strace -o /tmp/trace-$$.log -ff $LUA ./cmdmain.lua $@ 2>> $LOG_FILE
|
||||||
$LUA ./cmdmain.lua $@ 2>> $LOG_FILE
|
$LUA ./cmdmain.lua $@ 2>> $LOG_FILE
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
|
|
||||||
|
|
||||||
# Code below is for debugging incoming CGI data
|
# Code below is for debugging incoming CGI data
|
||||||
read -n $CONTENT_LENGTH POSTDATA
|
read -n $CONTENT_LENGTH POSTDATA
|
||||||
echo -e "Content-type: text/plain\r\n\r\n"
|
echo -e "Content-type: text/plain\r\n\r\n"
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
M.default = {
|
|
||||||
['options'] = { mode = 'keep', count = 'none' },
|
|
||||||
['patterns'] = {
|
|
||||||
['%(error%)'] = 'red',
|
|
||||||
['%(warning%)'] = 'yellow',
|
|
||||||
['%(bulk%)'] = 'gray',
|
|
||||||
['setState%(%)'] = 'bblue'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- filter rules for firmware log (/tmp/wifibox.log)
|
|
||||||
M.firmware = {
|
|
||||||
['parent'] = 'default',
|
|
||||||
['patterns'] = {
|
|
||||||
['START%-RQ'] = 'bblue',
|
|
||||||
['END%-RQ'] = 'blue'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- filter rules for print3d log (/tmp/print3d-*.log)
|
|
||||||
M.print3d = {
|
|
||||||
['parent'] = 'default',
|
|
||||||
['patterns'] = {
|
|
||||||
['Print 3D server'] = 'byellow',
|
|
||||||
['sendCode%(%)'] = 'green',
|
|
||||||
['readCode%(%)'] = 'blue',
|
|
||||||
['readResponseCode%(%)'] = 'blue'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- filter rules for serial communcation of print3d
|
|
||||||
M.serial = {
|
|
||||||
['options'] = { mode = 'delete', count = 'none' },
|
|
||||||
['patterns'] = {
|
|
||||||
['Print 3D server'] = 'byellow,_nodelete',
|
|
||||||
['sendCode%(%)'] = 'green,_nodelete',
|
|
||||||
['readCode%(%)'] = 'blue,_nodelete',
|
|
||||||
['readResponseCode%(%)'] = 'blue,_nodelete',
|
|
||||||
['setState%(%)'] = 'bblue,_nodelete',
|
|
||||||
['%[ABSD%]'] = 'gray,_nodelete', -- 0.10.10
|
|
||||||
['%[ABD%]'] = 'gray,_nodelete', -- 0.10.9
|
|
||||||
['%(info%)'] = 'gray,_nodelete' -- 0.10.10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
M.test = { -- TEST set
|
|
||||||
['options'] = { mode = 'keep', count = 'all' },
|
|
||||||
['patterns'] = {
|
|
||||||
['%(info%)'] = 'yellow'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
M.printstart = {
|
|
||||||
['options'] = { mode = 'delete' },
|
|
||||||
['patterns'] = {
|
|
||||||
['print started'] = '_uppercase,bwhite'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
|
@ -1,275 +0,0 @@
|
|||||||
#!/usr/bin/env lua
|
|
||||||
|
|
||||||
--[[
|
|
||||||
For documentation on this script, see README-loglite.md.
|
|
||||||
|
|
||||||
Ideas for improvement:
|
|
||||||
* add more directives like uppercase, prefix/suffix?
|
|
||||||
* create separate package for this script: a) since it is useful for any log file, b) this file is getting somewhat long
|
|
||||||
* for broader terminal support: detect `tput` and use it if available (http://wiki.bash-hackers.org/scripting/terminalcodes)
|
|
||||||
* pre-split keyword lists for efficiency instead of redoing this at every new line?
|
|
||||||
|
|
||||||
FIXME:
|
|
||||||
* with deleteMode enabled, multiple matches and _nodelete in a later match, previous directives are ignored
|
|
||||||
]]--
|
|
||||||
|
|
||||||
|
|
||||||
--[[========================================================================]]--
|
|
||||||
|
|
||||||
--Note: overview of ANSI escape codes: http://ascii-table.com/ansi-escape-sequences.php (support varies per terminal/termtype)
|
|
||||||
local ANSI_COLORS = {
|
|
||||||
['bold'] = 1,
|
|
||||||
['underscore'] = 4,
|
|
||||||
['blink'] = 5, -- on osx/iterm2, this has to be enabled in preferences
|
|
||||||
['reverse'] = 7,
|
|
||||||
['black'] = 30,
|
|
||||||
['red'] = 31,
|
|
||||||
['green'] = 32,
|
|
||||||
['yellow'] = 33,
|
|
||||||
['blue'] = 34,
|
|
||||||
['magenta'] = 35,
|
|
||||||
['cyan'] = 36,
|
|
||||||
['white'] = 37,
|
|
||||||
['bblack'] = 40,
|
|
||||||
['bred'] = 41,
|
|
||||||
['bgreen'] = 42,
|
|
||||||
['byellow'] = 43,
|
|
||||||
['bblue'] = 44,
|
|
||||||
['bmagenta'] = 45,
|
|
||||||
['bcyan'] = 46,
|
|
||||||
['bwhite'] = 47
|
|
||||||
}
|
|
||||||
|
|
||||||
local ESCAPE_STR = string.char(27) .. "["
|
|
||||||
local RESET_CODE = ESCAPE_STR .. "m"
|
|
||||||
|
|
||||||
local DFL_FILTERSET_FILE = "loglite-filters.lua"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--[[========================================================================]]--
|
|
||||||
|
|
||||||
--- Stringifies the given object.
|
|
||||||
-- From util/utils.lua
|
|
||||||
-- Note that self-referencing objects will cause an endless loop with the current implementation.
|
|
||||||
-- @param o The object to convert.
|
|
||||||
-- @treturn string Stringified version of o.
|
|
||||||
local function dump(o)
|
|
||||||
if type(o) == 'table' then
|
|
||||||
local s = '{ '
|
|
||||||
for k,v in pairs(o) do
|
|
||||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
|
||||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
|
||||||
end
|
|
||||||
return s .. '} '
|
|
||||||
else
|
|
||||||
return tostring(o)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Splits a string on a given divider character.
|
|
||||||
-- From util/utils.lua
|
|
||||||
-- @string[opt=':'] div The divider character to use.
|
|
||||||
-- @return An array containing the resultant substrings.
|
|
||||||
-- @usage local str = "a,b,c"; local parts = str:split(',')
|
|
||||||
function string:split(div)
|
|
||||||
local div, pos, arr = div or ':', 0, {}
|
|
||||||
for st,sp in function() return self:find(div, pos, true) end do
|
|
||||||
table.insert(arr, self:sub(pos, st - 1))
|
|
||||||
pos = sp + 1
|
|
||||||
end
|
|
||||||
table.insert(arr, self:sub(pos))
|
|
||||||
return arr
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Determines if filename exists and can be opened for reading.
|
|
||||||
-- From http://stackoverflow.com/a/4991602
|
|
||||||
-- @string filename The file to test.
|
|
||||||
-- @return True if the file exists and is readable, false otherwise.
|
|
||||||
function fileExists(filename)
|
|
||||||
local f = io.open(filename, "r")
|
|
||||||
if f ~= nil then io.close(f) return true else return false end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Converts keys of a table into a string.
|
|
||||||
-- Adapted from http://stackoverflow.com/a/12674376.
|
|
||||||
-- @string tbl A key/value table.
|
|
||||||
-- @string[opt=','] sep Separator to use between items.
|
|
||||||
-- @boolean[opt=false] sort Whether or not to sort the resulting list.
|
|
||||||
-- @return A string with all keys from the given table.
|
|
||||||
local function keysToString(tbl, sep, sort)
|
|
||||||
local sep, sort = sep or ',', sort or false
|
|
||||||
local keyset, n = {}, 0
|
|
||||||
for k,_ in pairs(tbl) do
|
|
||||||
n = n + 1
|
|
||||||
keyset[n] = k
|
|
||||||
end
|
|
||||||
if sort then table.sort(keyset) end
|
|
||||||
return table.concat(keyset, sep)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Merge two tables recursively (i.e., subtables also get merged).
|
|
||||||
-- from: http://stackoverflow.com/a/1283608
|
|
||||||
-- @table t1 Table to merge into.
|
|
||||||
-- @table t2 Table to merge into t1.
|
|
||||||
-- @return The combined table (actually t1).
|
|
||||||
function mergeTables(t1, t2)
|
|
||||||
for k,v in pairs(t2) do
|
|
||||||
if type(v) == "table" then
|
|
||||||
if type(t1[k] or false) == "table" then
|
|
||||||
mergeTables(t1[k] or {}, t2[k] or {})
|
|
||||||
else
|
|
||||||
t1[k] = v
|
|
||||||
end
|
|
||||||
else
|
|
||||||
t1[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return t1
|
|
||||||
end
|
|
||||||
|
|
||||||
local function hasValue(t, needle)
|
|
||||||
for k,v in pairs(t) do
|
|
||||||
if needle == v then return k end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function makeAnsiCode(key)
|
|
||||||
if not ANSI_COLORS[key] then return nil end
|
|
||||||
return ESCAPE_STR .. ANSI_COLORS[key] .. 'm'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--[[========================================================================]]--
|
|
||||||
|
|
||||||
local function tailStream(stream, filterSet)
|
|
||||||
patterns = filterSet and filterSet.patterns or {}
|
|
||||||
options = filterSet and filterSet.options or { ['mode'] = 'keep' }
|
|
||||||
local c = 0
|
|
||||||
|
|
||||||
for line in stream:lines() do
|
|
||||||
--c = c + 1 -- Note: this would also count deleted lines
|
|
||||||
local embellished = line
|
|
||||||
local keepLine = (options.mode == 'keep')
|
|
||||||
local keepLineOverridden = false
|
|
||||||
|
|
||||||
-- look for a pattern matching this line
|
|
||||||
for p,c in pairs(patterns) do
|
|
||||||
if line:match(p) then
|
|
||||||
-- print("[DEBUG] +matched rule '" .. p .. "'/'" .. c .. "' against '" .. line .. "'")
|
|
||||||
local kws = c:split(',')
|
|
||||||
|
|
||||||
if hasValue(kws, '_delete') then keepLine = false; keepLineOverridden = true
|
|
||||||
elseif hasValue(kws, '_nodelete') then keepLine = true; keepLineOverridden = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if keepLine then
|
|
||||||
-- first collect formatting sequences
|
|
||||||
local fmt = ''
|
|
||||||
for _,kw in ipairs(kws) do
|
|
||||||
local code = makeAnsiCode(kw)
|
|
||||||
if code then fmt = fmt .. code end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- then wrap the line in formatting, if any
|
|
||||||
if fmt:len() > 0 then embellished = fmt .. embellished .. RESET_CODE end
|
|
||||||
else
|
|
||||||
-- Note: break out of loop and stop processing when line should be deleted _if_ the default has been overridden to do so
|
|
||||||
if keepLineOverridden then
|
|
||||||
embellished = nil
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--break -- Note: don't break, allow multiple matches per line, e.g. to mix and match fg and bg colors
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if embellished and keepLine then
|
|
||||||
c = c + 1
|
|
||||||
|
|
||||||
if options.count == 'all' then print(c, embellished)
|
|
||||||
else print(embellished) end
|
|
||||||
else
|
|
||||||
-- print("[DEBUG] -skipped '"..line.."'")
|
|
||||||
end
|
|
||||||
|
|
||||||
--c = line:match 'truncated' and 0 or c -- from tail on stderr apparently
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--TODO: could be extended to look for multiple filenames in multiple paths
|
|
||||||
local function readConfigFile(filename, searchPath)
|
|
||||||
fullPath = searchPath .. '/' .. filename
|
|
||||||
if not fileExists(fullPath) then
|
|
||||||
--print("[DEBUG] config file '" .. fullPath .. "' not found")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
--print("[DEBUG] using config file '" .. fullPath .. "'")
|
|
||||||
-- require does not accept full paths? also, pcall does not help with dofile
|
|
||||||
return dofile(fullPath)
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Load filter set with given name from configSets, with inheritance as specified.
|
|
||||||
local function readFilterSet(configSets, setName)
|
|
||||||
local result = {}
|
|
||||||
for k,_ in pairs(configSets) do
|
|
||||||
if k == setName then
|
|
||||||
parent = configSets[setName]['parent']
|
|
||||||
if parent ~= nil then
|
|
||||||
--print("[DEBUG] recursing for filter set '" .. parent .. "' from config")
|
|
||||||
result = mergeTables(result, readFilterSet(configSets, parent))
|
|
||||||
end
|
|
||||||
--print("[DEBUG] using/merging filter set '" .. setName .. "' from config")
|
|
||||||
result = mergeTables(result, configSets[setName])
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
--NOTE: if command-line options get any more complex, switch to a lightweight
|
|
||||||
-- getopt like this one? https://attractivechaos.wordpress.com/2011/04/07/getopt-for-lua/
|
|
||||||
local function main()
|
|
||||||
-- handle command-line arguments
|
|
||||||
local showHelp, followFile, filterSetName = false, nil, 'default'
|
|
||||||
if #arg > 0 and arg[1] == "-h" or arg[1] == "--help" then
|
|
||||||
showHelp = true
|
|
||||||
else
|
|
||||||
if #arg > 0 and arg[1] ~= '-' then followFile = arg[1] end
|
|
||||||
if #arg > 1 then filterSetName = arg[2] end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- read filter set file if available
|
|
||||||
local configSets = readConfigFile(DFL_FILTERSET_FILE, os.getenv('HOME')) or {}
|
|
||||||
local filterSet = readFilterSet(configSets, filterSetName)
|
|
||||||
-- print("[DEBUG] final filter set for '" .. filterSetName .. "' from config: " .. dump(filterSet))
|
|
||||||
|
|
||||||
-- if requested, display help and exit
|
|
||||||
if showHelp and showHelp == true then
|
|
||||||
print("Usage: loglite.lua [file-to-tail] [filter-set]")
|
|
||||||
print(" If no arguments are supplied, or if the first one is `-', stdin is used as input.")
|
|
||||||
print(" If no filter set is supplied, a set named `default' will be looked for.")
|
|
||||||
print(" Filter sets can be defined in a file `loglite-filters.lua' in your home directory.")
|
|
||||||
print()
|
|
||||||
print(" Available filter sets in " .. os.getenv('HOME') .. "/" .. DFL_FILTERSET_FILE .. ": " .. keysToString(configSets, ', ', true))
|
|
||||||
os.exit(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
--print("[DEBUG] following file: '" .. (followFile and followFile or "<stdin>") .. "', with filter set '" .. filterSetName .. "'.")
|
|
||||||
|
|
||||||
--Info on tailing a file: https://stackoverflow.com/questions/17363973/how-can-i-tail-f-a-log-filetruncate-aware-in-lua
|
|
||||||
--local tailin = io.popen('tail -F '..(...)..' 2>&1', 'r')
|
|
||||||
local tailin = followFile and io.popen('tail -f ' .. followFile, 'r') or io.stdin
|
|
||||||
|
|
||||||
pcall(tailStream, tailin, filterSet) -- Note: protected call to suppress interrupt error thrown by lines iterator
|
|
||||||
end
|
|
||||||
|
|
||||||
main()
|
|
||||||
os.exit(0)
|
|
@ -1,36 +0,0 @@
|
|||||||
# Doodle3D logrotate configuration
|
|
||||||
|
|
||||||
compress
|
|
||||||
su
|
|
||||||
create
|
|
||||||
|
|
||||||
/tmp/wifibox.log /tmp/print3d-*.log {
|
|
||||||
rotate 2
|
|
||||||
size 1000k
|
|
||||||
missingok
|
|
||||||
olddir /tmp/wifibox-rotated
|
|
||||||
|
|
||||||
# as alternative to copytruncate (which *might* miss lines) we could implement
|
|
||||||
# SIGUSR1 in print3d and firmware to reopen their logs
|
|
||||||
copytruncate # 'create' is ignored with copytruncate, as the file stays in place
|
|
||||||
|
|
||||||
prerotate
|
|
||||||
FIRST_N_LINES=500
|
|
||||||
PRINT3D_LOGHEAD_FILE=print3d-loghead
|
|
||||||
WIFIBOX_LOGHEAD_FILE=wifibox-loghead
|
|
||||||
ROTATED_FILES_PATH=/tmp/wifibox-rotated
|
|
||||||
|
|
||||||
#Note: by looking at creation date of the print3d socket and comparing against that
|
|
||||||
# of print3d-loghead we could detect a server restart (e.g. due to reconnected printer)
|
|
||||||
|
|
||||||
echo "$1" | grep -q "print3d-.*\.log"
|
|
||||||
if [ $? -eq 0 -a ! -f "$ROTATED_FILES_PATH/$PRINT3D_LOGHEAD_FILE" ]; then
|
|
||||||
head -q -n$FIRST_N_LINES "$1" > "$ROTATED_FILES_PATH/$PRINT3D_LOGHEAD_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$1" | grep -q "wifibox.log"
|
|
||||||
if [ $? -eq 0 -a ! -f "$ROTATED_FILES_PATH/$WIFIBOX_LOGHEAD_FILE" ]; then
|
|
||||||
head -q -n$FIRST_N_LINES "$1" > "$ROTATED_FILES_PATH/$WIFIBOX_LOGHEAD_FILE"
|
|
||||||
fi
|
|
||||||
endscript
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
#!/usr/bin/lua
|
|
||||||
|
|
||||||
local function log(message)
|
|
||||||
os.execute("logger " .. message)
|
|
||||||
print(message)
|
|
||||||
end
|
|
||||||
|
|
||||||
if (table.getn(arg) == 0) then
|
|
||||||
print("Usage: ./print-fetch {printerSocket} {gcodeServerURL} {id} [startGcode] [endGCode]")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
log("starting gcode fetch program")
|
|
||||||
|
|
||||||
package.cpath = package.cpath .. '/usr/lib/lua/?.so'
|
|
||||||
JSON = (loadfile "/usr/share/lua/wifibox/util/JSON.lua")()
|
|
||||||
|
|
||||||
local p3d = require("print3d")
|
|
||||||
|
|
||||||
local printer = p3d.getPrinter(arg[1])
|
|
||||||
if printer == nil then
|
|
||||||
log("error connecting to printer")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local gcodeServer = arg[2]
|
|
||||||
|
|
||||||
local finished = false
|
|
||||||
|
|
||||||
local id = arg[3]
|
|
||||||
|
|
||||||
log("gcode file id: " .. id)
|
|
||||||
log("gcode server: " .. gcodeServer)
|
|
||||||
|
|
||||||
local info = JSON:decode(io.popen("wget -qO - " .. gcodeServer .. "/info/" .. id):read("*a"))
|
|
||||||
|
|
||||||
if info == nil then
|
|
||||||
log("could not retrieve file info")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local current_line = 0
|
|
||||||
local total_lines = tonumber(info["lines"])
|
|
||||||
local started = false
|
|
||||||
|
|
||||||
log("total lines: " .. total_lines)
|
|
||||||
|
|
||||||
local startCode = nil
|
|
||||||
local endCode = nil
|
|
||||||
|
|
||||||
function countlines(file)
|
|
||||||
return tonumber(io.popen("wc -l < " .. file):read('*a'))
|
|
||||||
end
|
|
||||||
|
|
||||||
function readGCodeArg(argi)
|
|
||||||
local gcodeFile = arg[argi]
|
|
||||||
return io.open(gcodeFile):read('*a')
|
|
||||||
end
|
|
||||||
|
|
||||||
if table.getn(arg) >= 5 then
|
|
||||||
startCode = readGCodeArg(4)
|
|
||||||
endCode = readGCodeArg(5)
|
|
||||||
end
|
|
||||||
|
|
||||||
if startCode ~= nil then
|
|
||||||
log("appending start gcode")
|
|
||||||
printer:appendGcode(startCode)
|
|
||||||
end
|
|
||||||
|
|
||||||
while(not finished)
|
|
||||||
do
|
|
||||||
local f = io.popen("wget -qO - " .. gcodeServer .. "/fetch/" .. id .. "/" .. current_line)
|
|
||||||
local line = f:read()
|
|
||||||
while line ~= nil do
|
|
||||||
printer:appendGcode(line, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
|
||||||
current_line = current_line + 1
|
|
||||||
line = f:read()
|
|
||||||
end
|
|
||||||
|
|
||||||
if not started then
|
|
||||||
started = true
|
|
||||||
print("send print start command")
|
|
||||||
printer:startPrint()
|
|
||||||
end
|
|
||||||
|
|
||||||
if current_line >= total_lines then
|
|
||||||
log("finished fetching gcode")
|
|
||||||
if endCode ~= nil then
|
|
||||||
log("appending end gcode")
|
|
||||||
printer:appendGcode(endCode, total_lines, { seq_number = -1, seq_total = -1, source = id })
|
|
||||||
end
|
|
||||||
finished = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local accepts_new_gcode = false
|
|
||||||
|
|
||||||
while (not accepts_new_gcode)
|
|
||||||
do
|
|
||||||
local current,buffer,total,bufferSize,maxBufferSize = printer:getProgress()
|
|
||||||
local percentageBufferSize = bufferSize / maxBufferSize
|
|
||||||
|
|
||||||
if percentageBufferSize < 0.8 then
|
|
||||||
print("buffer below 80% capacity, sending new gcode")
|
|
||||||
accepts_new_gcode = true
|
|
||||||
else
|
|
||||||
print("buffer above 80% capacity")
|
|
||||||
os.execute("sleep 10")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,12 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
[ "${ACTION}" = "released" ] || exit 0
|
|
||||||
|
|
||||||
. /lib/functions.sh
|
|
||||||
|
|
||||||
logger "$BUTTON pressed for $SEEN seconds"
|
|
||||||
if [ "$SEEN" -gt 4 ]
|
|
||||||
then
|
|
||||||
logger "Resetting Wireless"
|
|
||||||
d3dapi p=/network/reset r=POST
|
|
||||||
fi
|
|
@ -1,13 +1,6 @@
|
|||||||
config settings 'system'
|
config settings 'system'
|
||||||
#In addition to regular text, api_log_filename and p3d_log_basename may also be
|
option logfile '/tmp/wifibox.log'
|
||||||
#a stream enclose in angle brackets (e.g. '<stderr>') or
|
option loglevel 'debug'
|
||||||
#a command to send output to in back quotes (e.g. '`ssh USER@HOST "cat > /tmp/test.log"`').
|
|
||||||
#Note that using an SSH tunnel without public key auth will need interaction
|
|
||||||
|
|
||||||
option log_path '/tmp'
|
|
||||||
option api_log_filename 'wifibox.log'
|
|
||||||
option p3d_log_basename 'print3d'
|
|
||||||
|
|
||||||
config settings 'general'
|
config settings 'general'
|
||||||
option printer_type 'ultimaker'
|
option printer_type 'ultimaker'
|
||||||
option gcode_server 'http://gcodeserver.doodle3d.com'
|
|
||||||
|
@ -20,8 +20,6 @@ boot() {
|
|||||||
$LOGGER "Start signing in..."
|
$LOGGER "Start signing in..."
|
||||||
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
|
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
|
||||||
|
|
||||||
mkdir -p /var/lib # required by logrotate for logrotate.status
|
|
||||||
mkdir -p /tmp/wifibox-rotated # this is where rotated wifibox logs are placed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
@ -10,8 +10,6 @@ local log = require('util.logger')
|
|||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
local printerUtils = require('util.printer')
|
local printerUtils = require('util.printer')
|
||||||
|
|
||||||
local MOD_ABBR = "UACS"
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.hasControl(ip)
|
function M.hasControl(ip)
|
||||||
@ -43,7 +41,7 @@ end
|
|||||||
function M.getController()
|
function M.getController()
|
||||||
local file, error = io.open('/tmp/controller.txt','r')
|
local file, error = io.open('/tmp/controller.txt','r')
|
||||||
if file == nil then
|
if file == nil then
|
||||||
--log:error(MOD_ABBR, "Util:Access: Can't read controller file. Error: "..error)
|
--log:error("Util:Access:Can't read controller file. Error: "..error)
|
||||||
return ""
|
return ""
|
||||||
else
|
else
|
||||||
controllerIP = file:read('*a')
|
controllerIP = file:read('*a')
|
||||||
|
@ -13,51 +13,36 @@ local utils = require('util.utils')
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local logLevel, logVerboseFmt, logStream
|
local logLevel, logVerbose, logStream
|
||||||
local logFilePath = nil -- only used for reference
|
|
||||||
|
|
||||||
local LONGEST_LEVEL_NAME = -1
|
--- Available log levels
|
||||||
|
|
||||||
--- Available log levels (starting at 1)
|
|
||||||
-- @table LEVEL
|
-- @table LEVEL
|
||||||
M.LEVEL = {
|
M.LEVEL = {
|
||||||
'quiet', -- not used for logging, only for setting levels
|
'debug', -- for debug messages
|
||||||
'error', -- fatal or non-fatal error condition
|
'info', -- for informational messages
|
||||||
'warning', -- possibly troublesome situation
|
'warn', -- for warnings (something is wrong/fishy but not neccesarily problematic)
|
||||||
'info', -- information about what the application is doing
|
'error', -- for recoverable errors
|
||||||
'verbose', -- extra trail information on what the application is doing
|
'fatal' -- for unrecoverable errors
|
||||||
'bulk' -- debug information (in large amounts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- M.LEVEL already has idx=>name entries, now create name=>idx entries
|
||||||
--[[== module initialization code ==]]--
|
|
||||||
|
|
||||||
-- M.LEVEL already has idx=>name entries, now create name=>idx entries so it can be indexed both ways, and init LONGEST_LEVEL_NAME
|
|
||||||
for i,v in ipairs(M.LEVEL) do
|
for i,v in ipairs(M.LEVEL) do
|
||||||
M.LEVEL[v] = i
|
M.LEVEL[v] = i
|
||||||
if v:len() > LONGEST_LEVEL_NAME then LONGEST_LEVEL_NAME = v:len() end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--[[================================]]--
|
local function log(level, msg, verbose)
|
||||||
|
if level >= logLevel then
|
||||||
|
local now = os.date('%m-%d %H:%M:%S')
|
||||||
local function log(level, module, msg, verboseFmt)
|
|
||||||
if level <= logLevel then
|
|
||||||
local now = os.date('%d-%m %H:%M:%S')
|
|
||||||
local i = debug.getinfo(3) --the stack frame just above the logger call
|
local i = debug.getinfo(3) --the stack frame just above the logger call
|
||||||
local v = verboseFmt
|
local v = verbose
|
||||||
if v == nil then v = logVerboseFmt end
|
if v == nil then v = logVerbose end
|
||||||
local name = i.name or "(nil)"
|
local name = i.name or "(nil)"
|
||||||
local vVal = 'nil'
|
local vVal = 'nil'
|
||||||
local m = (type(msg) == 'string') and msg or utils.dump(msg)
|
local m = (type(msg) == 'string') and msg or utils.dump(msg)
|
||||||
if module == nil then module = "LUA " end
|
|
||||||
|
|
||||||
local levelName = M.LEVEL[level]
|
if v then logStream:write(now .. " (" .. M.LEVEL[level] .. ") " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n")
|
||||||
local padding = string.rep(' ', LONGEST_LEVEL_NAME - levelName:len())
|
else logStream:write(now .. " (" .. M.LEVEL[level] .. ") " .. m .. "\n") end
|
||||||
|
|
||||||
if v then logStream:write(now .. " [" .. module .. "] (" .. levelName .. ")" .. padding .. ": " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n")
|
|
||||||
else logStream:write(now .. " [" .. module .. "] (" .. levelName .. ")" .. padding .. ": " .. m .. "\n") end
|
|
||||||
|
|
||||||
logStream:flush()
|
logStream:flush()
|
||||||
end
|
end
|
||||||
@ -66,16 +51,11 @@ end
|
|||||||
|
|
||||||
--- Initializes the logger.
|
--- Initializes the logger.
|
||||||
-- @tparam @{util.logger.LEVEL} level Minimum level of messages to log.
|
-- @tparam @{util.logger.LEVEL} level Minimum level of messages to log.
|
||||||
-- @tparam bool verbose Write verbose log messages (include file/line information).
|
-- @tparam bool verbose Write verbose log messages (include file/line inforomation).
|
||||||
function M:init(level, verboseFmt)
|
function M:init(level, verbose)
|
||||||
logLevel = level or M.LEVEL.warning
|
logLevel = level or M.LEVEL.warn
|
||||||
logVerboseFmt = verboseFmt or false
|
logVerbose = verbose or false
|
||||||
--logStream = stream or io.stdout
|
logStream = stream or io.stdout
|
||||||
end
|
|
||||||
|
|
||||||
function M:setLevel(level, verboseFmt)
|
|
||||||
logLevel = level or M.LEVEL.warning
|
|
||||||
logVerboseFmt = verboseFmt or false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- pass nil as stream to reset to stdout
|
-- pass nil as stream to reset to stdout
|
||||||
@ -83,21 +63,10 @@ function M:setStream(stream)
|
|||||||
logStream = stream or io.stdout
|
logStream = stream or io.stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:getLevel()
|
function M:debug(msg, verbose) log(M.LEVEL.debug, msg, verbose); return true end
|
||||||
return logLevel, logVerboseFmt
|
function M:info(msg, verbose) log(M.LEVEL.info, msg, verbose); return true end
|
||||||
end
|
function M:warn(msg, verbose) log(M.LEVEL.warn, msg, verbose); return true end
|
||||||
|
function M:error(msg, verbose) log(M.LEVEL.error, msg, verbose); return false end
|
||||||
function M:getStream()
|
function M:fatal(msg, verbose) log(M.LEVEL.fatal, msg, verbose); return false end
|
||||||
return logStream
|
|
||||||
end
|
|
||||||
|
|
||||||
function M:setLogFilePath(path) logFilePath = path end
|
|
||||||
function M:getLogFilePath() return logFilePath end
|
|
||||||
|
|
||||||
function M:error(module, msg, verboseFmt) log(M.LEVEL.error, module, msg, verboseFmt); return false end
|
|
||||||
function M:warning(module, msg, verboseFmt) log(M.LEVEL.warning, module, msg, verboseFmt); return true end
|
|
||||||
function M:info(module, msg, verboseFmt) log(M.LEVEL.info, module, msg, verboseFmt); return true end
|
|
||||||
function M:verbose(module, msg, verboseFmt) log(M.LEVEL.verbose, module, msg, verboseFmt); return true end
|
|
||||||
function M:bulk(module, msg, verboseFmt) log(M.LEVEL.bulk, module, msg, verboseFmt); return true end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -10,14 +10,11 @@ local log = require('util.logger')
|
|||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
local printDriver = require('print3d')
|
local printDriver = require('print3d')
|
||||||
|
|
||||||
local MOD_ABBR = "UPRN"
|
|
||||||
|
|
||||||
local SUPPORTED_PRINTERS = {
|
local SUPPORTED_PRINTERS = {
|
||||||
rigidbot = "Rigidbot",
|
rigidbot = "Rigidbot",
|
||||||
ultimaker = "Ultimaker",
|
ultimaker = "Ultimaker",
|
||||||
ultimaker2 = "Ultimaker 2",
|
ultimaker2 = "Ultimaker 2",
|
||||||
ultimaker2go = "Ultimaker 2 Go",
|
ultimaker2go = "Ultimaker 2 Go",
|
||||||
ultimaker_original_plus = "Ultimaker Original Plus",
|
|
||||||
makerbot_replicator2 = "MakerBot Replicator2",
|
makerbot_replicator2 = "MakerBot Replicator2",
|
||||||
makerbot_replicator2x = "MakerBot Replicator2x",
|
makerbot_replicator2x = "MakerBot Replicator2x",
|
||||||
makerbot_thingomatic = "MakerBot Thing-o-matic",
|
makerbot_thingomatic = "MakerBot Thing-o-matic",
|
||||||
@ -57,14 +54,7 @@ local SUPPORTED_PRINTERS = {
|
|||||||
_3Dison_plus = "3Dison plus",
|
_3Dison_plus = "3Dison plus",
|
||||||
marlin_generic = "Generic Marlin Printer",
|
marlin_generic = "Generic Marlin Printer",
|
||||||
makerbot_generic = "Generic Makerbot Printer",
|
makerbot_generic = "Generic Makerbot Printer",
|
||||||
doodle_dream = "Doodle Dream",
|
doodle_dream = "Doodle Dream"
|
||||||
colido_2_0_plus = "ColiDo 2.0 Plus",
|
|
||||||
colido_m2020 = "ColiDo M2020",
|
|
||||||
colido_x3045 = "ColiDo X3045",
|
|
||||||
colido_compact = "ColiDo Compact",
|
|
||||||
colido_diy = "ColiDo DIY",
|
|
||||||
craftbot_plus = "CraftBot PLUS",
|
|
||||||
renkforce_rf100 = "Renkforce RF100"
|
|
||||||
}
|
}
|
||||||
local SUPPORTED_BAUDRATES = {
|
local SUPPORTED_BAUDRATES = {
|
||||||
["115200"] = "115200 bps",
|
["115200"] = "115200 bps",
|
||||||
@ -86,8 +76,8 @@ end
|
|||||||
--returns a printer instance or nil (and sets error state on response in the latter case)
|
--returns a printer instance or nil (and sets error state on response in the latter case)
|
||||||
function M.createPrinterOrFail(deviceId, response)
|
function M.createPrinterOrFail(deviceId, response)
|
||||||
|
|
||||||
--log:info(MOD_ABBR, "API:printer:createPrinterOrFail: "..utils.dump(deviceId))
|
--log:debug("API:printer:createPrinterOrFail: "..utils.dump(deviceId))
|
||||||
local rv,msg,printer = nil, nil, nil
|
local msg,printer = nil, nil
|
||||||
|
|
||||||
if deviceId == nil or deviceId == "" then
|
if deviceId == nil or deviceId == "" then
|
||||||
printer,msg = printDriver.getPrinter()
|
printer,msg = printDriver.getPrinter()
|
||||||
@ -103,18 +93,6 @@ function M.createPrinterOrFail(deviceId, response)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- only log these log setup errors, do not let them prevent further request handling
|
|
||||||
|
|
||||||
rv,msg = printer:setLocalLogStream(log:getStream())
|
|
||||||
if not rv then
|
|
||||||
log:error(MOD_ABBR, "could not set log stream in Lua binding (" .. msg .. ")")
|
|
||||||
end
|
|
||||||
|
|
||||||
rv,msg = printer:setLocalLogLevel(log:getLevel())
|
|
||||||
if not rv then
|
|
||||||
log:error(MOD_ABBR, "could not set log level '" .. log:getLevel() .. "' in Lua binding (" .. msg .. ")")
|
|
||||||
end
|
|
||||||
|
|
||||||
return printer
|
return printer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ local baseconfig = require('conf_defaults')
|
|||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
|
|
||||||
local MOD_ABBR = "USET"
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
--- UCI config name (i.e., file under `/etc/config`)
|
--- UCI config name (i.e., file under `/etc/config`)
|
||||||
@ -99,7 +97,7 @@ end
|
|||||||
|
|
||||||
--- Reports whether a value is valid given the constraints specified in a base table.
|
--- Reports whether a value is valid given the constraints specified in a base table.
|
||||||
-- @p value The value to test.
|
-- @p value The value to test.
|
||||||
-- @tab baseTable The base table to use constraint data from (min,max,regex,isValid).
|
-- @tab baseTable The base table to use constraint data from (min,max,regex).
|
||||||
-- @treturn bool Returns true if the value is valid, false if it is not.
|
-- @treturn bool Returns true if the value is valid, false if it is not.
|
||||||
local function isValid(value, baseTable)
|
local function isValid(value, baseTable)
|
||||||
local varType, min, max, regex, isValid = baseTable.type, baseTable.min, baseTable.max, baseTable.regex, baseTable.isValid
|
local varType, min, max, regex, isValid = baseTable.type, baseTable.min, baseTable.max, baseTable.regex, baseTable.isValid
|
||||||
@ -161,7 +159,7 @@ end]]--
|
|||||||
-- @return The associated value, beware (!) that this may be boolean false for keys of 'bool' type, or nil if the key could not be read because of a UCI error.
|
-- @return The associated value, beware (!) that this may be boolean false for keys of 'bool' type, or nil if the key could not be read because of a UCI error.
|
||||||
-- @treturn string Message in case of error.
|
-- @treturn string Message in case of error.
|
||||||
function M.get(key)
|
function M.get(key)
|
||||||
--log:info(MOD_ABBR, "settings:get: "..utils.dump(key))
|
--log:info("settings:get: "..utils.dump(key))
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
|
|
||||||
-- retrieve settings's base settings from conf_defaults.lua
|
-- retrieve settings's base settings from conf_defaults.lua
|
||||||
@ -179,7 +177,7 @@ function M.get(key)
|
|||||||
local uciV,msg = uci:get(UCI_CONFIG_NAME, section, key)
|
local uciV,msg = uci:get(UCI_CONFIG_NAME, section, key)
|
||||||
if not uciV and msg ~= nil then
|
if not uciV and msg ~= nil then
|
||||||
local errorMSG = "Issue reading setting '"..utils.dump(key).."': "..utils.dump(msg);
|
local errorMSG = "Issue reading setting '"..utils.dump(key).."': "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -246,21 +244,21 @@ end
|
|||||||
-- @treturn bool|nil True if everything went well, false if validation error, nil in case of error.
|
-- @treturn bool|nil True if everything went well, false if validation error, nil in case of error.
|
||||||
-- @treturn ?string Error message in case first return value is nil (invalid key).
|
-- @treturn ?string Error message in case first return value is nil (invalid key).
|
||||||
function M.set(key, value, noCommit)
|
function M.set(key, value, noCommit)
|
||||||
--log:info(MOD_ABBR, "settings:set: "..utils.dump(key).." to: "..utils.dump(value))
|
log:info("settings:set: "..utils.dump(key).." to: "..utils.dump(value))
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
|
|
||||||
local r = utils.create(UCI_CONFIG_FILE)
|
local r = utils.create(UCI_CONFIG_FILE)
|
||||||
local rv, msg = uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, UCI_CONFIG_TYPE)
|
local rv, msg = uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, UCI_CONFIG_TYPE)
|
||||||
if not rv and msg ~= nil then
|
if not rv and msg ~= nil then
|
||||||
local errorMSG = "Issue creating section '"..utils.dump(UCI_CONFIG_SECTION).."': "..utils.dump(msg);
|
local errorMSG = "Issue creating section '"..utils.dump(UCI_CONFIG_SECTION).."': "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
|
|
||||||
local base = getBaseKeyTable(key)
|
local base = getBaseKeyTable(key)
|
||||||
if not base then return false,ERR_NO_SUCH_KEY end
|
if not base then return false,ERR_NO_SUCH_KEY end
|
||||||
|
|
||||||
--log:info(MOD_ABBR, " base.type: "..utils.dump(base.type))
|
--log:info(" base.type: "..utils.dump(base.type))
|
||||||
if base.type == 'bool' then
|
if base.type == 'bool' then
|
||||||
if value ~= "" then
|
if value ~= "" then
|
||||||
value = utils.toboolean(value)
|
value = utils.toboolean(value)
|
||||||
@ -285,7 +283,7 @@ function M.set(key, value, noCommit)
|
|||||||
local rv, msg = uci:set(UCI_CONFIG_NAME, section, UCI_CONFIG_TYPE)
|
local rv, msg = uci:set(UCI_CONFIG_NAME, section, UCI_CONFIG_TYPE)
|
||||||
if not rv and msg ~= nil then
|
if not rv and msg ~= nil then
|
||||||
local errorMSG = "Issue getting subsection '"..utils.dump(base.subSection).."': "..utils.dump(msg);
|
local errorMSG = "Issue getting subsection '"..utils.dump(base.subSection).."': "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -294,14 +292,14 @@ function M.set(key, value, noCommit)
|
|||||||
local rv, msg = uci:set(UCI_CONFIG_NAME, section, key, toUciValue(value, base.type))
|
local rv, msg = uci:set(UCI_CONFIG_NAME, section, key, toUciValue(value, base.type))
|
||||||
if not rv and msg ~= nil then
|
if not rv and msg ~= nil then
|
||||||
local errorMSG = "Issue setting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg);
|
local errorMSG = "Issue setting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key)
|
local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key)
|
||||||
if not rv and msg ~= nil then
|
if not rv and msg ~= nil then
|
||||||
local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg);
|
local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -320,13 +318,13 @@ end
|
|||||||
-- @string key The key to set.
|
-- @string key The key to set.
|
||||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||||
function M.resetAll()
|
function M.resetAll()
|
||||||
log:info(MOD_ABBR, "settings:resetAll")
|
log:info("settings:resetAll")
|
||||||
|
|
||||||
-- find all sections
|
-- find all sections
|
||||||
local allSections, msg = uci:get_all(UCI_CONFIG_NAME)
|
local allSections, msg = uci:get_all(UCI_CONFIG_NAME)
|
||||||
if not allSections and msg ~= nil then
|
if not allSections and msg ~= nil then
|
||||||
local errorMSG = "Issue reading all settings: "..utils.dump(msg);
|
local errorMSG = "Issue reading all settings: "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -336,7 +334,7 @@ function M.resetAll()
|
|||||||
local rv, msg = uci:delete(UCI_CONFIG_NAME,key)
|
local rv, msg = uci:delete(UCI_CONFIG_NAME,key)
|
||||||
if not rv and msg ~= nil then
|
if not rv and msg ~= nil then
|
||||||
local errorMSG = "Issue deleting setting '"..utils.dump(key).."': "..utils.dump(msg);
|
local errorMSG = "Issue deleting setting '"..utils.dump(key).."': "..utils.dump(msg);
|
||||||
log:warning(MOD_ABBR, errorMSG)
|
log:info(errorMSG)
|
||||||
return nil, errorMSG;
|
return nil, errorMSG;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -358,7 +356,7 @@ end
|
|||||||
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when resetting multiple values
|
-- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when resetting multiple values
|
||||||
-- @treturn bool|nil True if everything went well, nil in case of error.
|
-- @treturn bool|nil True if everything went well, nil in case of error.
|
||||||
function M.reset(key, noCommit)
|
function M.reset(key, noCommit)
|
||||||
log:info(MOD_ABBR, "settings:reset: "..utils.dump(key))
|
log:info("settings:reset: "..utils.dump(key))
|
||||||
|
|
||||||
-- delete
|
-- delete
|
||||||
key = replaceDots(key)
|
key = replaceDots(key)
|
||||||
@ -373,7 +371,7 @@ function M.reset(key, noCommit)
|
|||||||
-- (which always happens when reset is used in resetall) it will also generate a error
|
-- (which always happens when reset is used in resetall) it will also generate a error
|
||||||
--if not rv and msg ~= nil then
|
--if not rv and msg ~= nil then
|
||||||
-- local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..section.."': "..utils.dump(msg);
|
-- local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..section.."': "..utils.dump(msg);
|
||||||
-- log:warning(MOD_ABBR, errorMSG)
|
-- log:info(errorMSG)
|
||||||
-- return nil, errorMSG;
|
-- return nil, errorMSG;
|
||||||
--end
|
--end
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
|
|
||||||
local MOD_ABBR = "USTS"
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local FOLDER = "/tmp/"
|
local FOLDER = "/tmp/"
|
||||||
@ -25,7 +23,7 @@ function M.get(fileName)
|
|||||||
local path = getPath(fileName)
|
local path = getPath(fileName)
|
||||||
local file, error = io.open(path,'r')
|
local file, error = io.open(path,'r')
|
||||||
if file == nil then
|
if file == nil then
|
||||||
--log:warning(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error)
|
--log:error("Util:Access:Can't read controller file. Error: "..error)
|
||||||
return "",""
|
return "",""
|
||||||
else
|
else
|
||||||
local status = file:read('*a')
|
local status = file:read('*a')
|
||||||
@ -37,7 +35,7 @@ function M.get(fileName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.set(fileName,code,msg)
|
function M.set(fileName,code,msg)
|
||||||
--log:info(MOD_ABBR, "setStatus: "..code.." | "..msg)
|
--log:info("setStatus: "..code.." | "..msg)
|
||||||
local path = getPath(fileName)
|
local path = getPath(fileName)
|
||||||
local file = io.open(path,'w')
|
local file = io.open(path,'w')
|
||||||
file:write(code.."|"..msg)
|
file:write(code.."|"..msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user