The Calendar Printer has several components which have the following functions:
ESP32 (EzSBC ESP32_ANT-01):
An ESP32 microcontroller is used as the main processor for this project. Firmware was written in Visual Studio Code with the PlatformIO extension (see GitHub). When powered on, the ESP32 connects to WiFi, choosing the first available network from a list. It then sends a HTTP GET request to a Google Apps Script (see below). The execute link to the Google Apps Script issues a redirect notice which is decoded and followed. The redirected address returns formatted text containing the events from the calendar specified in the script for only the current day. The text also contains the current date to eliminate the need for the ESP32 to fetch time from a NTP server.
First the date is pulled from the returned text and stored as an Arduino String for printing later. Then each line of the text is used as the initialising argument to a calEvent class object which decodes the line and stores event name, location, time etc. in separate Arduino String variables.
With all calendar events in calEvent objects, each piece of information is then pulled back out and stored in separate Arduino String arrays. The random_shuffle() function is then used to shuffle the information randomly before it is assigned back to the calEvent objects.
Using the Adafruit Thermal library to interact with the thermal receipt printer, a logo is first printed, then the date. Each event is then iterated through to print a formatted summary of the less than useful event. An all day event will be displayed with only title and location. Likewise, an event with no location or guests will not display that field on the printout.
If there are no events in a given day, to give you something to do, the logo and date will print and then feed the remainder of the paper roll out at you.
Google Apps Script (Google Apps)
The Google Apps Script is largely based off the work of MickMake's Project-mmClock (available on GitHub). The script is called when a HTTP GET request is received for the execute URL of the script. This URL contains a long random 'key' making it "secure" through obscurity. Do be aware that the information that is returned from the script should not be sensitive as this is not good security. The Google Apps Script being within the Google eco-system is able to be authorised to have access to Google Calendars, so access between the app and calendar is secure. Perhaps consider the script an API to your calendar, dependent on what you program.
The script first connects to the calendar specified by name in the script. A string is initialised which will be built up with the information to be returned. The current day is added as the first line of the string, formatted in human readable text. A variable is populated with all events for the current day, which are then written in a CSV type format. The guests of an event are also added, separated by colons if there are any.
The string is then returned at the end of the function. This string is read as plain text when received by the ESP32.
The thermal printer is controlled by a 9600 baud serial connection to the ESP32. The Adafruit Thermal library was used to facilitate simple communication with the printer. The bitmapImageConvert Processing utility included in the Adafruit Thermal library was used to generate an array containing the logo image.
Wiring and Power
The Calendar Printer is powered from a nifty switched 2.1mm barrel jack. This feeds a cheap 5V 3A regulator to power the thermal printer and the VIN of the ESP32. The ground of the thermal printer, ESP32 and voltage regulator are all connected. When developing, I found it useful to disconnect the 5V supply from the ESP32...Read more »