async function initRouterDevice() {
    const routerDeviceId = await createDeviceUnlessExists(gatewayId, 'router', true);
    const absPathPem = path.join(__dirname, config.SAP_router_device_pem_filename);
    const absPathPass = path.join(__dirname, config.SAP_router_device_pass_filename);
    if (!(fs.existsSync(absPathPem) && fs.existsSync(absPathPass))) {
        const resp = await SAP_DeviceManagement.apis.Devices.getPEMCertificateUsingGET({
            tenantId: config.SAP_tenantID,
            deviceId: routerDeviceId
        });
        if (resp.ok) {
            fs.writeFileSync(absPathPem, resp.body.pem);
            fs.writeFileSync(absPathPass, resp.body.secret);
            console.info('Saved the PEM and the passphrase for the router device.');
        }
    }

    // Contains both the certificate and the private key
    const router_device_pem = fs.readFileSync(absPathPem, {'encoding': 'utf8'});
    // The private key is encrypted with it
    const router_device_passphrase = fs.readFileSync(absPathPass, {'encoding': 'utf8'});
    console.debug('The PEM and the passphrase for the router device read OK.');
    const gateway_hostname = `${config.SAP_instance}.${config.SAP_landscape}`;
    return SAP_IoT_device_REST(
        gateway_hostname, router_device_pem, router_device_pem, router_device_passphrase);
}
/**
 * Create the SAP router device unless it already exists and fetch its certificate.
 * @return {Object} A proxy object with postMeasurementData() asynchronous method.
 */
Create the SAP router device unless it already exists and fetch its certificate.
@return {Object} A proxy object with postMeasurementData() asynchronous method.
Create the SAP router device unless it already exists and fetch its certificate . @return { Object } A proxy object with postMeasurementData () asynchronous method .
async function initRouterDevice() {
    const routerDeviceId = await createDeviceUnlessExists(gatewayId, 'router', true);
    const absPathPem = path.join(__dirname, config.SAP_router_device_pem_filename);
    const absPathPass = path.join(__dirname, config.SAP_router_device_pass_filename);
    if (!(fs.existsSync(absPathPem) && fs.existsSync(absPathPass))) {
        const resp = await SAP_DeviceManagement.apis.Devices.getPEMCertificateUsingGET({
            tenantId: config.SAP_tenantID,
            deviceId: routerDeviceId
        });
        if (resp.ok) {
            fs.writeFileSync(absPathPem, resp.body.pem);
            fs.writeFileSync(absPathPass, resp.body.secret);
            console.info('Saved the PEM and the passphrase for the router device.');
        }
    }
    const router_device_pem = fs.readFileSync(absPathPem, {'encoding': 'utf8'});
    const router_device_passphrase = fs.readFileSync(absPathPass, {'encoding': 'utf8'});
    console.debug('The PEM and the passphrase for the router device read OK.');
    const gateway_hostname = `${config.SAP_instance}.${config.SAP_landscape}`;
    return SAP_IoT_device_REST(
        gateway_hostname, router_device_pem, router_device_pem, router_device_passphrase);
}
async function initRouterDevice ( ) { const routerDeviceId = await createDeviceUnlessExists ( gatewayId , 'router' , true ) ; const absPathPem = path . join ( __dirname , config . SAP_router_device_pem_filename ) ; const absPathPass = path . join ( __dirname , config . SAP_router_device_pass_filename ) ; if ( ! ( fs . existsSync ( absPathPem ) && fs . existsSync ( absPathPass ) ) ) { const resp = await SAP_DeviceManagement . apis . Devices . getPEMCertificateUsingGET ( { tenantId : config . SAP_tenantID , deviceId : routerDeviceId } ) ; if ( resp . ok ) { fs . writeFileSync ( absPathPem , resp . body . pem ) ; fs . writeFileSync ( absPathPass , resp . body . secret ) ; console . info ( 'Saved the PEM and the passphrase for the router device.' ) ; } } const router_device_pem = fs . readFileSync ( absPathPem , { 'encoding' : 'utf8' } ) ; const router_device_passphrase = fs . readFileSync ( absPathPass , { 'encoding' : 'utf8' } ) ; console . debug ( 'The PEM and the passphrase for the router device read OK.' ) ; const gateway_hostname = ` ${ config . SAP_instance } ${ config . SAP_landscape } ` ; return SAP_IoT_device_REST ( gateway_hostname , router_device_pem , router_device_pem , router_device_passphrase ) ; }
Create the SAP router device unless it already exists and fetch its certificate.
Create the SAP router device unless it already exists and fetch its certificate .
// Contains both the certificate and the private key // The private key is encrypted with it