Shortened Link: https://git.io/fjiHy
Hello!
If you're reading this, you're hopefully at a workshop. Today, we're going to write a Workers function to manipulate LEDs on a Raspberry Pi.
- Node.JS/npm or Rust/Cargo installed (to install Wrangler)
- A workers.dev subdomain
Install Wrangler if you haven't already with npm i wrangler
or cargo install wrangler
(npm is recommended as it dispenses a precompiled Rust binary, while cargo builds the library on demand)
Run the following to clone the incomplete Workers function template and initialize your Wrangler project:
wrangler generate colorWorker https://github.com/nodebotanist/LED-Workers-Workshop.git
This will create a folder colorWorker
in the directory you ran it in. cd
into it and open index.js
in your favorite code editor.
create a wrangler.toml
file that contains the following:
name = "color"
type = "webpack"
private = false
account_id = "YOUR_ACCOUNT_ID"
YOUR_ACCOUNT_ID
can be obtained on the right side of the dashboard when you log in with the email you used to register for workers.dev.
Accepts: a JSON object with either:
- a
color
property that is any CSS color name r
,g
, andb
properties, all between 0-256, representing red, green, and blue valuesh
,s
, andv
properties;h
between 0 and 364,s
between 0 and 100, andv
between 0 and 100, representing hue, saturation, and value.
Returns: A JWT signed with a secret and the color you sent in the payload
Required: an Authorization
header with Bearer:
and a JWT from the previous endpoint.
Places the color in the queue to be shown and returns a response of 200 if successful