Introduction: ESP8266 Code Generator With 128bit Security - No Coding Requried
Code Generator for ESP8266 modules using pfodDesigner, pfodApp and Arduino with 128 bit security
Create custom menus for your Andriod. NO Android or Arduino Programming required.
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 instructable will cover generating code and programming ESP8266-06 style modules mounted on PCBs, using the Arduino IDE. Specifically OLIMEX ESP8266-EVB (and Adafruit Huzzah and SparkFun ESP8266 Thing, when they are available for testing) This tutorial is also available at ESP8266 and pfodApp™ Code Generator. That page also covers generating code for using the ESP8266-01 module in AT cmd mode.
Of these options, 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.
Step 1: 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 V5 supply to center-positive 2.1mm dia barrel connector of at least 1A capacity.
Step 2: Coding the OLIMEX ESP8266-EVB
The latest version of pfodDesigner supports generating code for OLIMEX ESP8266-EVB.
Here is an example sketch generated by pfodDesigner that switches the relay on/off (via D5).
Using the pfodDesigner, you can design you own menu, and sub-menus, to control any of the OLIMEX's pins.
To compile the sketch you will need to download and install the pfodParser libraryV2.15+ This sketch is also in the examples directory of the pfodParser library V2.15
You will also need to edit the generated sketch to insert your wifi network's ssid and password and it is also recommended that you set a staticIP (see the generated code for details)
#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters!
#define WLAN_PASS "myPassword"
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.
Step 3: 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.
If you do not set the staticIP string then DHCP is used 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.
On connecting, the sketch will send back this menu for you to control the relay on the OLIMEX ESP8266-EVB.
Step 4: Adding 128bit Security
Securing against unauthorized users accessing your device over the internet is 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 instructable shows just how easy it is to create a custom menu to control your ESP8266 and switch its relay on and off securely.
We have a be nice policy.
Please be positive and constructive.