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
  • Hi Christian,

    nRFConnect runs in electron engine, therefore all binary modules shall be compiled against electron and not node. To achieve this you need to configure your npm, can be done several ways. The easiest is to include .npmrc in your repo, like this: https://github.com/NordicSemiconductor/pc-nrfconnect-core/blob/master/.npmrc

    After that reinstall the module in question and you shall be good to go.

    Bence

  • 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.

  • My program is completed and works like a charm! Now I migrated it to Linux (Ubuntu 18.10, nRF version 2.6) and it occurs that the app is really unstable... Not only my modified code but also the default local repository.

    Only in rare cases it is possible to connect to the PKK Board. In most of the cases there is the error message: "Failed to start the PPK" and / or the program crashes. When I'm using the official version of the nRF Connect app (not my local compiled one) the problems do not occur.

    How can I fix the serial connection? I installed SEGGER, the udev rules and also ran "sudo usermod -a -G dialout <username>". I ran the program also as super user.

Related