bartbutenaers / node-red-contrib-blockly

A Node Red node for visual programming a function using Blockly
Apache License 2.0
89 stars 22 forks source link

Export the block in xml #54

Closed TechscFR closed 3 years ago

TechscFR commented 4 years ago

Hi,

I discovered blockly yesterday and i think it's the perfect aditionnal tools to node red with your work, thanks to you. I do a lot of iot stuff and i wanna apply visual programming to this. Visuino do that well but with it own spirit. Kb-ide exist and it comes with blockly (that's why i found your work). Kb-ide containt a lot of block very usefull to do iot stuff. So i wanna now 3 things:

1st: Can I export the blockly block create on your node in xml to create a .bly and open it on Kb-ide? 2st: How implement blockly block in the pallete in your node? 3st: It's possible to generate python instead of the javascript like the blockly demo show it?

My purpuse is to program and upload my iot device in node-red with blockly. Like that i can handle programming my iot device and use easly a global vue of my devices and configure them all with the same variable.

It's like use johny five except you don't need the firmata. Combine blockly and node-red to programm iot can be great to replace the esphome on home assistant home. Indeed node-red replace the automation and node-red-ui the lovelace UI of home assistant. It's would be wonderfull if we can have access to visual programming instead of the yaml present in home assistant.

Thank you for the work again.

bartbutenaers commented 4 years ago

1st: Can I export the blockly block create on your node in xml to create a .bly and open it on Kb-ide?

When you save your Node-RED flow, Node-RED will store the configuration of all Nodes (and the wiring between the nodes) in your_flow.json file.

For the blockly nodes, the workspaceXml variable (in the flow.json file) will contain the xml:

[{"id":"c57c2c6e.d7efa","type":"Blockly","z":"ed0f5786.2ba6d8","language":"en","func":"var gateMsg;\n\n/*\n Describe this function...\n /\nfunction setStatus() {\n if (!(context.get('gate'))) {\n node.status({fill:\"red\", shape:\"dot\", text:'closed'});\n } else {\n node.status({fill:\"green\", shape:\"dot\", text:'open'});\n }\n}\n\n\nif ((context.get('gate')) != false) {\n context.set('gate', true);\n}\nif ((msg['topic']) == 'gate') {\n gateMsg = (msg['payload']);\n if (gateMsg == true) {\n context.set('gate', true);\n } else if (gateMsg == false) {\n context.set('gate', false);\n } else if (gateMsg == 'toggle') {\n context.set('gate', (!(context.get('gate'))));\n }\n setStatus();\n} else {\n if (context.get('gate')) {\n return msg;\n } else {\n setStatus();\n }\n}\n","workspaceXml":"<xml xmlns=\"http://www.w3.org/1999/xhtml\"><variable type=\"\" id=\"d`=BUYN]|[8b:+QnCvIG\">gateMsg<block type=\"controls_if\" id=\"32ef6ggKH_Uy4XVr)tH\" x=\"-187\" y=\"-188\"><value name=\"IF0\"><block type=\"logic_compare\" id=\"h:L;a-RTj5WigvnV-[Y\"><field name=\"OP\">NEQ<value name=\"A\"><block type=\"node_object_get\" id=\"18/sklXD`tpFg7QX;Ve\"><value name=\"object\">...","outputs":1,"name":"Gate","x":610,"y":120,"wires":[["9c2a9d9c.c3daa"]],"icon":"node-red/alert.png"}]

You can select a blockly node and use the Node-RED "export" menu option, and then you will see this xml inside the json also.

But exporting the xml to create a .bly file (don't know what it is) looks something very specific to me, rather unrelated to this node.

2st: How implement blockly block in the pallete in your node?

Then you need to add a new block and do a pull request for this repository. But discuss it first before coding, because we had loooooong discussions already with the community (on the Node-RED Discourse forum) for the current Node-RED blocks. So it is not simply adding a new block, because they would be used by lots of people...

3st: It's possible to generate python instead of the javascript like the blockly demo show it?

No. All my custom blocks currently generate Javascript only. Then all blocks would have to get a second (Pyton) implementation, and everything else (e.g. the Javascript syntax in the ACE editor on the second tabsheet) would have to be implemented again.

Seem like you want to develop a completely new node, apart from this one I'm afraid ...