My Textable Cat Printer

I was scrolling on twitter one afternoon and saw that xssfox had a Bluetooth Thermal Cat Printer. I have had an idea that required a thermal printer for a while now and this looked like a really good printer for what I wanted to do, so I ordered one.


This content originally appeared on DEV Community and was authored by DEV Community

I was scrolling on twitter one afternoon and saw that xssfox had a Bluetooth Thermal Cat Printer. I have had an idea that required a thermal printer for a while now and this looked like a really good printer for what I wanted to do, so I ordered one.

The original idea I had was to set up a thermal printer so you could message it a picture, have it print off and stick it in a guest book, like you might do with a polaroid at a wedding. But It doesn't look like I will be going to a wedding any time soon. So instead, to allow people to interact with it remotely, I decided to give it a phone number and let people send messages that would print out on my desk.

To contact it, message cat:[message to print] to one of the below numbers to have it printed.
Aus: +61 480 029 995
US: +1 520 521 0228

Giving The Cat Printer A Number

To be able to give the cat printer a number, first I had to get it to print. I pulled out a raspberry pi I had from the time I had my apartment lights controlled using amazon dash buttons. xssfox had some code that allowed you to send messages and images to be printed via HTTP requests. After getting that running on my pi and debugging some differences between how python handles bytes between Windows and Linux, I was able to send my first messages to print!

The python code I am using is available at https://gist.github.com/mpomery/6514e521d3d03abce697409609978ede

Once I had it printing, I went into my Twilio console and started adding some functions to my textable light project. I created a new function that would look at the incoming message for the prefix cat: and redirect the message to the cat printer. Later I went back and made my light require the prefix light: and an error message if neither of the prefixes were present.

The function looks like this:

exports.handler = function(context, event, callback) {
  let twiml = new Twilio.twiml.MessagingResponse();

  if (event.Body.toLowerCase().startsWith("cat:"))
    twiml.redirect("/cat_printer");
  else if (event.Body.toLowerCase().startsWith("light:"))
    twiml.redirect("/textable_light");
  else
    twiml.message(`"light:[colour]" to add a colour to the light
"cat:[text]" to print on the cat printer`);

  return callback(null, twiml);
};

I then set up a second function cat_printer to format the message to be sent to the printer. It takes the incoming message, removes the cat: prefix, redacts part of the number it was received from and formats it with a timestamp for printing. Then it makes a call to the web server running on my raspberry pi (which was made available to the internet using ngrok) to print it. Once that request has been made, the response from the printer gets sent back to the number who texted it.

const axios = require('axios');

exports.handler = function(context, event, callback) {
  let twiml = new Twilio.twiml.MessagingResponse();

  let incomingMessage = event.Body;
  if (incomingMessage.toLowerCase().startsWith("cat:"))
    incomingMessage = incomingMessage.substr(4).trim();

  let from = event.From;
  from = from.substr(0,3) + "*".repeat(from.length-6) + from.substr(from.length-3);

  let now = new Date();

  let printMessage = now.toLocaleString('en-GB', { timeZone: 'Australia/Sydney' }) + "\r\nFrom: " + from + "\r\n" + incomingMessage;

  console.log(printMessage)

  axios.post(context.catURL + '?text=' + encodeURIComponent(printMessage))
    .then((response) => {
      twiml.message(`${response.data}`);
      return callback(null, twiml);
    })
    .catch((error) => {
      twiml.message(`You sent a message with special characters or the cat printer is offline.`);
      console.error(error);
      return callback(null, twiml);
    });
};

Getting People To Message It

Once I had it working I started telling people about it. Some of my friends had already seen my textable light, so the idea of sending a text message to something on my desk wasn't new to them. I was initially cryptic about what I had made, but once people knew what it was they started messaging it!

Some of my friends made me regret telling them about the cat printer:

I streamed it briefly so people could see what they sent print in real time, including this really long message:

Then I started to see several people sending it messages internationally, so I purchased a second Twilio number so I could respond to them:

And then the TwilioDev twitter account tweeted it, expediting this blog post:

Now that I have it built and it has a semi-permanent position on my desk, I need to make a better way to keep all of my projects displayed on my desk. I would really like to make them all visible on the internet permanently. I have ideas on how I could achieve this, but don't have access to what I need to make it possible or the space to do it at the moment.

And if you are considering making something similar yourself using Twilio Programmable Messaging, you can get $10 when you upgrade using this link.


This content originally appeared on DEV Community and was authored by DEV Community


Print Share Comment Cite Upload Translate Updates
APA

DEV Community | Sciencx (2021-08-11T04:39:08+00:00) My Textable Cat Printer. Retrieved from https://www.scien.cx/2021/08/11/my-textable-cat-printer/

MLA
" » My Textable Cat Printer." DEV Community | Sciencx - Wednesday August 11, 2021, https://www.scien.cx/2021/08/11/my-textable-cat-printer/
HARVARD
DEV Community | Sciencx Wednesday August 11, 2021 » My Textable Cat Printer., viewed ,<https://www.scien.cx/2021/08/11/my-textable-cat-printer/>
VANCOUVER
DEV Community | Sciencx - » My Textable Cat Printer. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/11/my-textable-cat-printer/
CHICAGO
" » My Textable Cat Printer." DEV Community | Sciencx - Accessed . https://www.scien.cx/2021/08/11/my-textable-cat-printer/
IEEE
" » My Textable Cat Printer." DEV Community | Sciencx [Online]. Available: https://www.scien.cx/2021/08/11/my-textable-cat-printer/. [Accessed: ]
rf:citation
» My Textable Cat Printer | DEV Community | Sciencx | https://www.scien.cx/2021/08/11/my-textable-cat-printer/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.