Bitlash

From London Hackspace Wiki
Jump to navigation Jump to search

Bitlash - An Interpreted Script Language for Nanode

This page is for documentation and developments specifically on the use of Bitlash (and RESTduino) to control and configure the Nanode via an online connection.


About Bitlash

Bitlash is a simple interpreted script language which runs on Nanode or Arduino. It allows you to define new functions, store them to EEprom memory and to control the I/O port pins with a few simple commands typed over the serial port.

It's a little reminiscent of the late 70's early 80's home-computers that from power-up ran an interpreted basic.

It's better than basic because it ties in with the Arduino libraries and function calls, and you can mix your C code with Bitlash running in the background - it just seems such a cool idea as an interface to a simple microcontroller.

Bitlash has a Telnet example, so that you can Telnet into it remotely and edit scripts to control different things. Well you could - if our TCP/IP stack supported a Telnet Client. Unfortunately it doesn't, so we have to find another way of getting our command line data up to the Nanode.

The mechanism we will attempt to use has been borrowed from RESTduino, a simple way of sending commands to manipulate the I/O of a web connected Nanode or Arduino. Fortunately Andy Lindsay has provided a port of RESTduino which works alongside his updated EtherShield library.

The way Restduino works is to embed the command line at the end of the URL you send to your Nanode server, where the data is parsed, executes a command and then some feedaback is returned via some simple JSON statements.

An Example

Suppose your Nanode is at IP Address 192.168.0.105 and has the means to serve a simple web page assembled from HTML and text in a small text buffer. Lets call this page page_one

HTTP allows for subfolders, so if your page was in a subfolder called password, you could type

http://192.168.0.105/password/page_one and it would serve the page.

If however you don't spell password correctly, the device will return with a 404 error - page not found. This simple mechanisms allows very crude password control over what is served - important if you don't want everyone tinkering with your Nanodes.

I've been looking at the RESTduino example - and it is quite simple to see how the code parses through the URL looking for backslashes and stripping out the parameters contained between them.

The command buffer is set to 50 characters - but I am sure we could extend this to get a good line length - say 127 chars.

So a merge between REST and bitlash would just have to have the REST command line buffer deposited into the bitlash command line buffer (make them one and the same) and bitlash will execute the commands included in the URL.

There is then another string buffer called the Client line - and this is used to send text back to the client. Again bitlash would populate this with the output response from the executed command and send it back.

So let's assume there's a Nanode lurking at IP Address 192.168.0.105

Bitlash sends its ">" prompt to the Client line

The user then wants to get the Nanode to print the answer to the sum 2 + 2 so the User types into the URL window of their browser

http://192.168.0.105/bl/PRINT 2+2 <CR>

The REST code, parses the URL from its command buffer until it finds the first backslash after the IP address where it encounters /bl and so it knows what next is going to be a bitlash command rather than a REST command

/bl/PRINT 2+2 <CR>

it then takes the PRINT 2+2 up to the final <CR> and puts that into the Bitlash command input

Bitlash parses and executes this command and prints 4 back into the Client's Line, followed by a newline and its > prompt.

To make this nice and elegant we would just need a bit of processing code or Python, which accepts lines of text commands and precedes them with the http://192.168.0.105/bl/ header.