0

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 :S I 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...

  • When you say the node is not "generated", do you mean that it does not appear in the Palette on the left-hand side of the editor? Does it show up as enabled in the "Installed" list of the Palette Manager? – SteveR May 16 '18 at 16:16
  • You **REALLY** need to upgrade your NodeJS install version 4.2 is very out of date. If you MUST stay on 4.x then you need to be at 4.9.x which is the last release, but you should probably move 8.x as soon as possible – hardillb May 16 '18 at 17:16
  • Also you should not be using sudo to install nodes into your own home directory – hardillb May 16 '18 at 17:21

1 Answers1

1

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.
hardillb
  • 54,545
  • 11
  • 67
  • 105
  • At the end I solved, But I had to split the functions that were declared in a single js file, in 3 different files and I do the same in html. Then I wrote the list of nodes and I finally get anymore missing types errors :D – Gianluca Petralia May 18 '18 at 14:07