Page 1 of 1

Working in dev but not after deploy

Posted: Wed Feb 08, 2023 10:42 pm
by itzybitzyspider
Hi guys,

I've got a small app testing printing to a EPSON TM30 POS printer.

I'm including external JS scripts from Epson and also some code that I have in JS format. Then after loading I'm just running a script to connect and test print. It works in dev but when I deploy, it doesn't work and I get a uncaught reference error like the script wasn't loaded. I checked the inspection and saw through the network tab that the relevant files are loaded.

Code: Select all

Global nLoaded
Global nImports = 2

Procedure Main()
  EnableJS
  Connect();
  DisableJS
EndProcedure


Procedure ScriptLoaded(URL$, Success)
  If Success
    nLoaded + 1
    If nLoaded = nImports ; the number of files to import
      Main()
    EndIf
  Else
    Debug "Failed to load external: " + URL$
  EndIf
EndProcedure

;Just open window
OpenWindow(0, 100, 100, 320, 200, "Window 0 - Resizable", #PB_Window_SizeGadget)

;from epson
LoadScript("epos-2.23.0.js", @ScriptLoaded())
;from myself
LoadScript("print.js", @ScriptLoaded())

Code: Select all

var ipAddress = "192.168.220.210";
var port = 8008;
var eposdev = new epson.ePOSDevice();
var printer = null;
var intervalID = null;

eposdev.onreconnecting = onReconnecting;
eposdev.onreconnect = onReconnect;
eposdev.ondisconnect = onDisconnect;

function onReconnecting(){
    console.log("reconnecting");
}
function onReconnect(){
    console.log("reconnect");
}
function onDisconnect(){
    console.log("clear");
    if ( intervalID == null ){
        intervalID = setInterval(function(){
            eposdev.connect(ipAddress, port, callback_connect);
        }, 5000);
    }
}

function Connect() {
    console.log("Connect() clear");
    eposdev.ondisconnect = null;
    eposdev.disconnect();
    eposdev.connect(ipAddress, port, callback_connect);

    console.log("Connect() clear2");
}


var printer = null;
function callback_createDevice(deviceObj, errorCode){
	console.log("callback_createDevice");
    if (deviceObj === null) {
        console.log("callback_createDevice error");
//Displays an error message if the system fails to retrieve the Printer object
        return;
    }
    printer = deviceObj;
	TestPrint();
//Registers the print complete event
    printer.onreceive = function(response){
        if (response.success) {
            console.log("OK! Everything");
			
        }
        else {

            console.log("NotOK! Everything");
        }
    };
}

function TestPrint() {
    printer.addText("\n\n");
    printer.addText("Test print:");
    printer.addText("\n\n");
                printer.addCut(printer.CUT_FEED);
    printer.send();
}


function callback_connect(data) {

    var deviceId = 'local_printer';
    var options = {'crypto' : false, 'buffer' : false};

    console.log("callback_connect");
    clearInterval(intervalID);
    intervalID = null;
    eposdev.ondisconnect = onDisconnect;
    console.log("Data", data);
    if (data == "OK" || data == "SSL_CONNECT_OK") {
        console.log("Printer conn");
        eposdev.createDevice(deviceId, eposdev.DEVICE_TYPE_PRINTER, options, callback_createDevice);
		console.log("Printing conn");

    } else {
        console.log('Recon');
        setTimeout(function(){
            eposdev.connect(ipAddress, port, callback_connect);
        }, 5000);
    }
}
For the epson js sdk
https://file.io/FXPWBBcsrQke

For creating the app, I'm simply putting the App Name, the HTML Filename and check the Copy spiderbasic libraries

Then deploy to webserver and try with SSL enabled.

Can someone look and see if I'm doing anything dumb here? Thanks.

Re: Working in dev but not after deploy

Posted: Fri Feb 10, 2023 7:43 am
by bembulak
Off topic:
Seems like another poor soul wants to update a firmware for Epson PoS/Fiscal printers via the Webinterface.


On topic:
I'm sorry, I can't test at the moment (no File.io access).

Re: Working in dev but not after deploy

Posted: Fri Feb 10, 2023 7:52 am
by Peter
@itzybitzyspider:

What is the exact error message?

Re: Working in dev but not after deploy

Posted: Tue Feb 14, 2023 2:30 am
by itzybitzyspider
@Peter,

Here's a capture

https://pasteboard.co/PiViJPerJpC8.png

It says reference error. I looked at the loaded files via network tab. I've pointed out the js files I'm loading externally.

https://pasteboard.co/3Zvd5MQ2mplG.png

So I'm not sure how the reference error happens.

Can you take a look and let me know. Thanks

Re: Working in dev but not after deploy

Posted: Tue Feb 14, 2023 2:32 am
by itzybitzyspider
bembulak wrote: Fri Feb 10, 2023 7:43 am Off topic:
Seems like another poor soul wants to update a firmware for Epson PoS/Fiscal printers via the Webinterface.


On topic:
I'm sorry, I can't test at the moment (no File.io access).
Nope, it's part of including that library so I can call it and print to the printer.
Not trying to update a firmware.

Re: Working in dev but not after deploy

Posted: Tue Feb 14, 2023 5:57 am
by Peter
1. Create a resource folder.
2. Copy epos-2.23.0.js into it.
3. In the "Create App" dialog specify the path of the resource folder.

Image

This code snippet works for me:

Code: Select all

Procedure Main()
  
  Protected ePosDev
  
  ! v_eposdev = new epson.ePOSDevice();
  
  If ePosDev
    MessageRequester("Seems to be OK")
  Else
    MessageRequester("Doesn't work")
  EndIf
    
EndProcedure

Procedure ScriptLoaded(URL$, Success)
  If Success
    Main()
  EndIf
EndProcedure

LoadScript("resources/epos-2.23.0.js", @ScriptLoaded())

Re: Working in dev but not after deploy

Posted: Sat Feb 25, 2023 5:43 am
by itzybitzyspider
@Peter, you are king. Thank you for the knowledge.