No internet connection
  1. Home
  2. How to

Middle Atlantic Racklink Power HTTP Commands

By Sam Read @Sam_Read
    2024-12-01 17:50:19.285Z

    Has anyone attempted to run HTTP commands through SF to a Middle Atlantic Racklink PDU? I see that HTTP requests can be completed straight from SF using a sf.net.httpRequest.

    • 6 replies
    1. Hi Sam,

      Do you have a link to some documentation for the HTTP requests that are possible to send? Then we could help you write the proper SF code to match.

      1. S
        In reply toSam_Read:
        Sam Read @Sam_Read
          2024-12-02 17:48:28.854Z

          Rest API using Fetch commands it appears:

          Middle Atlantic RackLink devices offer a robust API that you can interact with using JavaScript. Here's how you can get started:
          Understanding the RackLink API
          RESTful API:
          RackLink devices expose a RESTful API, which allows you to perform various operations like:
          Monitoring: Get data on power consumption, voltage, current, and other metrics.
          Control: Turn outlets on or off, set schedules, and configure IP sequencing.
          Configuration: Manage device settings and network parameters.
          Authentication:
          You'll typically need to authenticate your requests using credentials (username and password) or API keys.
          Data Format:
          The API usually returns data in JSON format, which is easy to parse in JavaScript.
          Example Using Fetch API
          JavaScript

          fetch('https:///api/v1/outlets', {
          method: 'GET',
          headers: {
          'Authorization': 'Basic ' + btoa('username:password')
          }
          })
          .then(response => response.json())
          .then(data => {
          // Process outlet data
          console.log(data);
          })
          .catch(error => {
          console.error('Error:', error);
          });
          Explanation:
          Import Libraries: If you're using Node.js, you might need to install a library like node-fetch to make HTTP requests.
          API Endpoint: Replace with the IP address of your RackLink device.
          Authentication: Use the appropriate authentication method. The example shows Basic Authentication.
          Request Method: Use GET, POST, PUT, or DELETE according to the desired action.
          Headers: Set necessary headers like Authorization and Content-Type.
          Response Handling: Parse the JSON response and process the data.
          Important Considerations
          API Documentation:
          Refer to the official Middle Atlantic RackLink API documentation for detailed information on available endpoints, parameters, and authentication methods.

          1. Hi Sam - thanks for this, could you share this as a link to make it easier to read and so that we'd have access to the full documentation as opposed to just a small portion?

            That being said - the following JS code:

            fetch('https:///api/v1/outlets', {
            method: 'GET',
            headers: {
            'Authorization': 'Basic ' + btoa('username:password')
            }
            })
            

            Could be done in SF as:

            
            function btoa(string) {
                var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
                string = String(string);
                var bitmap, a, b, c,
                    result = "", i = 0,
                    rest = string.length % 3; // To determine the final padding
            
                for (; i < string.length;) {
                    if ((a = string.charCodeAt(i++)) > 255
                        || (b = string.charCodeAt(i++)) > 255
                        || (c = string.charCodeAt(i++)) > 255)
                        throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");
            
                    bitmap = (a << 16) | (b << 8) | c;
                    result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63)
                        + b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
                }
            
                // If there's need of padding, replace the last 'A's with equal signs
                return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
            };
            
            var SERVER_IP = '192.168.0.blabla'; // Make sure to set to the proper IP
            var USERNAME = 'set to your username';
            var PASSWORD = 'set to your password';
            
            var outletsJson = sf.net.httpRequest({
                url: `http://${SERVER_IP}/api/v1/outlets`,
                method: 'GET',
                headers: {
                    'Authorization': 'Basic ' + btoa(USERNAME + ':' + PASSWORD),
                }
            }).asJson();
            
            log(outletsJson);
            
            

            This assumes using username + password. Using API keys is likely a better approach.

            1. SSam Read @Sam_Read
                2024-12-02 18:47:37.400Z

                Thank you!

                Here is a link to the control protocol that is referenced in their json example. Does that help?

                https://pimcore-dev.kindermann.de/_default_upload_bucket/7540000792_manual_en_1.pdf

                1. This appears to be a link to a custom TCP protocol - not a HTTP REST API which you were originally referencing. If they provide a HTTP-based REST API, that would be a lot simpler for you to integrate with.

                  1. Where did you take the text from that you quoted in your original message?