
In this lesson we will look at the use of user-defined system variables for connecting a web-based configuration interface and a project schema. We will also try to configure the synchronization of the system clock of the controller with the servers of the exact time.
This lesson is created for version 3.1.4, which is now in pre-release testing. Download it here . For more information about the project FLProg can be found in the company's blog on HabrΓ© , the project site and forum . In addition to the channel ArduinoProm you can watch a huge variety of video lessons.As a basis, we will use a
project created in the
past lesson .
')
To begin with, we will create in three system user parameters in which the current system time of the controller will be stored, the time zone, and the address of the exact time server with which we will synchronize. To do this, we find the β
Add Parameter β branch in the project tree in the β
User Parameters β node.

A dialog box for adding a new system parameter will open. Fill it up.

In the β
Name β field, enter the name of the parameter. Select the type of the parameter - β
String β. The value of this parameter will be dynamically changed during operation, therefore, disable saving the parameter value in the EEPROM. Therefore, do not set the default value. The maximum length of the string is 20 (the output will be in the form
01:01:01 01-01-2018, that is, 19 characters).
In the same way, add the second parameter

Just leave the save in the EEPROM, so that the controller remembers the server we entered, and set the default server.
Finally, create a third parameter, the time zone value, for the correct time display.

The type of the parameter
Integer . It is necessary to save in the EEPROM, the default value of your choice (I have 4 hours).
As a result, we got three user parameters.

We proceed to the firmware layout.
In the library of functional blocks we find the block β
Getting time from the NTP server β and drag it onto the workspace of the scheme

Double click on this block opens the block parameter editor.

Consider the settings in more detail.
NTP server -
server address from which the exact time will be taken. Can be set as a constant. You can choose from the list of standard. I checked everything - they work. Click the β
Standard Servers β button to select.

But since we want β
by adult β to set the server address from the web interface, we tick the check box β
Login β
The request period prior to receiving the first response is the frequency with which the controller will β
knock β on the server until it receives time for the first time. We leave the constant value every 30 seconds. It is also possible to set the input, then it will be necessary to feed the value in milliseconds.
Request period after receiving the first response - how often the controller will check the time at the server. We leave by default once every half hour. You can also set via the input, in milliseconds.
Time zone - Since the server gives time according to GMT, this parameter sets the time zone offset in hours. We decided to set this parameter through the web interface, so we tick the checkbox β
Login β
Exit βYearβ ,
Exit βMonthβ ,
Exit βDayβ ,
Exit βHourβ ,
Exit βMinuteβ ,
Exit βSecondβ - we do not need them in this lesson, therefore we do not set ticks.
Exit βUnix Timeβ - we donβt need this exit, we donβt put a tick (to be honest, I havenβt yet come up with a User Case for it. But just in case, Iβd need someone to use it).
So we got this block setting

The block on the firmware layout has changed accordingly.

Find the β
Read system parameter β block in the library and drag it onto the schematic.

Double click on this block, and begin to adjust its parameters.
First, press the system parameter selection button.

The system parameter selection window opens. Select the option β
Time server β

This completes the block setup.
We conveniently arrange the blocks and connect the output of the β
Read system parameter β block to the β
Server β input of the β
Get time from NTP server β block

Drag and drop one more β
Reading system parameter β block onto the scheme and set it to read the β
Time Zone β parameter.

We connect the output of this block to the β
TimeZone β input of the β
Getting time from NTP server β block

Add a new board to the scheme. To do this, click the button "
Add fee "

We turn off the first payment, we will not need it anymore. To do this, click on the arrow in the header of the first board.

We pull out the block β
Data acquisition from the clock of the exact time β to the second board

Double click on it to call the block setup dialog. Pressing the β
New β button, we open the clock selection dialog and select the β
System controller clock β.


Then put a tick β
Exitβ Watch β β

And we finish editing the block.
Then we copy this block five more times, rearranging in the settings of each of them the checkbox of the output in the sequence
Minute - Second - Day - Month - Year .

Now we pull out the β
String Conversion β block from the library.

And in its settings, select the type of conversion β
Time β

Copy the block five more times, and collect the scheme

Transferring the β
Addition of Strings β block to the scheme from the library

In the block settings, set 11 inputs.

And connect the blocks according to the scheme

Set the constants on the free inputs of a block.
Input 2 - β:β
Login 4 - β:β
Input 6 - Space
Sign 8 - β-β
Input 10 - β-β
To set a constant, right-click on a free entry and select β
Insert Constant β from the pop-up menu.

A constant input window opens, where the desired constant is entered in the β
Default Value β field.

Now we pull out from the library the β
Record of system parameter β block on the scheme

In the block settings, uncheck the β
Record entry input β checkbox and select the β
Date - Time β parameter

We connect the output of the block β
Addition of lines β with the input of the block β
Record system parameter β

As a result, we should have such a scheme (For clarity, we will deploy the first board).

With the firmware scheme finished, we return to the project tree.
We will add three parameters to the main page of the Web interface (see how to do this in the
previous lesson ).
Parameter 1 - System parameter β
Date - Time β, parameter type - β
Text β, label - β
Time β
Parameter 2 - System parameter β
Time server β, parameter type - β
Input field β, label - β
Server β
Parameter 3 - System parameter β
Time zone β, parameter type - β
Input field β, label - β
Time zone β

Turn on the β
Save β button on the page

Fill the program in the controller, and see what we did on the main page (how to do this, see the
previous lesson )
Immediately after connecting - not yet synchronized with the time server

In a minute (the page was updated) - synchronization passed

Changed the time zone and clicked save

The project created in the lesson can be downloaded
here .