简体   繁体   中英

no node generated in node-red

I try to solve the issue presented in Node-red: custom nodes waiting for missing types by creating a new node.

I try to use the "mqtt.js example" to obtain a pre-configured mqtt-client/subscriber to add in my palette.

So in the node folder I have the config file, named mqttConfig.json where are placed all data used by mqtt.js to enstablish the connection (ie. broker, topic, qos ...), the structure of this file is the same as in the previous one.

{
  "receiver": {
               "broker":"127.0.0.1",
               "topic":"topicRec",
               "qos":"2"
              }
}

Then I create the new preconf_mqtt.js that is:

var mqtt = require("/usr/local/lib/node_modules/node-red/node_modules/mqtt");
var mqttConfig = require("mqttConfig");
'use strict'

module.exports = function(RED)
 {
  function ConfiguredMqttOutNode(config)
      {
       RED.nodes.createNode(this,config);
       var node = this;

       var m = mqttConf.receiver;

       this.topic = m.topic;
       this.qos = parseInt(m.qos);
       if (isNaN(this.qos) || this.qos < 0 || this.qos > 2)
          this.qos = 2;
       this.broker = m.broker;
       this.client = mqtt.connect(this.broker);
       this.client.subscribe(this.topic);

       this.client.on('message', function (topic, message) {
            var msg = {};
            msg.topic = this.topic;
            msg.payload = JSON.stringify(message);
            node.send(msg);
            });

  }
  RED.nodes.registerType("configured-mqtt-out",ConfiguredMqttOutNode);
 }

While the preconf_mqtt.html that is:

     <script type="text/javascript">
        RED.nodes.registerType('configured-mqtt-out',{
          category: 'processing',
          color: '#a6bbcf',
           defaults: {
           name: {value:""}
        },
         inputs:0,
         outputs:1,
         icon: "bridge.png",
         label: function() 
         {
           return this.name||"c-mqtt-out";
         }
        }); 
    </script>

    <script type="text/x-red" data-template-name="configured-mqtt-out">
       <div class="form-row">
          <label for="node-input-name"><i class="icon-tag"></i> Name</label>
          <input type="text" id="node-input-name" placeholder="Name">
       </div>
    </script>

    <script type="text/x-red" data-help-name="configured-mqtt-out">
        <p>Pre-configured MQTT subscriber</p>
    </script>

No matter when I try to install program:

ute@preprocnr:~/.node-red$ sudo npm install /home/ute/mqtt_rules_definer

> node-red-dashboard@2.9.1 postinstall /home/ute/.node-red/node_modules/node-red-dashboard
> node fixfa.js

node-red-project@0.0.1 /home/ute/.node-red
├─┬ mqtt@2.18.0
│ ├─┬ concat-stream@1.6.2
│ │ └─┬ readable-stream@2.3.6
│ │   ├── isarray@1.0.0
│ │   └── string_decoder@1.1.1
│ ├─┬ help-me@1.1.0
│ │ ├─┬ glob-stream@6.1.0
│ │ │ ├─┬ ordered-read-streams@1.0.1
│ │ │ │ └─┬ readable-stream@2.3.6
│ │ │ │   ├── isarray@1.0.0
│ │ │ │   └── string_decoder@1.1.1
│ │ │ ├─┬ pumpify@1.5.0
│ │ │ │ └── pump@2.0.1
│ │ │ └─┬ readable-stream@2.3.6
│ │ │   ├── isarray@1.0.0
│ │ │   └── string_decoder@1.1.1
│ │ └─┬ through2@2.0.3
│ │   └─┬ readable-stream@2.3.6
│ │     ├── isarray@1.0.0
│ │     └── string_decoder@1.1.1
│ ├─┬ mqtt-packet@5.6.0
│ │ └─┬ bl@1.2.2
│ │   └─┬ readable-stream@2.3.6
│ │     ├── isarray@1.0.0
│ │     └── string_decoder@1.1.1
│ ├─┬ readable-stream@2.3.6
│ │ ├── isarray@1.0.0
│ │ └── string_decoder@1.1.1
│ └─┬ websocket-stream@5.1.2
│   ├─┬ duplexify@3.6.0
│   │ └─┬ readable-stream@2.3.6
│   │   ├── isarray@1.0.0
│   │   └── string_decoder@1.1.1
│   └─┬ readable-stream@2.3.6
│     ├── isarray@1.0.0
│     └── string_decoder@1.1.1
├── mqtt_rules_definer@1.0.0  extraneous
├── node-red-dashboard@2.9.1  extraneous
└── rule-definer@1.0.0  extraneous

npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.
ute@preprocnr:~/.node-red$ node-red

And node-red not show any particular error/warning when I start it:

16 May 15:21:23 - [info]

Welcome to Node-RED
===================

16 May 15:21:23 - [info] Node-RED version: v0.18.4
16 May 15:21:23 - [info] Node.js  version: v4.2.6
16 May 15:21:23 - [info] Linux 4.4.0-124-generic x64 LE
16 May 15:21:23 - [info] Loading palette nodes
16 May 15:21:23 - [info] Dashboard version 2.9.1 started at /ui
16 May 15:21:23 - [warn] ------------------------------------------------------
16 May 15:21:23 - [warn] [node-red/rpi-gpio] Info : Ignoring Raspberry Pi 
specific node
16 May 15:21:23 - [warn] [node-red-node-twitter/twitter] ReferenceError: 
Invalid left-hand side in assignment
16 May 15:21:23 - [warn] ------------------------------------------------------
16 May 15:21:23 - [info] Settings file  : /home/ute/.node-red/settings.js
16 May 15:21:23 - [info] User directory : /home/ute/.node-red
16 May 15:21:23 - [info] Server now running at http://127.0.0.1:1880/
16 May 15:21:23 - [info] Active project : pre-proc
16 May 15:21:23 - [info] Flows file     : /home/ute/.node-red/projects/pre- proc/preprocessor.json

But the node is not present in my palette and I don't know what to do to fix it. Please, help me, Kind regards, Gianluca

[EDIT] I forgot to add the nodes in package :SI had it and then I obtain the following warning, starting node-red:

16 May 16:36:41 - [warn] ------------------------------------------------------
16 May 16:36:41 - [warn] [node-red/rpi-gpio] Info : Ignoring Raspberry Pi specific node
16 May 16:36:41 - [warn] [node-red-node-twitter/twitter] ReferenceError: 
Invalid left-hand side in assignment
16 May 16:36:41 - [warn] [mqtt_rules_definer/mqtt_rules_definer] SyntaxError: Unexpected token .
16 May 16:36:41 - [warn] ------------------------------------------------------

And the node is not generated...

The error message is pretty clear, you have a syntax error in your mqtt_rules_definer.js file (You have a missplaced . somewhere in your code). You need to fix this before Node-RED can load it.

The quickest way to find out what line the problem is will be to do something like the following:

  • change to the ~/.node-red directory
  • run node with no file after the command $ node
  • This will start a interactive shell which you can then type in the following:

     require('mqtt_rules_definer') 
  • This should then print a stack trace with the details of where the error is in the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM