REST API to control NeoPixel strips via a serial link to a microcontroller.
Clone this repository, install package dependencies with npm install, and then from the root folder run at any time:
npm start
neopixel-serial-api will attempt to connect with a microcontroller at 9600 baud on a serial/USB link, and accept requests to configure via API any LED strips connected to that microcontroller.
The following microcontrollers are supported, with code provided:
| Microcontroller (and shield) | Code (in /microcontrollers folder) |
|---|---|
| Arduino Nano with Grove shield | arduino-nano.ino |
neopixel-serial-api's REST API includes the following base route:
- /strips for the configuration of a given LED strip
Update the configuration of the strip with the given id.
| Method | Route | Content-Type |
|---|---|---|
| PUT | /strips/0 | application/json |
[
{ "offset": 0, "rgb": "0770a2" },
{ "offset": 1, "rgb": [ 7, 112, 162 ] }
]
{
"_meta": {
"message": "ok",
"statusCode": 200
},
"_links": {
"self": {
"href": "http://localhost:3001/strips/0/"
}
}
}
Update the configuration of the LED with the given offset in the strip with the given id.
| Method | Route | Content-Type |
|---|---|---|
| PUT | /strips/0/0 | application/json |
{
"rgb": "0770a2"
}
{
"_meta": {
"message": "ok",
"statusCode": 200
},
"_links": {
"self": {
"href": "http://localhost:3001/strips/0/0/"
}
}
}
neopixel-serial-api translates API requests into serial messages, according to the following protocol, which can easily be interpreted by resource-constrained microcontrollers and transformed into neopixel commands using existing libraries.
Each serial message is 6 bytes long, as specified in the following table, and terminated with a newline character ('\n').
| Byte offset | Description |
|---|---|
| 0 | Strip id (0 to 127) or special command (128-255) |
| 1 | MSB of LED offset or strip id for special command |
| 2 | LSB of LED offset |
| 3 | Red intensity (0 to 255) |
| 4 | Green intensity (0 to 255) |
| 5 | Blue intensity (0 to 255) |
The following special commands are supported:
- 0xaa: display the current configuration
- 0xff: clear the current configuration
For example, to clear strip 1 and make the first three LEDs red, green and blue, respectively, the serial message sequence, as hexadecimal strings, would be as follows:
ff01000000000a
000000ff00000a
00000100ff000a
0000020000ff0a
aa01000000000a
The seventh byte in each message above is the newline character (0x0a).
MIT License
Copyright (c) 2023 reelyActive
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.