Build the Smart.js framework

Cesanta has developed a JavaScript engine, capable of run JavaScript code in the ESP8266 device and in other embedded devices. The JavaScript engine is provided with the Smart.js framework. The framework offers a set of APIs for files management, networking and WiFi management, SPI and I2C communication, GPIOs and Cloud services. The framework is distributed ready to flash under Windows and Mac. Here you can find a short guide.

In this article I will show how to build the framework under the Ubuntu’s like OS and flash your ESP8266-01 device with the latest Smart.js framework version.

Framework build

In order to build the Smart.js framework we need first to install Docker. A complete and updated set of instructions on how to install Docker can be found here. To make it short you can simply run this command in the console:

After the Docker installation is complete we checkout the framework code:

To build the framework move to the esp platform directory:

and run the build process:

The first time it will require a little bit because the tool has to download the docker images. Next builds will be really fast.

The three binary files composing our ESP firmware will be generated under the firmware folder. Now we need the tool to flash the ESP device.

Flash’n’Chips build

The Smart.js framework is provided with a tool for flashing our devices: Flash’n’Chips.

fnc

To build the tool first we need to install the required dependencies: Qt 5 and libftdi.

To install Qt 5 you can use the installer distributed by Qt here. It will install all the Qt tools under the specified folder. In the folder you will find the binary required to compile Flash’n’Chips. I suggest to add the bin folder to your PATH variable:

To install the libftdi library run:

Now we are ready to compile the Flash’n’Chips tool. Move to the source folder:

And run first:

then:

In a bit the tool will be ready to be executed. Time to connect the ESP device to your computer.

Wiring

To connect my ESP 8266-01 I’m using a FT232 adapter. If you are using it remember to set it to 3v3.

ft232

We connect the respective VCC and GND pins, same for RX and TX pins but inverting them. We need also to connect the ESP CH_PD to the VCC and, only for the flashing process, the ESP GPIO_0 to the GND.

ft232 esp8266_bb

We are now ready to flash the previously built firmware into the ESP device.

Flash the ESP

Connect the USB adapter and run the Flash’n’Chips tool using this command from the flashnchips folder (I had to use this parameters for some issues with my ESP board):

The tool should show the “Flash firmware” button active.

fnc ready

If not press the “Detect devices” button and see if the adapter is recognized.

Press the “Flash firmware” button and the flash process will start. You can see the progress bar running and the current operation explained under it.

fnc flash

When the process is completed the communication console will be activated under the progress bar area. You will see some messages from the device.

fnc console

Now we are ready to run some JavaScript commands in our ESP device.

Play with console

The Flash’n’Chips console has two areas, the first shows the device output, the second let us write commands to send to the device. The commands are snippets of JavaScript code that are executed on the device.

We can start writing a simple expression:

The device will calculate it and reply with the result:

We can also use the framework’s APIs, for example we can list the files present on the device:

It should output something like:

These are some of the JavaScript functions that our device can run. In the next article we will see how to run a simple program that reads values from a DHT11 sensor and publish them in a site.

How to build the Dart SDK for the Raspberry Pi

For a DIY project I’m working on I need to run a Dart project on my Raspberry Pi board, precisely in his Raspbian OS. The Dart team has done a good job publishing a wiki page with all the information to build the SDK. Here I’m summarizing the necessary steps in a handy list, or, if you prefer, at the end of the post you can find a zip file with the SDK already built.

MACHINE setup

I suggest you run the entire process in a virtual machine in order to have a clean environment and the best compatibility with the provided scripts.

  • Download the Ubuntu server 12.04.5 64-bit ISO.
  • Install your virtualization software, I’ve used VirtualBox.
  • Create a new Virtual Machine. In VirtualBox using the wizard, select Linux OS and Ubuntu 64 bit. Here’s my VM configuration:
    • 4 GB ram
    • 23 GB HD, the used space after the entire process is about 11 GB
    • 2 processors (the core available in my hosting machine)
    • TCP ssh port forwarding (My host OS is a Linux with sshd active)
  • Install Ubuntu server through the downloaded ISO. During the configuration, in the package selection phase, select the OpenSSH Server, we will use scp to copy the produced SDK.

READY TO START

Login in Ubuntu and create a working directory. All the following commands are relative to the created working folder.

DEPENDENCIES INSTALLATION

Download and run the script that installs all the necessary dependencies.

DEPOT TOOLS INSTALLATION

Download and setup the source code management tools provided for chromium.

SOURCE CODE DOWNLOAD

Download the Dart 1.7 source code (if you want the latest developed version use this url: http://dart.googlecode.com/svn/branches/bleeding_edge/deps/all.deps)

TOOL CHAIN DOWNLOAD

We are going to cross compile the code so we need the tool chain provided by Raspberry Pi.

SDK compilation

Finally we are ready to compile. In the meanwhile you can go to take a coffee.

SDK INSTALLATION

Copy the dart-sdk folder under the dart/out/ReleaseXARM folder to your Raspberry Pi machine (using scp or your folder explorer).

If you like to make the Dart commands available in the command line edit your .bashrc file in your Raspbian installation and add these lines (modify the dart-sdk path based on your installation path):

READY TO RUN

You can check if the dart installation is working by simply running it. You should see this output:

LET’S RUN HELLO WORLD

As final step let’s run a simple Hello World project. We can create such simple project quickly using the new Stagehand tool. First we need to install it:

We are now ready to create the project:

The project is ready, let’s get hits dependencies and run it:

THE FAST WAY

If all these steps scares you, then you can download the zipped folder with the Dart SDK that I’ve prepared. You’re downloading it and using it at your own risk.
dart-sdk-raspberry-pi-1.7.2