REST service : GSN virtual sensor wrapper

0 votes

I'm writing a GSN wrapper for a REST service. It basically, returns this output when called from the browser:

1, 23.22

This is my code. Can anybody tell me what I'm doing wrong?

WRAPPER

<?xml version="1.0" encoding="UTF-8"?>
<virtual-sensor name="ForecastService" priority="10" >
<processing-class>
    <class-name>org.openiot.gsn.vsensor.BridgeVirtualSensor</class-name>
    <init-params>
        <param name="allow-nulls">false</param>
        <param name="publish-to-lsm">true</param>
    </init-params>
    <output-structure>
        <field name="rain" type="Integer" />
        <field name="temperature" type="Double" />
    </output-structure>
</processing-class>
<description>weather forecast station</description>
<life-cycle pool-size="10"/>
<addressing>
    <predicate key="geographical"></predicate>
</addressing>
<storage history-size="1" />
<streams>
    <stream name="input1">
        <source alias="source1" sampling-rate="1" storage-size="1">
            <address wrapper="http-get">
                <predicate key="url">http://192.168.1.100:8080/ForecastService/webresources/forecastservice/forecast/true/csv</predicate>
                <predicate key="rate">1000</predicate>
            </address>
            <query>select * from wrapper</query>
        </source>
        <query>select * from source1</query>
    </stream>
</streams>

OUTPUT

18:16:11.229 [VSensorLoader-Thread0] DEBUG org.openiot.gsn.beans.StreamSource - validate() called
18:16:11.229 [VSensorLoader-Thread0] DEBUG org.openiot.gsn.VSensorLoader - Preparing input streams for: forecastservice
18:16:11.230 [VSensorLoader-Thread0] DEBUG o.o.g.w.general.HttpGetWrapper - AXISWirelessCameraWrapper is now running @1000 Rate.
18:16:11.230 [VSensorLoader-Thread0] DEBUG org.openiot.gsn.VSensorLoader - Wrapper name: Http Receiver -- view name _774699928
18:16:11.230 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.240 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.240 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create table statement is : CREATE TABLE _774699928 (PK BIGINT NOT NULL IDENTITY, timed BIGINT NOT NULL, DATA Binary)
18:16:11.242 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create index statement is : CREATE  UNIQUE  INDEX _774699928_INDEX ON _774699928 (timed DESC)
18:16:11.244 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.250 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.251 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Dropping table structure: _sql_view_helper_ With query: Drop table if exists _sql_view_helper_
18:16:11.263 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.264 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create table statement is : CREATE TABLE _sql_view_helper_ (PK BIGINT NOT NULL IDENTITY, timed BIGINT NOT NULL, U_ID varchar(17))
18:16:11.264 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - The create index statement is : CREATE  INDEX _sql_view_helper__INDEX ON _sql_view_helper_ (timed DESC)
18:16:11.266 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.270 [VSensorLoader-Thread0] DEBUG o.o.g.b.w.TupleBasedSlidingHandler - The original Query : select * from wrapper
18:16:11.271 [VSensorLoader-Thread0] DEBUG o.o.g.b.w.TupleBasedSlidingHandler - The merged query : select * from  (select * from _774699928 where timed >= (select distinct(timed) from _774699928 where timed in (select timed from _774699928 order by timed desc limit 1 offset 0 )) order by timed desc ) of the StreamSource source1 of the InputStream: input1
18:16:11.271 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.271 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Creating a view:create view __911689473 AS ( select * from  (select * from _774699928 where timed >= (select distinct(timed) from _774699928 where timed in (select timed from _774699928 order by timed desc limit 1 offset 0 )) order by timed desc ) )
18:16:11.274 [VSensorLoader-Thread0] DEBUG o.o.gsn.wrappers.AbstractWrapper - Adding listeners:  Stream Source object:  Alias: source1 uidS: __911689473 Active source: [http-geturl = http://192.168.1.100:8080/ForecastService/webresources/forecastservice/forecast/true/csv,rate = 1000,]
18:16:11.274 [VSensorLoader-Thread0] DEBUG o.openiot.gsn.storage.StorageManager - Asking a con. to DB: jdbc:h2:file:MyFile => busy: 0, max-size: 8, idle: 1
18:16:11.277 [VSensorLoader-Thread0] ERROR org.openiot.gsn.VSensorLoader - The column : RAIN in the >forecastservice< table is not compatible with type : Integer. The actual type for this table (currently in the database): 2005
org.openiot.gsn.utils.GSNRuntimeException: The column : RAIN in the >forecastservice< table is not compatible with type : Integer. The actual type for this table (currently in the database): 2005
    at org.openiot.gsn.storage.StorageManager.tableExists(StorageManager.java:241) ~[classes/:na]
    at org.openiot.gsn.storage.StorageManager.tableExists(StorageManager.java:270) ~[classes/:na]
    at org.openiot.gsn.VSensorLoader.loadPlugin(VSensorLoader.java:255) ~[classes/:na]
    at org.openiot.gsn.VSensorLoader.loadPlugin(VSensorLoader.java:210) ~[classes/:na]
    at org.openiot.gsn.VSensorLoader.run(VSensorLoader.java:134) ~[classes/:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]

Jan 17 in IoT (Internet of Things) by Shubham
• 13,300 points
28 views

1 answer to this question.

0 votes

You will have to write your own REST service wrapper and read the results. This is the description of a virtual sensor, I wrote:

<?xml version="1.0" encoding="UTF-8"?>
<virtual-sensor name="ForecastService" priority="10" >
    <processing-class>
        <class-name>org.openiot.gsn.vsensor.BridgeVirtualSensor</class-name>
        <init-params>
            <param name="allow-nulls">false</param>
            <param name="publish-to-lsm">true</param>
        </init-params>
        <output-structure>
            <field name="rain" type="Integer" />
            <field name="temperature" type="Double" />
        </output-structure>
    </processing-class>
    <description>weather forecast station</description>
    <life-cycle pool-size="10"/>
    <addressing>
        <predicate key="geographical"></predicate>
    </addressing>
    <storage history-size="1" />
    <streams>
        <stream name="input1">
            <source alias="source1" sampling-rate="1" storage-size="1">
                <address wrapper="forecast-service-get">
                    <predicate key="url">http://192.168.1.100:8080/ForecastService/webresources/forecastservice/forecast/true/csv</predicate>
                    <predicate key="rate">1000</predicate>
                </address>
                <query>select * from wrapper</query>
            </source>
            <query>select * from source1</query>
        </stream>
    </streams>
</virtual-sensor>
answered Jan 17 by Upasana
• 8,530 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

AWS IoT - Access shadow through .Net, REST, with certificate

If you want to publish and/or subscribe ...READ MORE

answered Jul 25, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
105 views
0 votes
1 answer

Azure - What service to use for Arduino data (iot)

That's because the two services do completely ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
108 views
0 votes
1 answer

Using FIWARE to start Cygnus as a Service in IoT Solution

Cygnus is supposed to create /var/run/cygnus/ when started. You ...READ MORE

answered Aug 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
84 views
0 votes
1 answer
0 votes
1 answer

Setting-up a RFID RC522 chip in Raspberry Pi?

First, let me congratulate you on buying ...READ MORE

answered Jul 9, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
178 views
0 votes
1 answer

Are there sensors that are platform Dependent ?

The short answer is: yes probably it ...READ MORE

answered Sep 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
30 views
0 votes
1 answer

Refactoring multi thread program on raspberry pi with sensors

Before re-engineering your application, you should narrow ...READ MORE

answered Sep 11, 2018 in IoT (Internet of Things) by Upasana
• 8,530 points
189 views
0 votes
1 answer

When to use MQTT and when to use REST for event submission?

MQTT is designed to be a fast ...READ MORE

answered Sep 14, 2018 in IoT (Internet of Things) by Upasana
• 8,530 points
136 views
0 votes
1 answer

Global Sensor Networks : adding https support in GSN

Try enabling it with the configuration. READ MORE

answered Jan 21 in IoT (Internet of Things) by Upasana
• 8,530 points
62 views
0 votes
1 answer