For the mySmartGrid project I will use a Chumby as a device for showing the resource consumption, in addition to providing other features. Since I will roll this out in up to 1000 households configuration needs to be automatic. The problem is: how does a Chumby (or any other device) locate the Flukso in the local LAN? Turns out that Zeroconf is a neat solution to this. I use http://www.avahi.org for this.
First, you need to install the avahi daemon on the Flukso. This is easy since OpenWRT provides a package for it:
- $ opkg install avahi-daemon
- $ cd /etc/avahi/services
- $ cp ssh.service flukso.service
Then, you edit flukso.service to your liking. I assume here that a TCP daemon listens on port 4422:
- <?xml version="1.0" standalone='no'?><!--*-nxml-*-->
- <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
- <name replace-wildcards="yes">Flukso on %h</name>
After starting the avahi-daemon you should be able to find the IP address and port number using any Zeroconf/Bonjour/Avahi client. On Mac OS I use the Bonjour Browser.
But I also wanted to write a small C program that just gives me the location of the Flukso. First, I installed a minimal version of the Avahi libraries on my Debian ARM NAS device:
- $ ./configure --disable-glib --disable-gobject --disable-qt3 --disable-qt4 \\
- --disable-gtk --disable-dbus --disable-gdbm --disable-python \\
- $ make
Afterwards, I modified one of the example programs to print the IP and port of the "_flukso-realtime._tcp" service type. You can find a small tarball of the code attached. CORRECTION: I am not allowed to upload a tarball :-( The tarball is here:
It works on my ARM-Debian machine and on an x86 Mac OS (Snow Leopard), please adjust the simple Makefile to your installation. This is how the output looks like:
- $ ./flukso-discover
- Joining mDNS multicast group on interface en0.IPv6 with address fe80::216:cbff:feaa:a726.
- New relevant interface en0.IPv6 for mDNS.
- Joining mDNS multicast group on interface en0.IPv4 with address 192.168.1.100.
- New relevant interface en0.IPv4 for mDNS.
- Network interface enumeration completed.
- (Resolver) Service 'Flukso on flukso' of type '_flukso-realtime._tcp' in domain 'local':
- 192.168.1.101:4422 (flukso.local)
- Leaving mDNS multicast group on interface en0.IPv6 with address fe80::216:cbff:feaa:a726.
- Leaving mDNS multicast group on interface en0.IPv4 with address 192.168.1.100.
I haven't figured out how to suppress the log messages, but this works for me.
Bart: What are the chances to integrate a realtime reading server in your lua code, instead of broadcasting realtime values? I will not investigate this today, but for mySmartGrid I have the following plan in my mind:
- Discover where the Flukso realtime service is, see above.
- Open a TCP connection and retrieve the current reading.
- Repeat the last step as often as needed.