Coder Social home page Coder Social logo

fauxmojs's Introduction

Build Status npm version

fauxmojs

Fake WeMo device ported to NodeJS. Allows Alexa to make api calls.

Based on the work of makermusings and n8henrie but written from scratch for NodeJS.

What does it do?

This service will setup the required UDP listener and HTTP listeners that support the SSDP that Amazon Echo (Alexa) uses in order to discover Belkin WeMo smart switches.

With this module you can hook up your own NodeJS code to run in response to an Alexa command such as: "Alexa, turn office light on". In this statement office light is the device name and on is the action.

Install

npm install fauxmojs

How do I use it?

Usage is simple. The heavy lifting is handled by this library so that all you need to do is create a new FauxMo class and pass in some options.

Below is a fully working example of two virtual devices. To use the first device through Alexa simply run the example and say "Alexa, turn office light on".

'use strict';

const FauxMo = require('fauxmojs');

let fauxMo = new FauxMo(
  {
    ipAddress: '192.168.1.230',
    devices: [
      {
        name: 'office light',
        port: 11000,
        handler: (action) => {
          console.log('office light action:', action);
        }
      },
      {
        name: 'office fan',
        port: 11001,
        handler: (action) => {
          console.log('office fan action:', action);
        }
      },
        {
        name: 'kitchen light',
        port: 11002,
        handler: (action, name, callback) => {
          console.log('kitchen light action:', action);
          let status = action === 'on' ? true : false;
          callback(status);
        }
      }
    ]
  });

console.log('started..');

OPTIONS

ipAddress - this is the ip address of the computer running FauxMo.

devices - an array of device definitions (see below).

The device object needs the following properties:

name - the name of the device, this is the name you will use when asking Alexa to control the device. E.g. if your name is office light you will say 'Alexa, turn office light on'.

port - each fake device needs to have a unique port. The amazon echo does not send back the device id in the action requests so the device is determined by the port number. FauxMo listens for actions on each device port.

handler - a function that will be called when the echo is attempting to perform the action. This functions first parameter 'action' which, when called, will be on or off or status. The second parameter is the device name e.g office light. The third parameter is a callback function that responds to Alexa with the device status true or false.

fauxmojs's People

Contributors

dsandor avatar janjohansen avatar mcchas avatar miyagawa avatar neophob avatar ramsnerm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fauxmojs's Issues

how to connect to AlexaOnOff module for smartmirror

Hi there,

I know this is probably a pain to listen to nearly every day but I'm relativley new to coding and stuff, I don't know the first thing about it to be honest, but I'm learning as I go on... I have my pi IP and I've tried to make a script in config.json file for a mirror, I tried running it but nothing has happened, it's not being discovered by my alexa plus, All i need is for the monitor to turn on and off via voice, if you could help me with this that would be great!

thanks,
will

Autodetect machine's IP address.

It would be nice to auto detect the IP address of the machine running fauxmo so the value does not need to be explicitly declared.

Add new devices after initialization.

Is there a way to publish new devices on the fly? I tried destroying the instance and reinitialize it with new devices, but it kicks out a "throw new Error('Socket is already bound');" error. Currently, the only way I can find is restarting the application entirely.

Unable to start FauxMo because of UDP port binding

When starting FauxMo using the example-updated method, this is what I see in the console:

started..
updated..
D:\Projects\Personal\FauxMo-Controller\node_modules\fauxmojs\lib\discoveryService.js:101
        throw err;
        ^

Error: bind EADDRINUSE 0.0.0.0:1900
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1045:20)
    at _handle.lookup (dgram.js:242:18)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:611:11)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:578:3

I'm using Windows 10 64-bit.

This line is the issue in discoveryService.js:

udpServer.bind(1900);

I was able to temporarily fix it by changing 1900 to 1901.

What's causing this port to already be in use? Is it possible I already have an SSDP server running?

When I do netstat -anobp udp, I see these:

  Proto  Local Address          Foreign Address        State           PID
 [svchost.exe]
  UDP    0.0.0.0:1900           *:*                                    94576
 [svchost.exe]
  UDP    127.0.0.1:1900         *:*                                    5248
  SSDPSRV

Support "dimming".

I know it's possible.. but as of now.. Alexa says "Office light doesn't support that"....

Gonna look at ESPalexa for clues on how to implement it...

Devices not discoverable

Using debug I can not see any problem, but the example devices doesnt appear at Alexa.

discoveryService >> sending response string: HTTP/1.1 200 OK
CACHE-CONTROL: max-age=86400
DATE: 2016-10-29
EXT:
LOCATION: http://192.168.1.22:11000/0de91340-5c21-4142-8353-9731b5633979/setup.xml
OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01
01-NLS: 12
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: urn:Belkin:device:**
USN: uuid:Socket-1_0-0de91340-5c21-4142-8353-9731b5633979::urn:Belkin:device:**

+4ms
discoveryService >> sending response string: HTTP/1.1 200 OK
CACHE-CONTROL: max-age=86400
DATE: 2016-10-29
EXT:
LOCATION: http://192.168.1.22:11001/3267998a-f46d-46ef-8474-0caab2b099b0/setup.xml
OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01
01-NLS: 12
SERVER: Unspecified, UPnP/1.0, Unspecified
ST: urn:Belkin:device:**
USN: uuid:Socket-1_0-3267998a-f46d-46ef-8474-0caab2b099b0::urn:Belkin:device:**

+4ms

Devices not discoverable by Gen 2 Echos

While debugging the discoveryService.js I can see that the XML formed in response doesn't appear to be compliant with what the latest echo firmware expects. I suspect its a matter of updating the response in similar fashion to how the guys on the original fauxmo project did.

It looks like the new Echos are now requesting a metainfoservice.xml and eventservice.xml
response and perhaps the setup.xml isn't formed correctly either.

See this issue for reference:
n8henrie/fauxmo@1c3389c

each device executed during discovery

Is there a way to differentiate between the callback function being triggered by Device Discovery and calling the function from a voice command? When I ask Alexa to discover all devices, it actually triggers each device to operate as if it were called with an "on". This is a bit of a problem, because it is activating devices, that I don't want activated during discovery.

README is lacking

I understand I need to make a new class for the fake devices, but where do I put it and what do I need to name it.

Thanks

Pass through IP addresses

If you look at the original fauxmo project you will see there is a multiple alexa solution that differentiates on IP address. I'd love it if you pass through the IP address (Or better yet the mac address) of each device so I can run scripts against the specific echo that picked it up.

Thanks!

SyntaxError: Unexpected token =

Hi
im getting this

/home/knu/bwired/alexa/node_modules/fauxmojs/lib/index.js:11
constructor(options = {}) {
^

SyntaxError: Unexpected token =

is it my node version?
4.2.6

Usage on multi interface devices

I borrowed your discoveryService.js for some work I was doing to add Alexa to homebridge, and found that it didn't work on one of my machines with dual interfaces. And to make it work I had to make a minor change, and specify which interface to use. The change was this.

PS It worked on other single interface machines as well

var ip = require('ip');

.
.
.

udpServer.addMembership('239.255.255.250', ip.address());

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.