mTANGO Rest API

Hi,

I am exploring mTANGO Rest API. I’ve downloaded the mtango.server-rc3-0.1.zip file.

I’m able to send GET and PUT requests (as per the specifications provided in this link) via the curl utility.

My aim is to develop User Interface using AngularJS. I tried using the jsTangORB-rc1-0.1.js file from the jsTangORB-rc1-0.1-bundle.zip file. But unfortunately, it is not compatible with the latest tango.war file.

Any related inputs will be much helpful.

Vatsal

Hi Vatsal,

Thanks for giving a try to mTangoUI.

mTangoUI is indeed outdated nowdays. You have to use mtangorest.server-rc1 (aka implementation of REST API specification version rc1) with it currently.

I plan to update mTangoUI (including jsTangORB) to be compatible with rc4 (latest version of REST API specification). Hopefully this will be done before the next Tango meeting i.e. begin of June.

Hi Igor,

Thanks for the prompt response. I’ll test mTangoUI with the mtangorest-server-rc1 and will get in touch with you in the case of any additional issues.

Vatsal

Hi Igor,

I deployed the mtango.war file from the mtango.server-rc1-0.1.zip as per your suggestion. I’m able to get a list of devices by doing a simple GET request via the browser. Attached is the snapshot for the reference.

I tried using the jsTangORB-rc1-0.1.js file from the jsTangORB-rc1-0.1-bundle.zip, but still I’m not able to invoke jsTangoORB APIs from the .html page. I used the HelloWorld.html file from the jsTangORB-rc1-0.1-bundle.zip.

Appropriate permissions for “mtango-js” user is added in Tango Access Control as well as Tomcat. Snapshots for the same are also attached for the reference.

The mTangoUI is not extracted in the webapps folder.

Your help is needed in resolving this.

Vatsal

Hi Vatsal,

I will have a look!

So here are some comments:

Entry point for mTangoUI is: http://localhost:8080/mtango/js NOT http://localhost:8080/mtango/rest/rc1

So in your JS use the following:


        var TangoTest = new DeviceProxy({url:'http://localhost:8080/mtango/js',device:'sys/tg_test/1'});//NOTE the url parameter
        TangoTest.executeCommand("DevString",{
            argin:"Hello World!!!"
        },{
            onSuccess:function(response){
                alert("Success!!! " + response.argout);
            },
            onFailure:function(response){
                alert("Failure :((( \n" + response.errors.join('\n'));
            }
        });

jsTangORB must be deployed on the same tomcat instance, otherwise you have to setup CORS filter

Applying these changes should help. Let me know your progress.

Hi Igor,

Your inputs helped in resolving the issue. I’ve been playing with jsTangORB since a couple of weeks. I encountered some problems on the way. Attached is the TestApp to demonstrate the problems. Google drive link to the mtango.war file that is being used is also attached.

The problem is I’m unable to invoke commands that take any of DevVarCharArray, DevVarDoubleStringArray, DevVarLongStringArray, DevVarULong64Array, DevVarULongArray, DevVarUShortArray as an input argument.

Also, I’m able to invoke commands that take DevDouble as input argument from Mozilla Firefox, but not from Google Chrome. Try opening the TestApp from Mozilla Firefox and Google Chrome. This is quite strange. I didn’t understand the reason behind it.

A folder is created for an application in the webapps folder of Tomcat. In application folder, jsTangORB-rc1-0.1.js file and jmvc folder containing include.js file is kept. I think, jsTangoORB can be used without mTangoUI. So there is no need to add anyother files apart from application files in the folder. Please correct me if I’ wrong.

I also wanted to check whether jsTangORB is updated to be compatible with rc4 (latest version of REST API specification). jsTangORB file compatible with REST API specification version rc1 does not support various features such as Pipes, Enumerated Attributes, Connectivity with devices from multiple TANGO Facility and so on.

If you find ways for solving the issues, please let me know.

Vatsal

Hi Vatsal,

Thank you very much for your feedback. It is cool that someone from the outside HZG has tested the things.

We never used that, so I have not implemented it.

Yes, you are right the idea behind jsTangORB is to use it without mTangoUI as a pure js library, but jmvc is not related to mTangoUI - it is a standalone JS framework for rich applications: https://en.wikipedia.org/wiki/JavaScriptMVC

I use my own fork of the framework: https://bitbucket.org/Ingvord/javascriptmvc-1.5.x

jmvc/include.js in this case is used to provide integration interface for other jmvc based applications (mTangoUI)

[quote=“Vatsal”]
I also wanted to check whether jsTangORB is updated to be compatible with rc4 (latest version of REST API specification). jsTangORB file compatible with REST API specification version rc1 does not support various features such as Pipes, Enumerated Attributes, Connectivity with devices from multiple TANGO Facility and so on.[/quote]

I have plans to update these libraries (jsTangORB, mTangoUI) to be compatible with rc5 (the next major update for Tango REST API). Not sure when I will be able to do it though…

[quote=“Vatsal”]
If you find ways for solving the issues, please let me know.[/quote]

I have already :slight_smile: One must seat and do the job :wink:

Regards,

Hi Igor,

Thanks for the detailed response.

Could you please include the support for commands with DevVarCharArray, DevVarDoubleStringArray, DevVarLongStringArray, DevVarULong64Array, DevVarULongArray, DevVarUShortArray as an input argument in the next release?

Detailed information about the jsTangORB and jmvc framework is quite useful.

Were you able to reproduce the issue related to Commands with DevDouble as an input argument that I described in the previous post? The output is different across Google Chrome and Mozilla Firefox Web browser. The same behavior can be observed by opening the mTangoTest application from Google Chrome and Mozilla Firefox. Try executing DevDouble command from the mTangoTest application.

If any additional inputs are needed, please let me know.

Vatsal

Hi Igor,

I’m unable to write attributes using the mTango.war file and jsTangORB file that is attached in the previous post.

I’m attempting to write ampli attribute on TangoTest device. Below is the javascript code.

<script>
            var ampliValue = 100.25;
            var TangoTest = new DeviceProxy({url:'http://localhost:8080/mtango/js',device:'sys/tg_test/1'});
            TangoTest.writeAttribute("ampli", {
                    argin:ampliValue
                }, {
                    onSuccess:function(response) {
                        console.debug("Response --- " + JSON.stringify(response));
                    },
                    onFailure:function(response) {
                        console.debug("Response --- " + JSON.stringify(response));
                    }
            });
</script>

The request is successful, but the value does not get updated at the Device side.

I also checked in the mTangoTest application. Same issue. This is kind of show stopper for us.

Please let me know if it has got something to do with the war file or jsTangoORB file.

Vatsal

Hi Vatsal,

I will have a look

Hi Igor,

Any updates on this?

Vatsal

Hi Vatsal,

Looks like there is a bug mtango.war. If you look through server’s log you will see the following:


INFO 12-07-2017 13:49:57 [http-nio-8080-exec-16 - o.t.w.s.f.TimeWatcher] Serving request. Stopwatch is active.
DEBUG 12-07-2017 13:49:57 [http-nio-8080-exec-16 - o.j.r.l.i.Slf4jLogger] PathInfo: /mtango/device/sys/tg_test/1/ampli=100.25
INFO 12-07-2017 13:49:57 [http-nio-8080-exec-16 - o.t.w.s.f.AccessControlFilter] Method is not allowed: put
INFO 12-07-2017 13:49:57 [http-nio-8080-exec-16 - o.t.w.s.f.TimeWatcher] Request processing time (nano):2426080
INFO 12-07-2017 13:49:57 [http-nio-8080-exec-16 - o.t.w.s.f.TimeWatcher] Request processing time (ms):2

Notice Method is not allowed: put even though mtango-js user has write access to the device.

We never experienced this due to read only applications. I have fixed this - you can use new war file: https://bitbucket.org/hzgwpn/mtangorest.server/downloads/mtangorest.server-rc1-0.4.zip

Concerning DevDouble I confirm that it works in FF and not in Chrome. As we are using FF by default this is not going to be fixed soon.j

Regards,

Hi Igor,

Thanks for resolving the issue. We have tested it and its working.

Will get in touch with you in case of any additional issues. Also let us know when jsTangORB compatible with rc5 (the next major update for Tango REST API) is released. We would like to play with it.

Regards,
Vatsal Trivedi

Hi Igor,

In the updated war file there is an issue while reading “State” of a TANGO Device.

Regards,
Apurva

Hi Apurva,

Works fine for me:


<script>
var TangoTest = new DeviceProxy({url:'http://localhost:8080/mtango/js',device:'sys/tg_test/1'});

TangoTest.state({}, {
   onSuccess:function(response) {
       debugger;
       console.debug("Response — " + JSON.stringify(response));
   },
   onFailure:function(response) {
       debugger;
       console.debug("Response — " + JSON.stringify(response));
   }
});
</script>

Gives this console output:


Sending request: http://localhost:8080/mtango/js/mtango/device/sys/tg_test/1/State
jsTangO...-0.1.js (line 3611)
Request has succeed: http://localhost:8080/mtango/js/mtango/device/sys/tg_test/1/State
jsTangO...-0.1.js (line 3617)
Response — {"errors":[],"argout":{"value":10},"quality":"VALID","timestamp":1500976579598,"responseText":"[object Object]","src":"http://localhost:8080/mtango/js/mtango/device/sys/tg_test/1/State"}
/test/ (line 24)

Hi Igor,

Thanks for the solution. It is just that we were able to read “State” of the tango device in the form of string using previous mtango.war file. With this mtango.war file, we get “State” as an integer value.

Regards,
Apurva

OK,

I see.

Will have a look

Hi Igor,

I want to read device properties using the REST API. But jsTangORB compatible with version rc1-0.4 of the TANGO REST API does not support reading of device properties.

So I tried a workaround. TANGO Database Server exposes a command DbGetDeviceProperty to read device properties. So I created a proxy to the TANGO Database Device (sys/database/2) and invoked DbGetDeviceProperty command with DevVarStringArray as input parameter containing TANGO Device Name and name of property to be read.

I have added a TestProperty in TANGO Test (sys/tg_test/1) device.

Below is the code snippet:

var TangoTest = new DeviceProxy({url:'http://localhost:8080/mtango/js',device:'sys/database/2'});
var testStrArr = ["sys/tg_test/1", "TestProperty"];
TangoTest.executeCommand("DbGetDeviceProperty",{
            argin:testStrArr
        },{
            onSuccess:function(response) {
                console.log("Success response is : " + JSON.stringify(response));
            },
            onFailure:function(response) {
                console.log("Failure response is : " + JSON.stringify(response));
            }
        });

But I get failed response. Below is the output on the console:

Failure response is : {"errors":[{"reason":"UnhandledException","description":"Response is committed, can't handle exception","severity":"ERR","origin":"org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:148)"},{"reason":"NotFoundException","description":"Could not find resource for full path: http://localhost:8080/mtango/js/mtango/device/sys/database/2/DbGetDeviceProperty=sys/tg_test/1,TestProperty?argin=sys%2Ftg_test%2F1&argin=TestProperty&cbk=MVC.JsonP._cbs.cnfRRg","severity":"ERR","origin":"org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:112)"}],"quality":"FAILURE","timestamp":1501246741912,"responseText":"[object Object]","src":"http://localhost:8080/mtango/js/mtango/device/sys/database/2/DbGetDeviceProperty=sys/tg_test/1,TestProperty"}

I think the issue is related to the war file.

Please have a look at it.

Regards,
Lochan

Hi Lochan,

I have uploaded new versions of jsTangORB and mtango.war:

jsTangORB-rc1-1.0.3.zip

mtangoserver-rc1-0.5.zip

Using this ones I can read device properties:


Sending request: http://localhost:8080/mtango/js/mtango/device/sys/database/2/DbGetDeviceProperty=X
Request has succeed: http://localhost:8080/mtango/js/mtango/device/sys/database/2/DbGetDeviceProperty=X
Success response is : {"errors":[],"argout":["sys/tg_test/1","1","TestProperty","1","blah blah"],"timestamp":1501344685895,"responseText":"[object Object]","src":"http://localhost:8080/mtango/js/mtango/device/sys/database/2/DbGetDeviceProperty=X"}

@Vatsal, this also fixes a few tests of yours:


Executing command DevVarULong64Array --- Success!!! 11,12

Executing command DevVarULongArray --- Success!!! 11,12

Executing command DevVarUShortArray --- Success!!! 11,12