FOTA remotely updating the firmware - Flyport GPRS PRO
What you are going to learn
This tutorial will walk you through the steps required to remotely update the firmware on the Flyport GPRS PRO device.
The FOTA feature requires an ftp server, to this end you'll find some details and links to setup your own ftp server.
The code will establish an update loop between two different firmwares: each one downloading the other
As always this is all free software provided as is, no explicit and/or implied responsibilities are admitted and/or accepted.
What you need
A Flyport GPRS PRO. This feature makes use of the Data Connection of GPRS network. Please be sure your provider allows your SIM card to use Data connections!
How to use it
Setup an FTP Server
First of all you should create a remote FTP Server. To do this you can use any cloud based services (like drivehq.com which provides a free account with some restrictions).
You could also install Filezilla Client on your PC, but you should be sure to provide the right port forwarding setup, and allow Flyport GPRS PRO to access your personal FTP Server.
We highly suggest you to use cloud ftp sites like drivehq.com to be sure all the TCP/FTP ports are accessible from Flyport GPRS data connection.
You may experience some problems related to FTP TCP access. Some providers do not allows to use FTP file exchange using GPRS connection. If you have problems with the FTP file transfer, please check your SIM provider if there are some limitation with your SIM.
About port forward For further information on network settings you can follow this article. Please note that this guide is about allowing access from outside of your LAN.
After you correctly setup your FTPServer, some more operations are required:
- create a user and a password (please change username and password on your firmware)
- create two folders “/FOTA_GPRS1” and “/FOTA_GPRS2” on the FTP Server to store the images of the two different firmware examples we add to this tutorial.
Firmware Development on IDE
You can download a single example firmware project which will be able to appear as two different firmwares. This will allow us to implement an auto-update loop, thus showing the auto-update feature in real time.
Let's start from the basics of the FOTA library: how it works.
How the FOTA library works
Each firmware should be compiled from our IDE. Once the compiling process is successful completed, you have a “.hex” file on the Obj folder of your project. Open the Hex2Bin for Flyport GPRS PRO tool to create the files needed to upgrade your Flyport GPRS PRO over the air.
Hex2Bin for Flyport GPRS PRO tool generates 8 splitted files that you have to upload to your FTP Server. Each file embeds a MD5 check, so we can check if a file is valid or corrupted and try to download it again without erase all the previously downloaded data.
All the files are downloaded via FTP and copied/checked to Flyport onboard Flash Memory. Once all the files are correctly downloaded user firmware can set a special value on MCU internal flash memory and provide a soft-reset. Openpicus bootloader will then read the special flag, and start the automatic update of MCU firmware. The new firmware is started and Flyport GPRS PRO module is upgraded!
Dual loop example
To provide a working example, the best way is to use two different firmwares that perform the upgrade process in a loop:
- FW1 look for FW2 FTP FOTA files.
- When the FOTA process is completed, Flyport is upgraded to FW2.
- FW2 checks for FW1 FTP FOTA files.
- When the FOTA process is completed, Flyport is upgraded to FW1, and so on...
At firmware startup the external Flash is erased so we can save the FTP downloaded files. After the configuration of APN parameters (please change parameters with the one provided by your mobile operator) and the connection to network, Flyport starts to download FOTA files.
In this example the upgrade process is automatic, but user can provide various methods to start the download (can be a SMS with the specific parameters - ftp server, filename, etc… - or it can be started with a button, UART commands, and so on…).
Configure with you own parameters
Please, add your parameters on the following firmware defines:
#define FTP_SERV_NAME "put.here.your.ftp.server" #define FTP_USER_NAME "username" #define FTP_PASSWORD "password" #define FTP_PORT 21 #define APN_SERV_NAME "put.your.apn"
To choose between FW1 and FW2 you have to uncomment one of the following defines:
#define _FW_1_FOTA_GPRS_ //#define _FW_2_FOTA_GPRS_
- uncomment FW2 and comment FW1
- open hex2bin tool
- create FW2 bin images naming the files fota.bin (there will be automatically created 8 files named fota.bin.0, fota.bin.1 … fota.bin.8)
- save the fota.bin.X files on a folder called FOTA_GPRS2
- uncomment FW1 and comment FW2
- open hex2bin tool
- create FW1 bin images naming the files fota.bin (there will be automatically created 8 files named fota.bin.0, fota.bin.1 … fota.bin.8)
- save the fota.bin.X files on a folder called FOTA_GPRS1
Upload Files on FTP Server
Once you correctly compiled the 2 firmware commenting/uncommenting the provided define, user should place the hex2bin generated files to two different paths of FTP Server:
- /FOTA_GPRS1 to store FW1 files
- /FOTA_GPRS2 to store FW2 files
Flash a firmware
Flash a firmware to Flyport GPRS PRO module using our IDE, each Firmware will be started and will be upgraded automatically!