23-05-2016, 11:14 AM (This post was last modified: 23-05-2016, 11:25 AM by simon.)
Hi Guys,
I just managed to get my eWON push its live data (Tag values) to a ThingWorx server. (http://www.thingworx.com)
Actually it is very easy to do with the new REQUESTHTTPX function (Implemented as of the firmware 11.1)
Find here below my example.
I have created a function that pushes a single Tag value to ThingWorx. Data must be pushed through simple JSON files.
Every time a Tag changes, the eWON then pushes the value to the Thingworx server.
Code:
Rem --- eWON start section: Init Section
ewon_init_section:
Rem --- eWON user (start)
This is a great example and its working for me. But I do have a couple questions. Is there an example to show how to dynanically build the json to send only the tag values that changed in one instance.
My application has multiple tags and I only want to send the changed values to thingworx in one json.
14-01-2019, 01:36 PM (This post was last modified: 26-05-2020, 03:59 PM by simon.)
Hi,
Good to see it is helpful!
To respond to your request, I have updated the script by adding some codes to push the Tags only when they change.
Actually, it uses two timers. One to push the values that have changed and one to push all values.
In the script header, you can customize
The Thingworx key
The Thingworx IP or Domain Name
The two timer intervals
The Tag groups to push
(Copy the script in the init section)
Code:
Rem --- eWON start section: Cyclic Section
eWON_cyclic_section:
Rem --- eWON user (start)
Rem --- eWON user (end)
End
Rem --- eWON end section: Cyclic Section
Rem --- eWON start section: Init Section
eWON_init_section:
Rem --- eWON user (start)
//################ CONFIGURATION #################
appKey$="6a2c195f-d0ca-4b43-97be-c2df3520dc21"
ThingworxIP_URL$="52.2.36.2:8090"
ThinkName$ = "Type TehThingName"
Changepushtime% = 1 //Timer to push only Tags that has changed
Fullpushtime% = 20// Timer to push all values
//Select the Tag Group to publish -> 0 or 1
//Tag must be created and at least set in one of the groups.
GROUPA% = 1
GROUPB% = 1
GROUPC% = 1
GROUPD% = 1
//################ ENDCONFIGURATION #################
//Record the Tag ONCHANGE events into an array.
//Allows to post only values that have changed
NB%= GETSYS PRG,"NBTAGS"
DIM a(NB%,2)
FOR i% = 0 TO NB%-1
k%=i%+1
SETSYS Tag, "load",-i%
a(k%,1)=-i%
a(k%,2) = 0
GroupA$= GETSYS TAG,"IVGROUPA"
GroupB$= GETSYS TAG,"IVGROUPB"
GroupC$= GETSYS TAG,"IVGROUPC"
GroupD$= GETSYS TAG,"IVGROUPD"
IF GroupA$ = "1" And GROUPA%= 1 THEN Onchange -i%, "a("+ STR$ k%+",2)= 1"
IF GroupB$ = "1" And GROUPB%= 1 THEN Onchange -i%, "a("+ STR$ k%+",2)= 1"
IF GroupC$ = "1" And GROUPC%= 1 THEN Onchange -i%, "a("+ STR$ k%+",2)= 1"
IF GroupD$ = "1" And GROUPD%= 1 THEN Onchange -i%, "a("+ STR$ k%+",2)= 1"
NEXT i%
IF GroupA$ = "1" And GROUPA%= 1 THEN TagIsSelected% = 1
IF GroupB$ = "1" And GROUPB%= 1 THEN TagIsSelected% = 1
IF GroupC$ = "1" And GROUPC%= 1 THEN TagIsSelected% = 1
IF GroupD$ = "1" And GROUPD%= 1 THEN TagIsSelected% = 1
IF TagIsSelected% = 1 THEN
IF counterSelectedTag% = 0 THEN
json$ = json$ + @ComputeJson$(tagName$)
ELSE
json$ = json$ + ',' + @ComputeJson$(tagName$)
ENDIF
counterSelectedTag% = counterSelectedTag% + 1
ENDIF
TagIsSelected% = 0
NEXT i%
json$ = json$ + '}'
@UpdateThingWorxData(json$)
End
//Publish just the changed tags
PublishChangedValues:
counter% = 0
//Compute JSON
json$ = '{'
FOR r% = 1 TO NB%
IF a( r%,2) = 1 THEN
a(r%,2) = 0
negIndex% = a(r%,1)
SETSYS Tag, "LOAD", negIndex%
tagName$= GETSYS Tag, "name"
IF counter% = 0 THEN
json$ = json$ + @ComputeJson$(tagName$)
ELSE
json$ = json$ + ',' + @ComputeJson$(tagName$)
ENDIF
counter% = counter% +1
ENDIF
NEXT r%
json$ = json$ + '}'
IF counter% > 0 THEN
@UpdateThingWorxData(json$)
ELSE
PRINT "[PUBLISH ONCHANGE TIMER] No Tag changes detected! -> Don't publish"
ENDIF
END
Function UpdateThingWorxData($json$)
$url$ = "http://"+ThingworxIP_URL$+"/Thingworx/Things/"+ThinkName$+"/Properties/*"
$method$ = "PUT"
$header$ = "Content-Type=application/json&Accept=application/json&appKey=" + appKey$
REQUESTHTTPX $url$, $method$, $header$, $json$
PRINT "[PUBLISH] " + $json$
ENDFN
My application is a piece of equipment the will be displayed at a trade show. I'm utilizing Thingworx to display live data via mashups. I also have a Vuforia augmented reality experience that will be displaying live data.
Now I'm looking for a way to push the tag history to Thingworx. Anyway to compile all the tag history to a single .csv and push to a Thingworx repository?
Yes, it should be possible (even if I don't know how to do that in Thingworx).
To get the Ewon history in a csv file, you should use the Export Block Descriptor. It is a syntax that allows you to extract any kind of data from the Ewon.
See https://websupport.ewon.biz/sites/defaul...riptor.pdf
Here an helper on https://ewonsupport.biz/ebd/ and https://ewonsupport.biz/post/index.php a test website to try a post data from a Flexy to a webserver (just need to copy the script to try)
I could use some help with a script to get the contents of the .CSV file into the body content. Below is the documentation Thingworx
The following bullets outline requirements when using [b]SaveText[/b] to upload a text file (the content below is required for the request in some format, whether software such as Postman is being used or a custom Java application) :
Then it should be possible to push a data file using the function REQUESTHTTPX.
Here is how you have to use it :
REQUESTHTTPX "username:password@http://1.2.3.4/Thingworx/Things/name_of_thing/Services/SaveText","POST","Content-Type=Application-json",'{ "path" : "name_of_file.txt", "content" : "I am the content of the file" }'
(16-01-2019, 11:55 AM)simon Wrote: Good point !!
I have modified the script above.
Thanks for your feedback!
By the way, could you explain what is your application ? How you use Flexy in combination to PTC Thingworx ?
Simon
This code worked for me as well. Now that you can read string tags, the string tag seems to create an error. Is there a basic function to check if a tag is a string? Then I believe I know how to modify your logic to work with string tags.