CPE with multiple conf get the IP address {SOLVED}

I have 2 CPE, one using dhcp, i get the ip using this:
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress
i have another CPE using PPPoE, i get the ip using this:
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.ExternalIPAddress

reading i think i need to use virtual parameter, to have one parameter that select one or another value
but i dont understand how, where i can get a step by step to doing this if this is doadable?

Regards.

solved.

Here is a very elegant way of handling multiple parameters to check for a value in a vparam. Replace the values under keys with your own.

const keys = [
    'InternetGatewayDevice.DeviceInfo.Manufacturer',
    'Device.DeviceInfo.Manufacturer'
];

let result = {writable: false, value: [getParameterValue(keys, 'UNKNOWN'), 'xsd:string']};

return result;

function getParameterValue(keys, def) {
    for (let key of keys) {
        let d = declare(key, {value: Date.now()});

        for (let item of d) {
            if (item.value && item.value[0]) {
                return item.value[0];
            }
        }
    }

    return def;
}

Just as @akcoder did, sharing your solution helps the community.

1 Like

virtual parameter:

// Example: Unified IP address parameter across different device models
let m = "0.0.0.0";
let d = declare(
  "InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.ExternalIPAddress",
  {value: Date.now()});
let igd = declare(
  "InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.ExternalIPAddress",
  {value: Date.now()});

if (d.size) {
  for (let p of d) {
    if (p.value[0]) {
      m = p.value[0];
      break;
    }
  }  
}
else if (igd.size) {
  for (let p of igd) {
    if (p.value[0]) {
      m = p.value[0];
      break;
    }
  }  
}

return {writable: false, value: [m, "xsd:string"]};

provision:

declare("VirtualParameters.*", {value: Date.now()});

In the device page under the refreshed parameters:

        - type: "'summon-button'"
          parameters:
            - VirtualParameters.* <------  this
            - InternetGatewayDevice.DeviceInfo.HardwareVersion
            - InternetGatewayDevice.DeviceInfo.SoftwareVersion

i can do the same with the code that @akcoder provided?

For the virtual parameter, yes.

1 Like