cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to run Kepware IOT Gateway APIs in Thingworx services

SriH
8-Gravel

How to run Kepware IOT Gateway APIs in Thingworx services

Hi,

 

I am trying to update Kepware Tag through API call from IOT Gateway setup. 

Refering the document in http://127.0.0.1:39320/iotgateway/

I am using this API 

http://127.0.0.1:39320/iotgateway/write

to update a tag. Based on the example given, I was able to successfully run the API through Postman but unable to run it through Thingworx API.

 

cURL example given in the doc:

curl -H "Content-Type: application/json" -vX POST -d "[{ \"id\": \"Channel1.Device1.tag1\", \"v\": 42},{ \"id\": \"Channel1.Device1.tag2\", \"v\": 17},{ \"id\": \"Channel1.Device1.tag3\", \"v\": 36}]" http://127.0.0.1:39320/iotgateway/write

 

In postman which is on same server:   

(POST) http://127.0.0.1:39320/iotgateway/write

input in json format : 

[{"v":0,"id":"Channel1.Device1.status"}]

 

 

Thingworx server on the same instance

try{
var Obj = [{'id': 'Channel1.Device1.status','v': 1}];

let params = {
proxyScheme: undefined /* STRING {"defaultValue":"http"} */,
headers: {'Content-Type': 'application/json'} /* JSON */,       // also tried keeping it as undefined
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN {"defaultValue":false} */,
workstation: undefined /* STRING {"defaultValue":""} */,
useProxy: undefined /* BOOLEAN {"defaultValue":false} */,
withCookies: undefined /* BOOLEAN {"defaultValue":false} */,
proxyHost: undefined /* STRING {"defaultValue":""} */,
url: "http://127.0.0.1:39320/iotgateway/write" /* STRING */,
content: Obj /* JSON */,
timeout: undefined /* NUMBER {"defaultValue":60} */,
proxyPort: undefined /* INTEGER {"defaultValue":8080} */,
password: undefined /* STRING */,
domain: undefined /* STRING {"defaultValue":""} */,
username: undefined /* STRING */
};
// result: JSON
var result = Resources["ContentLoaderFunctions"].PostJSON(params);

} catch(err){
// result = err;
}

 

Output (Type Json) Service execution failed. An input value is required.

 

I fond a post and also tried to run the cURL in the service, but it didnt work.

let params = {
proxyScheme: undefined /* STRING {"defaultValue":"http"} */,
headers: undefined /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN {"defaultValue":false} */,
workstation: undefined /* STRING {"defaultValue":""} */,
useProxy: undefined /* BOOLEAN {"defaultValue":false} */,
withCookies: undefined /* BOOLEAN {"defaultValue":false} */,
proxyHost: undefined /* STRING {"defaultValue":""} */,
url: 'curl -H "Content-Type: application/json" -vX POST -d "[{ \"id\": \"Channel1.Device1.status\", \"v\": 1}]" http://127.0.0.1:39320/iotgateway/write' /* STRING */,
timeout: undefined /* NUMBER {"defaultValue":60} */,
appendHeader: undefined /* BOOLEAN {"defaultValue":true} */,
proxyPort: undefined /* INTEGER {"defaultValue":8080} */,
password: undefined /* STRING */,
domain: undefined /* STRING {"defaultValue":""} */,
username: undefined /* STRING */
};

// result: STRING
let result = Resources["ContentLoaderFunctions"].LoadText(params);

 

So how do i work with this API in service.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
slangley
23-Emerald II
(To:SriH)

For the sake of others in the community, the following solution was found after opening a case:

 

  1. Uncheck the "logged" property at property level so that updates are not sent to value streams as soon as they are received
  2. Through a data change subscription, send the values first to a data table or stream
  3. Create a timer subscription which runs every minute and logs all the property values to value stream from the data table/stream
  4. Purge the data table/stream values

Regards.

 

--Sharon

 

View solution in original post

3 REPLIES 3
VladimirN
23-Emerald IV
(To:SriH)

tmisner
16-Pearl
(To:SriH)

Hello,

 

UPDATE

I did some quick testing with this. I was able to get the REST call to execute properly but not having a IoT Gateway configured I could not get it to complete. I end up with the error below (which is expected):

Error executing service WriteTag. Message :: Connect to 127.0.0.1:39320 [/127.0.0.1] failed: Connection refused: connect - See Script Error Log for more details.

 

What I believe is happening is that your try/catch is consuming the otherwise helpful error which is resulting in an unset result value. When result is unset you will see "Service execution failed. An input value is required.".

 

I would recommend removing your try/catch and seeing what error you end up with. It will likely be helpful such as pointing to an SSL issue for instance.


Out of this recommendation you can proceed to open a case. Once we have a Technical Support case we can look further into setting up a test case with an IoT Gateway and reproducing this internally.

 

Tyler Misner

Senior Technical Support Engineer

slangley
23-Emerald II
(To:SriH)

For the sake of others in the community, the following solution was found after opening a case:

 

  1. Uncheck the "logged" property at property level so that updates are not sent to value streams as soon as they are received
  2. Through a data change subscription, send the values first to a data table or stream
  3. Create a timer subscription which runs every minute and logs all the property values to value stream from the data table/stream
  4. Purge the data table/stream values

Regards.

 

--Sharon

 

Announcements