• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Import javascript library

    Scripting general Discussion
    scipting javascript
    3
    98
    92.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      arvand.owji
      last edited by

      So i created an internal data source and also added a data point for that data source. Now when i try to edit that data point using MangoAPI.defaultApi.putValue(xid, pvt) (**running on a seperate webpage but on the same server)i get an error that the data point is not settable. inside the DP, all i see for "set permission" is blank, Admin and super admin. How can i set me DP permission to be able to set it from outside? Am i even right to use an internal data source for this purpose? All i need is an arbitrary datapoint that i can be able to set it from outside. Maybe i have to use http data source instead?

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Hi Arvand,

        You would rather use a virtual data source for that purpose. The internal data source is for gathering information on how Mango or the system are running.

        A 1 Reply Last reply Reply Quote 0
        • A
          arvand.owji @phildunlap
          last edited by

          @phildunlap said in Import javascript library:

          Hi Arvand,

          You would rather use a virtual data source for that purpose. The internal data source is for gathering information on how Mango or the system are running.

          Thanks and it worked. I can now Get data and then set them in my webpage.
          Im encountering a new problem now. I created a http data retriever and passed my webpage address as the data source url . I set the update time to 5 minutes and when I save/enable the data source i get the following error:
          INFO 2017-07-17 14:41:34,313 (com.serotonin.m2m2.rt.RuntimeManager.stopDataSource:383) - Data source 'CoolPropRet' stopped
          INFO 2017-07-17 14:45:03,419 (com.serotonin.m2m2.rt.RuntimeManager.initializeDataSourceStartup:351) - Data source 'CoolPropRet' initialized
          INFO 2017-07-17 14:45:03,423 (com.serotonin.m2m2.rt.RuntimeManager.initializeDataSourceStartup:356) - Data source 'CoolPropRet' took 33.553523ms to start
          ERROR 2017-07-17 14:45:03,424 (com.serotonin.m2m2.web.dwr.util.ExceptionDetectionFilter.doFilter:38) - DWR invocation exception
          java.lang.IllegalStateException: Timer already cancelled.

          A 1 Reply Last reply Reply Quote 0
          • A
            arvand.owji @arvand.owji
            last edited by

            Hi All,
            Any chance we know why i'm getting the above error? Thanks.

            1 Reply Last reply Reply Quote 0
            • phildunlapP
              phildunlap
              last edited by

              Hi Arvand,

              Off hand I'm not quite sure. Can you possibly share the JSON for the HTTP Retriever data source that you are experiencing this with? Export it from the row in the table of data sources on /data_sources.shtm so that it also exports its points.

              A 1 Reply Last reply Reply Quote 0
              • A
                arvand.owji @phildunlap
                last edited by

                @phildunlap said in Import javascript library:

                Hi Arvand,

                Off hand I'm not quite sure. Can you possibly share the JSON for the HTTP Retriever data source that you are experiencing this with? Export it from the row in the table of data sources on /data_sources.shtm so that it also exports its points.

                Maybe im not using the right tool. I wrote a webpage that uses mango api to retrieve bunch of DPs and and then set some DPs. What i'm trying to do is to use the HTTP retriever to act like a cron job and simply send a request to that url every X minutes. I dont really care whats being oasses ot that url or what that url returns. Here is the datasrouce export. I removed the website name from the url but i have validated that the mango box has access to the url (i can ping the host from command prompt.

                {
                "dataSources":[
                {
                "xid":"DS_608664",
                "name":"CoolPropRet",
                "enabled":true,
                "type":"HTTP_RETRIEVER",
                "alarmLevels":{
                "DATA_RETRIEVAL_FAILURE":"URGENT",
                "POLL_ABORTED":"URGENT",
                "SET_POINT_FAILURE":"URGENT",
                "PARSE_EXCEPTION":"URGENT"
                },
                "purgeType":"YEARS",
                "updatePeriodType":"MINUTES",
                "quantize":false,
                "retries":2,
                "setPointUrl":"",
                "timeoutSeconds":30,
                "updatePeriods":2,
                "url":"http://www.MYWEBSITE.COM:85/coolprop4.html",
                "editPermission":"",
                "purgeOverride":false,
                "purgePeriod":1
                }
                ],
                "dataPoints":[
                ]
                }

                A 1 Reply Last reply Reply Quote 0
                • A
                  arvand.owji @arvand.owji
                  last edited by

                  I also just tried http://192.168.1.125/coolprop4.html as the url and i got the same error.

                  1 Reply Last reply Reply Quote 0
                  • phildunlapP
                    phildunlap
                    last edited by

                    Hmm. Can you try clearing your browser cache (ctrl + shift + delete in Chrome) and deleting your Mango/work/jsp directory, then trying again?

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      arvand.owji @phildunlap
                      last edited by

                      @phildunlap said in Import javascript library:

                      Hmm. Can you try clearing your browser cache (ctrl + shift + delete in Chrome) and deleting your Mango/work/jsp directory, then trying again?

                      ia have bunch of stuff in /opt/mango/work/jsp. is it ok to delete them?

                      1 Reply Last reply Reply Quote 0
                      • phildunlapP
                        phildunlap
                        last edited by

                        Yeah those are compiled JSPs. It will recompile them when the pages are loaded if you delete that.

                        A 1 Reply Last reply Reply Quote 0
                        • A
                          arvand.owji @phildunlap
                          last edited by

                          @phildunlap my permission doesnt let me to delete them. I dont have the SU password. I tried to go another route and see if ican just invoke this from linux command prompt. "curl -ls http://xxxxxxxx". It didnt work and prompt me to try the url in another browser and there i realzied that im getting error "MANGO XHR access failed". It seems im not login and doesnt let me to make any changes (which is a good thing). How can i easily login without going through the REST API. is there anyway to login from MangoAPI jquery?

                          1 Reply Last reply Reply Quote 0
                          • phildunlapP
                            phildunlap
                            last edited by phildunlap

                            I think you're looking for this page: https://help.infiniteautomation.com/mango-rest-api-authentication/

                            If this is an ES you can sudo using the regular user's password to sudo su, you don't need to su root.

                            A 2 Replies Last reply Reply Quote 0
                            • A
                              arvand.owji @phildunlap
                              last edited by

                              @phildunlap Thanks. Assuming we get the http get working, do we still need to implement the login or because mango is doignthe request, the authentication is not needed

                              1 Reply Last reply Reply Quote 0
                              • A
                                arvand.owji
                                last edited by

                                btw, i delete the folder and i still get the same error. Thanks

                                1 Reply Last reply Reply Quote 0
                                • A
                                  arvand.owji @phildunlap
                                  last edited by

                                  @phildunlap

                                  @phildunlap said in Import javascript library:

                                  I think you're looking for this page: https://help.infiniteautomation.com/mango-rest-api-authentication/

                                  If this is an ES you can sudo using the regular user's password to sudo su, you don't need to su root.

                                  What will be the request url? I tried to replace the localhost:8080 with my mango box url and im getting page not found error inside mango website when i try it in the browser
                                  http://xxxxxx.com/rest/v2/login

                                  1 Reply Last reply Reply Quote 0
                                  • phildunlapP
                                    phildunlap
                                    last edited by

                                    It should be a POST to /rest/v2/login

                                    What version of Mango and the API do you have installed?

                                    A 1 Reply Last reply Reply Quote 0
                                    • A
                                      arvand.owji @phildunlap
                                      last edited by

                                      @phildunlap said in Import javascript library:

                                      It should be a POST to /rest/v2/login

                                      What version of Mango and the API do you have installed?

                                      mangoES3273

                                      1 Reply Last reply Reply Quote 0
                                      • A
                                        arvand.owji
                                        last edited by

                                        [0_1500407785003_coolprop4.html](Uploading 100%)

                                        Here is the file file im experimenting with. Its pretty simple. All im doing is setting the xid = 'DP_274226';

                                        A 1 Reply Last reply Reply Quote 0
                                        • A
                                          arvand.owji @arvand.owji
                                          last edited by

                                          <!DOCTYPE html>
                                          <html>
                                          <head>
                                          <title>Set Point Value</title>
                                          <!-- Add the Mango Favicon -->
                                          <link rel="icon" href="/images/favicon.ico">

                                              <!-- Page Style -->
                                              <style></style>
                                              <link href="/resources/bootstrap/css/bootstrap.min.css" rel="stylesheet">
                                              <link href="/modules/dashboards/web/private/css/dashboard.css" rel="stylesheet">
                                          
                                              <!-- Base Library -->
                                              <script type="text/javascript" src="/resources/loaderConfig.js"></script>
                                              <script type="text/javascript" src="/resources/require.js"></script>
                                              <script type="text/javascript" src="/resources/main.js"></script>
                                              <script type="text/javascript" src="coolprop.js"></script>
                                              <script type="text/javascript">
                                          
                                              require(['jquery', 'mango/api'],
                                                      function($, MangoAPI) {
                                              
                                                $('#document').ready(function(){
                                          		
                                          		
                                          		
                                                	//We need the data type for the point
                                                	var xid = 'DP_274226';
                                                	MangoAPI.defaultApi.getPoint(xid).then(function(point){
                                                		
                                                		//Check to see if settable
                                                		if(point.pointLocator.settable === false){
                                                			var statusRow = [];
                                                        	statusRow.push(xid + ' not settable.');
                                                        	statusRow.push(new Date());
                                                        	//Append a status row
                                                        	$('#status').append(createRow(statusRow));
                                                        	return;
                                          				}
                                                    	var pvt = getPointValueTime(point);
                                                    	MangoAPI.defaultApi.putValue(xid, pvt).then(function(response){
                                                          	var statusRow = [];
                                                          	statusRow.push('Set Value For ' + xid + ' to ' + pvt.value);
                                                          	statusRow.push(new Date());
                                                          	//Append a status row
                                                          	$('#status').append(createRow(statusRow));
                                                    	}).fail(MangoAPI.logError);        		
                                                	}).fail(MangoAPI.logError);
                                                });
                                                
                                                function createRow(columns){
                                                	var tr = $('<tr>');
                                                	for(var i=0; i<columns.length; i++){
                                                		 var td = $('<td>');
                                             			  td.text(columns*);
                                             			  tr.append(td);
                                                	}
                                                	return tr;
                                                }
                                          
                                                
                                                function getPointValueTime(dataPoint){
                                          		
                                                	var value = null;              
                                          		value= Module.PropsSI('S', 'P', 55, 'T', 400, 'Nitrogen');
                                                	return {
                                                    		value: value,
                                                    		timestamp: new Date().getTime(),
                                                    		annotation: 'Set by custom dashboard',
                                                    		dataType: dataPoint.pointLocator.dataType,
                                                    	};
                                                }
                                              });
                                              </script>
                                              
                                          </head>
                                          <body>
                                            <div id="main">
                                              
                                              <div class="row">
                                                <div class="col-md-12">
                                                  <table class="table">
                                                    <tr><th>Status</th><th>Time</th></tr>
                                                    <tbody id="status"></tbody>
                                                  </table>
                                                </div>
                                              </div>
                                          
                                            </div>
                                          </body>
                                          

                                          </html>

                                          1 Reply Last reply Reply Quote 0
                                          • phildunlapP
                                            phildunlap
                                            last edited by phildunlap

                                            @arvand.owji said in Import javascript library:

                                            mangoES3273

                                            Try going to the /modules.shtm page and checking for updates. That page is also the right place to get version information. I can assume that you haven't modified it since it was shipped, but then I have to make an assumption and look up your system. It's easier for me if you report the current reality. You haven't really done anything with your data source from the json, so it doesn't make any sense it wouldn't be working.

                                            There was no stack trace for the timer already cancelled message, was there?

                                            My impression is that something is misconfigured. Otherwise, something is overridden. Can you share the output of find /opt/mango/overrides?

                                            If there are no upgrades, I would try starting Mango on a clean database (move your existing Mango/databases directory to Mango/databases-bck while Mango is off) and setting up a new HTTP Retriever data source in the clean environment. If that works, you could consider restoring your system from a json export or database restore if something has gone awry somehow in the database.

                                            Edit: If you haven't restarted Mango since those memory errors, maybe that's related? Give it a restart from the /modules.shtm page

                                            A 3 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post