time-to-go

command module
v0.0.0-...-70d5835 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 1 Imported by: 0

README

time-to-go

Command line tool to display upcoming NYC subway times on a Raspberry Pi OLED monitor

Command Usage

Print next subway times to OLED display:

./time-to-go subway --mta-api-key YOUR_MTA_API_KEY --stop-id YOUR_STOP_ID [--i2c-bus YOUR_I2C_BUS]

Print next subway times to terminal:

./time-to-go subway --debug --mta-api-key YOUR_MTA_API_KEY --stop-id YOUR_STOP_ID

Print next bus times to OLED display:

./time-to-go bus --mta-api-key YOUR_MTA_API_KEY --stop-id YOUR_STOP_ID [--i2c-bus YOUR_I2C_BUS]

Print next bus times to terminal:

./time-to-go bus --debug --mta-api-key YOUR_MTA_API_KEY --stop-id YOUR_STOP_ID

Clear OLED display:

./time-to-go clear [--i2c-bus YOUR_I2C_BUS]

IMG_2382 (1)

Installing

  1. Install Go on your Raspberry Pi, if you don't have it already

Follow this guide to install Go. I used go1.22.0.linux-arm64.tar.gz for my Raspberry Pi 4 running a 64 bit OS.

  1. Download the repo to your Raspberry Pi
git clone https://github.com/christian-doucette/time-to-go.git
  1. Build the executable

Navigate into the repo then run:

go build

This should create an executable time-to-go file

  1. Request an API key from the MTA

Sign up for a subway API key here. Sign up for a bus API key here.

  1. Test run (print to output)

At this point, try running the following command, using your MTA subway API key:

./time-to-go subway --debug --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16N

This will print the next subway times at stop R16N (Times Square–42nd Street NQRW) to output. If something goes wrong, resolve it before continuing.

  1. Connect the OLED display

I used a 0.96 inch display with an SSD1306 driver connecting over I2C. Follow the beginning part of this guide for wiring and setup of the OLED display. If you want to use multiple monitors, follow this guide for adding additional I2C buses and wiring the additional displays.

  1. Test run (print to OLED display)

At this point, try running the following command:

./time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16N

This should display the next subway times at stop R16N to your OLED display. If something goes wrong, resolve it before continuing.

You can run the following command to clear the display:

./time-to-go clear
  1. Set up a Cronjob to run the command continuously

For a refreshing display, you will want to rerun the command every 30 seconds to ensure the OLED dispaly always has up to date info.

Edit cronjobs:

crontab -e

Add the following lines:

* * * * *            ~/Desktop/time-to-go/time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16N
* * * * * (sleep 30; ~/Desktop/time-to-go/time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16N)

Cronjobs can be run at most once per minute, so to run it every thirty seconds there are two Cronjobs kicked off on the minute, one which waits 30 seconds before execution.

  • Switch subway for bus if you want to pull bus times instead of subway
  • Replace the mta-api-key argument with your key (subway or bus as appropriate)
  • Replace the stop-id argument with the ID of the stop you want to display (find a stop ID by name here).
  • Replace ~/Desktop/time-to-go/time-to-go with the full path to the executable

If you are using multiple I2C devices on different buses, specify the buses (1 will be used as the default):

* * * * *            ~/Desktop/time-to-go/time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16N --i2c-bus 1
* * * * * (sleep 30; ~/Desktop/time-to-go/time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16N --i2c-bus 1)
* * * * *            ~/Desktop/time-to-go/time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16S --i2c-bus 3
* * * * * (sleep 30; ~/Desktop/time-to-go/time-to-go subway --mta-api-key XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --stop-id R16S --i2c-bus 3)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
mta

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL