async function post_LogRecords(records) {
    const measurements = {}; // Key: vehicle identification number (VIN), value: an array of measurements
    for (const record of records) {
        const geotabDeviceId = record.device.id;
        // The device alternate IDs used by SAP IoT Services are generally supposed to have some
        // real-world meaning, so that they can be derived from real-world data. We use VIN numbers
        // to identify vehicles.
        let vin = geotabDeviceCache[geotabDeviceId];
        if (!vin) {
            // Cache lookup failed.
            try {
                const device = await lookupDevice(geotabDeviceId);
                vin = device.vehicleIdentificationNumber;
                if (vin) {
                    console.info(`Caching the SAP device for the vehicle with VIN='${vin}'`);
                    const sapDeviceId = await createDeviceUnlessExists(gatewayId, vin);
                    await createSensorUnlessExists(sapDeviceId, 'LogRecord', sensorTypeId_LogRecord);
                    // Add the VIN to the cache.
                    geotabDeviceCache[geotabDeviceId] = vin;
                } else {
                    console.error(`Geotab device with ID ${geotabDeviceId} has no vehicleIdentificationNumber, skipped!`);
                }
            } catch (err) {
                console.error(`Could not look up device with ID ${geotabDeviceId}!`);
            }
        }
        if (vin) {
            // Construct the SAP IoT measurement from the Geotab record.
            (measurements[vin] = measurements[vin] || []).push({
                latitude: record.latitude,
                longitude: record.longitude,
                speed: record.speed,
                dateTime: record.dateTime
            });
        }
    }

    const promises = [];
    for (const vin of Object.keys(measurements)) {
        // The VIN is used as the identifier of the device for SAP IoT Service.
        promises.push(routerDevice.postMeasurementData(vin, 'LogRecord', 'LogRecord', measurements[vin]));
    }
    // Measurements for different vehicles (devices) are POSTed concurrently.
    // The maximum number of parallel connections is defined in SAP_IoT_device_REST.
    return Promise.all(promises);
}
/**
 * Post an array of LogRecord objects to SAP IoT Service.
 * @param {!Object[]} records  the records to post
 */
Post an array of LogRecord objects to SAP IoT Service.
@param {!Object[]} records  the records to post
Post an array of LogRecord objects to SAP IoT Service . @param { !Object [] } records the records to post
async function post_LogRecords(records) {
    const measurements = {}; 
    for (const record of records) {
        const geotabDeviceId = record.device.id;
        let vin = geotabDeviceCache[geotabDeviceId];
        if (!vin) {
            try {
                const device = await lookupDevice(geotabDeviceId);
                vin = device.vehicleIdentificationNumber;
                if (vin) {
                    console.info(`Caching the SAP device for the vehicle with VIN='${vin}'`);
                    const sapDeviceId = await createDeviceUnlessExists(gatewayId, vin);
                    await createSensorUnlessExists(sapDeviceId, 'LogRecord', sensorTypeId_LogRecord);
                    geotabDeviceCache[geotabDeviceId] = vin;
                } else {
                    console.error(`Geotab device with ID ${geotabDeviceId} has no vehicleIdentificationNumber, skipped!`);
                }
            } catch (err) {
                console.error(`Could not look up device with ID ${geotabDeviceId}!`);
            }
        }
        if (vin) {
            (measurements[vin] = measurements[vin] || []).push({
                latitude: record.latitude,
                longitude: record.longitude,
                speed: record.speed,
                dateTime: record.dateTime
            });
        }
    }
    const promises = [];
    for (const vin of Object.keys(measurements)) {
        promises.push(routerDevice.postMeasurementData(vin, 'LogRecord', 'LogRecord', measurements[vin]));
    }
    return Promise.all(promises);
}
async function post_LogRecords ( records ) { const measurements = { } ; for ( const record of records ) { const geotabDeviceId = record . device . id ; let vin = geotabDeviceCache [ geotabDeviceId ] ; if ( ! vin ) { try { const device = await lookupDevice ( geotabDeviceId ) ; vin = device . vehicleIdentificationNumber ; if ( vin ) { console . info ( ` ${ vin } ` ) ; const sapDeviceId = await createDeviceUnlessExists ( gatewayId , vin ) ; await createSensorUnlessExists ( sapDeviceId , 'LogRecord' , sensorTypeId_LogRecord ) ; geotabDeviceCache [ geotabDeviceId ] = vin ; } else { console . error ( ` ${ geotabDeviceId } ` ) ; } } catch ( err ) { console . error ( ` ${ geotabDeviceId } ` ) ; } } if ( vin ) { ( measurements [ vin ] = measurements [ vin ] || [ ] ) . push ( { latitude : record . latitude , longitude : record . longitude , speed : record . speed , dateTime : record . dateTime } ) ; } } const promises = [ ] ; for ( const vin of Object . keys ( measurements ) ) { promises . push ( routerDevice . postMeasurementData ( vin , 'LogRecord' , 'LogRecord' , measurements [ vin ] ) ) ; } return Promise . all ( promises ) ; }
Post an array of LogRecord objects to SAP IoT Service.
Post an array of LogRecord objects to SAP IoT Service .
// Key: vehicle identification number (VIN), value: an array of measurements // The device alternate IDs used by SAP IoT Services are generally supposed to have some // real-world meaning, so that they can be derived from real-world data. We use VIN numbers // to identify vehicles. // Cache lookup failed. // Add the VIN to the cache. // Construct the SAP IoT measurement from the Geotab record. // The VIN is used as the identifier of the device for SAP IoT Service. // Measurements for different vehicles (devices) are POSTed concurrently. // The maximum number of parallel connections is defined in SAP_IoT_device_REST.