PeerTalk, BeagleBone, and Raspberry Pi

Computers & Mobile Other Boards Raspberry Pi

The Monday Jolt

This post was originally published in two parts [1,2] on the The Daily ACK Aug. 25, 20012. It is reposted here on the MAKE site with permission.

I came across an excellent bit of wizardry by Rasmus Andersson called PeerTalk. It’s a Objective-C library allowing you to communicate between your iPhone and your Mac over the USB dock cable using TCP sockets.

YouTube player

My immediate thought was that if this really only depended on having USB host mode capability at the far end, the same mechanism should be able to be used to talk to something like the BeagleBone, or the Raspberry Pi, not just your Mac. This would allow you connect your phone directly to the micro controller board and to drive hardware directly, a lot like the Redpark cable but bypassing Apple’s External Accessory framework.

PeerTalk

So I started digging around inside the source code to see if it depended on anything that was going to be specific to OS X, it became apparent that PeerTalk was mostly some really nice socket code sitting on top of the USB Multiplex Daemon (usbmuxd). This bit of software is in charge of talking to your iPhone over USB and coordinating access to its services by other applications. Effectively this is what iTunes and Xcode use to talk to your phone when you plug it into your Mac’s USB port.

So any device that wants to talk to the iPhone using this method needs usbmuxd. Fortunately  for me there are a number of people who have worked out how to talk to the iPhone from Linux, and there is a working usbmuxd for Linux.

BeagleBone

There are also As a few other dependencies which aren’t present on the stock Ångström Linux distribution on my BeagleBone, or even packages via opkg, building usbmuxd on my BeagleBone requires libusb and cmake. So before building usbmuxd, I had to build cmake, which meant resolving some problems with the stock compression libraries that shipped with Ångström.

However several hours later after enough waiting around for software to build to convince me that before doing any serious development on the BeagleBone I really had to build an ARMv7 toolchain on my Mac to cross-compile things instead of building them directly on the board….

iPhone talking directly to my BeagleBone using PeerTalk

…I managed to get a simple “hello” from my iPhone to the BeagleBone and then via screen to my Mac using port forwarding and that old stand by, telnet.

While I was hacking away on getting this working, I wasn’t alone. David House was looking down some of the same back alleyways to get PeerTalk talking to his Raspberry Pi, and we batted the problem back and forth on Twitter while waiting for code to compile well into the night…

While I was working on one end, David was working on the other, putting together a client on the Raspberry Pi sitting on top of usbmuxd that’d talk natively to the PeerTalk on iOS which he called peertalk-python. Since we had the source code of both ends, it wasn’t that hard. Just hard enough.

If you want to replicate this on the BeagleBone, or the Raspberry Pi, you should first download and build the PeerTalk library, and then build and deploy the iOS and OSX example applications and get that up and running.

Then connect up and boot your BeagleBone. You’ll need to power the board using a mains adapter as when you’re compiling things. It’s possible you’ll be drawing enough amperage that your computer will turn off the USB port to protect itself and as a result power down your BeagleBone. I had this happen to me a couple of times before I finally dug a mains adapter out of my office drawer. However since you’re powering the board from the mains you’ll also have to connect an Ethernet cable so that you can ssh root@beaglebone.local and log into the board over the network.

1. Go ahead and login to your BeagleBone as root.

2. Download, build and install libusb. Version 1.0.9 builds, links and installs okay.

3. Download, build and install cmake, which you’ll need to buildusbmuxd later. You’ll need to grab the latest Git nightly checkout as older release versions don’t build, having problems with the stock libbz2compression on the BeagleBone.

4. We also need libplist, however this is available as part of the package management system on Ångström Linux, so all you need to do to install this is type opkg install libplist-dev at the prompt.

5. Download, build and install usbmuxd. Version 1.0.8 builds, links and installs okay, although you may beed to use ccmake and configure by hand, rather than using cmake, as it can’t seem to find the libusb include files that got installed into /usr/local.

6. Create a usbmux user

groupadd -r usbmux -g 114
useradd -r -g usbmux -d / -s /sbin/nologin -c “usbmux user” -u 114 usbmux

7. As the BeagleBoard doesn’t have syslog turned on by default, and you’ll need it for debugging, turn on syslogd from the relevant script in /etc/init.d.

8. Run up the usbmux deamon, by typing usbmuxd -v -v at the prompt.

9. Plug your iPhone into the (host side) USB on your BeagleBoard, you should see some debug scrolling by in /var/log/messages.

10. Download David House’s peertalk-python and its dependances.

11. On your iPhone start the PeerTalk client for iOS.

12. Start the python client on the BeagleBone by typing python ./peertalk.py at the prompt.

Type in a message at the prompt, and you should see something like this…

Bi-directional communication between the iPhone and the BeagleBone via USB

From there it’s pretty trivial to build a “Hello World” example, just by hacking around with David’s code and toggling the heartbeat LED when the BeagleBone receives any messages.

    def run(self):
        framestructure = struct.Struct("! I I I I")
        ledOn ='echo 1 > /sys/class/leds/beaglebone::usr0/brightness'
        ledOff ='echo 0 > /sys/class/leds/beaglebone::usr0/brightness'
        i = 0
        while self._running:
            try:
                msg = self._psock.recv(16)
                if len(msg) > 0:
                    frame = framestructure.unpack(msg)
                    size = frame[3]
                    msgdata = self._psock.recv(size)
                    print "Received: %s" % msgdata
                    if i == 0:
                       os.system(ledOn)
                       i = 1
                    else:
                       os.system(ledOff)
                       i = 0
            except:
                pass
Which gets you to this point…

Which is pretty much where I’ve reached right now. Next steps is a proper application on the iOS end of things with more generic control of the BeagleBone’s header pins, and a more flexible Python backend on the BeagleBone itself. David House also managed to get everything up and working on the Raspberry Pi.

YouTube player

The only changes from the BeagleBone set up procedure is that you should grab libplist using apt-get rather than opkg, and since you won’t be logged in as root you should remember to sudo usbmuxd -v -v when you start the USB daemon. Apart from that, you should be good to go…

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Tagged

Alasdair Allan is a scientist, author, hacker and tinkerer, who is spending a lot of his time thinking about the Internet of Things. In the past he has mesh networked the Moscone Center, caused a U.S. Senate hearing, and contributed to the detection of what was—at the time—the most distant object yet discovered.

View more articles by Alasdair Allan
Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK