FTP datalogger (OP-AN-015)

From openPicus Wiki
Jump to: navigation, search



Application Note PDF

Source Code


In the current example will be shown:

  • how to retrieve a file from the remote server and to load a string with application settings;
  • how to save the application settings to a remote file;
  • how to log the data, adding formatted strings in a file to the remote server.

The proposed example takes advantage of many features of the FLYPORT module:

  • SNTP Client
  • RTCC – Real Time Clock Calendar and Alarm
  • FTP Client
  • Web Server
  • Sleep mode (only for FLYPORT Wi-Fi)

The SNTP (Simple Network Time Protocol) Client permits to synchronize automatically the RTCC values with the remote servers, with a minimal user :interaction. The user only can change the GMT value, its preferred time zone value (from -12 up to +12 hours), using the embedded Web Server of the :FLYPORT module.

The RTCC (Real Time Clock Calendar) is a internal hardware module of the FLYPORT. It allows to keep track of instantaneous Clock and Date, and also :to activate an interrupt Alarm at a certain scheduled date/clock combination. This alarm is used to start the data log sequence. The RTCC Alarm is also :raised if the FLYPORT Wi-Fi is in its lower power consumption mode: the SLEEP mode.

FTP Client can upload and download data to a remote Server. Using the file storage of a FTP Server, the Flyport can both save and load data, virtually with :no memory size problems.

Required Hardware

Required Software and Libreries


  • OpenPicus Free IDE 2.2+
  • Filezilla


  • FTPClient
  • RTCC


The very first firmware customization for this application is done inside the TCP/IP Wizard of the openPicus IDE. Using this tool, it is mandatory to enable the SNTP Client service, to increase the FTP_DATA Socket TX Buffer to (at least) 1000 Bytes, and to reduce the DEFAULT TCP Socket TX and RX buffer size to 500 Bytes each one.

Implementation OP-AN-015 1.png
Implementation OP-AN-015 2.png
Implementation OP-AN-015 3.png

This customization is already done in the provided templates.

The next step is to change the FTP Server information inside the taskFlyport.c:

char ftpServIP[] = "";
char ftpServPort[] = "21";
char ftpServUser[] = "flyport";
char ftpServPass[] = "flypass";

Those information depends on the used environment, and suggested values are for reference only

For the FLYPORT Wi-Fi, remember to change also the wireless parameter to let the module to be connected to your router.

The application is now ready to be downloaded to the FLYPORT module using the openPicus IDE.

Once the Flyport is started and connected to the network, open the Web Server page of the FLYPORT and setup the application parameters:

Implementation OP-AN-015 4.png
  • The GMT selection can change the time zone value. Values from -12 up to +12 are available in the drop-down list.
  • RTCC Alarm Time Lapse Settings permits to insert values for the hours and minutes that should pass from 1 data log to another one. If the chosen values are 0 hours and 0 minutes, the application will automatically choose a time stamp of 30 seconds.
  • Data to Log checkboxes helps the user to select the data that should be sampled in the prepareLog() function. Since the data is formatted in csv, the unselected data will be written as a “-” mark, and the file contents will not be corrupted.
  • Sleep Enable checkbox will enable the SLEEP MODE between the logs. This feature is available for FLYPORT Wi-Fi ONLY!

The data of the web page are sent to FLYPORT with a CGI request on the “Send” button pressure, after a validation process. The CGI request is handled then by the FLYPORT inside the HTTPApp.c file, using the HTTPExecuteGet function.

These parameters are saved to a FTP Server file by the FlyportTask(). The file name is created dynamically to allow the use of more than one FLYPORT with different settings. The file name will be created with the algorithm:

filename = “settings”+”MAC ADDRESS of FLYPORT Module”.fly

Since the MAC Address is unique for each FLYPORT Module, every module will use only one specific file.

Application functions developed

There are some specific functions developed for this example to give a better separation of concerns.

Some of them are stored in external library files, others are more specific and so written inside the taskFlyport.c.

The taskFlyport.c functions developed are:

Command Description Description
void prepareLog()
Function needed to append the CSV formatted string of the data in order to log into the char logMsg[1000] buffer.
This function can append up to 10 different logs to prevent wrong uploads.
BYTE loadSettings ()
Function needed to download and parse the settings file content from FTP Server.
If the download is done well, it changes the flags inside the application.
Return: the Report of FTP operations
BYTE saveSettings ()
Function needed to prepare and upload the settings file content to FTP Server.
Return: the Report of FTP operations.

For a better understanding and debugging of the FlyportTask() execution, the user can send commands to FLYPORT module via UART1. The allowed commands are:

  • rtcc – Forces the printing of the RTCC values on UART1
  • alarm – Forces the printing of the next Alarm values on UART1
  • printlog – Prints the string to be uploaded on UART1, and forces the execution of the data log, enabling the alarmflag.

NOTE: In order to prevent the FLYPORT Wi-Fi remains in a sleep condition (for example a bad next alarm value that does not raises the interrupt, or a too big time lapse between samples), an external interrupt was assigned to the pin “p9” of JP1 FLYPORT's connector.

A normally open button should be connected to “p9” and Ground. The pressure of the button ties the signal to ground, raising the “void external_interrupt_function()” inside the taskFlyport.c. This function forces the wake up of the FLYPORT, and also clears the sleep and enables the flag to prevent further issues.


The first step to start with a FTP datalogger is to enable a local FTP Server.

To properly test the application, an FTP server is needed. A free and easy-to-use solution is given by Filezilla (http://filezillaproject. org/ ), at the moment the current version is the 0.9.40. In this paragraph it will be shown how to configure it. After installing the program, the configuration of the server can be changed using the “Filezilla server interface”. Once the interface is started, is possible to change/add users from the menu Edit->users. In the “User” form, in page “general”, just add your username and enable the password you prefer.

Testing OP-AN-015 1.png

Then go to “shared folder” page to add folder and to share with FTP clients. If you share more folder, you can also choose your home folder.

Testing OP-AN-015 2.png

Be sure the server is online – watch the icon on the upper left corner. Now you are ready to connect to your personal FTP server.

IMPORTANT: if your pc has a running firewall, remember to enable Filezilla server and the port 21 on it.


Personal tools