issue require nodejs module in functionGlobalContext doesn't work
Home › Forums › Conduit: AEP Model › issue require nodejs module in functionGlobalContext doesn't work
Tagged: functionGlobalContext
- This topic has 22 replies, 6 voices, and was last updated 8 years, 3 months ago by Jeff Hatch.
-
AuthorPosts
-
November 1, 2015 at 3:02 pm #9752Lawrence GriffithsParticipant
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 undefinedSo 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') },
- This topic was modified 9 years ago by Lawrence Griffiths.
- This topic was modified 9 years ago by Lawrence Griffiths.
- This topic was modified 9 years ago by Lawrence Griffiths.
November 1, 2015 at 5:59 pm #9756Jason ReissKeymasterI think the file may need to be settings.js
November 2, 2015 at 3:07 am #9757Lawrence GriffithsParticipantJason that is a snippet from my settings.js file in opt/node-red/settings.js
November 2, 2015 at 5:49 am #9758Jason ReissKeymasterLook at /etc/init.d/node-red, it maybe using the –userDir option. Try moving the settings.js file to that folder.
November 2, 2015 at 8:20 am #9760Jason ReissKeymasterFrom 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.jsonNovember 2, 2015 at 3:29 pm #9782Lawrence GriffithsParticipantJason 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
LawrenceNovember 2, 2015 at 5:02 pm #9783Jason ReissKeymasterLooks 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.November 3, 2015 at 3:08 am #9784Lawrence GriffithsParticipantJason 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?
November 3, 2015 at 8:01 am #9788Jason ReissKeymasterIf 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.
November 3, 2015 at 1:25 pm #9795Jeff HatchKeymasterLawrence,
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
November 3, 2015 at 3:05 pm #9796Lawrence GriffithsParticipantJeff 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
- This reply was modified 9 years ago by Lawrence Griffiths.
- This reply was modified 9 years ago by Lawrence Griffiths.
November 6, 2015 at 3:53 am #9813Lawrence GriffithsParticipantForgot From DeviceHQ can we have Remote Re-Start of Node-Red please
November 6, 2015 at 8:48 am #9815Jesse GillesBlockedFYI – you can issue a remote reboot command which will reboot the entire device (and thus Node-RED).
November 7, 2015 at 7:10 am #9825Lawrence GriffithsParticipantJesse 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!
November 7, 2015 at 9:19 am #9826Jason ReissKeymasterWhen 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.
November 8, 2015 at 5:21 am #9833Lawrence GriffithsParticipantJason
>> 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 feedbackWhy 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
July 21, 2016 at 10:24 am #14270Lawrence GriffithsParticipantHi, 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 refreshingLawrence
- This reply was modified 8 years, 4 months ago by Lawrence Griffiths.
July 22, 2016 at 10:41 am #14279Ajay KParticipantJust 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.July 22, 2016 at 11:18 am #14284Brandon BayerBlockedAjay,
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
July 22, 2016 at 11:29 am #14285Ajay KParticipantThanks 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.July 27, 2016 at 8:15 am #14338Jeff HatchKeymasterLawrence,
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
July 27, 2016 at 11:23 am #14339Lawrence GriffithsParticipantJeff, 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.
July 27, 2016 at 11:36 am #14341Jeff HatchKeymasterLawrence,
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
-
AuthorPosts
- You must be logged in to reply to this topic.