If you’ve ever had a puppy or a baby, you’ll know how important it is to track their bodily functions. Are they ok, healthy and pooping according to plan? If you’re super organized you can track those shenanigans in a spreadsheet.

In other news, Amazon kickstarted the Internet of Things (IoT) with their impressive $5 wifi buttons. You literally push a button with a product name on it, and Amazon will send you that thing.

Kudos to Ted Benson, who posted an inspirational HOW-TO for parents over on Medium, combining these concepts. Now you can hack Amazon’s tiny one-button device to track events - such as your baby’s bowel movements - with a button push!

dash button

It takes three or four minutes before you even realise it’s an advert for his company CloudStitch. Well played, that man.

I love the idea and had to try it. But with engineer OCD we can do better. Let’s do it my way!

1. Use IFTTT

There are over nine billion things you could do with a pushbutton trigger. Say, push a button to call an Uber/Lyft to your house. Let’s drop CloudStitch and leverage the great variety of outbound channels in IFTTT.

Up until recently this would be annoyingly difficult. Thankfully since IFTTT introduced the Maker channel in June we are sorted - you can easily set up inbound webhooks from anywhere.

(1) Create a recipe with a Maker web request inbound, and outbound sending to a Google Spreadsheet. Give it a charming name indicative of the great event:

ifttt recipe

Take note of the secret key and the trigger URL.

(2) Configure the outbound channel to accept a couple of values from the HTTP call that we’ll be sending. We’ll use this for the date and time portions of the timestamp:

ifttt config

(3) Now create another recipe for a baby_peed event. Lovely!

2. Prepare a spreadsheet

Open a new Sheet and put header values in for the data that’s about to arrive:

3. Improve the script

Here’s my adapted Python:

import socket
import struct
import binascii
import time
import json
import urllib2
# Use your own IFTTT key, not this fake one
ifttt_key = '9cn3847ntc8394tn8-ab'
# Set these up at https://ifttt.com/maker
ifttt_url_poop = 'https://maker.ifttt.com/trigger/baby_pooped/with/key/' + ifttt_key
ifttt_url_pee = 'https://maker.ifttt.com/trigger/baby_peed/with/key/' + ifttt_key
# Replace these fake MAC addresses and nicknames with your own
macs = {
'34545555e7ad' : 'chromebook',
'48d703450d65' : 'macbook',
'ec3454354536' : 'nexus6',
'2c3453455541' : 'apple_tv',
'6c7092236348' : 'airport_express',
'74234223434a' : 'dash_glad',
'7234234417c2' : 'dash_tide'
}
# Trigger a IFTTT URL. Body includes JSON with timestamp values.
def trigger_url(url):
data = '{ "value1" : "' + time.strftime("%Y-%m-%d") + '", "value2" : "' + time.strftime("%H:%M") + '" }'
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
response = f.read()
f.close()
return response
def record_poop():
print 'triggering poop event, response: ' + trigger_url(ifttt_url_poop)
def record_pee():
print 'triggering pee event, response: ' + trigger_url(ifttt_url_pee)
rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
while True:
packet = rawSocket.recvfrom(2048)
ethernet_header = packet[0][0:14]
ethernet_detailed = struct.unpack("!6s6s2s", ethernet_header)
# skip non-ARP packets
ethertype = ethernet_detailed[2]
if ethertype != '\x08\x06':
continue
# read out data
arp_header = packet[0][14:42]
arp_detailed = struct.unpack("2s2s1s1s2s6s4s6s4s", arp_header)
source_mac = binascii.hexlify(arp_detailed[5])
source_ip = socket.inet_ntoa(arp_detailed[6])
dest_ip = socket.inet_ntoa(arp_detailed[8])
if source_mac in macs:
#print "ARP from " + macs[source_mac] + " with IP " + source_ip
if macs[source_mac] == 'dash_glad':
record_poop()
if macs[source_mac] == 'dash_tide':
record_pee()
else:
print "Unknown MAC " + source_mac + " from IP " + source_ip
view raw arp_to_ifttt.py hosted with ❤ by GitHub

The improvements:

  • Use standard libs! If we’re going to run this on a Raspberry Pi (one day) let’s avoid installing random stuff. We’ll drop the scapy library and use the socket lib thanks to Bob over here.
  • Similarly we’ll avoid using fancy libs like Request for the HTTP stuff. We’ll DO IT LIVE with urllib2.
  • I store all my home-network MACs in a dictionary object macs and key off that. There’s amazing scope for triggering IFTTT events based on other events happening in your hoose.
  • Naturally it posts to IFTTT instead of CloudStitch.
  • It is no accident that baby’s pee uses the TIDE button and poop uses the GLAD button. They seemed appropriate.

It all works and is 100% amazing!

3. Things still to do

  • Remove the Python stuff and use a simple tool like arpalert or arpwatch.
  • Find a good device to run this 24/7. Maybe a Raspberry Pi, or a hacked router.
  • Improve the destination Sheet to draw graphs of baby’s excretions! I’m working on this - the Annotated Timeline chart is pretty cool.