-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1d13ce7
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gyro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## Gryo Button | ||
|
||
When you press the button on an Amazon Dash, we increment the Salt | ||
Mines gyro counter. See the current count [on the | ||
dashboard](http://dashboard.saltmines.us/south). | ||
|
||
Inspired by [this article by Ted | ||
Benson](https://medium.com/@edwardbenson/how-i-hacked-amazon-s-5-wifi-button-to-track-baby-data-794214b0bdd8). | ||
|
||
## Development and deployment | ||
|
||
This runs on the Raspberry Pi in the office. I develop it on my Mac | ||
and cross compile it for linux/arm. You will need Go with the | ||
linux/arm toolchain. If you're on a Mac, this is easy: | ||
|
||
$ brew install --with-cc-common go | ||
|
||
Once that's done: | ||
|
||
$ GOOS=linux GOARCH=arm go build | ||
|
||
Then scp the `gyro` binary to `[email protected]` and run it: | ||
|
||
$ sudo ./gyro wlan0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
|
||
"github.com/mdlayher/arp" | ||
) | ||
|
||
const gyroURL = "http://saltmines.us/gyroup.php" | ||
const name = "Some button pusher" | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatal("Usage: arp <iface>") | ||
} | ||
|
||
iface, err := net.InterfaceByName(os.Args[1]) | ||
if err != nil { | ||
log.Fatal("InterfaceByName: ", err) | ||
} | ||
|
||
c, err := arp.NewClient(iface) | ||
if err != nil { | ||
log.Fatal("arp.NewClient: ", err) | ||
} | ||
|
||
for { | ||
p, _, err := c.Read() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if p.Operation == arp.OperationRequest && p.SenderIP.Equal(net.IPv4zero) { | ||
resp, err := http.PostForm(gyroURL, url.Values{"user_name": {name}}) | ||
if err != nil { | ||
log.Printf("Error updating count: %s", err) | ||
} | ||
resp.Body.Close() | ||
} | ||
} | ||
} |