This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Power Profiler Kit modification for long time measurements: Problem with npm

Hello,

my goal is to measure the average current consumption of an external chip connected to the Power Profiler Kit on Windows 7. Since the Software inside the nRF Connect App only allows a maximum of 120s, I want to modify the NodeJS source code and save all measured current values into an SQLite3 database. Afterwards I want to do the averaging by myself by evaluating the database file. My modification inside the Chart.jsx file starts like this:

const sqlite3 = require('sqlite3').verbose();

My problem is about including the sqlite3 module into the package. After using "npm install sqlite3" (I also tried many options like  --build-from-source or --save) there is the right directory in node_modules and the command "npm run dev" succeeds. But at runtime I receive the error: 

 Cannot find module 'C:\Users\MyUser\.nrfconnect-apps\local\pc-nrfconnect-ppk-master\...\node_sqlite3.node'

The required node file is actually located in C:\Users\MyUser\.nrfconnect-apps\local\pc-nrfconnect-ppk-master\node_modules\sqlite3\lib\binding\node-v57-win32-ia32
Any suggestions how to make the node file visible to the package? In the error message there are only the dots in the path, so I also don't know where the programm is searching for the file.

Hope you can help.

Kind regards,

Christian
Parents Reply Children
  • Hi Bence,

    thank you for your answer.

    I did as you said and added the .npmrc file. For installing the sqlite3 I used the command:

    npm install sqlite3 --build-from-source --runtime=electron --target=2.0.11 --dist-url=https://atom.io/download/electron

    After running "npm run dev" I started the PPK from the nrf connect app but my code modifications just don't have any effect. Simple modifications such as changing the values in constants.js however are visible.

    I wrote as follows:

    const sqlite3 = require('sqlite3').verbose();


    const db = new sqlite3.Database('sample.db', err => {
    if (err) {
    return console.error(err.message);
    }
    return console.log('DB created');
    });
    // close the database connection
    db.close(err => {
    if (err) {
    return console.error(err.message);
    }
    return console.log('DB closed');
    });

    No file "sample.db" is being created. Also my attempts with createWriteStream to create a .csv file failed. It seems like the app is just ignoring these file operations...

  • I repeated your steps and the database has been created successfully.

    Please look into %USERHOME%\AppData\Local\Programs\nrfconnect if your luck is to work with windows. The file is created under the current working directory, which is not what the app's data should be kept.

    I suggest to use the following function to get the data dir of the app, and path.join() the result for an absolute path:

    require('nrfconnect/core').getAppDataDir();

  • Thank you so much! Never would've guessed that it's deployed there! I did use the windows search but seems like AppData is not indexed.

    I think from now on I can finish my job.

Related