Publishing IoT IP Addresses to MQTT

I have been playing around with using ESP8266’s as endpoints around the house for collecting temperature, turning the sprinkler pump on, texting me when the doorbell is pressed, etc.  One of the challenges when doing setup/testing is getting the IP address of them when they first come online.

I am running dnsmasq on a raspberry pi, which provides both local DNS and DHCP services.  This is in no way novel, as it is a pretty vanilla configuration.  What I wanted to share is a small script that monitors for updates to the dnsmasq log, watches for new client releases/renewals and then posts those to the MQTT service.  There are lots of things you can do with it from there, but I usually just subscribe to the topic via terminal or mqtttool on my iPhone.

#!/usr/bin/python
from pygtail import Pygtail
import sys
import re
import time
import paho.mqtt.client as mqtt

client = mqtt.Client()
client.username_pw_set("xxxxxx","xxxxxx")

while (1):
 for line in Pygtail("/var/log/dnsmasq.log"):
   isItACK = re.search(r'DHCPACK',line)                #see if its an ACK
   if isItACK:
     newInput = re.sub(r'^.*DHCPACK\(eth0\).', "", line) #strip everything before mac address
     newInput = newInput.rstrip()                        #strip newlines
     client.connect("xxxxxx.widgetninja.net",1883)       #connect to mqtt
     client.publish("/network/DHCP",newInput)            #publish to mqtt
     client.disconnect                                   #hang up
     #sys.stdout.write(newInput)                         #debugging
 time.sleep(10)

Hope this helps save you some time trying to find the ip address of that new device, be it something you made or otherwise just added to your network.

mqtt

Advertisements

Word Clock Build

This project was one of those long-running ones which took almost 7 months from when I saw the first one out there and wanted to make one, to when I actually got started.  One of the big catalysts was Joe’s blog post on his build – so hats off to him!  Joe did perf board wiring, and I wanted to create a circuit board for the task.  The reason for this was twofold: (1) I hate perf board and (2) I wanted to build the atmega circuit and bootstrap it myself.

So if you watch the video below, you will see I failed at getting my atmega to run.  Could not figure it out!  Next time I will surely include additional LED’s (pin 13 anyone?) to aid troubleshooting.  So, that said in the zip file attached you will find my eagle schematics.  If you use them, be aware the microcontroller portion requires some additional scrutiny.  Maybe its fine, and I just messed up the wiring.  Who knows.  If you want to take a peek at it and give me feedback I would appreciate it!

Other big change/addition from Joe’s build was I added a Real Time Clock (RTC).  In my case I used the ChronoDot.  It is much more accurate, and tracking time in code was MUCH easier.  Here is my code, eagle schematic, and .DXF file for the led array.

WP_20130217_001