diff --git a/src/FIRMWARE-VERSION b/src/FIRMWARE-VERSION index 2003b63..85b7c69 100644 --- a/src/FIRMWARE-VERSION +++ b/src/FIRMWARE-VERSION @@ -1 +1 @@ -0.9.2 +0.9.6 diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index c7141b6..fd4ebbb 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -13,6 +13,8 @@ NOTE that the all-caps definitions will be changed into configuration keys, or moved to a different location ]]-- local printer = require('util.printer') +local log = require('util.logger') +local utils = require('util.utils') local M = {} @@ -84,6 +86,18 @@ M.printer_type = { return printers[value] ~= nil end } +M.printer_bed_width = { + default = 220, + type = 'int', + description = '', + min = 0 +} +M.printer_bed_height = { + default = 220, + type = 'int', + description = '', + min = 0 +} M.printer_baudrate = { default = '115200', @@ -207,18 +221,30 @@ M.printer_enableTraveling = { description = '' } -M.printer_startgcode = { +M.printer_startcode_marlin = { default = ';Generated with Doodle3D\nM109 S{printingTemp} ;set target temperature \n;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)', type = 'string', description = '' } -M.printer_endgcode = { +M.printer_endcode_marlin = { 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;M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)', type = 'string', description = '' } +M.printer_startcode_x3g = { + default = '(**** CONFIGURATION MACROS ****)\n;@printer r2x\n;@enable progress\n(** This GCode was generated by ReplicatorG 0040 **)\n(* using Skeinforge (50) *)\n(* for a Dual headed Replicator 2 *)\n(* on 2013/10/27 15:07:27 (+0100) *)\n(**** start.gcode for Replicator 2X, single head ****)\nM103 (disable RPM)\nM73 P0 (enable build progress)\nG21 (set units to mm)\nG90 (set positioning to absolute)\nM104 S240 T0 (set extruder temperature) (temp updated by printOMatic)\nM140 S110 T0 (set HBP temperature)\n(**** begin homing ****)\nG162 X Y F2500 (home XY axes maximum)\nG161 Z F1100 (home Z axis minimum)\nG92 Z-5 (set Z to -5)\nG1 Z0.0 (move Z to "0")\nG161 Z F100 (home Z axis minimum)\nM132 X Y Z A B (Recall stored home offsets for XYZAB axis)\n(**** end homing ****)\nG1 X-141 Y-74 Z10 F3300.0 (move to waiting position)\nG130 X20 Y20 Z20 A20 B20 (Lower stepper Vrefs while heating)\nM6 T0 (wait for toolhead, and HBP to reach temperature)\nG130 X127 Y127 Z40 A127 B127 (Set Stepper motor Vref to defaults)\nM108 R3.0 T0\nG0 X-141 Y-74 (Position Nozzle)\nG0 Z0.6 (Position Height)\nM108 R5.0 (Set Extruder Speed)\nM101 (Start Extruder)\nG4 P2000 (Create Anchor)\nG92 X0 Y0\nM106\n(**** end of start.gcode ****)', + type = 'string', + description = '' +} + +M.printer_endcode_x3g = { + default = '(******* End.gcode*******)\nM73 P100 ( End build progress )\nG0 Z150 ( Send Z axis to bottom of machine )\nM18 ( Disable steppers )\nM104 S0 T0 ( Cool down the Right Extruder )\nG162 X Y F2500 ( Home XY endstops )\nM18 ( Disable stepper motors )\nM70 P5 ( We <3 Making Things!)\nM72 P1 ( Play Ta-Da song )\n(*********end End.gcode*******)', + type = 'string', + description = '' +} + M.printer_maxObjectHeight = { default = 150, type = 'int', diff --git a/src/network/signin.lua b/src/network/signin.lua index e1a2f2e..9a27096 100644 --- a/src/network/signin.lua +++ b/src/network/signin.lua @@ -4,12 +4,33 @@ local uci = require('uci').cursor() local iwinfo = require('iwinfo') local settings = require('util.settings') local wifi = require("network.wlanconfig") +local urlcode = require('util.urlcode') +local status = require('util.status') local M = {} +local STATUS_FILE = "signinstatus" + +local IDLE_STATUS = 1 +local SIGNING_IN_STATUS = 2 + --- Signin to connect.doodle3d.com server -- function M.signin() + + --log:debug("signin:signin"); + + local code, msg = M.getStatus() + --log:debug(" status: "..utils.dump(code).." "..utils.dump(msg)); + + -- if we are already signin in, skip + if(code == SIGNING_IN_STATUS) then + log:debug(" skipping signin") + return + end + + M.setStatus(SIGNING_IN_STATUS,"signing in") + local baseurl = "http://connect.doodle3d.com/api/signin.php" local localip = wifi.getLocalIP(); @@ -19,12 +40,24 @@ function M.signin() end local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid')) + wifiboxid = urlcode.escape(wifiboxid) local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip; local output = utils.captureCommandOutput(cmd); log:info("signin: "..output) + M.setStatus(IDLE_STATUS,"idle") + return string.len(output) > 0, output end +function M.getStatus() + return status.get(STATUS_FILE); +end + +function M.setStatus(code,msg) + log:info("signin:setStatus: "..code.." | "..msg) + status.set(STATUS_FILE,code,msg); +end + return M \ No newline at end of file diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index 0ea2c18..137f491 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -2,7 +2,7 @@ local log = require('util.logger') local utils = require('util.utils') local settings = require('util.settings') local printer = require('util.printer') -local signin = require('network.signin') +--local signin = require('network.signin') local wifi = require('network.wlanconfig') local accessManager = require('util.access') local printerAPI = require('rest.api.api_printer') @@ -72,12 +72,13 @@ function M._global_POST(request, response) local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) response:addData("substituted_ssid",substitutedSsid) - log:info("API:Network:try signing in") + -- we now call signin seperatly trough cgi-bin + --[[log:info("API:Network:try signing in") if signin.signin() then log:info("API:Network:signin successfull") else log:info("API:Network:signin failed") - end + end]]-- end function M.all_GET(request, response) diff --git a/src/rest/api/api_info.lua b/src/rest/api/api_info.lua index 8dc8753..6645064 100644 --- a/src/rest/api/api_info.lua +++ b/src/rest/api/api_info.lua @@ -5,6 +5,7 @@ local accessManager = require('util.access') local printDriver = require('print3d') local printerUtils = require('util.printer') local printerAPI = require('rest.api.api_printer') +local wifi = require('network.wlanconfig') local TMP_DIR = '/tmp' local LOG_COLLECT_DIRNAME = 'wifibox-logs' @@ -112,10 +113,13 @@ end function M.status(request, response) + local ds = wifi.getDeviceState() + log:debug(" ssid: "..utils.dump(ds.ssid)) + local rv rv, state = printerAPI.state(request, response) if(rv == false) then return end - + if(state ~= "disconnected") then rv = printerAPI.temperature(request, response) if(rv == false) then return end diff --git a/src/rest/api/api_network.lua b/src/rest/api/api_network.lua index fa6c344..af5d1da 100644 --- a/src/rest/api/api_network.lua +++ b/src/rest/api/api_network.lua @@ -209,6 +209,10 @@ end function M.alive(request, response) response:setSuccess("alive") + + local ds = wifi.getDeviceState() + log:debug(" ssid: "..utils.dump(ds.ssid)) + end return M diff --git a/src/rest/api/api_printer.lua b/src/rest/api/api_printer.lua index 908642f..054e0b2 100644 --- a/src/rest/api/api_printer.lua +++ b/src/rest/api/api_printer.lua @@ -119,26 +119,32 @@ function M.stop_POST(request, response) end local argId = request:get("id") + local argGcode = request:get("gcode") local printer,msg = printerUtils.createPrinterOrFail(argId, response) if not printer then return end - -- replacing {printingTemp} and {preheatTemp} in endgcode + --[[ + -- replacing variables in endgcode local printingTemperature = settings.get('printer.temperature') local printingBedTemperature = settings.get('printer.bed.temperature') local preheatTemperature = settings.get('printer.heatup.temperature') local preheatBedTemperature = settings.get('printer.heatup.bed.temperature') - local endGcode = settings.get('printer.endgcode') + local endCode = settings.get('printer.endcode.marlin') --log:info(" printingBedTemperature: "..utils.dump(printingBedTemperature)) --log:info(" preheatBedTemperature: "..utils.dump(preheatBedTemperature)) - --log:info(" endGcode : "..utils.dump(endGcode)) - endGcode = string.gsub(endGcode,"{printingTemp}",printingTemperature) - endGcode = string.gsub(endGcode,"{printingBedTemp}",printingBedTemperature) - endGcode = string.gsub(endGcode,"{preheatTemp}",preheatTemperature) - endGcode = string.gsub(endGcode,"{preheatBedTemp}",preheatBedTemperature) - --log:info(" >endGcode : "..utils.dump(endGcode)) - - local rv,msg = printer:stopPrint(endGcode) + --log:info(" endCode : "..utils.dump(endCode)) + endCode = string.gsub(endCode,"{printingTemp}",printingTemperature) + endCode = string.gsub(endCode,"{printingBedTemp}",printingBedTemperature) + endCode = string.gsub(endCode,"{preheatTemp}",preheatTemperature) + endCode = string.gsub(endCode,"{preheatBedTemp}",preheatBedTemperature) + --log:info(" >endCode : "..utils.dump(endCode)) + ]]-- + + if(argGcode == nil) then + argGcode = "" + end + local rv,msg = printer:stopPrint(argGcode) response:addData('id', argId) if rv then response:setSuccess() diff --git a/src/util/printer.lua b/src/util/printer.lua index 13f65a2..2c8fa43 100644 --- a/src/util/printer.lua +++ b/src/util/printer.lua @@ -33,7 +33,9 @@ local SUPPORTED_PRINTERS = { robo_3d_printer = "RoBo 3D Printer", shapercube = "ShaperCube", tantillus = "Tantillus", - vision_3d_printer = "Vision 3D Printer" + vision_3d_printer = "Vision 3D Printer", + marlin_generic = "Generic Marlin Printer", + makerbot_generic = "Generic Makerbot Printer" } local SUPPORTED_BAUDRATES = { ["115200"] = "115200 bps", diff --git a/src/util/status.lua b/src/util/status.lua new file mode 100644 index 0000000..f2368a0 --- /dev/null +++ b/src/util/status.lua @@ -0,0 +1,38 @@ +local log = require('util.logger') +local utils = require('util.utils') + +local M = {} + +local FOLDER = "/tmp/" +local FILE_PREFIX = "d3d-" +local FILE_EXTENSION = ".txt" + +function getPath(fileName) + return FOLDER..FILE_PREFIX..fileName..FILE_EXTENSION +end + +function M.get(fileName) + local path = getPath(fileName) + local file, error = io.open(path,'r') + if file == nil then + --log:error("Util:Access:Can't read controller file. Error: "..error) + return "","" + else + local status = file:read('*a') + file:close() + local code, msg = string.match(status, '([^|]+)|+(.*)') + code = tonumber(code) + return code,msg + end +end + +function M.set(fileName,code,msg) + --log:info("setStatus: "..code.." | "..msg) + local path = getPath(fileName) + local file = io.open(path,'w') + file:write(code.."|"..msg) + file:flush() + file:close() +end + +return M