diff --git a/extra/scripts/auto-flash.sh b/extra/scripts/auto-flash.sh new file mode 100755 index 0000000..da5b486 --- /dev/null +++ b/extra/scripts/auto-flash.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Adapted from: http://wiki.openwrt.org/toh/tp-link/tl-mr3020?s[]=3020#oem.mass.flashing + +# Pass the firmware file to be flashed as the first parameter. +# +# The second curl call will time out, but it's expected. Once the +# script exits you can unplug the ethernet cable and proceed to the +# next router, but KEEP each router ON POWER until the new image is +# fully written! When flashing is done the router automatically +# reboots (as shown by all the leds flashing once). + +#IMAGE_FILE_DEFAULT=bin/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin +IMAGE_FILE_DEFAULT=bin/ar71xx/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin + +QUIET=no +IMAGE_FILE=$IMAGE_FILE_DEFAULT + +while getopts hqf: arg; do + case $arg in + h) + echo "$0: automatically flash an openwrt image to a TP-Link MR3020;" + echo " default image file: '$IMAGE_FILE_DEFAULT';" + echo " pass -q to be less verbose and optionally specify a different image file." + exit + ;; + q) + QUIET=yes + ;; + f) + IMAGE_FILE=$OPTARG + ;; + esac +done + +if [ ! -f $IMAGE_FILE ]; then + echo "$0: image '$IMAGE_FILE' does not exist" + exit 1 +fi + +if [ $QUIET == "yes" ]; then + exec > /dev/null +fi + + +curl \ + --user admin:admin \ + --user-agent 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0' \ + --referer 'http://192.168.0.254/userRpm/SoftwareUpgradeRpm.htm' \ + --form "Filename=@$IMAGE_FILE" -F 'Upgrade=Upgrade' \ + http://192.168.0.254/incoming/Firmware.htm + +sleep 1 + +curl \ + --max-time 2 \ + --user admin:admin \ + --user-agent 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0' \ + --referer 'http://192.168.0.254/incoming/Firmware.htm' \ + http://192.168.0.254/userRpm/FirmwareUpdateTemp.htm diff --git a/src/rest/api/api_printer.lua b/src/rest/api/api_printer.lua index a0c1429..5d27901 100644 --- a/src/rest/api/api_printer.lua +++ b/src/rest/api/api_printer.lua @@ -12,7 +12,7 @@ local ULTIFI_BASE_PATH = '/tmp/UltiFi' local TEMPERATURE_FILE = 'temp.out' local PROGRESS_FILE = 'progress2.out' local COMMAND_FILE = 'command.in' -local GCODE_TMP_FILE = '/tmp/UltiFi/combined.gc' +local GCODE_TMP_FILE = 'combined.gc' -- returns full path + ultifi path or nil local function printerExists(id) @@ -66,13 +66,15 @@ local function sendGcode(printerPath, gcode) return true end -local function addToGcodeFile(gcode) +local function addToGcodeFile(printerPath, gcode) if not gcode or type(gcode) ~= 'string' then return nil,"missing gcode data" end - local gcf,msg = io.open(GCODE_TMP_FILE, 'a+') + local gtFile = printerPath .. '/' .. GCODE_TMP_FILE + + local gcf,msg = io.open(gtFile, 'a+') if not gcf then return nil,msg end - log:debug("appending " .. gcode:len() .. " bytes of gcode to " .. GCODE_TMP_FILE) + log:debug("appending " .. gcode:len() .. " bytes of gcode to " .. gtFile) gcf:write(gcode) gcf:write("\n") gcf:close() @@ -83,14 +85,15 @@ end -- assumes printerPath exists, returns true if successful, false if command file already exists and is non-empty (i.e. printer busy), -- nil+err if file could not be opened local function printGcodeFile(printerPath) + local gtFile = printerPath .. '/' .. GCODE_TMP_FILE local cmdPath = printerPath .. '/' .. COMMAND_FILE local cmdf,msg = io.open(cmdPath, 'a+') -- 'a+' is important, do not overwrite current contents in any case if not cmdf then return nil,msg end if utils.fileSize(cmdf) > 0 then return false end - log:debug("starting print of gcode in " .. GCODE_TMP_FILE) - cmdf:write('(SENDFILE=' .. GCODE_TMP_FILE) + log:debug("starting print of gcode in " .. gtFile) + cmdf:write('(SENDFILE=' .. gtFile) cmdf:close() return true @@ -277,6 +280,8 @@ end --accepts: last(bool) (chunks will be concatenated and only when this argument is true will printing be started) function M.print_POST(request, response) local argId,devpath,ultipath = getPrinterDataOrFail(request, response) + local gtFile = ultipath .. '/' .. GCODE_TMP_FILE + if argId == nil then return end local argGcode = request:get("gcode") @@ -289,14 +294,14 @@ function M.print_POST(request, response) end if argIsFirst == true then - log:debug("clearing all gcode in " .. GCODE_TMP_FILE) + log:debug("clearing all gcode in " .. gtFile) response:addData('gcode_clear',true) - os.remove(GCODE_TMP_FILE) + os.remove(gtFile) end local rv,msg - rv,msg = addToGcodeFile(argGcode) + rv,msg = addToGcodeFile(ultipath, argGcode) if rv == nil then response:setError("could not add gcode") response:addData('msg', msg)