Automation, Orchestration and IoT

Providing digital transformation through DevOps

IoT - Wi-Fi Voucher Printing

Sam Lay

Sam Lay

Sam is an infrastructure engineer at The Network Factory. He's a fan of Ansible, Linux and open-source software. He makes some superb seitan soybean satay stirfry.

Star TSP100 receipt printer

We are often asked for proof-of-concept and implementation of IoT and embedded solutions. One example of this was for a hospitality client, who asked us to help out with token-based access to their public Wi-Fi, via a printed till receipt given with each purchase.

Unlike the majority of our clients, this business had no existing systems in place to host a print server. After some consideration, we decided to provision a Raspberry Pi Zero (Wi-Fi model) for the job. The Raspberry Pi is an ideal fit for this situation, thanks to its extremely low cost, exceptional energy-efficiency and its tiny profile and size.

We decided to set up the Raspberry Pi using our automation and provisioning tool of choice, Ansible. This approach means that the steps involved are documented and the setup can be quickly and easily deployed to other Raspberry Pis (or, with minor changes, other devices and distributions).

For development of the system, we created a VM that made use of the official x86 variant of Raspbian (the Raspberry Pi's official Debian-based Linux operating system). This allowed to closely approximate the environment of an actual Raspberry Pi running Raspbian, but with the performance advantage of deploying to a local VM (the Raspberry Pi Zero is a brilliant little device but it's not lightning fast) and the convenience advantage of VM snapshots, allowing us to instantly restore the VM to a fresh, unmodified state for testing fresh deployments of the setup.

For similar work in the future, we could even more closely replicate the Raspberry Pi environment by making use of Vagrant and Qemu to actually run an emulated ARM environment (allowing us to use the standard ARM version of Raspbian intended for deployment to actual Raspberry Pis, as opposed to the x86 variant).

Raspberry Pi Zero

To generate the voucher itself we used PHP with the TCPDF library. There are several excellent options for generating PDFs (such as FPDF and DOMPDF), but TCPDF's feature list was pretty hard to beat, not to mention no requirement of additional external libraries.

One nice touch we wanted to add was a QR code on each voucher. This allows the client's customers to connect simply by scanning the QR code, saving them having to locate the correct Wi-Fi network in the list. To achieve this we installed the qrencode Linux package, which allows us to quickly and easily generate QR codes that we then embed in the PDF voucher file.

One final thing we wanted to integrate was notifications for when a voucher roll was running low. In the event of vouchers running out entirely, we put in place code to make the printer output a 'Voucher roll empty' error. Ideally though we're not expecting to ever reach that point, because notifications will kick in first, so that the voucher roll can be replaced with a fresh one long before it runs out entirely. For this we decided to send notifications to our company Slack's client notifications channel via curl and Slack WebHook.

Ideally the provision of new voucher rolls would be handled automatically without the need for human intervention. In our next iteration of this project, we aim to achieve that via the Raspberry Pi sending a request when it runs low on vouchers that fetches a freshly-generated voucher roll.

Overall this was a hugely educational and rewarding project and we (and our client) are delighted with the result.

For IoT and embedded solutions (and for many other things too), we can help.

To learn more about our services and what we can do for you, call us on +44(0)207 100 666 8 or email us at hello@thenetworkfactory.com and we'll find a dependable, cost-effective solution that works for you.