Erlang

Erlang on RPi, starting with a fresh 2013-05-25-wheezy-raspbian.zip image. Erlang takes a couple of hours to compile (when you run "make").

You start the interactive shell with erl and quit with Ctrl-g q. Read about Erlang here

Introduction
On this page I will show how to use Erlang on RPi to put a sensor value from Gertboard on the web using an interface written in Forth and how to put a picture from Pi Camera on the web.

A Web Server
Erlang is a perfect language to use for programming a web server, and that is exactly what Loïc Hoguin did. Cowboy is one of the most scalable web servers there is and it's also small so it fits nicely in a RPi. I was thinking of using it to display the kW load from my Atlast Forth interface to   Gertboard. Here is how I did it, first install the cowboy web server and test run it: To make it run you first have to tell it to accept HTTP: Start a browser and point it to your RPi:8080, eg 192.168.0.178:8080

External interfaces - Gertboard
Erlang processes communicate with the outside world using the same message passing mechanism as used between Erlang processes. This mechanism is used for communication with the host operating system and for interaction with programs written in other languages. If required for reasons of efficiency, a special version of this concept allows e.g. C programs to be directly linked into the Erlang runtime system. The easy way is good enough so just open a port to  Atlast Forth  in the file examples/hello_world/src/toppage_handler.erl. Replace toppage_handler.erl with the following: cd to ebin and compile the file: Now, we need to put atlast in the ./priv directory, but first we have to get rid of the banner and the prompt.

In atlmain.c comment out PR("ATLAST 1.2 (2007-10-07) This program is in the public domain.\n"); at line 55 and comment out       if (!fname) at 162,163,164 and 165. Save and run make again.

In directory cowboy, create a directory priv and copy atlast to it: Create a file kwh.atl and put it in the same priv directory with the word definitions for getting kW and W load values from Gertboard: Ok, now we just have to call start.sh again ( sudo is needed by the Gertboard driver, not by Cowboy, and for pure simplicity I take another shortcut and starts the Cowboy with sudo rights. Don't do this in a production environment). Point the browser to 192.168.0.178:8080 or whatever ip address you have on your RPi. After a few seconds the W load should show up. I stop here, this is not the right forum to discuss how to make a web gui, lots of other sites can help with that. Have fun :)

Note: The suggested way to call the port directly from examples/hello_world/src/toppage_handler.erl is just to make it easy. In a real website with thousands of users you should open the port from a separate process and let it run and serve more than one web call.

External Interfaces - Pi Camera
If you have a PiCamera and wants to have a picture on a web page. The cool thing with this is that it's in real time, it is not a file that is served but a new picture is taken when you do the web call. Check that /opt/vc/bin/raspistill works on your system, then replace the code in examples/hello_world/src/toppage_handler.erl with the following: (Then follow the Gertboard example for compiling and running). Note: The suggested way to call the port directly from examples/hello_world/src/toppage_handler.erl is just to make it easy. In a real website with thousands of users you should open the port from a separate process and let it run and serve more than one web call.