Working in dev but not after deploy

Just starting out? Need help? Post your questions and find answers here.
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Working in dev but not after deploy

Post 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.
bembulak
Posts: 71
Joined: Wed Feb 26, 2014 9:53 am

Re: Working in dev but not after deploy

Post 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).
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Working in dev but not after deploy

Post by Peter »

@itzybitzyspider:

What is the exact error message?
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Re: Working in dev but not after deploy

Post 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
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Re: Working in dev but not after deploy

Post 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.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Working in dev but not after deploy

Post 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())
itzybitzyspider
Posts: 27
Joined: Tue Nov 22, 2022 4:36 am

Re: Working in dev but not after deploy

Post by itzybitzyspider »

@Peter, you are king. Thank you for the knowledge.
Post Reply