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

    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

    raylatbasix

    @raylatbasix

    0
    Reputation
    941
    Profile views
    70
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Location 03820

    raylatbasix Unfollow Follow

    Latest 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