Receive POST Logic Block

When using the Receive POST Logic Block does it need to be connected to any input in order to receive a value? Or can the POST request just send to the logic block’s url?

The receivePost block doesn’t need to be connected to any input – it is unique among all the blocks in that it will generate an output based on an external event.

I just re-tested the feature, and found it working. Here’s what I did:

Step 1: Add a logic node, open it up, and add the receivePost block with this configuration

Step 2: Connect the output of the logic block to something else, like a graph tool

Step 3: Check the block’s URL by tapping on it

Step 4: Make the POST request

I sent a value of 0.5 from my terminal to the block using this command.

curl -X POST -H "Content-Type: application/json" -d "{ \"value\": 0.5 }" http://localhost:8080/triggerBlock/blockGq9gutf993sw

I used localhost instead of the IP since I ran it from the same computer as the server, but you could also trigger it from another IP.

Thank you for the response. I was able to use the block to get a value from an online weather api and then output it to a progress meter. As I was looking through the logic blocks documentation, I noticed there is a Web POST block description, however I was not able to find the block on the toolbox app. Is Web POST an available tool through the app?

@alinashah that’s awesome that you were able to connect it to a weather API! I haven’t seen anyone do that before, it would be cool to see a demo if you have one :slightly_smiling_face:

The Web POST block is actually there in the app, but is hidden due to a problem with the UI – the block menu is scrollable but has no scroll bar! You can still access it if you drag on a “background” part of the menu (in between the blocks).

I’ve been meaning to split up the blocks into the different categories, but currently they’re all on the same page and overflow beyond the height of the screen.

I haven’t tested this block in a long time though – hopefully all is working!

I will definitely try to post a demo a little later. I was just displaying some weather values on the toolbox.

I was able to find the Web POST block, but when I try to enter a URL my keyboard pops up yet I am not allowed to input anything/change the URL. Nothing happens when I try typing. Is there something different that I should be doing?

I had another question about the Receive POST block. Currently it accepts values between 0 and 1, which is working on our toolbox. However, as we are working with color data from the LEGO Boost that has values between 0 and 255, when we post it to the toolbox we have to scale down those values for the receive block to accept them. If I wanted to change which values can be received by the block, which part of the code should I be looking at?

Generally, you can change the behavior of blocks by editing their respective index.js file in the vuforia-spatial-core-addon/blocks/{block name} directory, for example the delay block.

The receivePost block is a bit unique in that, in order to expose a public endpoint that can be triggered, that part of the implementation is in the main server.js. You can look at the function triggerBlock on line 1920 of server.js:

Essentially, you need to assign[0].value to whatever value you want the block to output, and then you need to trigger engine.blockTrigger for the server to process that new value and propagate it to any linked components.

This block was a bit of an experimental feature and doesn’t follow all of the design guidelines of our system, but it (or a modification of it) could be useful in accomplishing your goal.

Ah, that is a bug (same thing happens for me when I try). Thanks for reporting!

The code for that settings page is here:

If you need to quickly test something out, you could edit the webPost block in your core-addon and hard-code your desired URL as the default value in the text box, so that just tapping on Update will set it without having to use the keyboard. I’ll look into why the keyboard isn’t working, but it’ll likely take at least until next week before I have a chance to fix it.

(Note: in order for the block on your server’s addon to overwrite the default version of the block in your phone, you need to load a world object into your scene or be looking at an object hosted by the server whose addon you changed)

Thank you so much for the advice for changing the WEB and RECEIVE Post blocks. We were able to hard-code the webPost to post to Thingworx, but if the app can be updated so that a specific url can be inputted that would be very appreciated. Also the block is currently limited from our experience where a webPost can only go to an API without a key, so we had to adjust the code to specify our API key.

With the receivePost block it seems that the endpoint can only be triggered once within the code. We are trying to have the block constantly listen for posts and update every few second by posting to the url in a while loop. It does not seem to change the value more than once. Is there any way to change the code so that the receivePost block constantly updates?

Are you repeatedly sending the same value or different values to the block?

I think there may be an underlying bug/feature where the data is only getting processed if it is a new value as compared to the previous value the block received. I can look at fixing it but it’s helpful if I know what values you were sending.

I believe we are sending different values using the code below:

while (True) {
light_val = GetInfo(“Boost_light”)/255;
setTimeout(() => {PostInfo(“value”,light_val);}, 5000);

Every time we call GetInfo a new value is stored in the variable light_val and we’ve checked that using console.log.

@ben I do not know if it is still relevant or helps, but I was able to fix the bug for taking the input in from the user by commenting out the line:

    <script src="../../../objectDefaultFiles/logicNodeSettings.js"></script>

at the top of the file.