0

members

Easy Basics: Project 072a ESP32 Development board - Over the Air updates via ESP Web server

of Acoptex.com in ESP8266 ESP-32

Basics: Project 072a

Project name: ESP32 Development board - Over the Air updates via ESP Web server

Tags: Arduino, ESP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, Installing the ESP32 Board in Arduino IDE, Uploading sketch, OTA ESP32, Wi-Fi OTA, Wireless Update ESP32 from the Arduino IDE, ESP32 Over-the-Air (OTA) Updating, OTA update, Over the Air updates (OTA), OTA updates for ESP32 via ESP Web server, ESP32 HTTP Web server

Attachments: OTAWebUpdater1OTAWebUpdater2 , ArduinoOTAlibrary

In this project, you need these parts :

1. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc

2. Arduino IDE version 1.6.13 ( you can download it here )

3. Python 2.7.15 ( you can download it here )

4. Led (red and green) 2 pcs

5. Resistor 220 Ohm 2 pcs

6. Breadboard 1 pc

7. Jumper wires F-M, M-M

General

We will learn how to do update through WiFi  via ESP Web server (OTA - Over The Air Update) with ESP32 development board.

OTA (Over the Air) update is the process of loading a new firmware to ESP32 development board using WiFi connection rather than a serial communication. This type of functionality is extremely useful in case of no physical access to the ESP module.

Uploading a new sketch wirelessly from Arduino IDE is intended for the following typical scenarios:

  1. during firmware development – as a quicker alternative to uploading a new sketch over a serial.
  2. for updating the firmware of multiple ESPs in your network.

The ArduinoOTA library for wireless updates (OTA) in Wi-Fi is also compatible with ESP32. It is integrated into the Arduino Core for ESP32 developed by Espressif. It is not yet possible to install the development kit from the card manager. Since the SDK is still in development, the installation process depends on the machine on which the Arduino IDE is installed. It is now possible to use the password hash to further secure the remote update. Another novelty, it is now possible to update in Wi-Fi the SPIFFS memory area.

The ESP32 is much more secure than the ESP8266, it is possible to store the hash of the password in place of it. To create your password fingerprint, you can use an online MD5 hash generator. For example, the hash of the admin password will give the fingerprint 21232f297a57a5a743894a0e4a801fc3. We suggest you do not use the admin password.

MD5 hash generator

MD5 hash generator is useful for encoding passwords, credit cards numbers and other sensitive date into MySQL, Postgress or other databases. PHP programmers, ASP programmers and anyone developing on MySQL, SQL, Postgress or similar should find this online tool an especially handy resource.

What is an MD5 hash?

An MD5 hash is created by taking a string of an any length and encoding it into a 128-bit fingerprint. Encoding the same string using the MD5 algorithm will always result in the same 128-bit hash output. MD5 hashes are commonly used with smaller strings when storing passwords, credit card numbers or other sensitive data in databases such as the popular MySQL. This tool provides a quick and easy way to encode an MD5 hash from a simple string of up to 256 characters in length.

MD5 hashes are also used to ensure the data integrity of files. Because the MD5 hash algorithm always produces the same output for the same given input, users can compare a hash of the source file with a newly created hash of the destination file to check that it is intact and unmodified. An MD5 hash is NOT encryption. It is simply a fingerprint of the given input. However, it is a one-way transaction and as such it is almost impossible to reverse engineer an MD5 hash to retrieve the original string.

There are a lot of different development boards made. You can find more information about them here

Understanding the ESP32 Development board with WiFi and Bluetooth

We will discuss here an Espressif Systems products. Our development board is using ESP-WROOM-32 module from Espressif Systems.

Espressif offers a wide range of fully-certified Wi-Fi & BT modules powered by their own advanced SoCs.

1. Dual-core Modules with Wi-Fi & Dual-mode Bluetooth

Features

  • Two independently-controlled CPU cores with adjustable clock frequency, ranging from 80 MHz to 240 MHz
  • +19.5 dBm output at the antenna ensures a good physical range
  • Classic Bluetooth for legacy connections, also supporting L2CAP, SDP, GAP, SMP, AVDTP, AVCTP, A2DP (SNK) and AVRCP (CT)
  • Support for Bluetooth Low Energy (BLE) profiles including L2CAP, GAP, GATT, SMP, and GATT-based profiles like BluFi, SPP-like, etc
  • Bluetooth Low Energy (BLE) connects to smart phones, broadcasting low-energy beacons for easy detection
  • Sleep current is less than 5 μA, making it suitable for battery-powered and wearable-electronics applications
  • Integrates 4 MB flash
  • Peripherals include capacitive touch sensors, Hall sensor, low-noise sense amplifiers, SD card interface, Ethernet, high-speed SPI, UART, I2S and I2C
  • Fully certified with integrated antenna and software stacks

2. Single-core Modules with Wi-Fi & Dual-mode Bluetooth

Features

  • High-performance 160 MHz single-core CPU
  • +19.5 dBm output at the antenna ensures a good physical range
  • Classic Bluetooth for legacy connections, also supporting L2CAP, SDP, GAP, SMP, AVDTP, AVCTP, A2DP (SNK) and AVRCP (CT)
  • Support for Bluetooth Low Energy (BLE) profiles including L2CAP, GAP, GATT, SMP, and GATT-based profiles like BluFi, SPP-like, etc
  • Bluetooth Low Energy (BLE) connects to smart phones, broadcasting low-energy beacons for easy detection
  • Sleep current is less than 5 μA, making it suitable for battery-powered and wearable-electronics applications
  • Peripherals include capacitive touch sensors, Hall sensor, low-noise sense amplifiers, SD card interface, Ethernet, high-speed SPI, UART, I2S and I2C
  • Fully certified with integrated antenna and software stacks

 

3. Single-core Modules with 802.11b/g/n 2.4 GHz Wi-Fi

Features

  • High-performance 160 MHz single-core CPU
  • +19.5 dBm output at the antenna ensures a good physical range
  • Sleep current is less than 20 μA, making it suitable for battery-powered and wearable-electronics applications
  • Peripherals include UART, GPIO, I2C, I2S, SDIO, PWM, ADC and SPI
  • Fully certified with integrated antenna and software stacks

There are different development Boards made by Espressif Systems and other manufacturers. We will publish some information about Espressif Systems boards but you can also find out more information about other development boards here.

1. 2.4 GHz Wi-Fi & BT/BLE Development Boards

Features

  • PC connectivity: USB
  • Power supply options: USB (by default), or 5V/GND header pins, or 3V3/GND header pins
  • SDK: ESP-IDF source code and example applications

2. 2.4 GHz Wi-Fi Development Boards

Features

  • PC connectivity: USB
  • SDK: ESP8266 SDK source code and example applications

3. 2.4 GHz Wi-Fi + BT/BLE + Sensor Development Boards

Features

  • PC connectivity: USB
  • SDK: ESP-IOT-SOLUTION source code and example applications

You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board by pressing Getting started link close to each board here.

ESP32 chip

ESP32 is a series of low cost, low power system on a chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations and includes in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company, and is manufactured by TSMC using their 40 nm process. It is a successor to the ESP8266 microcontroller.

ESP32 can perform as a complete standalone system or as a slave device to a host MCU, reducing communication stack overhead on the main application processor. ESP32 can interface with other systems to provide Wi-Fi and Bluetooth functionality through its SPI / SDIO or I2C / UART interfaces.

ESP32 is highly-integrated with in-built antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. ESP32 adds priceless functionality and versatility to your applications with minimal Printed Circuit Board (PCB) requirements.

ESP32 is capable of functioning reliably in industrial environments, with an operating temperature ranging from –40°C to +125°C. Powered by advanced calibration circuitries, ESP32 can dynamically remove external circuit imperfections and adapt to changes in external conditions.

Engineered for mobile devices, wearable electronics and IoT applications, ESP32 achieves ultra-low power consumption with a combination of several types of proprietary software. ESP32 also includes state-of-the-art features, such as fine-grained clock gating, various power modes and dynamic power scaling.

Functional Block Diagram:

Features of the ESP32 include the following:

Processors:

  • CPU: Xtensa dual-core (or single-core) 32-bit LX6 microprocessor, operating at 160 or 240 MHz and performing at up to 600 DMIPS
  • Ultra low power (ULP) co-processor
  • Memory: 520 KiB SRAM

Wireless connectivity:

  • Wi-Fi: 802.11 b/g/n
  • Bluetooth: v4.2 BR/EDR and BLE

Peripheral interfaces:

  • 12-bit SAR ADC up to 18 channels
  • 2 × 8-bit DACs
  • 10 × touch sensors (capacitive sensing GPIOs)
  • Temperature sensor
  • 4 × SPI
  • 2 × I²S interfaces
  • 2 × I²C interfaces
  • 3 × UART
  • SD/SDIO/CE-ATA/MMC/eMMC host controller
  • SDIO/SPI slave controller
  • Ethernet MAC interface with dedicated DMA and IEEE 1588 Precision Time Protocol support
  • CAN bus 2.0
  • Infrared remote controller (TX/RX, up to 8 channels)
  • Motor PWM
  • LED PWM (up to 16 channels)
  • Hall effect sensor
  • Ultra low power analog pre-amplifier

Security:

  • IEEE 802.11 standard security features all supported, including WFA, WPA/WPA2 and WAPI
  • Secure boot
  • Flash encryption
  • 1024-bit OTP, up to 768-bit for customers
  • Cryptographic hardware acceleration: AES, SHA-2, RSA, elliptic curve cryptography (ECC), random number generator (RNG)

Power management:

  • Internal low-dropout regulator
  • Individual power domain for RTC
  • 5uA deep sleep current
  • Wake up from GPIO interrupt, timer, ADC measurements, capacitive touch sensor interrupt

You can find ESP32 chip datasheet here, hardware design here, technical reference manual here.

Signals and connections of the ESP32 Development board with WiFi and Bluetooth

You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.

Let's check our development board - ESP32 DEVKITV1 with ESP-WROOM-32 module from Espressif Systems:

Pinout diagram for the ESP Wroom 32 breakout:

ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.

USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.

BOOT button - Download button: holding down the Boot button and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.

EN button - Reset button: pressing this button resets the system.

Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.

TX0, TX2 - transmit pin. GPIO pin

RX0, RX2  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND - ground pin.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

Wiring


Step by Step instruction

The ESP32 is currently being integrated with the Arduino IDE like it was done for the ESP8266. There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language.

We are using PC with Windows 10 OS.

1. Installation of  ESP32 add-on in Arduino IDE on Windows OS.

  1. Download and install the Arduino IDE version 1.6.13 Windows Installer. You can download it here.
  2. Download and install Git and Git GUI from git-scm.com
  3. Search for Git GUI, right-click the icon and select “Run as administrator
  4. Select the Clone Existing Repository option.
  5. Select source and destination. Source Location: https://github.com/espressif/arduino-esp32.git
  6. Target Directory:C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32
  7. Do not create the espressif/esp32 folders, because they will be created automatically.
  8. Click Clone to start cloning the repository.Wait a few seconds while the repository is being cloned.
  9. Open the folder: C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32/tools
  10. Right-click the get.exe file and select “Run as administrator“.
  11. You will see that necessary files will be downloaded and upzipped. It will take some time.
  12. When get.exe finishes, you should see the following files in the directory.

2. Installing Python 2.7.x

  1. You need to install Python 2.7.X on your PC. Go to python.org website and download the latest version of Python 2.7.X for your OS (Operating System) (We are using Python 2.7.15 version in this project. You can download it here).
  2. Open the downloaded file to start the Python installation wizard. 
  3. Press Next button. Select destination directory.
  4. Press Next button.
  5. Scroll down in the Customize Python 2.7.15window and open the Add python.exe to Path. Select the option Will be installed on local hard drive.
  6. Press Next button to complete the installation. Press Yes button to give access to the drive.
  7. Press Finish button to complete installation.

3. Uploading the OTAWebUpdater1 sketch to ESP32 development board

  1. Do wiring.
  2. Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
  3. Open Arduino IDE and open OTAWebUpdater1 sketch.
  4. Open Boards manager. Go to Tools -> Board -> Boards Manager… (in our case it’s the DOIT ESP32 DEVKIT V1)
  5. Select COM port that the board is attached to (if you don’t see the COM Port in your Arduino IDE, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers)
  6. Modify sketch with your SSID and password for WiFi network which you are going to use for OTA updates.
  7. Compile and upload the OTAWebUpdater1 to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
  8. Open the Serial Monitor at a baud rate of 115200 to verify that the ESP32 development board is properly connected to the Wi-Fi network. 
  9. Press the ESP32 on-board EN button to reboot it. When your ESP32 development board restarts, you will see the IP address of your ESP32 development board in Serial monitor (we have 192.168.0.116). You will see the red LED blinks and the green LED is off.

4. Uploading a OTAWebUpdater2 sketch Over the Air via ESP Web server

  1. Now your ESP32 development board is ready to receive OTA firmware updates. You can unplug your ESP32 development board from your PC and power it through any power source (for example a power bank). If your ESP32 development board has a wireless connection to your router, you should be fine to upload new firmware.
  2. Open Arduino IDE and open OTAWebUpdater2 sketch.
  3. Modify sketch with your SSID and password for WiFi network which you are going to use for OTA updates.
  4. Go to Sketch->Export compiled binary. Your sketch will be compiled and saved in the same folder as the sketch.
  5. Go to Sketch -> Show Sketch Folder. You will see the OTAWebUpdater2.ino.doitESP32devkitV1.bin file there, rename it as fw1.bin
  6. You can access your web server, if you type your ESP32 development board IP address in your browser. In our case - http://192.168.0.116.
  7. Enter username - admin and password - admin. Press Login button. You can upload the update now.
  8. Press Choose file button to select fw1.bin file.
  9. Press Open button. The pop up window close.
  10. Press Update button. OTA update will start. You can monitor the progress in percents %.
  11. Update will be done when the progress 100%. Congrats! OTAWebUpdater2 sketch uploaded. This sketch blinks the green LED now and red LED is off.

Code

In the code, the variable serverIndex holds the index page which is return to the web browser firstly. We will use "$.ajax" to create asynchronous uploading request. This request will be handled by "/update" action at web server. We also use "var xhr = new window.XMLHttpRequest()" to handle the progress of uploading. 

 

The code "MDNS.begin(host)" will use MDNS to resolve "http://esp32webupdate.local" to our web server IP address.
The code "server.on("/", HTTP_GET, []()" will handle the first HTTP GET request from web browser and return the http status code 200 and the web page content in serverIndex variable.
The code "server.on("/update", HTTP_POST, []()" will handle the uploading firmware file process via HTTP POST. We handle the order of process via "upload.status" and use Update for flashing firmware. After finishing, we call "ESP.restart();" to restart ESP to get effect.

The code "MDNS.begin(host)" will use MDNS to resolve "http://myesp32.local" to our web server IP address.The code "server.on("/", HTTP_GET, []()" will handle the first HTTP GET request from web browser and return the http status code 200 and the web page content in serverIndex variable.The code "server.on("/update", HTTP_POST, []()" will handle the uploading firmware file process via HTTP POST. We handle the order of process via "upload.status" and use Update for flashing firmware. After finishing, we call "ESP.restart();" to restart ESP to get effect.

 

Summary

We have learnt how to do update through WiFi  via ESP Web server (OTA - Over The Air Update) with ESP32 development board.

Library

  • ArduinoOTA library included in your Arduino IDE.
  • No additional libraries required.

Sketch

  • See attachments on the begining of this project


Other projects of Acoptex.com
Easy CBASIC Lesson 9 Compiling and debugging in Visual Studio of Acoptex.com in Csharp 10-04-2019
Easy Basics: Project 081d ESP8266 ESP-12E module and Nextion HMI display of Acoptex.com in ESP8266 ESP-12 24-03-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 22-08-2018
Viewed: 275 times