简体   繁体   English

没有节点生成为红色节点

[英]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. 我尝试解决Node-red中提出的问题通过创建新节点, 等待缺少类型自定义节点。

I try to use the "mqtt.js example" to obtain a pre-configured mqtt-client/subscriber to add in my palette. 我尝试使用“ mqtt.js示例”来获取预先配置的mqtt-client / subscriber,以添加到我的调色板中。

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. 因此,在节点文件夹中,我有一个名为mqttConfig.json的配置文件,其中放置了mqtt.js用于建立连接的所有数据(例如,broker,topic,qos ...),此文件的结构相同和上一个一样。

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

Then I create the new preconf_mqtt.js that is: 然后创建新的preconf_mqtt.js,它是:

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: 而preconf_mqtt.html是:

     <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: 启动时,node-red不会显示任何特定的错误/警告:

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: [编辑]我忘了在包:SI中添加节点,然后我收到以下警告,以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). 该错误消息非常清楚,您在mqtt_rules_definer.js文件中存在语法错误(您在代码中的某处放错了. )。 You need to fix this before Node-RED can load it. 您需要先解决此问题,然后Node-RED才能加载它。

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 切换到〜/ .node-red目录
  • run node with no file after the command $ node 在命令$ node之后运行没有文件的$ 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. 然后,这应该打印一个堆栈跟踪,其中包含文件中错误位置的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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