The ESP8266 is an increasingly popular chip to power IoT devices with. It has amazing specs for its size and price (~$3), WiFfi built-in and a large community backing it up. It’s also an amazingly interesting chip to experiment with in SAP HCP IoT scenario’s.

There is a set of blog post already, written by Prashantha H J that can show you how to connect the chip to the SAP HANA Cloud via a broker, and I have noticed that several other community members (e.g. Gregor Wolf) have also embraced this chip in various projects:

After showing my power-strip and plug-in thermometer on a recent VNSG Custom Development SIG meeting, followed by a dicussion on how to get started, I thought it would be nice to show you an easy way to get your development environment ready for programming of the chip.

power-strip[1].jpg

The aim of this blog is to quickly get you started programming the chip.As most people developing SAP solutions are currently using Eclipse for their edge projects, I thought it would be convenient to write a blog on how to connect your Eclipse environment to the ESP8266.

Step 0: Get some ESP8266 chips and connect one to your computer


The ESP8266 chips can be bought from various sources. Great resources to get the chip are Ebay, AliExpress or Banggood. You can buy the bare ones, but you can also buy a development board along with it.

I’d highly recommend to buy a development board, because it makes life a lot easier. Most development boards allow you to just plus in your ESP8266 chip, and provide a USB port, leds and switches hardwired to the chip’s GPIO ports and even some contain relays, buzzers and photoresistors.

If you want to have a look at the board I bought to get started with, please have a look at my blog post “Getting started with the ESP8266“.


Step 1: Prepare your Eclipse environment for C programming

As most SAP developers won’t have their environment setup for C programming, this is the first step. To prepare Eclipse for C programming, the C developer tools (CDT) should be installed. To install the CDT, go to the market place (Help | Eclipse Marketplace), search for CDT and install it:

/wp-content/uploads/2015/06/2015_06_08_9_15_24_720032.png

During installation, you will the usual pop-up to accept the license agreement and eventually the installation end with the proposal to restart your eclipse environment (recommended). And that’s all there is to it. Once you have installed CDT, you’re ready to use your Eclipse environment for C programming as well.

For now, just close Eclipse and proceed with step 2.

Step 2: Install the C compiler and ESP8266 SDK

To start programming the ESP8266, a few additional steps are necessary to install the ESP8266 SDK and the C-compiler though. Fortunately Mikhail Grigoriev has made these steps extremely easy by packaging a few smart installation scripts with the original SDK. His blog post “Работа с ESP8266 (working with ESP8266)“, was picked up by my embedded expert colleague Stijn van Drunen who kindly turned it into a blogpost on his own site stijnvandrunen.nl.

During installation, it’s recommended to use the default paths/folders as other components rely on that.

2.1: Download and install Mikhail Grigoriev’s Unofficial Development Kit for Espressif ESP8266.

2.2: Download and install MinGW. Get mingw-get-setup.exe from the official SourceForge project. During the installation uncheck the “… also install support for the graphical user interface” option as we won’t be needing it.

2.3: Mikhail Grigoriev made some awesome scripts to automate the installation of additional modules in MinGW which are needed for compiling. You can download his package here, extract it somewhere and then run install-mingw-package.bat.

Step 3: Import and run an example

Start Eclipse again and select to the C/C++ perspective (Window | Open perspective | Other):

/wp-content/uploads/2015/06/2015_06_08_10_25_01_720033.png

From the C/C++ perspective import one of the existing projects in the examples folder using “File | Import | General | Existing Project into Workspace”. If you then point it to e.g. folder “c:\Espressif\examples\hello_world”, you’ll import the hello_world program into your Eclipse workspace.

To build and upload the example, you will have to figure out which serial portal the ESP8266 is connected to, using the Windows Device Manager.

/wp-content/uploads/2015/06/2015_06_08_10_45_28_720034.png

Once you know which serial port is is connected to, you can open the makefile and change the serial port in the make file (ESPPORT) accordingly.

While still in the C/C++ perspective, you’ll have a set of views on the right set, including “Make Target”. If you select it, you get a nice overview of all make-targets, including “All”, “Clean”, “Flash” and “FlashOneFile”. Once you have make sure the serial port in the makefile is set properly, set the ESP8266 to firmware mode (GIO0 = High during boot) and double click “Flash”. The firmware will then be build and flashed to the chip.

Please find an example of what this looks like in the video below:

To connect to the ESP8266 to see its output, you could use putty. By starting putty using the command below, you’ll connect to COM3 and can inspect it’s output.:

putty -serial com3 -sercfg 115200,8,n,1,n

In the case of the hello_wold example, you should see “Hello World” being printed every second.

Step 4: Use the latests SDK

At the moment of writing, the latests Espressif SDK included in Mikhail’s Unofficial Development Kit is 1.0.1. However, to connect to SAP HANA Cloud platform, an SSL connection is required. As there have been quite some bug fixes in the SSL libraries, I would strongy advice to use SDK 1.1.1 instead.

To install the most recent development kit, please follow the steps below:

4.1: Go to directory c:\EspressIf and rename directory ESP8266_SDK to ESP8266_SDK_101.

4.2: Download EspressIf SDK 1.1.1 from http://bbs.espressif.com/download/file.php?id=484

4.3: Unpack the SDK zip file to C:\Espressif\ESP8266_SDK

4.4: Move all files and folders from folder C:\Espressif\ESP8266_SDK\esp_iot_sdk_v1.1.1 to C:\Espressif\ESP8266_SDK, and remove folder esp_iot_sdk_v1.1.1 afterwards.

Step 5: Modify the hello_world example to print the SDK version

The hello_world example currently prints only “Hello World” every second. To get the hello_world example to print the SDK version used to compile the program with, make the following modification:


LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg)
{
    ets_uart_printf("Hello World from SDK %s!\r\n", system_get_sdk_version());
}










Once you have flashed the modification, the ESP8266 should be returning “Hello World from SDK 1.1.1!” every second.

Catch: undefined reference to `user_rf_pre_init’

If you get this error message during compilation, it means that you have installed SDK 1.1.0 or above. SDKs of version 1.1.0 and above require you to define a new function that is not included in the samples yet. To define this new function, just open your user/user_main.c and add the line below at the bottom of the file:

void user_rf_pre_init(void) {}


What’s Next

In my next blog I’ll show you how to connect to SAP HANA Cloud Platform IoT Services, without a bridge, straight from the ESP8266.

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Robin van het Hof

    Great blog, and makes me want to try out this chip as soon as possible!

    One setback though: the last time I programmed in C++ (not C) was 18 years ago…

    (0) 
    1. Jan Penninkhof

      Ow, comon Robin! You’ve even taken the effort to learn Javascript. And on top of that, C is like riding a bike!

      (0) 
      1. Robin van het Hof

        Well, C++ I learned in 1995 and abandoned in 1998…

        Javascript is something I learned in 1997, and never ceased to use. And unlike C/C++, I didn’t have to worry about pointers. malloc, etc 😉

        (0) 
        1. Jan Penninkhof

          There’s also a way to program the chip in Lua in case you want to avoid pointers and mallocs. Perhaps I should write a blog about that too sometime.

          How do Lua sound to you?

          (0) 

Leave a Reply