Sofia2 java client execution in Linux environments

This entry shows step by step how to download and test the Sofia2 Java client in any device with Linux. Raspberry Pi is a good example of linux device.


Sofia2 Java Client is self explanatory and easy to use, and you can start using it without previous knowledge. It includes two tools to help you start: An interactive command line client and a configurable Junit test suite.


Environment setting

In order to follow this tutorial maven and git are needed. It is also necessary that the device has internet access configured. Of course it is necessary a Java version that comes by default in any Linux distribution.

In order to test that maven and git are installed, run the below commands:

> mvn -version

> git –version

If any of them are not installed, run the next commands to install them (Optionally, you can follow this tutorial to install maven with less footprint)

> sudo apt-get install maven

> sudo apt-get install git

Once the environment is ready we can move to the next step.


Download and package the java client

The client sources of Sofia2 are hosted open source  at github Once you are in the Sofia2 account, you can navigate to the java client section and copy the master repository url. With this url run the following command.

mvn clean package -Dmaven.test.skip=true

Now that the source code is compiled and packaged we can run the client on the device.


Unit tests execution

Sofia2 api comes with a Junit test suite ready to send tests messages directly to Sofia2 platform

The tests suite has two main goals:

  1. Provide useful usage examples (self explanatory api)
  2. Check the connectivity with Sofia2

In order to execute the test suite, run the bellow command (optionally you can set up the log4j level in file)

mvn test

You can also set up the tests suite with a custom ontology and thinkp with two short steps. You can see how to create your own ontology and thinkp following this link.

  1. Configuration of GENERAL SETTINGS section of file.
  2. Putting test data for your custom ontology in fixtures folder.

Once the configuration is complete you can compile and run the tests suite again.


Interactive client execution

Sofia2 api has also included an interactive command line example. With this example you can explore and experiment with Sofia2 in a Linux command line way.

To launch this example run the below maven command:

mvn exec:java -Dexec.mainClass=””

Once launched it will offer you the following options to enter in command line:

List of kp actions to perform (Type de option and pulse enter):


Once the option is selected, two more options are shown. Native (mongoDB is the native real time sofia database) or sqllike query/statement

In the third step you can type a mongoDB or Sql statement to run against Sofia2. Next we present to you some examples of use:
Query example native and sqllike:


native -> db.TestSensorTemperatura.find().limit(1)
sql  ->  SELECT * FROM TestSensorTemperatura LIMIT 1;

Operation success with response: [ { “_id” : { “$oid” : “585a4fc9e4b0f6e1f805f2e1”} , “Sensor” : { “geometry” : { “coordinates” : [ 40.512967 , -3.67495] , “type” : “Point”} , “assetId” : “S_Temperatura_00066” , “measure” : 25 , “timestamp” : { “$date” : “2014-04-29T08:24:54.005Z”}}}]


Insert exmaple native and sqllike:


native -> {“Sensor”:{“geometry”:{“coordinates”:[40.512967,-3.67495],”type”:”Point”},”assetId”:”S_Temperatura_00066″,”measure”:25,”timestamp”:{“$date”:”2014-04-29T08:24:54.005Z”}}}

sql -> insert into TestSensorTemperatura(geometry, assetId, measure, timestamp) values (“{ ‘coordinates’: [ 40.512967, -3.67495 ], ‘type’: ‘Point’ }”, “S_Temperatura_00067”, 15, “{ ‘$date’: ‘2014-04-29T08:24:54.005Z’}”);
Operation success with response: {“_id”:ObjectId(“585a8c35e4b060800da5e8c4”)}


Update example native and sqllike:


native -> db.TestSensorTemperatura.update({“Sensor.assetId” : “asset1”}, {$set : {“measure” : 21}}, {multi : true})
sql -> update TestSensorTemperatura set measure = 20 where Sensor.assetId = “S_Temperatura_00067”;

Operation success with response: {“_ids”:[{“_id”:ObjectId(“585a887ae4b060800da5e820”)},{“_id”:ObjectId(“585a8a97e4b060800da5e835”)},{“_id”:ObjectId(“585a8aa6e4b060800da5e837”)},{“_id”:ObjectId(“585a8c35e4b060800da5e8c4”)}]}

This example uses a demo ontology and thinkp. In the same way that the Junit test suite you can use your own thinkp and ontology by only configuring the file.

With this querys you can explore and experiment the power of Sofia2 in terms of real time data insertion and management.


Rather, if you are interested in publishing your data in Sofia2 or you are just looking to dig in the IoT world, here you have an easy to follow example but with a lot of possibilities to start with.

If you are already a Sofia2 user and you need to run AdHoc functional tests, the Java client is a good interactive working tool.

Sofia2 java client execution in Linux environments

Un comentario en “Sofia2 java client execution in Linux environments


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s