beyondscreen / node-rpi-ws281x-native

native bindings to drive WS2811 (or WS2812) LED-Controllers on a Raspberry Pi
MIT License
224 stars 101 forks source link

No LEDs turn on #94

Open davidpuetter opened 5 years ago

davidpuetter commented 5 years ago

Hi, I'm attempting to create a web interface for controlling WS2812 LEDs. I managed to get the rainbow.js example working from the examples folder using sudo node rainbow.js and that worked fine. However I am now attempting to port this code over to my own use-case but it isn't working. I copied the ws281x-native stuff over and its related dependencies. The library initializes fine (logging ws281x in init() shows the bindings and functions. However, calling ws281x.render(this.pixelData); yields no results, no errors.

This script is being called from index.html running on an apache2 webserver on my RPI 3B+. Connections to the webserver work fine. No errors during load, either.

const NUM_LEDS = 60;
const ws281x = require('./lib/ws281x-native');
ws281x.init(NUM_LEDS);

export default class Main {
    constructor() {
        this.pixelData = new Uint32Array(NUM_LEDS);
    }

    init() {
        console.log(ws281x);
        for(var i = 0; i < NUM_LEDS; i++) {
            this.pixelData[i] = 0xffcc22;
        }
        ws281x.render(this.pixelData);
    }
}

Maybe I am misunderstanding how these work. Or I am possibly running it wrong, because I noticed that I run rainbow.js using sudo node but not the apache webserver. How could I use these two together?

adamcoulombe commented 5 years ago

Is apache running with root priviledges? Ultimately the script needs to be run with root.

adamcoulombe commented 5 years ago

The way I did it was using express.js to handle http requests and running that script using root (sudo). I am not as familiar with how it gets called if youre using apache.