Update Flexy Tag Database vis M2Web


#1

Hello,

I have a customer that needs to set up an automated way to update the tag database in their Flexys. I have tried to find a way to do this via the M2Web API, but I did find a way to send the “var_list.csv” file to the Flexy. Please let me know if there is a way to do this.

Thanks!
Trevor


#3

@trevor_hms

I wanted to confirm, when you say update the tag database, do you mean adding and deleting tags or just adding new tags?


#5

The customer didn’t say specifically. I assume that they may want to add new tags, delete tags and modify existing tags.


#6

Hi Trevor,
Let me see what I can put together. I should have something for you tomororw.


#8

@trevor_hms

Apologies on the delay preparing this. In order to do what you would like to do, we are going to need to interface with the BASIC scripting engine inside of the eWON. By using the scripting engine we are able to directly add, delete or update new and existing tags.

It is important to note however that of the two examples below, only one is directly integrated into the Flexy meaning you do not have to update anything on the Flexy. I personally recommend the pre-written solution as it results in far shorter API calls.

Option 1 - Embedded Functions:

In this solution I have pre-written 3 functions that need to be imported into your Flexy. These functions can exist anywhere in the Flexy, though I recommend creating a section specifically for API scripts.


Create Tag:
The create tag script accepts a tag name, address and an existing tag to mirror from. It is important to note that this function directly depends on another tag to clone existing information into. This negates the need to pass in the IOServer name, Topic and other small details, though please note that you can pass these as well.

In this example, the new tag will receive all properties (IOServer name, topic, alarming etc) from the existingTag parameter.

REM - Create a new tag in your eWON (usage guide on hms.how)
REM - PARAMS
REM - tagname - Name of the new tag to create
REM - address - The address of the tag
REM - existingTag - The existing tag to copy
REM - #########################################
FUNCTION createNewTag($tagname$, $address$, $existingTag$)
  SETSYS TAG, "LOAD", $existingTag$
  SETSYS TAG, "NAME", $tagname$
  SETSYS TAG, "Address", $address$
  SETSYS TAG, "SAVE"
  CFGSAVE
ENDFN


Delete Tag:
As the name states, this function simply deletes a tag by the passed tag name.

REM  - Delete a tag by the tag name
REM - PARAMS
REM - tagname - Name of tag to delete
REM - ########################################
FUNCTION deleteTag($tagname$)
  SETSYS TAG, "LOAD", $tagname$
  SETSYS TAG, "DODelete", 1
  SETSYS TAG, "SAVE"
  CFGSAVE
ENDFN

Modify Tag:
The tag modification function accepts three parameters, the tag name, the parameter to modify and finally the new value. So for example, say I wanted to update the address of a tag, I would simply call:

@modifyTag('myTag', 'Address', 'NewAddress')

REM - Modify a tag by the tag name
REM - PARAMS
REM - tagname - The tag name to modify
REM - modify - The parameter to edit
REM - newVal - The value to update the modify parameter to
REM - #############################################
FUNCTION modifyTag($tagname$, $modify$, $newVal$)
  SETSYS TAG, "LOAD", $tagname$
  SETSYS TAG, $modify, $newVal$
  SETSYS TAG, "SAVE"
  CFGSAVE
ENDFN


API Integration:

I can imagine by this point you are wondering how does this help with the API, well lets discuss that. The M2Web API offers an script execution endpoint. This endpoint is: rcgi.bin/ExeScriptForm?

The script form can take raw BASIC commands and executes them on the Flexy. Here is an example API call to execute the add tag function from above:

https://m2web.talk2m.com/t2mapi/get/yourewon/rcgi.bin/ExeScriptForm?Command1=@createNewTag("tagname", "address", "existing")&t2mdeveloperid=yourid&t2maccount=account&t2mpassword=password&t2mdeviceusername=adm&t2mdeviceusername=password

In order to make this easier to test, here is a Postman entry that you can simply import into postman and update the values inside of the body.

Download: M2Web API.postman_collection.json (1.4 KB)


Option 2 - Directly Calling Scripts:

As previously mentioned, the second solution is essentially the same as the first however instead of calling a single function we have to pass each parameter manually in the API call. I will not go over the commands again as those were discussed earlier, however here is an example API call to update the tag.


https://m2web.talk2m.com/t2mapi/get/yourewon/rcgi.bin/ExecScriptForm?Command1=SETSYS "TAG", "LOAD", "YourTag"&Command2=SETSYS TAG, "NAME", "newname"&Command3=SETSYS TAG, "Address", "new address"&Command4=SETSYS TAG, "SAVE"&command4=cfgsave&t2mdeveloperid=yourid&t2maccount=account&t2mpassword=password&t2mdeviceusername=adm&t2mdeviceusername=password

I hope this helps! Let me know if you need any clarification.


RE: eWon reading incorrect tag on I/O server config change