Nodes using External JS and HTML

695 views
Skip to first unread message

Peter Scargill

unread,
Apr 2, 2015, 6:00:27 PM4/2/15
to node...@googlegroups.com
I am having immense difficulty debugging a node-red node.. and the worse part about it is having to stop and start node-red every time I make a change. Someone, somewhere pointed me to a node that would use an external JS file and external HTML file that could be changed without stopping Node-Red - I have scoured my blog and the web and I can't find it - anyone know where this is?

What I'm trying to do is merge the inject node and dusk-dawn into a new node that checks every minute for a series of circumstances not covered by the current inject node - ie the very things you'd find  on any old mechanical/lcd timer and a little more. For example I want to say turn on for 10 minutes (or until an end time) if it is lighting up time on Monday, Tuesday and Wednesday but only from January to April - until midnight.

Well, you get the general idea - unless I've missed something, not such block exists. Not interested in the inject bit and I'd rather not use a Cron job...  I'm about 25% through and Node-Red won't start up - I can't find anything wrong and the debugging is, well, non-existant the way I'm doing it (edit file, send back to Raspberry Pi, restart Node-Red - all of which takes an age.

Any thoughts?

Julian Knight

unread,
Apr 3, 2015, 5:03:25 AM4/3/15
to node...@googlegroups.com
The node you want is:

https://www.npmjs.com/package/node-red-contrib-file-function

There has been quite a bit of discussion about scheduling nodes but I can certainly see a case for a node that is simpler to understand from a user perspective & has real-world controls rather than the technical ones we have at present. Might be interesting to share a little more of your ideas though and maybe get some feedback from others in the community?

Peter Scargill

unread,
Apr 3, 2015, 5:47:41 AM4/3/15
to node...@googlegroups.com

Thanks for that – I’ll check that node out.

 

Well, for those of us looking to use Node-Red for IOT, the one thing that is missing is a replacement for the good old timer.  The inject tool is ok but very limiting… so what I want and am trying to create, hampered only by the utter lack of debugging ability when the JS doesn’t work – is a super version of the old mechanical timer…

 

A simple example of use which will not work with Inject..

 

Turn the hose on at dusk every night for 15 minutes but only in the summer.

 

I’ve modified the sunrise node so I can get dusk and dawn out of it – that works – I’ve published that elsewhere (and made a mistake which I need to fix) but I’ve not tried to add in start and end times – and…. It kills Node-Red – no error messages, nothing… I must’ve stared at the code 100 times…

--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/eyDCH9mis3Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Max Hadley

unread,
Apr 3, 2015, 6:08:26 AM4/3/15
to node...@googlegroups.com, pe...@scargill.org
You might try a different tack. Use an inject node to send a message every minute or so to a function node with code that determines 'should the hose be on now?'. It's not the most node-RED way to do it but it might be easier!

Max

Nicholas O'Leary

unread,
Apr 3, 2015, 9:38:01 AM4/3/15
to Node-RED Mailing LIst
Peter,

The node Julian linked to is effectively a Function node that uses an external file for the code it runs. That will certainly help you sort out the logic of your node, but isn't quite the same thing as testing a new node in its entirety - but one step at a time.

As for the specific problem you are trying to solve; there has been a lot of discussion about a more fully featured schedule node. Have a search on the forum for "schedule node" and you'll soon find what has been discussed. 

Nick

On 3 April 2015 at 11:08, Max Hadley <m...@zepler.org> wrote:
You might try a different tack. Use an inject node to send a message every minute or so to a function node with code that determines 'should the hose be on now?'. It's not the most node-RED way to do it but it might be easier!

Max

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Julian Knight

unread,
Apr 3, 2015, 10:02:18 AM4/3/15
to node...@googlegroups.com
I'm with Peter on this. We have lots of quite technical nodes but NR doesn't seem yet to be getting closer to something a non-programmer could use.

I think that there is room in the toolbag for both a fully featured scheduler and the kind of flexible timer that Peter is talking about.

Peter, it might also be useful to have your node check for some in-memory variables - perhaps a "thruthiness" field into which you can put a JS true/false statement such as:

    context.someoneAtHome && context.global.isItDark

Where each of those variables is true or false so the statement is also true or false. True allowing your switch to activate, false not.

Of course, this can be done by a separate node as well but it may get messy and require a function node.

Hmm, in fact it might be interesting to have an output node that sends msg.payload to a defined context.xxxx element? Be nice to be able to do that without another function node.


Nicholas O'Leary

unread,
Apr 3, 2015, 10:34:04 AM4/3/15
to Node-RED Mailing LIst
I would argue a well designed scheduler node would cater for the both scenarios. That is preferable to having multiple nodes that do similar things.

But I would always council against throwing too many concerns into a single node - you end up with a very scenario-specific node that is not easily reused. It would be more reusable to have a scheduler node that handles the time-based triggering of a flow and make any state based decisions in a subsequent node, such as the Switch node - along the lines of what Max describes.

We already have an issue to make context a more widely used concept - https://github.com/node-red/node-red/issues/567 - to enable accessing context variables without resorting to a Function node.


Nick



Dave C-J

unread,
Apr 3, 2015, 11:00:47 AM4/3/15
to node...@googlegroups.com
Hi Peter,

yes the "scheduler" node is an often discussed missing piece of the jigsaw. Another recent approach is in this thread - https://groups.google.com/forum/#!topic/node-red/qz98gNGcx18

Re debugging - what I do when I get myself tied in knots is...

1) double check it's my new node that is the issue... 
      rename the js and html to something else and start Node-RED with a blank flow file -  node-red blank.json
      (just to make sure it still works and I'm not going mad)
2) Use jsHint ( http://jshint.com/install/ ) to give my .js file the once over - we use the settings as per file attached. I have it embedded as a plugin in my editor so I can just call it as I edit.
3) Restart Node-RED with my files in place -  node-red -v blank.json
     see if any errors in console
4) start browser
     use Ctrl-Shift-J - or whatever is needed to get the browser developer tools console open...  reload the Node-RED web page - see if there are any errors in the browser tools console
5a) if almost working I often use nodemon to start node so it autorestarts when I save any edits. http://nodemon.io/
5b) if not... scratch head... start drinking heavily... consume chocolate...




.jshintrc
Reply all
Reply to author
Forward
0 new messages