• Recent
    • Tags
    • Popular
    • Register
    • Login
    1. Home
    2. raylatbasix
    3. Posts

    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
    • Profile
    • Following 0
    • Followers 0
    • Topics 13
    • Posts 70
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by raylatbasix

    • RE: Help needed (newbie) Accessing an API with a Scripting Datasource Mango 4.4.2

      @MattFox Thanks for posting this Fox!! And thank you again for all your help! Your an invaluable asset to this forum!

      Note: For others that try to access this data from the DegreeDays.net API as shown above, you may need to adjust the CRON polling time to something a little later than 12:30AM as listed above. Some weather stations do not fully update yesterdays available Heating Degree Data until a couple hours or so after midnight, so experiment with the CRON polling time accordingly.

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: Help needed (newbie) Accessing an API with a Scripting Datasource Mango 4.4.2

      @MattFox Thank you for trying Fox! It's the end of my day here in the US, but I will plan on getting in touch with you for some NodeJS help via PM soon! Thanks again.

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: Help needed (newbie) Accessing an API with a Scripting Datasource Mango 4.4.2

      @MattFox Thanks for the info Fox! Being new to this, If I install NodeJS on the same Windows installation that Mango 4 resides on, will I be able to write to a Mango datapoint through the Mango Rest API? I've searched the forum, and see NodeJS referred to quite a bit, but not being a web developer, I'm afraid I would need a set of instructions on how to implement that with Mango.

      I've got other Mango scripting data sources grabbing weather data from an outside API and successfully writing to Mango data points just by finding resources on this Forum of which you seem to contribute quite a bit to. Thanks for that!

      I've also tried copy/pasting the simplecrypto.js you mentioned into a Global Script but it will not validate. I'll keep trying things on my own, but if you have any further pointers they are much appreciated. Thank you for your time!

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • Help needed (newbie) Accessing an API with a Scripting Datasource Mango 4.4.2

      If someone could point me in the right direction getting the following sample code working as a scripting datasource in Mango 4, it would be appreciated. I have the need to connect to DegreeDays.net API so I can import a history of Heating Degree Days into a Mango Datapoint. Here is the following sample code from the DegreeDays.net API developer's page:

      const crypto = require('crypto'), // built-in module, no need to npm install
        fetch = require('node-fetch'); // install with npm install node-fetch
      
      // The test API access keys are described at www.degreedays.net/api/test
      // They will let you access data from the Cape Cod area only.
      // To fetch data from locations worldwide, sign up for a proper API account at
      // www.degreedays.net/api/ and copy your API access keys here.
      const accountKey = 'test-test-test';
      const securityKey = 'test-test-test-test-test-test-test-test-test-test-test-test-test';
      // You can call the API over HTTP using http://apiv1.degreedays.net/json or
      // over HTTPS using https://apiv1.degreedays.net/json - set the endpoint URL
      // below as appropriate.
      const endpoint = 'http://apiv1.degreedays.net/json';
      
      
      
      // ************* STEP 1: Create the request ************************************
      // First we create a JSON request that specifies what we want from the API.
      // See www.degreedays.net/api/json#request for more on this.
      
      // You can fetch data from a station ID, a longitude/latitude position, or a 
      // postal/zip code.
      const location = {
        type: 'PostalCodeLocation',
        postalCode: '02532',
        countryCode: 'US'
      };
      // In this example we fetch both HDD and CDD, using the same breakdown (daily
      // data covering the last 7 days) for both. For more breakdown options see
      // www.degreedays.net/api/json#breakdown
      const breakdown = {
        type: 'DailyBreakdown',
        period: {
          type: 'LatestValuesPeriod',
          numberOfValues: 7
        }
      };
      const locationDataRequest = {
        type: 'LocationDataRequest',
        location: location,
        dataSpecs: {
          // Here we specify 2 DataSpec items: one for HDD and one for CDD.  You
          // can specify up to 100 DataSpec items in one request (e.g. to fetch
          // data in lots of base temperatures).  With an API Standard+ account you
          // can have a DataSpec for hourly temperature data too.
          // Give each DataSpec a unique name so you can get the corresponding
          // DataSet from the response.
          myHDD: {
            type: 'DatedDataSpec',
            calculation: {
              type: 'HeatingDegreeDaysCalculation',
              baseTemperature: {
                unit: 'F',
                value: 60
              }
            },
            breakdown: breakdown
          },
          myCDD: {
            type: 'DatedDataSpec',
            calculation: {
              type: 'CoolingDegreeDaysCalculation',
              baseTemperature: {
                unit: 'F',
                value: 70
              }
            },
            breakdown: breakdown
          }
        }
      };
      const fullRequest = {
        securityInfo: {
          endpoint: endpoint,
          accountKey: accountKey,
          timestamp: new Date().toISOString(),
          random: Buffer.from(crypto.randomBytes(12)).toString('hex')
        },
        request: locationDataRequest
      };
      const fullRequestJson = JSON.stringify(fullRequest);
      // Now our JSON request is ready.  Uncomment the line below to log the JSON:
      //console.log(fullRequestJson);
      
      
      
      // ************* STEP 2: Send the request to the API ***************************
      // Next we sign the JSON request and package everything together into an HTTP
      // request which we send to the Degree Days.net API.  This follows the spec at
      // www.degreedays.net/api/json#send
      const signatureBytes = 
        crypto.createHmac('sha256', securityKey).update(fullRequestJson).digest();
      // The API requires the JSON request and the signature to be base64url encoded.
      function base64urlEncode(unencoded) {
        return Buffer.from(unencoded).toString('base64')
          .replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
      }
      // Send the HTTP request to the API servers using node-fetch.  You could change
      // this to use another HTTP library if you wanted.
      fetch(endpoint, {
          method: 'POST',
          body: 'request_encoding=base64url' +
            '&signature_method=HmacSHA256' +
            '&signature_encoding=base64url' +
            '&encoded_request=' + base64urlEncode(fullRequestJson) +
            '&encoded_signature=' + base64urlEncode(signatureBytes),
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
          }
        })
        .then(response => {
          if (!response.ok) {
            throw new Error(response.status + ': ' + response.statusText);
          }
          return response.json();
        })
        .catch(err => console.error('Problem connecting to API:', err)
        .then(parsedObject => handleResponse(parsedObject))
        .catch(err => console.error('Problem handling API response:', err));
      
      
      
      // ************* STEP 3: Process the response from the API *********************
      // The JSON response is explained at www.degreedays.net/api/json#response
      function handleResponse(fullResponse) {
        // fullResponse.metadata has some rate limit info, but we are mainly
        // interested in fullResponse.response (a LocationDataResponse in this case).
        const response = fullResponse.response;
        if (response.type === 'Failure') {
          // See www.degreedays.net/api/json#failure for more about failures.
          console.log('Request failure:', response);
        } else {
          // The response contains a lot of useful info, as shown in the JSON docs
          // at www.degreedays.net/api/json#response
          console.log('Station ID: ', response.stationId);
          // "myHDD" is the name we gave the HDD DataSpec in our request.
          const hddData = response.dataSets.myHDD;
          if (hddData.type === 'Failure') {
            console.log('Failure for HDD DataSet:', hddData);
          } else {
            console.log('HDD:');
            for (var v of hddData.values) {
              console.log(v.d + ': ' + v.v);
            }
          }
          const cddData = response.dataSets.myCDD;
          if (hddData.type === 'Failure') {
            console.log('Failure for CDD DataSet:', cddData);
          } else {
            console.log('CDD:');
            for (var v of cddData.values) {
              console.log(v.d + ': ' + v.v);
            }
          }
        }
      }
      
      

      I appreciate the help. Thanks.

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Good Morning Phil,

      You can cancel this request, I was able to solve my Authorization Request Header issue.

      Thanks again for all the help!!

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Hi Phil,

      Yes, I saw that, and forgive my ignorance, I can generate user tokens. My problem is that I can only modify the URL on my third party app. I am not understanding how to pass this authorization token from within my request URL.

      Sorry for the crazy question :)

      EDIT: In other words, what is my URL's format for reqesting data? ie:

      http://localhost:8080/rest/v2/custom/latest-value-only/DP_e64bb726-ddd4-4065-8972-21c9441af408?access_token=<auth token here>??????
      
      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Hi Terry,
      Sorry for being a newbie, but How would I pass this JWT Auth token within a request URL to the Rest API?

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      On a side note to this application, When I use this Rest URL from my third-party app on the same network, Will I recieve any authentication challenges "Auth Tokens" before Mango will display the data? Right now, It works fine in my localhost browser, but I'm not sure about a remote application.

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Hi Phil,

      Nevermind! Apparently the command:

      jar uf mango-api-3.6.0.jar com/infiniteautomation/mango/rest/v2/CustomizedRestController.class
      

      did not actually take the first time. I think Mango was running by mistake, when I ran it the first time.

      It's actually all working now, and I see the plain text data that I need for my application!!

      Brilliant as always Phil!!

      Thanks again!!

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Thanks Phil,

      I was able to get it to compile by switching to the C:\Mango356\web\modules\mangoApi\lib directory, and then use the following command:

      javac -cp C:\Mango356\lib\*;C:\Mango356\web\modules\mangoApi\lib\* CustomizedRestController.java
      

      I then copied the CustomizedRestController.class file that was created, to the C:\Mango356\web\modules\mangoApi\lib\com\infiniteautomation\mango\rest\v2 directory.

      I then ran jar uf mango-api-3.6.0.jar com/infiniteautomation/mango/rest/v2/CustomizedRestController.class and did not recieve any errors at all. I then restarted Mango, and went into swagger, but fail to see any URL path t o access this custom endpoint. I tried accessing: http://localhost:8080/rest/v2/custom/latest-value-only/DP_059c7915-c0e7-48dc-b9e3-28ca8b92da01?fields=VALUE&limit=1&useCache=NONE but got a "page not found" error. Again, thanks for all the help!

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Hi Phil,
      Thanks so much for offering a solution!! I believe I understand what I need to do.
      However, When I try to compile the class in Windows 7 using the following command:

      C:\Program Files\Java\jdk1.8.0_144\bin>javac -cp C:\Mango356\lib\*; C:\Mango356\
      web\modules\mangoApi\lib\CustomizedRestController.java
      

      I Recieve the following error:

      C:\Mango356\web\modules\mangoApi\lib\CustomizedRestController.java:11: error: pa
      ckage com.infiniteautomation.mango.rest.v2.exception does not exist
      import com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException;
                                                           ^
      1 error
      

      I had copied the CustomizedRestController.java to my "C:\Mango356\web\modules\mangoApi\lib" directory,
      and also created the folders "com\infiniteautomation\mango\rest\v2" within the "C:\Mango356\web\modules\mangoApi\lib" directory as well. I'm sure I'm missing something. I do not do much java compiling.

      Thanks again for the help!

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Hi Phil,

      I can update the URL on the third-party app, Just not modify any scripting on that side.

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: How to negotiate a Plain text response from Mango 3.6 Rest API

      Hi Phil,

      There is a third-party app looking for plain text, when it query's another rest server's URL. This third-party app is currently connecting to a DGLux5 Rest server service which is responding with the plain text that the third-party app needs. I am looking to move to the Mango Rest API in order to eliminate the DGLux5 from the equasion. I am not able to modify the script on the third-party app that is currently looking for plain text, so I need a solution on the Mango side. Any ideas as to how I would go about creating a script that would accomplish stripping the JSON down to just the value alone being returned from the the third-party apps URL Get Request? Thanks for the help.

      posted in User help
      raylatbasixR
      raylatbasix
    • How to negotiate a Plain text response from Mango 3.6 Rest API

      Rather new to the Rest API. Looking for help on changing the Response type when I request the following point Value URL:
      http://localhost:8080/rest/v2/point-values/latest/DP_059c7915-c0e7-48dc-b9e3-28ca8b92da01?fields=VALUE&limit=1&useCache=NONE
      Returns JSON:

      [ {
        "value" : "Community Center"
      } ]
      

      Instead, I need to strip off any JSON characters, and simply recieve a plain text response with the following:

      Community Center
      

      Any help on What I need to do to accomplish this, would be appreciated.

      posted in User help
      raylatbasixR
      raylatbasix
    • RE: Meta script for calculating the current years monthly totals for a given point.

      Boy, do I feel stupid!! It was the Logging Interval!! All set now!

      Thanks for putting up with me!!

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: Meta script for calculating the current years monthly totals for a given point.

      Hi Phil,
      Sorry for the late reply. Just checked my settings for both meta points. My originating kWh meta point is set up for "Start of Hour" on update event, and the "Updates context" checkbox is unchecked for the modbus kW point (p40). I generate my kWh calculation from my modbus kW point as follows:

      var stats = p40.past(HOUR, 1);
      if(stats.count !== 0) return stats.average;
      return 0;
      

      My new Meta point is setup "Start of Month" for update event, and "Updates context" is unchecked for my kWh meta point (p130) as well. My code:

      TIMESTAMP=CONTEXT.getRuntime()-1;
      return p130.past(MONTH).sum;
      

      Like I said, it seems to calculate monthly totals ok, Just looking for a way to "Rollup" the data rows to 1 monthly total per month. Thanks again.

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: Meta script for calculating the current years monthly totals for a given point.

      Hi Phil,

      This looks like it's working!! Just one more question. Is there any way to rollup the data so there is only one row per month in the dataset? Right now, it shows the same monthly sum total for every kWh hourly entry for each month, which equals over 283,000 rows. Do you know how to just display one row per month showing the total?

      Thanks Again!

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: Meta script for calculating the current years monthly totals for a given point.

      Awesome Phil!! I will give this a try! Thanks for the help!

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • Meta script for calculating the current years monthly totals for a given point.

      Looking for a solution in Mango 2.8 Meta Script.
      I have a kilowatt/hour meta point that I sample once an hour.
      I need to sum up the total kWh usage for each month for the current year to date (ie. Jan '18 through today's last kWh entry.) Any guidance would be appreciated.

      posted in Scripting general Discussion
      raylatbasixR
      raylatbasix
    • RE: Java update to 1.8 162 has caused Mango ES 3.2.2 to become unreachable.

      Thanks for the excellent support today Phil!!

      posted in MangoES Hardware
      raylatbasixR
      raylatbasix