Coder Social home page Coder Social logo

sp108e's Introduction

sp108e Javascript Library

What is this?

This is a Javascript library to control SP108E Wi-Fi controller.

There are also very basic Express Web Server and AWS Lambda examples that will get you up and running really quickly controlling your sp108e LED light strips from a browser or from Google Home / Google Assistant using IFTTT.

Let's make this clear!

This is the version 1 of the library so the code isn't pretty, but it's not a big deal, for V1 - Just be mindful and empathetic that I haven't spent much time on this!

Why Javascript?

I'll be really honest here: I haven't invented anything new here. All the hard work was done by the awesome Lehkeda who reverse-engineered the sp108e device and wrote a PHP Library for it. But I'm a NodeJS person so I have ported across the bits that I need. That is all.

There are lots more interesting pieces in the PHP api, like auto-detecting the device on the network so if anyone would like to extend what I've done here - Please go crazy!

How does the API communicate with the sp108e?

I won't go into detail here since it is really well described at https://github.com/Lehkeda/SP108E_controller

API Usage

npm install sp108e

const { sp108e, ANIM_MODE_FLOW, ANIM_MODE_STATIC } = require("sp108e");

const sp108e_options = {
  host: "192.168.86.124",
  port: 8189,
};

const test = async () => {
  const p = new sp108e(sp108e_options);

  // If making sequential calls you should use 'await' to wait for each command to finsh
  // or you will confuse the controller. Look in `sp108e.js` for all available commands!
  await p.on();
  await p.toggleOnOff();
  await p.setColor("ffffff");
  await p.setAnimationMode(ANIM_MODE_FLOW);
  await p.setAnimationSpeed(255);
  await p.setDreamMode(1);
  await p.setColor("FF6717", ANIM_MODE_STATIC);
  await p.setBrightness(255);
};

test();

Developing

$ npm install

Update examples/example.js with your hostname. The port should be correct

$ npm run example

Running example web server

Update examples/service.js with your hostname. The port should be correct.

$ npm run server // or npm run hotserver for hot reloading on code changes

The sever will run on localhost and you can manage your leds with simple GET requests:

Using sp108e with Google Home / Google Assistant

The web server and lambda have both been written so that it can be called with natural language allowing it to be used with Google Assistant using IFTTT:

My IFTTT configutaion looks like this:

If You say "set front lights $", then Make a web request

What do you want to say? set front lights $
What do you want the Assistant to say in response? no problem, setting front lights $
URL: http://mydomain:3000/?command={{TextField}}    OR    your AWS API Gateway url
Method: GET
ContentType: text/plain

Contributing

This is a very first attempt - v1 - of an sp108e node library. There is lots more that could be done (even if just porting missing functionality from https://github.com/Lehkeda/SP108E_controller). I'm very happy to get Pull Requests!

sp108e's People

Contributors

georgeburrows avatar greenwombat avatar smith288 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.