Posts Tagged guile

Guile on a Ben NanoNote

Received a Ben NanoNote today. It is a really natty little device with a lot of potential.

My standard test on how hackable a device is involves getting Guile running. Anyway, it was pretty easy to accomplish this despite not using openWrt before.


root@BenNanoNote:~#
root@BenNanoNote:~# guile
guile> (map (lambda (x) (+ x 1)) '(1 2 3 4 5))
(2 3 4 5 6)
guile>

To install get the 3 xburst packages from here.

Happy Scheming!

Tags: ,

Scripting with Guile on Openmoko

Having Guile running on an embedded device is very powerful. You can add scripting capabilities to a C program and avoid some of the cross compilation -> deploy cycles by simply editing the script to change some functionality. As an example I have taken the code from the excellent introductory article Scripting with Guile. I packaged the code so that if you install the tarball or the ipk it will install both the binary and script to a suitable place.

Tarball: http://zedstar.org/tarballs/square-0.1.tar.gz

ipk: http://zedstar.org/ipk/square_0.1-r0_armv4t.ipk

After installing Guile do:

root@om-gta02 ~/ipks $ opkg install square_0.1-r0_armv4t.ipk
Installing square (0.1-r0) to root...
Configuring square
root@om-gta02 ~/ipks $ square
result of square is 49
result of square2 is 81

Tags: , ,

Guile on an Openmoko Freerunner

I recently got hold of a bunch of Openmoko Freerunners. I needed a distribution which installs to Flash (NAND) so I chose SHR.

I am very impressed how things have progressed especially in terms of being a phone!

Anyway, this gave me a chance to try out some Guile packages I built. If you have a recent version of SHR unstable the following should work:

http://zedstar.org/guile/

Happy Scheming!

Tags: , ,

Tweeting from an IRC bot

I have made a Guile module which is capable of being used by the IRC bot bobot++. The code is available here:

http://zedstar.org/tarballs/sneektweet-0.1.tar.gz

The readme:

sneektweet 0.1:

Wraps some C/GLib code which posts to Twitter.

setup:

Edit configure.ac to set twitter account details.

from REPL:

john@thinkpad:~/workspace/sneektweet$ guile
guile> (use-modules (twitter sneektweet))
guile> (tweet "foobar")
guile> ** Message: posted update to Twitter

todo:

Add reading updates and posting back to IRC channel. 

bobot example code:

(use-modules (twitter sneektweet))

(define (sneektweet channel message)
  (if (> (string-length message) 140)
    (bot:say channel "Your message needs to be under 140 characters in length!")
    (tweet message)))

(bot:addcommand "tweet" sneektweet #t 2 0)

Tags: , , ,

geotwitta

geotwitta lets you see how far you are from other twitter users running the program. It will post to your twitter account letting you know the distance in kilometers from those users. It is based on a bunch of technologies I wanted to try out. As a result it is somewhat over-engineered for what it does. For those that are interested it uses Guile to script a binary network protocol that happens to be encoded efficiently over UDP packets.

It is a command line program. An example of usage is:

geotwitta -u foo -p bar --lat=55.55 --long=-0.25

This would authenticate against the Twitter account ‘foo’ with password ‘bar’ and ping in those coordinates. These account details are only exchanged securely with Twitter and not sent over the network protocol. The protocol also does not provide coordinates back of other users. It simply shows a relative distance. The full source of the client is available. If there is an interest I will also tidy up the server code and release it.

To get started you need two packages: The program itself and the Guile module which does the network protocol work. The following tarballs are availble for those who want to build from source.

http://zedstar.org/tarballs/packedobjects-0.1.tar.gz

http://zedstar.org/tarballs/geotwitta-0.1.tar.gz

http://zedstar.org/tarballs/geotwitta-0.2.tar.gz

Untar and do the usual ./configure… routine. The configure script will let you know which dependencies are required to compile. If you don’t feel like building from source I have also built some Debian packages. I have tested these on Ubuntu (Intrepid Ibex).

http://zedstar.org/deb/packedobjects_0.1-1_i386.deb

http://zedstar.org/deb/geotwitta_0.1-1_i386.deb

http://zedstar.org/deb/geotwitta_0.2-1_i386.deb

If you manage to get the software running I will see you on Twitter!

All the usual disclaimers about the software apply.

**update**

Version 0.2 of geotwitta added: ignores UDP packet loss on pings

Tags: , ,

Building a Guile extension on an embedded device

Thanks to OpenEmbedded building extensions for Guile that run on embedded devices such as the BeagleBoard is fairly painless. As I have previously mentioned, Guile is already supported by OpenEmbedded. If you have an extension which is made up of some C code and some Scheme code you first should automate building it with autoconf. This might install a shared library and install some Scheme files into Guile specific locations. The next step is to write a bitbake recipe which will work with this autoconf based project. Typically this recipe will download a tarball or checkout some code from version control and then begin its magic. The end product hopefully is a binary package which can be easily installed onto the device. As an example I built packedobjects as a Guile extension for my BeagleBoard. The bitbake recipe is availabe here:

http://packedobjects.cvs.sourceforge.net/viewvc/packedobjects/packedobjects_project/openembedded/

This works by getting the latest code from CVS. It builds the code and is told which files need to be part of the package. So if you have OpenEmbedded setup you just need to issue the command:

bitbake packedobjects

This will build and package the lastest code as an ipk.

We should test the built ipk on the device to see if it works:

root@beagleboard:~# opkg install http://zedstar.org/ipk/libpackedobjects0_0.1-r0.1_armv7a.ipk
Downloading http://zedstar.org/ipk/libpackedobjects0_0.1-r0.1_armv7a.ipk
Installing libpackedobjects0 (0.1-r0.1) to root...
Configuring libpackedobjects0
root@beagleboard:~# guile
guile> (use-modules (packedobjects))
guile> (exit)

Tags: , , ,

Packedobjects for Guile

I have created a sourceforge project for the new Guile version of packedobjects:

http://packedobjects.sourceforge.net/

This is an early version without documentation. The API has changed from the Chicken version so I will document this soon. Eventually I will push back the improvements to the Chicken version.

So far it builds as a Guile module. I also need to look at how to embed this version into a C application.

Tags: ,

Groking Guile’s FFI

I have lately been very busy with work, life and the universe and subsequently have done little hacking. I have recently been examining Guile. Guile has been part of OpenEmbedded for a while so should be easy to get running on numerous embedded devices. Chicken was very recently added to OpenEmbedded, however, lacks support for building eggs in this environment. One thing I really love about Chicken is its very easy to use foreign function interface (FFI). After spending the odd hour over various weekends I have finally begun to grok Guile’s FFI. I plan to build packedobjects for Guile and possibility extend its features.

I really like the idea of extension languages ever since I did some work with Tcl a number of years ago. A great example application was Eggdrop the IRC bot. Lots of kids at the time would program their eggdrop bots using the simple Tcl interface. I think a lot can be said about this approach in terms of learning/teaching programming. I hope to explore this further with my education hat on.

Tags: , , ,