Эта страница является
переводом страницы
Shared data. Перевод выполнен на 100%.
Creating Shared Data on the Server
It is often necessary to control equipment of a smart home or a smart building from several smart phones or tablets. And there is a server in a project that is responsible for controlling equipment work 24/7 and for storing data in the database.
Clients (smart phones and tablets) can have common access to the same data on the server, each client can change shared data and changes must be displayed on the server and other clients must see them. Clients can lose connection with the server, and in this case it is not possible to have the latest data. But when a client connected to the server, data in the client have to be updated automatically (have to be synchronized).
Solution:
In this case a project for a server is created and one or several panel projects are created. A server project is integrated in each panel project.
Description of example
There are two fields on panel to enter time "Hours" and "Minutes". When Enter is pressed data are sent to virtual channels of iRidium server. Then virtual_to_virtual() script is launched by event, and the script writes received data in virtual tags. Time is displayed on all panels, that are subscribed to data in these tags. Besides, virtual tags are stored in the server database.
Thus, each client (panel) can change time and all changes are stored in the database and are displayed on the screen of each client in real time.
Creating and setting a server project
1 Create a server project.
2 Go to I/O tab and create the required number of virtual channels and virtual tags of shared data. Each channel must have a corresponding tag. Use the same name for corresponding channels and tags.
3 Create a script for data exchange.
function virtual_to_virtual(in_Type, in_Name, in_Value) {
IR.SetVariable("Server.Tags." + in_Name, in_Value);
return in_Value;
}
More:Data exchange between a virtual channel and a tag..
4 Select virtual_to_virtual() data exchange function in the Script Modifier parameter in the properties of virtual channels.
5 Set each virtual tag as required by the task.
- Store in DB: None / Signed 32bit / Float 64bit / String UTF-8
- DB Save Strategy: Deadband / Interval
More: Driver and server variables.
You can store tags in the database but it is not required for creating shared data.
6 Save a server project.
Creating and setting panel projects
1 Create a panel project.
2 Add a driver to connect to iRidium server then indicate the file of a server project (a server project must be opened in iRidium studio at this moment).
3 Select a server driver and Sync With Server Project button becomes available to get a list of all virtual tags of a server. Click this button.
More: Visualization of iRidium server control
4 Set Save Value When Disconnected parameter - required behavior of virtual tags in panels when a server is disconnected:
True - to remember the last tag value,
False - to make the tag value empty.
5 Add graphic items:
- items to enter data, for example, Edit Box,
- items to display data, for example, Label (Type: Button, Hit: PassThrough).
6 Drag'n'drop virtual channels of "iRidium server" driver on graphic items for entering data and set them to work by Enter or Release event (depending on the type of graphic item).
7 Drag'n'drop virtual feedback of "iRidium server" driver on display graphic items and set Text or Value property (depending on the type of graphic item).
8 Enter server IP address.
9 Save a project.
You can create several panel projects you can also use one project on several devices - there will be no conflict.
Launching projects
1 Launch projects on devices in any order. You can use i3 pro Emulator and iRidium server for Windows.
2 You can check how data are displayed in case a client is disconnected and connected again.
3 You can also test stopping the server (close the server app) and then starting it again to make sure that data are stored (on condition that Persist = Yes).
Synchronizing projects
It's recommended first to create virtual channels and tags in a server project and then start using them in panel projects. But while creating a panel project changes in a server project can be made thanks to the following capabilities.
- Updating virtual channels and tags in a panel project (synchronization of server and panel projects)
If there are changes in the number of virtual channels and tags in a server project while panel projects are created, these changes are not displayed on a panel automatically, though they are intergrated in a project. To update the list of channels and tags, select the server driver in a panel project and "Sync With Server Project" button becomes available. Press it and the list of virtual channels and tags is updated.
- Renaming channels and tags in a server project
You can rename virtual channels and tags in a server project freely. After synchronization names are updated, and all connections set earlier on the panel side are saved.
- Renaming the file of a server project
After renaming the file of a server project open both projects in iRidium studio and then update Source Project parameter of the server driver in a panel project.
- Separate work with project files
As server and panel projects are synchronized manually, it is possible to work with projects separately. For example, two developers can work with projects on different PCs. A server project is not required to launch a panel project.