Error connecting to TM-U220 - javascript

I have downloaded 2 javascript SDK for Epson printer that supports TM-U220, and both of them won't connect to my printer and won't print. But when I tried to use other SDK such as QZ Tray, it worked, but the QZ Tray must be turned on, I want this to work in android, so I use the javascript SDK from Epson.
The problem is when I use the printer sample that Epson provided in the javascript SDK and input the ip: 192.168.1.98, port: 9100, and device id: local_printer, I got this error :
connected to ePOS Device Service Interface is failed. [ERROR_TIMEOUT]
.
But the printer did a small printing, letter that I can't read, and at the very end of the print : 2http/1.1. And in the console :
OPTIONS https://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 net::ERR_CONNECTION_REFUSED
and
OPTIONS https://192.168.1.98/cgi-bin/eposDisp/service.cgi?devid=local_display&timeout=10000 net::ERR_CONNECTION_REFUSED
I've also created my own simple code.
This is my first code using epos-2.3.0.js :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Print Test</title>
<script type="text/javascript" src="epos-2.3.0.js"></script>
<script type="text/javascript">
// Retrieving Printer objects (printer selection)
var printer = null;
// Retrieving Printer objects (printer selection)
// Creating ePOSDevice objects (device connection and communication)
var ePosDev = new epson.ePOSDevice();
function connect() {
var ipAddress = '192.168.1.98'; var port = '9100';
ePosDev.connect(ipAddress, port, callback_connect);
}
// Creating ePOSDevice objects (device connection and communication)
// Retrieving Printer objects (printer selection)
function callback_connect(resultConnect) {
var deviceId = 'local_printer';
var options = {'crypto' : false, 'buffer' : false};
if ((resultConnect == 'OK') || (resultConnect == 'SSL_CONNECT_OK')) {
// Retrieves the printer object
alert("Success callback connect");
ePostDev.createDevice(deviceId, ePosDev.DEVICE_TYPE_PRINTER, options, callback_createDevice);
}
else {
// Displays error messages
alert("Error callback connect");
}
}
function callback_createDevice(deviceObj, errorCode) {
if (deviceObj === null) {
// Displays an error message if the system fails to retreive the printer object
return;
}
printer = deviceObj;
// Registers the print complete event
printer.onreceive = function(response) {
if (response.success) {
// Displays the successful print message
alert("Callback create device response success");
}
else {
// Displays error messages
alert("Callback create device response failed");
}
}
}
// Retrieving Printer objects (printer selection)
// Creating print data (data buffering)
function createData() {
printer.addTextAlign(printer.ALIGN_CENTER);
printer.addText('Hello World\n');
}
// Creating print data (data buffering)
// Sending print data (printing and disconnection)
function send() {
if (ePosDev.isConnected) {
printer.send();
}
}
// Sending print data (printing and disconnection)
</script>
</head>
<body>
<input type="button" onclick="connect()" value="Connect" />
<input type="button" onClick="send()" value="Print Hello World" />
</body>
</html>
And this one I'm using epos-print-3.2.0.js :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Print Test 2</title>
<script type="text/javascript" src="epos-print-3.2.0.js"></script>
<script type="text/javascript">
function buildMessage() {
// Create a print document
var builder = new epson.ePOSBuilder();
builder.addTextLang('en');
builder.addTextSmooth(true);
builder.addTextFont(builder.FONT_A);
builder.addTextSize(3, 3);
builder.addText('Hello,\tWorld!\n');
builder.addCut(builder.CUT_FEED);
var request = builder.toString();
var address = 'http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000';
// Create an ePOS-Print object
var epos = new epson.ePOSPrint(address);
//Send the print document
epos.send(request);
}
</script>
</head>
<body>
<button onclick="buildMessage()">Run</button>
</body>
</html>
When I run the second code, I got this error in my console :
OPTIONS http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
and
XMLHttpRequest cannot load http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000. Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access. The response
had HTTP status code 405.
But When I change the address from
http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
to
http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
it printed me this :
OPTIONS /cgi-bin/epos/service.cgi?devid=local-printer&timeout=10000
HTTP/1.1 Host: 192.168.1.98:9100 Connection: keep-alive Access-Control-Request-Method: POST Origin: null
User-Agent: Mizilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Access-Control-Request-Headers: content-type, if-modified-since,
soapaction Accept: */* Accept-Encoding: gzip,
deflate,sdch Accept=Language: en-US, en;q=0.8

I was getting the same errors for a new TM-T88VI. Then I saw in the ePOS SDK User's Manual that in order to control a TM printer you need to enable the ePOS-Print setting from within the EpsonNet Config on the printer.
Looking at the manual in order to control a TM-U220 directly (without using a TM Intelligent printer) you'll need to have a UB-E04 or UB-R04 network interface installed. It says you can check which interfaces are installed by printing a status sheet.

From the look of it, this is a Cross Origin HTTP Request issue (CORS). This MDN article explains this: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
I am guessing that the IP 92.168.1.98 is the printer IP (which is on the local network). See: http://trendblog.net/ever-wondered-use-192-168-x-x-ip-addresses-home/ and you can access it via port 9100 as described in your post above.
So since your actual web application is residing on a different IP than the printer IP and the way the web work, CORS is required when you are calling to a different IP / host so to prevent cross site scripting attack.
It's common sense that if the printer is exposing itself via port 9100, you should have that as part of your URI. That is the reason why http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000 works and the other one did not.
As for trying to access this via an Android device... the question is does the device is joined to your local network (192.168....) or is it on the Internet? If it is joined to the internet, I don't think you can access the printer which is probably not going to be exposed to the internet (having public IP). As long as they belong to the same network, they should be able to talk. If not, you will need to expose it to the internet (bad idea) or make sure they can see each other (Android connecting to your corporate WIFI and the printer can be reached via the WIFI).

I had the same problem with a TM-T20III. You have to use the utility software from Epson for your printer. In the advanced network settings, there is a menu which call "Filters" and I add the IP address of my POS as accept address.

But When I change the address from
http://192.168.1.98/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
to
http://192.168.1.98:9100/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000
it printed me this :
Port 9100 is the raw input port of the printer, it seems to print the whole input request without interpreting it. ePOS Service seems to be available on ports 80 / 443.
I was getting the same errors for a new TM-T88VI. Then I saw in the ePOS SDK User's Manual that in order to control a TM printer you need to enable the ePOS-Print setting from within the EpsonNet Config on the printer.
Enabling the ePOS Print Service was the right solution for me. In order to do this, i had to update the firmware of the printer (TM-T88VI). In factory defaults, there was no option to switch on the ePOS Service.

Related

Trouble executing server-side cgi code from javascript or JQuery

I am trying to send a message from the webclient via JavaScript or JQuery to the Apache2 webserver on Debian Jessie, to execute a compiled C program that sends a POSIX message_queue, but I cannot get it to work.
I have the following files in my cgi directory:
root#asus:/var/www/cgi-bin# ls -l
-rwxr-xr-x 1 www-data www-data 59008 Mar 20 17:47 mq_client.cgi
-rwxr-xr-x 1 www-data www-data 115 Mar 17 18:14 test.pl
mq_client.cgi is a C-compiled executable that generates the POSIX message. If I execute
lachlan#asus:~$ /var/www/cgi-bin/mq_client.cgi
the correct message is sent and received by the server.
Test.pl is a perl scrpt that generates html code and if I execute
lachlan#asus:~$ /var/www/cgi-bin/test.pl
this works fine also and gives the output:
Content-type: text/html
Just testing.
If I use the chromium webserver as follows:
http://localhost/cgi-bin/test.pl
I get the correct result: 'Just Testing'
However, I have not been able to get the mq_client.cgi code to execute from the webserver. I have searched many website and tried many options as indicated below.
This is my code of “index.html” (Note the errors only occur when I press the button)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jq_182.js"></script>
<script type="text/javascript">
function mapToggle(){
// different options as indicated below
}
</script>
</head>
<body>
<div id = "label"> </div>
<form action = "" class = "mapButton">
<p> <button type= "button" onclick = "mapToggle()" class = "button2property"> Map Toggle </button> </p>
</form>
</body>
</html>
The different options I have tried (one by one) in the location indicated above are:
// option 1.
var site = 22;
$.ajax({type: "PUT", url: "/cgi-bin/mq_client.cgi", async: false, data: site});
This gives the following 2 errors in Chromium:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
jq_182.js:2
PUT http://localhost/cgi-bin/mq_client.cgi 500 (Internal Server Error)
// option 2.
var site = 22;
$.ajax({type: "GET", url: "/cgi-bin/mq_client.cgi", async: false, data: site});
This gives the following 2 errors:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
jq_182.js:2
GET http://localhost/cgi-bin/mq_client.cgi 500 (Internal Server Error)
// option 3.
var myRequest = new XMLHttpRequest();
myRequest.open("GET", "/cgi-bin/mq_client.cgi");
myRequest.send();
This gives the following error code:
index2.html:21 GET http://localhost/cgi-bin/mq_client.cgi 500 (Internal Server Error)
//option 4.
src = "/cgi-bin/mq_client.cgi";
No errors are indicated in Chromium, but there is also no message sent
// option 5.
var img = new Image();
img.src = "/cgi-bin/mq_client.cgi";
Resulting error: GET http://localhost/cgi-bin/mq_client.cgi 500 (Internal Server Error)
// option 6. Also changed the filename to index.shtml
<!--#exec cmd="/cgi-bin/mq_client.cgi" -->
No errors are indicated in Chromium, but there are no messages sent
// Option 7.
var client = new XMLHttpRequest();
client.open("post", "/cgi-bin/mq_client.cgi", true);
No errors are indicated in Chromium, but there are no messages sent.
// Option 8.
var client = new XMLHttpRequest();
var formx = new FormData();
formx.append("dummy","data");
client.open("post", "/cgi-bin/mq_client.cgi", true);
client.setRequestHeader("Content-Type", "multipart/form-data");
client.send(formx);
Error: index2.html:45 POST http://localhost/cgi-bin/mq_client.cgi 500 (Internal Server Error)
I have reviewed many references and tried their suggestions, but have not yet solved the problem.
Any ideas on where to look for the problem would be appreciated.
Lachlan
The Server side code generates a POSIX Message queue:
The server code sends out a POSIX message to a server. The code is as follows:
int main(void) {
char msg[5];
// Open queue already created
mqd_t mQueue = mq_open("q1", O_WRONLY, NULL);
if (mQueue == (mqd_t) -1){
puts("Queue Open Failed\n");
return EXIT_FAILURE;
}
puts("Queue Opened\n");
// Send Message
msg[0] = 22;
if ( mq_send(mQueue, msg, 5, 1) == -1){
puts("Queue Send Failure\n");
return EXIT_FAILURE;
}
puts("Message Sent\n");
mq_close(mQueue);
return EXIT_SUCCESS;
}
Here is the Server code to receive the message queue:
int main(void) {
char msg[MAX_MSG_SIZE];
unsigned int prio;
ssize_t msgLength = 0;
// Create queue
struct mq_attr attr;
attr.mq_maxmsg = 4;
attr.mq_msgsize = 5;
mQueue = mq_open(“q1”, O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO, &attr);
if (mQueue == (mqd_t) -1){
puts("Queue Create Failed\n");
return EXIT_FAILURE;
}
puts("Queue Created\n");
// get message - This blocks
msgLength = mq_receive(mQueue, msg, MAX_MSG_SIZE, &prio);
if (msgLength == -1){
puts("Queue Read Failure\n");
return EXIT_FAILURE;
}
printf("Message Received: %i\n", (int)msg[0]);
mq_close(mQueue);
return EXIT_SUCCESS;
}
The permissions to access the server queue are:
S_IRWXU | S_IRWXG | S_IRWXO
The permissions for executing the cgi code are:
-rwxr-xr-x 1 www-data www-data 59008 Mar 20 17:47 mq_client.cgi
If this is a permission problem can you suggest which permissions are missing?
I finally found another post that helped solve the problem. Yes it was a permissions problem. The program permissions were overriding the message queue permissions. Once this was addressed the problem was solved.
Regards
Lachlan

Indesign javascript Socket always performs requests using host: localhost

I'm trying to use a Socket connection to read a file on a remote website. So far, my code:
conn = new Socket;
if( conn.open( 'example.com:80' ) ) {
conn.write( 'GET /indesign-page/ HTTP/1.0' + "\n\n" );
reply = conn.read(999999);
conn.close();
} else {
alert( 'Problem connecting to server' );
}
The socket connects to example.com fine, but the request comes across as this:
GET http://localhost/indesign-page/ HTTP/1.0
when it should be this:
GET http://example.com/indesign-page/ HTTP/1.0
I've tried changing the conn.write parameters to 'GET http://example.com/indesign-page/ ...', but then it comes across as:
GET http://localhosthttp://example.com/indesign-page/ HTTP/1.0
The webserver requires that the host be set correctly to serve correctly.
You need to set the "Host" header.
conn.write( 'GET /indesign-page/ HTTP/1.0' + "Host: example.com\r\n" + "\n\n" );
Because conn.open( 'example.com:80' ) means find example.com's server ip then connect that ip address at 80 port, so the web server does not know that you had resolved example.com before connected to it.
Do you need to use a manual socket object? On Adobe's Community Site there's a mention to this already created FTP Script where you could call a GET or PUT to a file on a FTP server.
Otherwise which OS are you using? If you'll always be on a Mac, you could shell out to an AppleScript command and place the file anywhere you'd like:
var command = 'do shell script "curl http://localhost/indesign-page"';
var response = app.doScript(command, ScriptLanguage.APPLESCRIPT_LANGUAGE);
The nice thing about the AppleScript is that you can execute the command manually using the AppleScript Editor (or Script Editor if you're earlier than 10.6).

error on connecting to the server : socket io is not defined

i know there's been couple of question about the same problem , i've already check them .
i have very simple node.js chat app
i have a server running on 8000 port and it works fine
my client pages are html , they are running on apache and i'm using socket.io to connect them to the server and it works fine on the local host
but when i upload the app on the server i keep on getting this error in the firebug
io is not defined
var socket = io.connect('http://atenak.com:8000/');
or sometimes it doesn't show that but when i try to broadcast message from cliend i get this error :
socket is undefined
socket.emit('msg', { data: msg , user:'max' });
the only difference is i've changed the localhost with atenak.com !
here is my html code
var socket = io.connect('http://atenak.com:8000/');
var user = 'jack';
socket.on('newmsg', function (data) {
if(data.user == user )
{
$('#container').html(data.data);
}
});
function brodcast(){
var msg = $('#fild').val();
socket.emit('msg', { data: msg , user:'max' });
}
</script>
</head>
<body>
<div id="container"> </div>
<input id="fild" type="text"> <input name="" type="button" onClick="brodcast();">
</body>
i have included the sockt.io.js
src="http://atenak.com:8000/socket.io/socket.io.js"
and server is running ok which means socket.io is installed on the server
here is the live page
http://atenak.com/client.html
I'm getting:
> Uncaught ReferenceError: io is not defined client.html:7
x GET http://atenak.com:8000/socket.io/socket.io.js
indicating that your page cannot load http://atenak.com:8000/socket.io/socket.io.js; indeed, if you try to load that URL in the browser, you get a connection error. Make sure that your Node.js server (running Socket.IO) is accessible (e.g. ports not being blocked by a firewall, etc).
Seems port 8000 is not open on your host as per links below
Reverse ip check for atenak.com and Open port check
Socket.io need a javascript file and this file does not load correctly.
Here is the url: http://atenak.com:8000/socket.io/socket.io.js
In this file is defined the îo object.

python websocket handshake (RFC 6455)

I am trying to implement a simple websoket server on python, using RFC 6455 protocol.
I took handshake format from here and here.
I am using Chromium 17 and Firefox 11 as clients, and getting this error:
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
I expect to see hello from server in my browser and hello from client in server log.
I guess my handshake is wrong, can you point me to my mistake?
##Server log, request:
GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 127.0.0.1:8999
Origin: null
Sec-WebSocket-Key: 8rYWWxsBPEigeGKDRNOndg==
Sec-WebSocket-Version: 13
##Server log, response:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 3aDXXmPbE5e9i08zb9mygfPlCVw=
##Raw-string response:
HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: 3aDXXmPbE5e9i08zb9mygfPlCVw=\r\n\r\n
##Server code:
import socket
import re
from base64 import b64encode
from hashlib import sha1
websocket_answer = (
'HTTP/1.1 101 Switching Protocols',
'Upgrade: websocket',
'Connection: Upgrade',
'Sec-WebSocket-Accept: {key}\r\n\r\n',
)
GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 8999))
s.listen(1)
client, address = s.accept()
text = client.recv(1024)
print text
key = (re.search('Sec-WebSocket-Key:\s+(.*?)[\n\r]+', text)
.groups()[0]
.strip())
response_key = b64encode(sha1(key + GUID).digest())
response = '\r\n'.join(websocket_answer).format(key=response_key)
print response
client.send(response)
print client.recv(1024)
client.send('hello from server')
##Client code:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
var s = new WebSocket('ws://127.0.0.1:8999');
s.onmessage = function(t){alert(t)};
s.send('hello from client');
</script>
</head>
<body>
</body>
</html>
Your server handshake code looks good.
The client code looks like it'll try to send a message before the (asynchronous) handshake completes however. You could avoid this by moving your message send into your websocket's onopen method.
Once the connection is established, the server does not send or receive messages as plain text. See the data framing section of the spec for details. (Client code can ignore this as the browser takes care of data framing for you.)
I was trying the same thing, but could never get it working. In the end i found an article Library for building WebSocket servers and clients in Python by Aymeric Augustin. The way he does it (code below) does the handshake for you automatically.
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
await websocket.send(message)
asyncio.get_event_loop().run_until_complete(websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()

Cross domain access permission denied in iframe

I am trying to embed OWA (Microsoft Exchange Server 2010) in a web page within an iframe but I get a JavaScript error on the OWA page saying Access Denied and then none of the controls within the OWA window work.
I have to use OWA in web page, I read in the form that cross domain does not work properly. Error comes as:
Client Information
User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 GTB7.1 (.NET CLR 3.5.30729)
CPU Class: undefined
Platform: Win32
System Language: undefined
User Language: en-US
CookieEnabled: true
Exception Details
Date: Wed Oct 27 2010 10:17:05 GMT+0530 (India Standard Time)
Message: Permission denied for <http://domain_2> to get property HTMLIFrameElement.ownerDocument from <domain_1>.
Url: http://domain_2/owa/testuser#exch2k10.com/14.0.639.21/scripts/premium/uglobal.js
Line: 1
Call Stack
undefinedError()#:0 window$onerror("Permission denied for <http://domain_2> to get property HTMLIFrameElement.ownerDocument from <domain_1>.","http://domain_2/owa/testuser#exch2k10.com/14.0.639.21/scripts/premium/uglobal.js",1)#http://domain_2/owa/testuser#exch2k10.com/14.0.639.21/scripts/premium/uglobal.js:1 (domain_1>.","http://domain_2/owa/testuser#exch2k10.com/14.0.639.21/scripts/premium/uglobal.js",1%29#http://domain_2/owa/testuser#exch2k10.com/14.0.639.21/scripts/premium/uglobal.js:1) function Array$get_Length() { return this.length; } function Array$get_Item(index) { return this[index]; } function Array$get_Enumerator() { return new (Owa.Collections.ListEnumerator)(this); } function Array$remove(oItem) { var index = this.indexOf(oItem); if (index > -1) { this.splice(index, 1); } return index > -1; } function Array$removeAt(iIndex) { if (iIndex < this.length) { this.splice(iIndex, 1); return true; } return false; } function Array$add(oItem) { this.push(oItem); } function Array$clone() {
What I saw is that the error comes when uglobal.js which comes with the Exchange in the iframe trying to access property of parent.
Message: Permission denied for <http://domain_2> to get property HTMLIFrameElement.ownerDocument from <domain_1>.
Is there any other way by which I can use OWA in my page?
That's the cross domain policy restricting you. It's designed to prevent cross site scripting (XSS) attacks.
Basically, only pages from the same domain, protocol and port can alter each other's content.
I faced similar issues when trying to make cross domain calls. For IE8 you can use the following approach
var xdr = new XDomainRequest();
xdr.open("get", "http://domain2");
xdr.onload = function(){
//your code
};
xdr.send();
Additionally in IE only for testing purposes there is an option to add the specific address (domain1 in your case) to the trusted list Tools>Security>Trusted Sites>Sites and allow it to make cross domain requests by going to custom level and selecting Access data sources across domains. Please ensure the second is used only for testing.
If no JSONP solution exists, build a server side proxy.

Categories

Resources