Setting up an Epson receipt printer

I recently picked up one of these networked thermal receipt printers.

Epson receipt printer
An open Epson receipt printer

Being Point-of-Sale equipment, these come from a different tradition of printing, and have only a few things in common with regular laser printers. This post will cover the basic steps to getting the printer up and running.

This one is model TM-T82II.

Setting up the printer

Firstly, this particular printer only has an ethernet interface, which comes configured with a static IP by default, rather than DHCP. Holding the button next to the network port prints out the settings:

Epson receipt printer network card.
Epson receipt printer network settings.

The IP address of the printer is shown 192.168.192.168, and subnet mask 255.255.255.0. To speak to it, we need a computer on the same subnet— in this case the last number of the IP address is the only part which needs to be different.

On GNU/Linux, this is best done with ifconfig:

sudo ifconfig eth0 192.168.192.169 netmask 255.255.255.0

If you used the correct interface, address and netmask, then you should now be able to ping the printer:

$ sudo ifconfig
eth0      Link encap:Ethernet  HWaddr ...
          inet addr:192.168.192.169  Bcast:192.168.192.255  Mask:255.255.255.0
          ...
$ ping 192.168.192.168
PING 192.168.192.168 (192.168.192.168) 56(84) bytes of data.
64 bytes from 192.168.192.168: icmp_seq=1 ttl=255 time=1.09 ms
64 bytes from 192.168.192.168: icmp_seq=2 ttl=255 time=0.506 ms
...

The printer has a web interface, and is open on two ports for printing:

$ nmap 192.168.192.168
...
PORT     STATE SERVICE
80/tcp   open  http
515/tcp  open  printer
9100/tcp open  jetdirect

The web interface will let you set different IP settings, so that you can get the printer on your network. If you mess up and can’t connect, then do a factory reset: Hold the button used before, and then reboot the printer.

Using the printer

Epson provides drivers for several platforms, which may fit your use case.

However, these printers do support ESC/POS (See Wikipedia). making it quite accessible without installed drivers.

The printer will immediately print any regular text it receives over Port 9100, line by line:

echo "Hello World" | nc 192.168.192.168 9100

ESC/POS commands allow you to to format the text, print barcodes, and cut the paper. A good resource for them is this PDF reference from Epson.

I’ve included a PHP script to produce the ESC/POS commands for the below receipt, showing how to use a few of the supported features:

Example receipt from an Epson receipt printer, printed using PHP

And the script which created it:

<?php
/* ASCII constants */
const ESC = "\x1b";
const GS="\x1d";
const NUL="\x00";

/* Output an example receipt */
echo ESC."@"; // Reset to defaults
echo ESC."E".chr(1); // Bold
echo "FOO CORP Ltd.\n"; // Company
echo ESC."E".chr(0); // Not Bold
echo ESC."d".chr(1); // Blank line
echo "Receipt for whatever\n"; // Print text
echo ESC."d".chr(4); // 4 Blank lines

/* Bar-code at the end */
echo ESC."a".chr(1); // Centered printing
echo GS."k".chr(4)."987654321".NUL; // Print barcode
echo ESC."d".chr(1); // Blank line
echo "987654321\n"; // Print number
echo GS."V\x41".chr(3); // Cut
exit(0);

This would again sent to the printer using netcat:

php foo.php | nc 192.168.192.168 9100

Good luck!

23 Replies to “Setting up an Epson receipt printer”

  1. Hi,
    I want to send the hello text in php alone without using the shell or cmd.
    Do I write a php file with data then include the script with the formatting.
    How do I work in php alone without DOS or CMD shell
    Thanks
    David

  2. Hi Mike,

    I am using a pos system which prints German Umlauts and thee Euro sign right away.

    When I print via your php library, I only get the Umlauts to work by default. cut and close my print job yet, afterwards the other pos system no longer can also find the euro sign?! How come..

    And your cut command gives me only half cut by default the other pos system fully cuts it off…

    Your feed really appreciated, THX! Still great works of yours all in all…

    I hoppe your cms here tells me about replies ;)

  3. Hi actually i developed an e-commerce website so in that i have a seller Panel and when a order will come to a particular seller panel he should be able to print that order in to the THERMAL PRINTER by Bluetooth from the website. so i am now in the order page so when i am trying to print A4 size paper is coming but i want to print to the THERMAL PRINTER so is there any chances to print from website? please help me out..

  4. Hey, I don’t have any posts that discuss browser-based print setups at the moment, but I’ll take this on board as a possible future topic.

  5. Hey, how do you print a qr code?
    The manuals don’t explain it very well, and I wasn’t able to find it in your code on github.
    I’m writing my code in python, but I only need to know the correct sequence for the qr code.
    Thanks

  6. Dear Mr.Mike,

    Hope, you are doing good.

    I need a clarification from you. My project source is at the server. How can my code at the server find the POS printers installed in the client computer?

    Thanks in advance.

  7. @Sobotkama Your vendor’s programming guide is actually the best source for this. If you’re interested, my QR code implementation for mike42/escpos-php is here, see here for the PHP usage, and consider checking out python-escpos/python-escpos for python, which I have also contributed ESC/POS QR code rendering to. Best of luck!

  8. Dear Mr.Mike,

    Thanks for your kind reply.

    how to find that the epson printer is in online?
    By the way, how to get the response from the epson printer that the print task has been successfully finished? I checked this “getPrinterStatus” method which is not currently available in the printer.php file. Could you please help me outta this?

  9. Hi All,

    I’m new for Epson TM-T20II integration ,can any one please give a for integrate our website.Currently we use PHP platform.

  10. @alejandro – Check out the pulse() function in the GitHub readme. Check your cash drawer vendor docs if you have issues with the default pulse durations.

  11. Hi Mike,

    thank you for the great info. Wondering if you had an idea on how to map a linux device to the netcat command so that I could “convert” the printer to be a local one ?

  12. my pos code working in localhost when i use online server it can not connect to the system what i do??

  13. Hi Mike!

    Thanks for the code, it was really helpful to get us started on how to send commands to our printer, an Epson TM-T88IV model.

    We adapted the php script to parse a query string and send commands to the printer using fsockopen/fclose. The script is hosted on a RaspberryPi on the same network as our printer.

    The script works the first time it is called, but subsequent ones are random and takes a long time before the printer does anything.

    Just wondering what could be the issue? Is there is a “end print” command to send to the printer that we missed out?

  14. Hi Mike,

    Fantastic work with ESC/POS print driver.

    I’m getting started with adding support for thermal print in a Cloud-based POS application.

    I have a few question:
    1. How can we allow users to use the printer connected in their local machine? Can we do it if the user has a static IP and we use that IP to connect to his computer and then send binary code to the printer? Maybe using “NetworkPrintConnector”?

    How can we do the above for Windows, iOS and Linux?

    It will be great if you point out to some solution to it. Looking forward to a response.

    Thank you in advance.

  15. Hello Mike,

    I am facing problem: atal error: Uncaught Error: Class ‘Mike42\Escpos\PrintConnectors\WindowsPrintConnector’ not found in C:\wamp64\www\VorTex\POSInv\example\demo.php on line 23
    ( ! ) Error: Class ‘Mike42\Escpos\PrintConnectors\WindowsPrintConnector’ not found in C:\wamp64\www\VorTex\POSInv\example\demo.php on line 23

    Please advice where should be copy the Mike42 folder

Leave a Reply

Your email address will not be published. Required fields are marked *