ESP8266 + FLProg - Custom system settings and time server synchronization

  • Tutorial


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 the 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, find the branch " Add parameter»In the project tree in the“ User settings ” 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 parameter type - “ 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 string length is 20 (the output will be 01:01:01 01-01-2018, that is, 19 characters).

In the same way, we add the second parameter. We



just leave the saving 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 . Be sure to save in the EEPROM, the default value of your choice (I have 4 hours).

As a result, we received 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-clicking 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 to set the server address from the web interface “ by adult ”, we tick the check box “ Login

Request period before receiving the first answer - 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, 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 put a check in the checkbox “ Login

Exit “Year” , Exit “Month” , Exit “Day” , Exit “Hour” , Exit “Minute” , Exit “Second” - in this we do not need them in the lesson, so we do not check the boxes.

Exit “Unix Time”- we don’t need this output, we don’t put a tick (to be honest, I haven’t yet come up with a User Case for it. But I did it just in case, it would be useful to someone).

In total, we have obtained such a setting of the block.



Accordingly, the block has changed on the firmware diagram.



We find the block “ Read system parameter ” in the library and drag it to the diagram.



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 setting.

We arrange conveniently the blocks and connect the output of the block “ Reading the system parameter”With the“ Server ” input of the“ Getting time from the NTP server



block Drag and drop one more“ Read 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 circuit. To do this, click the button “ Add a fee. ” We



turn off the first board, we will no longer need it. 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 call the clock selection dialog and select the “ System controller clock ”.





Then we tick “ Exit“ Clock ”



And we finish editing the block.

Then we copy this block five more times, rearranging in the settings of each of them the output checkbox 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 block from the library to the scheme “Addition of strings



In the block settings, set 11 inputs.



And we connect the blocks according to the scheme.



On free inputs of the block we set constants

Input 2 - “:”
Input 4 - “:”
Input 6 - Space
Input 8 - “-”
Input 10 - “-”

To set a constant, right-click on a free input and from the drop-down menu, select " Insert constant "



appears constant input window, where in the " default " is introduced the necessary constant



Now we take out of the library to the circuit block " recording system parameter "



in the block settings, remove a tick " write enable input”And select the“ Date - Time ” parameter. We



connect the output of the“ Addition of lines ”block to the input of the“ Record system parameter ” block .



As a result, we should have such a circuit (for clarity, let's expand 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



We turn on the“ Save ” button on the page .



Fill the program into the controller , and we look at what we did on the main page (how to do this, see the previous lesson )

Immediately after connecting, the time server was not yet synchronized.



After a minute (updated page), the synchronization was



changed. The time zone was changed and the save button was saved



. in class you can with achat here.

Also popular now: