Blockly for running backend code at runtime

557 views
Skip to first unread message

Madhushan Tennakoon

unread,
Mar 25, 2021, 3:07:59 PM3/25/21
to Blockly
Hi everyone!

So I'm working on an IoT project where a user would be able to create a flow of commands on a UI, and then have that code be executed on a backend. Is this feasible with Blockly? I'm working with a Spring Boot app, so ultimately the blocks would need to be parsed to Java/Kotlin, which doesn't seem to be officially supported. Are there any sample projects you think might help to get started?

This headless demo that generates python code from xml seems pretty relevant: 

Would this xml then need to be parsed at runtime on the backend? Or is there a more straightforward way?

I just started looking into Blockly and I'm still digging through the awesome documentation, so I could have easily missed something.

Thank you,

Madhu

amir maalaoui

unread,
Mar 26, 2021, 3:03:00 AM3/26/21
to Blockly
how can i make dark theme

Beka Westberg

unread,
Mar 26, 2021, 10:28:17 AM3/26/21
to blo...@googlegroups.com
Hello,

This sounds awesome! I love IoT projects :D May I ask what type of IoT thing it is?

> ...ultimately the blocks would need to be parsed to Java/Kotlin, which doesn't seem to be officially supported. Are there any sample projects you think might help to get started?

Java/Kotlin is not one of the built-in language generators, but it is definitely possible to build one! There's a codelab that walks you through building a JSON language generator, which will help familiarize you with the API. You can also check out the source code of the built-in language generators. And ask questions here of course :D

> Would this xml then need to be parsed at runtime on the backend? Or is there a more straightforward way?

I'm not sure that you /need/ to parse the XML on the back end. I think you may also be able to generate the code in the client and then send that to the back end to be evaluated? But that doesn't sound very secure. My instinct is that it's safer to pass the XML as shown in the demo you linked to, but I'm really no expert.

I hope that helps! If you have any further questions please reply!
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/8255fb09-5554-4d61-8af5-5b931b545c0en%40googlegroups.com.

Beka Westberg

unread,
Mar 26, 2021, 10:33:00 AM3/26/21
to blo...@googlegroups.com
Sorry I forgot to add hyperlinks.

Built-in language generator source code:  https://github.com/google/blockly/tree/master/generators
For example, the JavaScript language generator: https://github.com/google/blockly/blob/master/generators/javascript.js

Madhushan Tennakoon

unread,
Mar 27, 2021, 1:19:09 AM3/27/21
to Blockly
Hi Beka, 

Thanks for your reply, and the links! I'm trying out that codelab to make my own custom generator, but I do agree there'd need to be some kind of sanitization. Plus it could get a little tricky if I needed to inject additional logic on the backend.
Looks like there was also some decent work being done to parse the xml to java code:


That does seem like the right way to go, but also the most challenging. Will definitely be relying on this forum for support in the coming weeks!
And the IoT project is for designing some simple rule-based temperature controls. Blockly seemed like a neat way to do it :)

Thanks for the help!
Madhu

Beka Westberg

unread,
Mar 27, 2021, 11:15:26 AM3/27/21
to blo...@googlegroups.com
Hello,

> And the IoT project is for designing some simple rule-based temperature controls.

Oh that sounds super cool! I hope the work on it goes well :D

Best,
--Beka

TT

unread,
Apr 28, 2021, 4:29:53 AM4/28/21
to Blockly

I also encountered the same difficulty, we need to generate java code, but it is not officially supported, and the third-party library is not available

The solution we came up with:

1. Get the fast JSON configuration, and then send it to the back end. The back end parses it and gets the desired fields for processing

2. Self developed Java generator
Reply all
Reply to author
Forward
0 new messages