hortinstein / node-dash-button

A small module to emit events when an Amazon Dash Button is pressed
949 stars 94 forks source link

New buttons are using UDP instead of ARP #42

Closed kim3er closed 7 years ago

kim3er commented 7 years ago

My button was initially picked up using the ARP method, but after about 20 minutes, stopped being picked up. Turns out, possibly through a firmware update, the message protocol had switched to UDP.

This pull request adds the ability to monitor UDP. I've implemented in a way as to not break existing implementations. The index script defaults to ARP only, which you can configure to search for UDP only or both protocols. findbutton now searches both by default, and outputs the protocol used.

I've updated the documentation, but have not written any additional tests. I've not really tested anything on the network before, so guidance would be appreciated.

Thanks for the library! It allowed me (initially at least), to get up and running very quickly.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-6.0%) to 92.063% when pulling 1063db0bdc814639e63002dd6127e41441dcfc5c on kim3er:feature/udp into f969c3abcb98752f3e7bc9f3745ca0f76c7aab9d on hortinstein:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-6.0%) to 92.063% when pulling 3e30b794af7fe8ca21c89bf6adcb90802b861699 on kim3er:feature/udp into f969c3abcb98752f3e7bc9f3745ca0f76c7aab9d on hortinstein:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.4%) to 98.413% when pulling 7f3f92647c24e67484e2de3998e6ecc35cc61968 on kim3er:feature/udp into f969c3abcb98752f3e7bc9f3745ca0f76c7aab9d on hortinstein:master.

kim3er commented 7 years ago

I've added some tests.

thbaumbach commented 7 years ago

this is working way better than just the ARP-method (which missed some requests), good job, thank you +1

Bastl34 commented 7 years ago

Wouldn't it be better if you try to catch all requests from a dash-button mac address? Then you wouldn't need a ARP/UDP filter.

kim3er commented 7 years ago

Hi @Bastl34. Logically, I'd say yes. Do you know if pcap can be configured in that way?

Bastl34 commented 7 years ago

What if you just check if the package was sent by the mac address by removing these checks:

packet.payload.ethertype === 2054
packet.payload.ethertype === 2048
kim3er commented 7 years ago

Those checks are required, because I detect the UDP MAC differently to that of the ARP MAC. It maybe that the ARP MAC can be identified using the same method that I'm employed for UDP, but I haven't checked. The focus of this pull request was to get UDP working, not refactoring the existing process.

If @hortinstein is up for it, I have couple more ideas for optimisations, once this PR has been resolved.

hortinstein commented 7 years ago

hey thank you for the pull request! I haven't been able to put much work into this library for a while so community help means a lot.

I will merge and push to NPM today. (thanks for writing tests too!)

kim3er commented 7 years ago

That's great, and no problem!

Bastl34 commented 7 years ago

This is still not pushed to npm? :) Latest npm version is 0.5.5

kim3er commented 7 years ago

I'm sure you're probably aware of this (and it's not ideal), but just in case!

You can switch the version for 'hortinstein/node-dash-button' in the package.json file. This will allow you to install from GitHub Master.

"node-dash-button": "hortinstein/node-dash-button"
hortinstein commented 7 years ago

strange, on search results it shows that 0.6.0 is published: https://www.npmjs.com/search?q=node-dash-button

But on the actual page: https://www.npmjs.com/package/node-dash-button it shows 0.5.5.

I will try to repub.

hortinstein commented 7 years ago

weird so it rejected my repub of 0.6.0 but took 0.6.1. It appears to be updated now, let me know if there are anymore issues!

johnmckerrell commented 7 years ago

Hi, I had issues too, I have a button that definitely used to work and I haven't changed anything, it's on a Pi running openelec so I definitely haven't updated anything since setting it up. It really does seem like they updated the firmware. I continued to have issues until I found that I needed to specify all protocols (well, udp would probably do but all protects me for the future). So my updated code for setting up a button is:

var dash_button = require('node-dash-button'),
    dash = dash_button(dashAddress, null, null, 'all'), //REPLACE WITH YOUR ADDRESS
    exec = require('child_process').exec;