Skip to content

Firebase Cloud Function server for Label Commander client

License

Notifications You must be signed in to change notification settings

heston/label-commander-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Label Commander Server

Firebase Cloud Function server for Label Commander client.

Approach

  1. The cloud functions in this project write label requests to a Firebase Realtime database.
  2. The Label Commander client reads these entries and then prints labels on an attached Dymo LabelWriter.
  3. IFTTT is optional, but provides numerous triggers to call the cloud functions. It acts as a frontend. The cloud functions can also be called directly. See below for the API.

Installation

Configure Cloud Functions

  1. On the command line, clone this repo and change into the cloned directory.
  2. Follow the Firebase Cloud Functions Get Started Guide.
    1. If prompted to overwrite any files during the init process, always select no.
    2. When prompted to select a language, select Javascript.
  3. Set your authentication key by running: firebase functions:secrets:set IFTTT_SECRETKEY.
    1. Follow any prompts to set up Google Cloud Secret Manager.
    2. Select a long random string to use as an authentication key. It doesn't matter what this is, only that it's a strong password. Here's a good starting place: openssl rand -base64 18.
    3. Take note of this key, as you will need it later.
  4. Deploy the functions: npm run deploy.
  5. Take note of the Function URL lines printed near the end. You will need these later.

Configure IFTTT

To print a label, you need to set up IFTTT to trigger a Webhook action in response to a trigger of your choice.

  1. Create a new applet in IFTTT.
  2. Set up the "If This" trigger of your choice. In my case, I used the Google Assistant "Say a phrase with a text ingredient" trigger.
  3. For the "Then That" service, select "Webhooks."
  4. Select the "Make a web request" action.
  5. Set the URL to the Function URL parameter printed during deployment. It will be something like, https://us-central1-myproject.cloudfunctions.net/printBatch, where myproject will be the name of your Firebase project.
  6. Set the method to POST.
  7. Set the content type to application/json.
  8. Under "Additional Headers" enter:
    Authorization: AUTH_KEY
    
    Where AUTH_KEY is the authentication key you set earlier.
  9. Set the body to:
    { "items": [ {"body": "Text to print", "qty": 1} ] }
    The body and qty may be ingredients from your trigger.
  10. Click "Update action" to save your applet.
  11. Try it out!

API

This project provides two cloud functions: printLabel and printBatch. The former prints a single label, while the latter prints any number of different labels.

In the below examples, replace MY-PROJECT with the name of your cloud function deployment. The complete URLs for your particular project are printed on the console after a successful deployment (see Installation, above).

Authentication

The AUTH_KEY set during setup must be provided for every request. There are two ways to do this:

  1. As a header (preferred). Send the following header with every request:

    Authorization: AUTH_KEY
    
  2. In the JSON body of the request. Set the following key in the JSON request body:

    "authentication": "AUTH_KEY"
    

    For example, the body of the request sent to printLabel would look like this:

    {
        "authentication": "AUTH_KEY",
        "body": "Text to print",
        "qty": 1
    }

printLabel Endpoint

POST https://MY-PROJECT.cloudfunctions.net/printLabel

{
    "body": "Text to print",
    "qty": 1
}

Returns 200 on success.

printBatch Endpoint

POST https://MY-PROJECT.cloudfunctions.net/printBatch

{
    "items": [
        {
            "body": "Text to print",
            "qty": 2
        },
        {
            "body": "Other text to print",
            "qty": 1
        }
    ]
}

Returns 200 on success.

About

Firebase Cloud Function server for Label Commander client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published