ESP8266 + FLProg - User-defined system parameters and synchronization with the exact time server
In this lesson, we'll look at using custom system variables to link the web configuration interface and the project schema. Also try to configure the synchronization of the system clock of the controller with the servers of the exact time.
here . More details about the project FLProg can be found from the company's blog on Habr , site of the project and forum . In addition, on the channel ArduinoProm you can see a lot of video lessons. [/b] [/i]
As a basis, we will use project , created on last lesson .
First of all, we will create three system user parameters in which the current system time of the controller, the time zone, and the exact time server address with which we will synchronize will be stored. For this we find the branch " Add the parameter "In the project tree in the node" The custom parameters are ".
The Add New System Parameter dialog box opens. Fill it.
In the field " The name is "We enter the name of the parameter. We choose the type of the parameter - " String ". The value of this parameter will change dynamically during operation, so disable saving the parameter value in EEPROM. Therefore, we do not set the default value. The maximum length of the line is 20 (the output will be ? 01:01:???-01-2018 ? that is, 19 characters).
In the same way, we add the second parameter
Just leave the saving in the EEPROM, so that the controller memorizes the server we entered, and set the server to default.
Finally, create the third parameter, the time zone value, for the correct time display.
Parameter type is Integer , Be sure to save to EEPROM, the default value, to your choice (I have it 4 hours).
As a result, we got three user parameters
Let's go to the firmware diagram.
In the library of function blocks, we find the block " Getting the time from the NTP server "And drag it to the working area of the scheme
A double click on this block opens the block parameters editor.
Consider the settings in more detail.
NTP server - the server address from which the exact time will be taken. Can be specified as a constant. You can choose from the list of standard. I've checked everything - they're working. To select, press the " Standard servers are ".
But since we want " by adult "Set the server address from the web interface, put a tick in the check box" The entry is "
The period of the request until the first response is received - the frequency with which the controller will be " knock "The server will not get the time for the first time. Leave the value once every 30 seconds. It is also possible to set the input, then it will need to be given a value in milliseconds.
The request period after receiving the first response is - how often the controller will specify the time at the server. Leave by default, every half hour. You can also specify through the input, in milliseconds.
Time zone - Since the server gives time by Greenwich, this parameter sets the offset of the time zone in hours. We decided to set this parameter through the web interface, so put a tick in the box check " The entry is "
[b] The output is "Year" , The output is "Month" , The exit is "Day" , The output is "Hour" , Exit the "Minute" , Output "Second" - in this lesson we do not need them, so we do not install checkboxes.
The "Unix Time" output is - We do not need this output, we do not put a tick (if I honestly have not yet invented the User Case for it. But just in case, I did, suddenly, to someone it's useful).
Total we have such a setting of the block
Accordingly, the block on the firmware scheme
has also changed.
Let's find in the library the block " Reading the system parameter "And drag it to the diagram.
Double click on this block, and start to configure its parameters.
First click the system parameter selection button.
The system parameter selection window opens. Choose the parameter " The server of exact time "
This completes the block setup.
We have convenient blocks and connect the output of the block " Reading the system parameter "With the entrance" Server "Block" Getting the time from the NTP server "
We drag on the circuit one more block " Reading the system parameter "And set it to read the parameter" Time zone ".
We connect the output of this block to the input " TimeZone "Block" Getting the time from the NTP server "
We add a new board to the circuit. To do this, press the button " Add the board "
We turn off the first payment, we will not need it any more. To do this, click on the arrow in the header of the first board.
We take out the block " Receiving data from the hour clock "
Double click on it to call the dialog box settings. By clicking the " New "Call the clock selection dialog and select" System clock of the controller ".
Then put a tick " The output is "Clock" "
And finish editing the block.
Then copy this block five more times, rearranging the output check-box in the sequence in the settings of each of them. Minute - Second - Day - Month - Year .
Now we pull out the block " String conversion ".
And in its settings, select the conversion type " The time is "
We copy the block five more times, and collect the
We transfer to the scheme from the library the block " Adding rows to "
In the settings of the block, we set 11 inputs.
And we connect the blocks according to the scheme
At the free inputs of the block, we set the constants
Input 2 - ":"
Input 4 - ":"
Input 6 - Space
Input 8 - "-"
Input 10 - "-"
To set the constant, we right click on the free input and from the drop-down menu select " Insert the constant "
A window for entering a constant opens, where in the field " The default value is "The required constant
Now we pull out the block " Record the system parameter "
In the settings block remove the checkmark " The recording resolution input is "And select the parameter" Date - Time "
We connect the output of the block " Adding rows to "With the input of the block" Record the system parameter "
As a result, we should get such a scheme (For clarity, we deploy the first board).
With the firmware completed, go back to the project tree.
On the Web interface home page, add three parameters (see for the previous lesson ).
Parameter 1 3 r3r3679. - The system parameter " [i] Date - Time ", The parameter type is" Text ", The label -" The time is "
Parameter 2 3 r3r3679. - The system parameter " [i] The server of exact time ", The parameter type is" The input field is ", The label -" Server "
Parameter 3 3 r3r3679. - The system parameter " [b] Time zone ", The parameter type is" The input field is ", The label -" Time zone "
Turn on the page button " [i] Save "
Fill the program with controller, and see what we got on the main page (see for the previous lesson )
Immediately after the connection, the
has not yet synchronized with the exact time server.
A minute later (updated the page) - synchronized
Changed the time zone and pressed the save button
The project created in the lesson can be downloaded here .
It may be interesting
houston embroidery service
Houston Embroidery Service