-
Notifications
You must be signed in to change notification settings - Fork 1
6. Synchronizing Instance Data
With various deployments available the system allows for synchronizing data between instances. The main use case is for automatically synchronizing data gathered by Bluetooth sensors and updating data to main data stores either locally or in the cloud. Bluetooth sensors may send data to either the Windows Instance or the Linux Raspberry Pi instance (or both). The following is a sample of the scenarios supported.
- Raspberry Pi H2 Database instance uploading data to Local PostgreSQL instance
- Local Windows PostgreSQL instance uploading data to Heroku PostgreSQL instance
- Raspberry Pi H2 Database instance uploading data to Heroku PostgreSQL instance
Data synchronization adds new data, updates and deletes are also implemented. The following tables have a Synch Token Field: Sensors, Batches, Measurements and Styles. The Synch Token entry in each table should be unique. When adding new data it is automatically generated. For legacy data the same entry should be make in both the source and remote instances to configure data synchronization. To delete data locally and to not delete the remote instance first delete the Synch Token entry locally prior to deleting the data, this will disable the synchronization.
The configuration sets documented here implement the following scenario:
- Arduino temperature controller monitors temperature
- Raspberry Pi Brewery Services gathers data from Arduino using Bluetooth. Data is stored in H2 Database.
- Raspberry Pi post data to Windows Instance using Brewery Services Restful API.
- Windows instance post data to Heroku Cloud Instance.
The Raspberry Pi instance is not required as the Windows instance may also gather data from the Arduino using Bluetooth.
The application will pull configuration data from a remote host during the first synchronization of each day. The pull process will and and update date from the remote to the local instance. Restarting the application will also pull configuration data during the first data synchronization. Data from the following tables will be pulled from the remote host: Measure Types, Processes and Styles.
To enable pulling of configuration data set the following application property to true.
dataSynch.pullConfig=true
Each Instance Is required to be configured and deployed to each device.
Configure the Raspberry Pi for Bluetooth and H2 database as described in other sections. Configure the following data synchronization settings in the application.properties file prior to build and deployment.
- dataSynch.enabled=true
- dataSynch.delayMinutes=15
- dataSynch.deleteDuplicates=true
- dataSynch.deleteSynched=true
- dataSynch.url=http://192.168.1.11:8080/api/
- dataSynch.apiId=BrewAppPi
- dataSynch.apiPassword=password
These settings enables data synchronization to another instance. Data will be posted every 15 minutes. To avoid loss of memory duplicate data (data with same value as prior entry) will be deleted. Once data is posted to the next instance it will also be deleted. The target instance is configured using the dataSynch.url property.
A user id is required to be entered in both the source and target instances as defined by the dataSynch.apiId and dataSynch.apiPassword properties. The role of the user must be API and both instances need to have the same password set.
Once the data is is synchronized with the target instance it is removed from the Raspberry Pi h2 database. Only new records will be present.
Configure the Windows instance with the PostGreSQL database as described in other sections. Configure the following data synchronization settings in the application.properties file prior to build and deployment.
- dataSynch.enabled=true
- dataSynch.delayMinutes=15
- dataSynch.deleteDuplicates=true
- dataSynch.deleteSynched=false
- dataSynch.url=https://brewery-services-test.herokuapp.com/api/
- dataSynch.apiId=BrewAppWin
- dataSynch.apiPassword=password
These settings enables data synchronization to another instance. Data will be posted every 15 minutes. To avoid loss of memory duplicate data (data with same value as prior entry) will be deleted. The target instance is configured using the dataSynch.url property.
A user id is required to be entered in both the source and target instances as defined by the dataSynch.apiId property. The role of the user must be API and both instances need to have the same password set.
Once the data is is synchronized with the target instance the Synched Table field will be updated to SYNCHED.
Configure the Heroku instance with the PostGreSQL database as described in other sections.
A user id is required to be entered as defined by the dataSynch.apiId property of the source system. The role of the user must be API and both instances need to have the same password set.
A REST API is available to update and retrieve data. The API is automatically documented using Swagger. While the application is running the following URL may be used to view the API interface.
http://localhost:8080/swagger-ui.html
The Swagger API documentation allows for testing each of the methods. Authentication will be required.