cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, how is it possible to change a variable by pressing a button? I just can change a variable by using the write panel but. regards

danielspronk9
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Landry
Senior

Hi danielspronk9 ,

To write data by flow, the following payload must be sent to probe out node ,with the topic “write�? :

{

   "variablelist": [

       {

           "address": "0x20000060",

           "type": 4,

           "value": "xxxx"

       }

   ],

   "accesspoint": 0

}

 My proposed solution with standard nodes is :

0693W000000TrYOQA0.png

I have added a slider to generate the value (but can be done by any node) then the “template�? node formats the payload, and the change node set the topic.

the template node content :0693W000000TrYYQA0.png

0693W000000TrYnQAK.png

The variable address and variable type must be filled here. For the type and address, the easiest way it to try first with a write panel and a debug node, and see the values. The payload value from input will be inserted in the template. (the value to write).

The next node is a “change�? to set the topic to write 0693W000000TrZ7QAK.png0693W000000TrZCQA0.png

the result :

0693W000000TrZMQA0.png

When the slider is moved, the new value is written to g_constDouble

I attach the 3 nodes flow to the message.

Let me know if it is ok.

Best regards

Landry

View solution in original post

9 REPLIES 9
Landry
Senior

Hello danielspronk9 ,

Can you give me more information on your usecase ?

-You want to write always the same value when you click on your button ?

-You want also a text box to enter the value before clicking on the button write ?

Everything is possible with STM32CubeMonitor :smiling_face_with_smiling_eyes: , that's why i need more explanation.

Thank you,

Landry

danielspronk9
Associate II

Hi Landry,

thanks for your fast answer.

I use the write panel to change intern variables, this works fine.

Now i want change variables over a switch, a button or a slider but i dont know how it is possible.

For the beginning i want change a variable to a fix value if i press a button.

regards

Landry
Senior

Hi danielspronk9 ,

To write data by flow, the following payload must be sent to probe out node ,with the topic “write�? :

{

   "variablelist": [

       {

           "address": "0x20000060",

           "type": 4,

           "value": "xxxx"

       }

   ],

   "accesspoint": 0

}

 My proposed solution with standard nodes is :

0693W000000TrYOQA0.png

I have added a slider to generate the value (but can be done by any node) then the “template�? node formats the payload, and the change node set the topic.

the template node content :0693W000000TrYYQA0.png

0693W000000TrYnQAK.png

The variable address and variable type must be filled here. For the type and address, the easiest way it to try first with a write panel and a debug node, and see the values. The payload value from input will be inserted in the template. (the value to write).

The next node is a “change�? to set the topic to write 0693W000000TrZ7QAK.png0693W000000TrZCQA0.png

the result :

0693W000000TrZMQA0.png

When the slider is moved, the new value is written to g_constDouble

I attach the 3 nodes flow to the message.

Let me know if it is ok.

Best regards

Landry

danielspronk9
Associate II

Thanks you, it works :)

But one more question. Is it possible to use the variable name not the address? the address can change and then it didnt work any more.

Landry
Senior

It's mandatory to send addresses to the probe. You can use a "trick" by using information containing in the node variables ( mapping names <-> addresses ).

I copy a flow example for the variable called "sum".

When you update your executable file, you can do an automatic update of addresses by opening and saving your variable configuration file.

It's not fully automatic but better than nothing.

KJeps.2
Associate II

Hi,

On the variables node, put this in a function block, it will store the adress in the "global" flow context, and can referenced when doing the writing.

msg.payload.variablelist.forEach(myFunction);

function myFunction(item, index) {

  if (item.name == "direction"){

    flow.set('direction_adr',item.address);

  }

  if (item.name == "current_limit"){

    flow.set('current_limit_adr',item.address);

  }  

in a template note:

{"variablelist":[{"address":"{{flow.current_limit_adr}}","name":"current_limit","type":5,"checked":true,"value":"{{payload}}"}],"accesspoint":0}

   

}

vtran1
Associate II

Hello,

I follow the instruction and receive this error:

10/6/2020, 5:31:11 PMnode: ST Link out

 "Bad parameter (7)"

msg : string[264]

"Unsuccessful write (Bad parameter (7)) on 48FF6E064986484820270787, for data = "{\n \"variablelist\": [\n {\n \"address\": \"0x20000000\",\n \"type\": 3,\n \"value\": \"3678\"\n }\n ],\n \"accesspoint\": 0\n}": write"

Do you know what's wrong with it? I check the address and type and they are correct.

Hi,

I have the same error

Hello,

I follow the instruction and receive this error:

 "Bad parameter (7)"

msg : string[264]

"Unsuccessful write (Bad parameter (7)) on 48FF6E064986484820270787, for data = "{\n \"variablelist\": [\n {\n \"address\": \"0x20000000\",\n \"type\": 3,\n \"value\": \"3678\"\n }\n ],\n \"accesspoint\": 0\n}": write"

Do you know what's wrong with it? I check the address and type and they are correct.