0

I'm new to WSO2 CEP and Siddhi queries. I have created three different event streams, each stream is about an particular sensor, as shown in the image below:

enter image description here

Each event stream of sensors has the latitude and longitude of the sensor. The sensors placed on different coordinates and I want to compare/correlate their coordinates (latitude and longitude). How can I compare their coordinates through Siddhi query (coordinates do not vary by more than 4 meters)? Thanks a lot!

Community
  • 1
  • 1
fay
  • 49
  • 1
  • 7

1 Answers1

2

Siddhi has a separate set of operations for geo operations. To calculate the distance between the sensors, you will be able to use geo distance function.

Since you want to compare the sensor distance, you will have to keep the sensor locations in a window or in a table. Whenever a sensor location comes in the stream, you will be able to store it in the window or in the table, and join with the rest of the table contents and get the relevant output adheres to your requirement(within 4 meters)

/* Enter a unique ExecutionPlan */
@Plan:name('ExecutionPlan')

/* Enter a unique description for ExecutionPlan */
-- @Plan:description('ExecutionPlan')

/* define streams/tables and write queries here ... */

@Import('sensor4:1.0.0')
define stream sensor4 (id int, lat double, long double);

@Import('sensor3:1.0.0')
define stream sensor3 (id int, lat double, long double);

@Import('sensor2:1.0.0')
define stream sensor2 (id int, lat double, long double);

@Import('sensor1:1.0.0')
define stream sensor1 (id int, lat double, long double);

@Export('measuredStream:1.0.0')
define stream measuredStream (sensor1Id int, sensor2Id int);

define table sensorTable (id int, lat double, long double);

from sensor1
select *
insert into sensorTable;

from sensor2
select *
insert into sensorTable;

from sensor1 join sensorTable
    on sensorTable.id != sensor1.id and 4 > geo:distance(sensorTable.lat, sensorTable.long, sensor1.lat, sensor1.long)
select sensorTable.id as sensor1Id, sensor1.id as sensor2Id
insert into measuredStream;

from sensor2 join sensorTable
    on sensorTable.id != sensor2.id and 4 > geo:distance(sensorTable.lat, sensorTable.long, sensor2.lat, sensor2.long)
select sensorTable.id as sensor1Id, sensor2.id as sensor2Id
insert into measuredStream;

The above execution plan will work, since you have after you create 2 more queries each to insert to the event table and join with event table. You can verify the results by adding a logger publisher(the events in the measured stream will be logged in the terminal) to the measured stream. And using event simulator, simulate the event flow.

Ramindu De Silva
  • 194
  • 4
  • 13
  • Hi! Thanks a lot for your reply! Could you explain to me what is the sensor1Id, sensor2Id into the measuredStream? And why there are not the other sensors (e.g. sensor3Id and sensor4Id)? – Furthermore, i tried the execution plan which you have write but an error occurs (" 'distance' is neither a function extension nor an aggregated attribute extension in execution plan "ExecutionPlan"), do you now how to solve this error? – fay Mar 15 '17 at 13:21
  • i used sensor id to differentiate the streams inside the execution plan. If there are no event id generated from you event stream you can write a simple query as follows to make enhance the stream with a sensor id.Right after you import the stream, you can add the following query for all the streams from sensor1 select "sensorId" as id, lat, long insert into enhancedSensorStream; you can add the other two sensors just as similar to the sensors I added. – Ramindu De Silva Mar 16 '17 at 08:19
  • as the solution for the error occurring, please install the Siddhi-gpl features as mentioned in this link https://docs.wso2.com/display/CEP420/Installing+WSO2+GPL+Features – Ramindu De Silva Mar 16 '17 at 08:23
  • Thanks a lot for your help! – fay Mar 22 '17 at 14:12
  • Hi! I installed the Siddhi-gpl features, but still the error occuring " 'distance' is neither a function extension nor an aggregated attribute extension in execution plan "CorrelateCoordinates_ExecutionPlan" " - Could you help me, please? – fay Mar 28 '17 at 07:59
  • Hi again! I have tested the example that you have sent to me, but the error " 'distance' is neither a function extension nor an aggregated attribute extension in execution plan "CorrelateCoordinates_ExecutionPlan" " still occurs. I tried to fix this error, but I have not managed to solve it. As I said in the previous comment, i have installed the Siddhi-GPL features. Could you help me why is this error occurring, please? – fay Mar 31 '17 at 08:03
  • Hi, can you please check whether the siddhi-gpl features are installed correctly by checking "installed features" from the management console. Or else, we can check whether the bundle is active by starting the server on osgi mode (./wso2server.sh -DosgiConsole ). And when the server is started, try to execute command "-ss gpl" and check whether siddhi geo gpl bundle is active. – Ramindu De Silva Mar 31 '17 at 09:10
  • Thank you very much for your reply. I checked the "Installed features" from the management console and there is the " GPL - Siddhi Geo Extension ". Now, that it is installed what can I do to solve the problem? I should start the server on osgi mode as you said in your comment above or I should do something else? – fay Mar 31 '17 at 10:37
  • No problem. If the extension is installed, the execution plan should work. Willl you be able to send me the execution plan, the cep version and the siddhi gpl version installed? – Ramindu De Silva Apr 03 '17 at 13:35
  • Thanks @RaminduDeSilva for your response. The execution plan that I used is the one you proposed above (I used this to test the 'distance' function). The CEP version is the latest one (wso2cep-4.2.0) and the siddhi GPL version is 2.0.4 (as specified in github and the "installed features" area of the management console. BUT: the jar in the p2-repo bundle says: siddhi-gpl-extension-geo_3.0.0.jar). I downloaded the siddhi-gpl from this url https://github.com/wso2-gpl/carbon-event-processing/releases/download/v2.0.4/p2-repo.zip – fay Apr 04 '17 at 08:55
  • I solved the problem with the function by building the P2 repositories, because the most repositories were not up to date, with the official installation instructions [https://docs.wso2.com/display/CEP400/Installing+WSO2+GPL+Features#InstallingWSO2GPLFeatures-BuildingtheP2repositories(Optional)], after the building I installed them again. I would like to thank you again for your help and for your answers. – fay Apr 08 '17 at 20:11