[ANNOUNCE] Visual programming a function node with Blockly - Feedback request

So I deleted the node-red-contrib-blockly folder, restarted NR, F5 - no blockly node

cleaned cache and re-installed - got this
C:\Users\Simon.node-red>npm cache clean --force
npm WARN using --force I sure hope you know what you are doing.

C:\Users\Simon\.node-red>npm install bartbutenaers/node-red-contrib-blockly

> fs-ext@0.5.0 install C:\Users\Simon\.node-red\node_modules\fs-ext
> node-gyp configure build


C:\Users\Simon\.node-red\node_modules\fs-ext>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" configure build )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" configure build )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  fs-ext.cc
  win_delay_load_hook.cc
..\fs-ext.cc(108): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(153): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(1568): note: see declaration of 'Nan::Callback::Call'
..\fs-ext.cc(195): error C3861: 'fcntl': identifier not found [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
..\fs-ext.cc(297): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(339): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(374): error C3861: 'fcntl': identifier not found [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
..\fs-ext.cc(375): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(433): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Users\Simon\.node-red\node_modules\fs-ext
gyp ERR! node -v v8.9.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs-ext@0.5.0 (node_modules\fs-ext):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs-ext@0.5.0 install: `node-gyp configure build`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ node-red-contrib-blockly@0.0.1
added 1 package and removed 1 package in 23.856s

restart NR -F5 in browser - Blockly block available again but still looks like the old version

Could you try updating you version number to 0.0.2 to see if it helps kick my install to getting a newer version?

Thanks for trying - has made no difference my send block still has send msg on it :frowning:

C:\Users\Simon\.node-red\node_modules\fs-ext>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" configure build )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" configure build )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  fs-ext.cc
  win_delay_load_hook.cc
..\fs-ext.cc(108): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(153): warning C4996: 'Nan::Callback::Call': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(1568): note: see declaration of 'Nan::Callback::Call'
..\fs-ext.cc(195): error C3861: 'fcntl': identifier not found [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
..\fs-ext.cc(297): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(339): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(374): error C3861: 'fcntl': identifier not found [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
..\fs-ext.cc(375): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
..\fs-ext.cc(433): warning C4996: 'Nan::NanErrnoException': was declared deprecated [C:\Users\Simon\.node-red\node_modules\fs-ext\build\fs-ext.vcxproj]
  C:\Users\Simon\.node-red\node_modules\nan\nan.h(887): note: see declaration of 'Nan::NanErrnoException'
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd C:\Users\Simon\.node-red\node_modules\fs-ext
gyp ERR! node -v v8.9.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs-ext@0.5.0 (node_modules\fs-ext):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs-ext@0.5.0 install: `node-gyp configure build`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ node-red-contrib-blockly@0.0.2
added 1 package and removed 1 package in 15.483s

Just installed Node-RED on a new Pi install - all seems fine on that one

pi@s27Jun18:~/.node-red $ npm install bartbutenaers/node-red-contrib-blockly
npm WARN node-red-project@0.0.1 No repository field.
npm WARN node-red-project@0.0.1 No license field.

+ node-red-contrib-blockly@0.0.2
added 1 package in 24.53s

image

So ignoring my deployment issues on Windows - its all working fine on a Pi

I had to change the algorithm as there is no "return" block so the JS codes ended up as

if ((context.get('gate')) != false) {
  context.set('gate', true);
}
if ((msg['topic']) == 'gate') {
  context.set('gate', (msg['payload']));
} else if ((context.get('gate')) == true) {
  node.send([msg]);
}

At the end of the day - not using the "return msg" concept is work-around-able but I think it would be nice to have that option (either instead of or as well as send) as its the method most promoted in Node-RED examples that I've seen

Simon

One thing I noticed is that in my orignal JS I used context.get('gate') but the Blockly syntax says node memory

I think the Blockly syntax should follow standard Node-RED ways of describing operations wherever possible

e.g

get context/flow/global value of property "gate"

type of syntax

(I actually think the having node instead of context is better terminology but I'd stick with current concepts wherever possible)

1 Like

JFI - I tried updating Blockly node on my other Node-RED install running on my Windows PC

I don't get all the error messages but it didn't update the block to just send - still says send msg

c:\newnodered\node-red>npm install bartbutenaers/node-red-contrib-blockly
npm WARN node-red-node-test-helper@0.1.8 requires a peer of node-red@~0.18.4 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ node-red-contrib-blockly@0.0.2
updated 1 package in 54.566s

Tried converting another of my functions (takes 6 digit hex RBG colour and converts to a 9digit decimal version)

100% success :slight_smile:

[REQUEST]
Can the pink get (and set) property payload of object blocks have msg object as a default value?

Found another function and re-did in in Blockly
(It parses cheerlight tweets and extracts any colours present in the text and outputs a series of those colours in the order they appear)

And if we can have defaults, could we have msg as default object on the send block as well please

OK - tried out replacing a simple JSONata expression from a change node

image

Obviously the JSONata is much shorter but with Blocky I don't have to remember that I have to use & and not + to concatenate and remember that they are differences between accessing msg object properties and flow context values

I have found one function that I don't think I can use Blockly for

var msglength = msg.payload.length;
var msgbuff = new Buffer(msg.payload, "utf-8")
var outbuff = new Buffer(4 + msglength);
//msg.payload = buff.write("Happy birthday! ", "utf-8");
msgbuff.copy(outbuff,4);
outbuff[3] = msglength;
msg.payload = outbuff;
return msg;

Its used to convert a string payload into a Scratch Remote Sensor Connection format to send messages between Node-RED and Scratch 1.4

(Not a real problem as Blockly cannot be expected to cope with all scenarios)

Hi Simon,
could you please describe with a bit more detail which part of the code cannot be converted to Blockly (since I have no pc at my disposal currently)? Is it perhaps the (NodeJs) Buffer part???

Thanks!!

Bart

Yes - the buffer bit (maybe it can be done but I don't know how)

Had a quick look, but I don't think anybody has ever build Blockly blocks for Buffer support. Moreover the NodeJs API is quite extensive, so it would be quite a job to implement the whole API...

Anyway the function node will always be the big brother of the blockly node, offering much more functionality. Perhaps others can create pull requests afterwards to extend the toolbox with extra blocks. I could add a quick intro on my Github repository, about creating new blocks...

In version 0.0.2 I will offer some basic Buffer functionality, since I think that is used quite a lot in Node-RED.

Bart

If that use case of buffer is an interface to blockly 1.4 then that could be a specific block which would mean fewer options

Hi Dave (@dceejay) ,
think my brain has (hopefully partially) melted because of the heat. Could you please give some more details, because I'm not quite sure what you mean...
Enjoy (the remainder of) your holiday!!
Bart

I was only posting that I'd only found one of my exisiting function nodes that I couldn't replace with a Blockly node

I don't need/want/expect Blocky to do it :slight_smile:

Its a node to convert text to Scratch 1.4 broadcast message format - an experiment of mine to link Node-RED to Scratch

Simon,
to be honest I was so focussed on
Javascript objects (and Json), that I completly forgot about NodeJs buffers. Buffers are widely used in Node-red, e.g. to represent images. So I just need to support them in version 0.0.2. Will make some prototype blocks in the next weeks, and discuss them here ...
Good that you have noticed this during your tests!!!
Bart