An MQTT and HomeAssistant driven automatic news printer
- Requirements
- Wiring
- Configuration
- Installation
- Usage with HomeAssistant
- 3D-Printable case
- Troubleshooting
- Contributing
- A Raspberry Pi Zero W.
- A TTL-capable thermal printer (Adafruit, AliExpress).
- (Optional) A HomeAssistant server with an embedded or external MQTT server.
Raspberry | Printer | Power Supply |
---|---|---|
Pin 4 (5V) | VCC | 5V |
Pin 6 (GND) | GND | GND |
Pin 8 (TX) | RX | |
Pin 10 (RX) | TX |
As usual with Pis, a power supply of at least 2A is recommended.
You can either edit the main config.yaml
file or create a config.local.yaml
copy of it that, if present, will be read instead.
- Fill the
mqtt
section with your MQTT server's details. - The
printer
section preconfigured for Raspbian; if you chose to use another distro, these values may need to be tweaked. - The
maxRows
key in thefilter
section defines the maximum number of rows that an article's fields are allowed to occupy when being printed. - Change your desired locale for date formatting in the
locale
section. - Add RSS feeds' URLs in the
feeds
section.url
is the direct URL to the XML feed. Some feeds may show a rich interface when viewed from a browser even if the URL is correct.schema
is a list that specifies which sections of the feed's articles you want to print out.- Possible values are
title
anddescription
, respectively for the title and summary/content of the article.
- Possible values are
count
specifies how many of the latest articles you want to fetch from this feed.
- Prepare your RPi Zero as usual. Using Raspbian Lite is recommended.
- Run
sudo raspi-config
on it:- Interfacing options > Serial > No (disable the login shell) > Yes (enable the serial port hardware).
- Note: reboot at least once before connecting the printer, if possible. System logs could get printed out while shutting down otherwise.
- Install NodeJS manually.
- The most recent
armv6l
prebuilt archive still available seems to be v11.15.0. - For enhanced ease of use, just download the tarball and extract in the root of your filesystem. This would be bad practice in standard systems.
- The most recent
- Clone this repo in your user's home.
git clone https://github.com/nmaggioni/MorningNews.git /home/pi/MorningNews
- Run the install script:
./install.sh
. The script will automatically take the following actions:- Install the needed tools and dependencies from Raspbian's repos.
- Download and build the needed NodeJS dependencies.
- Create en entry in your crontab that will start the MQTT/HomeAssistant script at boot.
- Create a logrotate entry to ensure that logs don't grow too large.
- Reboot.
Make sure that your HA instance has MQTT discovery enabled.
Upon boot, the MorningNews MQTT script will make new entities available in HA:
You can then customize them to your liking with the usual methods.
The core NodeJS project can easily be ran standalone: just run ./print_news.sh
or npm start
whenever you want to print some news.
The /docs/printable_box
folder contains a simple case for mounting the printer with the included hardware and sliding a Pi Zero underneath it. The back cover has holes for routing both a Micro USB cable for powering the Pi and a 2-pin JST-PH connector for powering the printer, in case you want to power them from different sources.
The fit of the back cover may require tweaking depending on your printer's characteristics.
Make sure the printer is correctly powered.
Given that no scripts are logging any error, your printer might be recognized under a different serial port or could be using a different baud rate.
If /dev/ttyAMA0
is present of your system, try setting the baud rate in the config file to 19200
.
If everything else fails, power on the printer while holding the button on the front: a diagnostics page will be printed and it might contain some clues.
Manually execute SIMULATE_PRINTER=1 npm start
to show debug info and simulate the printer by outputting directly to screen.
Feel free to dive in! Open an issue or submit PRs.