Skip to content

Commit

Permalink
the Salt Mines gyro button
Browse files Browse the repository at this point in the history
  • Loading branch information
joeshaw authored and Joe Shaw committed Aug 24, 2015
0 parents commit 1d13ce7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gyro
24 changes: 24 additions & 0 deletions README.md
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
45 changes: 45 additions & 0 deletions gyro.go
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()
}
}
}

0 comments on commit 1d13ce7

Please sign in to comment.