Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us

Forward Logo (image)      

ESP8266 and pfodApp™
Code Generator

by Matthew Ford 12th August 2017 (originally posted 26th May 2015)
© Forward Computing and Control Pty. Ltd. NSW Australia
All rights reserved.

Code Generator for ESP8266 modules
using pfodDesigner, pfodApp and Arduino
Create custom menus for your Andriod
NO Android or Arduino Programming required.

(Note: ESP8266 needs pfodParser library V2.15+)

ESP8266 is a low cost wifi enabled chip. It comes in a variety of module types and can be programmed in a variety of ways.

This web page will cover generating code and programming (Arduino style) natively for ESP8266-06 style modules mounted on PCBs. Specifically OLIMEX ESP8266-EVB and Adafruit Huzzah and SparkFun ESP8266 Thing

Of these the OLIMEX ESP8266-EVB is my current favourite. It is easy to program and includes a 5V to 3V3 supply as well as a built in relay and access to the ESP8266 GPIO pins.

Since these modules connect to the internet (via wifi), security is important. You don't want just anyone to be able to open your garage door. The code generator and library shown supports 128 bit security. This security does not encrypt the messages but instead adds a cryptographic hash to each message to protect against un-authorized connection and control. See SipHash Secure Challenge and Response for details of how this security is implemented.

Other ESP8266 Alternatives

If you are just looking for a very cheap and simple WiFi Shield for Arduino and other micros (using Adafruit HUZZAH ESP8266), then check out this page.
f you are looking for an ESP8266-01 WiFi Shield that is just as simple to use as the Very cheap and simple WiFi Shield for Arduino and other micros, but which requires more components and wiring up, one then check out this page instead.

Code Generator for OLIMEX ESP8266-EVB

Note the code generator has been updated to buffer sending data into a single packet. Use pfodDesigner V1.2.870+ and pfodParser library V2.15+ and pfodApp V1.2.87+)

Setting up to Program the OLIMEX ESP8266-EVB

To setup to program the OLIMEX ESP8266-EVB, follow the steps given on https://github.com/esp8266/arduino under Installing With Boards Manager. When opening the Boards Manager from the Tools → Board menu and select Type Contributed and install the esp8266 platform. This project was compiled using the ESP8266 version 1.6.4-673-g8cd3697. Later versions well be better but may have their own bugs as the platform is evolving rapidly.

To program the OLIMEX ESP8266-EVB from the Arduino IDE, I used a USB Serial Cable F from Olimex and its drivers. It is connected to the ESP8266-EVB as shown above. You will also need a 5V power supply to center-positive 2.1mm dia barrel connector of at least 1A capacity. Also see ESP8266 Programming Tips (espcomm failed)

Coding the OLIMEX ESP8266-EVB

The latest version of pfodDesigner supports generating code for OLIMEX ESP8266-EVB. Here is an example sketch generated by pfodDesignerV2 that switches the relay on/off (via D5). To compile the sketch you will need to download and install the pfodParser library V2.15+ (This sketch is also in the examples directory of the pfodParser library V2.15) You will also need to edit the sketch to insert your wifi network's ssid and password and it is also recommended setting a staticIP

Programming the OLIMEX ESP8266 is as simple as plugging in the USB Serial cable, pressing the white pushbutton on the OLIMEX ESP8266-EVB and, while holding it down, plugging the power cable in. You can release the push button once the board is powered up.

Then click the Arduino download button to compile sketch and download it to the OLIMEX ESP8266-EVB. When the download is completed, the board reboots in normal operating mode and you can open the Arduino IDE serial monitor (set to 115200 baud) to see any sketch's startup messages.

Controlling the OLIMEX ESP8266-EVB with pfodApp.

After you load the sketch, edited with your network's ssid and password, the ESP8266 connects to your network. If the module does not connect to your network and you should check your ssid and pw settings.

The library uses DHCP to get an IP for the module, so you will need to check which IP as been assigned. You can do this by logging in to your router and seeing what new IP has just connected OR you can use fing on your mobile to see what IPs are active. Look for the IP of Espressif.

Then install pfodApp on your Android mobile and setup a connection for this IP (see pfodAppForAndroidGettingStarted.pdf). On connecting, the sketch will send back this menu for you to control the relay on the OLIMEX ESP8266-EVB.

Using the pfodDesignerV2, you can design you own menu, and sub-menus, to control any of the OLIMEX's pins.

Adding 128bit security

Securing against un-authorized users accessing your device over the internet is a as easy as editing
#define pfodSecurityCode ""
to add your own secret code. (up to 32 Hex digits)

For example to set a security code of 173057F7A706AF9BBE65D51122A14CEE you would use
#define pfodSecurityCode "173057F7A706AF9BBE65D51122A14CEE"
Of course you should use your own secret code. Setting your own code in your pfodApp connection allows you, and no-one else, to connect.

A long random code is necessary for good security. pfodApp supports up to 128bits as 32Hex digits.

To generate your own secret code can download a random Secret Key Generator from here. As well as generating random keys, this program writes them out as QR codes so you can easily and accurately set them in your pfodApp connection.

You print out the QR code and attach it to your pfodDevice. Then you then use a QR reader on your mobile, for example QR Droid Private, to read in into you mobile and copy it to your pfodApp connection password, in order to connect.

See A Simple WiFi/Arduino pfodDevice™ with 128 bit security for a detailed example of using the key generator and the QR code.

This shows just how easy it is to create a custom menu to control your ESP8266 and switch its relay on and off securely.


This tutorial has shown how to use the pfodDesigner to generated code for ESP8266 modules. You can use the pfodDesignerV2 to design your custom menu and then generate the code for you. No Arduino coding required. The pfodApp takes care of all the Android side, no Android coding required.

AndroidTM is a trademark of Google Inc. For use of the Arduino name see http://arduino.cc/en/Main/FAQ

The General Purpose Android/Arduino Control App.
pfodDevice™ and pfodApp™ are trade marks of Forward Computing and Control Pty. Ltd.

Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2020 Forward Computing and Control Pty. Ltd. ACN 003 669 994