issue require nodejs module in functionGlobalContext doesn't work

Home Forums Conduit: AEP Model issue require nodejs module in functionGlobalContext doesn't work

Viewing 23 posts - 1 through 23 (of 23 total)
  • Author
    Posts
  • #9752
    Lawrence Griffiths
    Participant

    Ok I noticed that AEP used bcryptjs so I wanted to try it as use bcrypt but can’t install on AEP.

    But it looks like the use of of module require and use in function nodes is not supported?

    When I reference var foo = context.global.bcryptjs.hashSync(msg.topic,10)
    I get TypeError: Cannot call method ‘hashSync’ of undefined

    So I NPM installed dequeue which I use. Same sort of thing when trying to reference. TypeError: undefined is not a function

    // my setting.js
    functionGlobalContext: {
    	  bcryptjs:require('bcryptjs'),
    	  dequeue:require('dequeue')
            // os:require('os'),
            // bonescript:require('bonescript'),
            // arduino:require('duino')
        },
    #9756
    Jason Reiss
    Keymaster

    I think the file may need to be settings.js

    #9757
    Lawrence Griffiths
    Participant

    Jason that is a snippet from my settings.js file in opt/node-red/settings.js

    #9758
    Jason Reiss
    Keymaster

    Look at /etc/init.d/node-red, it maybe using the –userDir option. Try moving the settings.js file to that folder.

    #9760
    Jason Reiss
    Keymaster

    From the node-red.log the settings file can be found. It has been moved into the /var/config directory so it will not be overwritten during a firmware upgrade.

    /var/log/app/node-red.log

    30 Oct 21:09:46 – [info] Settings file : /var/config/app/install/development/settings.js
    30 Oct 21:09:46 – [info] User directory : /var/config/app/install/development
    30 Oct 21:09:46 – [info] Flows file : /var/config/app/install/development/flows.json

    #9782
    Lawrence Griffiths
    Participant

    Jason edited /var/config/app/install/development/settings.js and a Node-RED restart overwrites settings.js as does a Save & Restart from admin UI.

    The preserved/retained for upgrade version of settings.js must be stored some place else!

    Thanks
    Lawrence

    #9783
    Jason Reiss
    Keymaster

    Looks like the /sbin/app.py script is writing the settings.js file.
    There appears no place for a user settings.js file to incorporate functionality you are attempting.

    At the end of line 604 in /sbin/app.py is the global context setting

    I added the following and was able to use bcrypt in node-red.

    functionGlobalContext: {bcrypt: require(“/opt/node-red/node_modules/bcrypt”)}

    I tried using the bcryptjs modules hashSync it was not very responsive (never returned).
    The bcrypt module version seemed to work ok.

    #9784
    Lawrence Griffiths
    Participant

    Jason thanks for digging there needs to be some Dev. Docs for AEP.
    But modifying the python script won’t withstand a firmware upgrade!

    There is clearly a reason why the AEP team think uses shouldn’t go near settings.js but it’s a key part of Node-RED so I’m going to raise a ticket.

    One thing I have’t tried do custom nodes survive a firmware upgrade?

    #9788
    Jason Reiss
    Keymaster

    If the custom nodes are installed in /opt/node-red then they will not be saved over upgrade. Only files in the /var/config will not be touched by an upgrade.

    This will also need some dev to get working. It appears the nodeDir option is not used in the settings.js file.

    #9795
    Jeff Hatch
    Keymaster

    Lawrence,

    Could you please try to keep me in the loop on this feature request, maybe post what identifying information you get for the request? I am currently working on a list of features for upcoming releases.

    Thank You,

    Jeff Hatch

    #9796
    Lawrence Griffiths
    Participant

    Jeff I fired a list of features to Dan & Derek not sure they got through to you.

    // AEP database node
    We need pestilence on AEP file store not good enough. A time series one would be Fab but appreciate that would take some work. I see mLinux has SQLite why not AEP?

    I’ve been following http://lokijs.org/ it’s pure JS nosql db and small size and have been considering creating a NR node for it.

    // custom NR node preservation on Firmware update

    // LoRaOUT node I want to track & guarantee the sending of downlink commands to mDots. It would save me having to develop a queue manager if the node provided 2 output events on recite of an input:
    1. output queue_id or msg_id in msg.payload, msg.action=”queued” & msg.timeStamp
    2. output queue/msg_id in msg.payload, msg.action=”sent” & msg.timeStamp
    At the moment from AEP you have no way of knowing if msg been sent all you can do is monitor mqtt with a filter lora/+/down

    // Protocol nodes Modbus Serial/TCP (some MT equipment have modbus support) there is npm module https://www.npmjs.com/package/jsmodbus

    Bug fix please for Ticket #5065120

    Lawrence

    #9813
    Lawrence Griffiths
    Participant

    Forgot From DeviceHQ can we have Remote Re-Start of Node-Red please

    #9815
    Jesse Gilles
    Blocked

    FYI – you can issue a remote reboot command which will reboot the entire device (and thus Node-RED).

    #9825
    Lawrence Griffiths
    Participant

    Jesse yep know that thanks but with a NR re-start you still have all your LoRa end nodes joined to network. A complete reboot requires the LoRa end-nodes to re-join which is unnecessary in that it uses up battery and duty cycle!

    #9826
    Jason Reiss
    Keymaster

    When the network server is shutdown all the database is saved to flash and reloaded on boot with all node session keys still intact. Nodes should not have to rejoin the network after a reboot.

    Let us know if it is actually the case and we will address that.

    Under what scenario would a Node-RED app that has been installed and running need to be rebooted? There may be an issue with other systems of the device not functioning properly. Perhaps the full reboot would be the appropriate action.

    #9833
    Lawrence Griffiths
    Participant

    Jason
    >> When the network server is shutdown all the database is saved to flash…
    Just supports my request for some AEP documentation. Without it you just make assumptions to fill the VOID. I will test this and feedback

    Why NR re-boot I have a custom NR node that uses long polling and on occasions it needs a NR restart. But if a AEP reboot preserves LoRa end-node session keys then having a separate NR re-start isn’t required.

    Lawrence

    #14270
    Lawrence Griffiths
    Participant

    Hi, I’ve just got round to trying out 1.2.2 mods to settings.js
    From precious posts we are told that only stuff in /var/config/ isn’t over written on firmware upgrade.

    /var/config/app/current link directory takes you
    /var/config/app/install/development/settings.js
    This is nothing like the standard Node-Red settings.js file adding bcrypt
    functionGlobalContext: {bcrypt: require(“/opt/node-red/node_modules/bcrypt”)}

    NB. you have to specify the full path in “quotes” not ‘single’
    If you make a mistake Node-RED won’t load you will see the Disco Loading Node-RED page constantly refreshing

    Lawrence

    #14279
    Ajay K
    Participant

    Just wanted to check the status of some of the feature requests in the earlier forum threads, are they implemented in the latest 1.2.2 build?

    I was looking to build a custom node module so I can npm install it into the node-red. These are custom utility functions to manage the data that I would re-use from my Node-Red function nodes. With the current version of AEP would these node-modules need to be re-installed on a firmware upgrade or would get blown away on an NR Reboot/full system reboot?

    Thanks,
    Ajay.

    #14284
    Brandon Bayer
    Blocked

    Ajay,

    I’m not sure which feature requests you were wondering about, but you can see all the changes in the AEP Changelog.

    As for NPM modules, yes, they will be lost on firmware upgrade unless you install them under /var/config/

    -Brandon

    #14285
    Ajay K
    Participant

    Thanks Brandon. Is that the standard node_modules path that the node-red would recognize? Also the feature requests in the earlier threads which Lawrence seems to have requested a while back was the once I was talking about…
    “custom NR node preservation on Firmware update
    LoRaOUT node I want to track & guarantee the sending of downlink commands to mDots.”

    Thanks,
    Ajay.

    #14338
    Jeff Hatch
    Keymaster

    Lawrence,

    I am confused as to what you’re trying to get at with this post. To clarify:

    The settings.js file that support for modification and persisting through firmware upgrade is the settings.js in the applications that are installed on the Conduit. You can modify the development (default) application’s settings.js, and you can modify the settings.js in any Node-RED application that you have installed through DeviceHQ in the /var/config/app/ directory.

    The /opt/node-red/settings.js file currently is overwritten on firmware upgrades and will continue to be until we have new hardware and support package upgrades on the AEP Conduit.

    Jeff

    #14339
    Lawrence Griffiths
    Participant

    Jeff, my post of 21st July is just letting others know the outcome of my testing with 1.2.2 as there is no Manual for the AEP most Node-Red’s would head to /opt/node-red/settings.js

    And in my case I need to access nodejs modules in my function nodes which I can now do.

    #14341
    Jeff Hatch
    Keymaster

    Lawrence,

    Thank you for your efforts. I know there isn’t much documentation for the Node-RED app stuff on AEP right now. Hopefully that will be rectified in the near future.

    Jeff

Viewing 23 posts - 1 through 23 (of 23 total)
  • You must be logged in to reply to this topic.