Modifications

Sauter à la navigation Sauter à la recherche
4 691 octets ajoutés ,  2 avril 2017 à 10:58
aucun résumé de modification
Ligne 2 : Ligne 2 :     
{{traduction}}
 
{{traduction}}
 +
 +
Node-Red comes with an excellent set of basic nodes within its palette however there are more out there and there is certainly nothing stopping you from writing your own!
 +
 +
Some of the nodes also have dependencies on external libraries and without these being installed will not function correctly. As an example for the twitter node to work correctly you need OAuth which allows you to authenticate with twitter.com to be able to send/receive tweets.
 +
 +
You may remember from the initial starting of node red we saw a list of these missing dependencies as shown below.
 +
 +
<syntaxhighlight lang="python">
 +
25 Jan 11:31:45 - [red] Loading palette nodes
 +
25 Jan 11:31:45 - ------------------------------------------
 +
25 Jan 11:31:54 - [61-email.js] Error: Cannot find module '/home/pi/node-red/../emailkeys.js'
 +
25 Jan 11:31:54 - [imap] : Failed to load Email credentials
 +
25 Jan 11:31:55 - [66-mongodb.js] Error: Cannot find module 'mongodb'
 +
25 Jan 11:31:57 - [74-swearfilter.js] Error: Cannot find module 'badwords'
 +
25 Jan 11:31:57 - [72-wordpos.js] Error: Cannot find module 'wordpos'
 +
25 Jan 11:31:57 - [78-ledborg.js] Warning: PiBorg hardware : LedBorg not found
 +
25 Jan 11:31:57 - [76-blinkstick.js] Error: Cannot find module 'blinkstick'
 +
25 Jan 11:31:57 - [77-blink1.js] Error: Cannot find module 'node-blink1'
 +
25 Jan 11:31:57 - [78-digiRGB.js] Error: Cannot find module 'node-hid'
 +
25 Jan 11:31:57 - [103-hue_discover.js] Error: Cannot find module 'node-hue-api'
 +
25 Jan 11:31:57 - [104-hue_manage.js] Error: Cannot find module 'node-hue-api'
 +
25 Jan 11:31:57 - [103-hue_discover.js] Error: Cannot find module 'node-hue-api'
 +
25 Jan 11:31:58 - [104-hue_manage.js] Error: Cannot find module 'node-hue-api'
 +
25 Jan 11:31:58 - [101-scanBLE.js] Error: Cannot find module 'noble'
 +
25 Jan 11:31:58 - [79-sensorTag.js] Error: Cannot find module 'sensortag'
 +
25 Jan 11:31:58 - [60-wemo.js] Error: Cannot find module 'wemo'
 +
25 Jan 11:31:58 - [26-rawserial.js] Advise: Only really needed for Windows boxes without serialport npm module installed.
 +
25 Jan 11:31:58 - [39-wol.js] Error: Cannot find module 'wake_on_lan'
 +
25 Jan 11:31:58 - [69-mpd.js] Error: Cannot find module 'komponist'
 +
25 Jan 11:31:58 - [57-notify.js] Error: Cannot find module 'growl'
 +
25 Jan 11:31:58 - [57-prowl.js] Error: Cannot find module 'node-prowl'
 +
25 Jan 11:31:58 - [57-pushbullet.js] Error: Cannot find module 'pushbullet'
 +
25 Jan 11:32:00 - [56-twilio.js] Error: Failed to load Twilio credentials
 +
25 Jan 11:32:00 - [92-xmpp.js] Error: Cannot find module 'simple-xmpp'
 +
</syntaxhighlight>
 +
 +
You may have more in your list as I have installed quite a few but the main point is that the "Cannot find module 'X'" is Node-Red telling us that we have a missing dependency.
 +
 +
Luckily it is very easy to install these and as an example if we wanted to install the swear filter node, which filters out bad words we just simply have to carry out the following steps.
 +
 +
First stop node red if it is running using the management script from earlier on in the tutorial.
 +
 +
<syntaxhighlight lang="python">
 +
sudo service node_red stop
 +
</syntaxhighlight>
 +
 +
Then ensure you are within your Node-Red directory. If you have been following this tutorial yours will match mine as shown below.
 +
 +
<syntaxhighlight lang="python">
 +
cd ~/node-red/
 +
</syntaxhighlight>
 +
 +
Next we use node package manager to install the dependency for us, which is named exactly as the "Cannot find module" statement told us.
 +
 +
<syntaxhighlight lang="python">
 +
sudo npm install badwords
 +
</syntaxhighlight>
 +
 +
You will then see the package being installed.
 +
 +
<syntaxhighlight lang="python">
 +
npm http GET https://registry.npmjs.org/badwords
 +
npm http 200 https://registry.npmjs.org/badwords
 +
npm http GET https://registry.npmjs.org/badwords/-/badwords-0.0.3.tgz
 +
npm http 200 https://registry.npmjs.org/badwords/-/badwords-0.0.3.tgz
 +
badwords@0.0.3 node_modules/badwords
 +
</syntaxhighlight>
 +
 +
Once that has completed we can start Node-Red up again and you will be able to now use the Swear Filter node.
 +
 +
<syntaxhighlight lang="python">
 +
sudo service node_red start
 +
</syntaxhighlight>
 +
 +
(ou la commande systemclt appropriée si vous utilisez systemD).
 +
 +
{{ADFImage|Rasp-Node-Red-Install-Node-00.jpg}}
 +
 +
To ease the pain of you having to go through the whole process each time for each module I have constructed a list of the common modules that you will need to install.
 +
 +
Simply stop Node-Red and follow the process as we did for the bad words example but replace sudo npm install badwords with the following line.
 +
 +
<syntaxhighlight lang="python">
 +
sudo npm install ntwitter oauth sentiment wordpos xml2js firmata fs.notify serialport feedparser pushbullet irc simple-xmpp redis mongodb
 +
</syntaxhighlight>
    
{{Rasp-Node-Red-TRAILER}}
 
{{Rasp-Node-Red-TRAILER}}
29 918

modifications

Menu de navigation