Virtuino Forum
Text script or JSON creator - Printable Version

+- Virtuino Forum (https://virtuino.com/forum)
+-- Forum: Virtuino (https://virtuino.com/forum/forumdisplay.php?fid=1)
+--- Forum: Virtuino IoT (https://virtuino.com/forum/forumdisplay.php?fid=2)
+--- Thread: Text script or JSON creator (/showthread.php?tid=1255)



Text script or JSON creator - samxhot - 04-05-2023

Hello to all. New to Virtuino IoT.

I have a question on how to use the test script or Json creator widget.

My JSON text is the following:

{
"CID":
{
"deviceID":"SN23030001"
},
"measurments":
{
"weight":{"value":$C1_V1,"valid":$C1_V5},
"tempe1":{"value":23,"valid":true},
"tempe2":{"value":14,"valid":true}
},
"status":
{
"power":
{
"Battery":$C1_V2,
"mains":$C1_V4,
"devicePower":$C1_V3},
"health":
{
"code":0
}}}

I made it as the examples says so.
I selected the OUTPUT variable to be one of my MQTT connection (e.g V10)
and now I need to create / activate this function of JSON->Variable

There is no input or enable variable to do so.
How can I have the final JSON text to my V10 variable to send it via MQTT?

Thank you.


RE: Text script or JSON creator - iliaslamprou - 04-05-2023

Hi,

use $C1_Vx.value instead of $C1_Vx1
like this:

{
"CID":
{
"deviceID":"SN23030001"
},
"measurments":
{
"weight":{"value":$C1_V1.value,"valid":$C1_V5.value},
"tempe1":{"value":23,"valid":true},
"tempe2":{"value":14,"valid":true}
},
"status":
{
"power":
{
"Battery":$C1_V2.value,
"mains":$C1_V4.value,
"devicePower":$C1_V3.value},
"health":
{
"code":0
}}}


I have checked. It works fine!


RE: Text script or JSON creator - samxhot - 04-06-2023

Good morning,

Thank you for your reply.
I missed the (.value). It is working fine now.
Are there any other .properties availble?

Also, I noticed something that I do not understand.
I use NodeRED for debbuging / testing mqtt messages.

With my project unalerted, sometimes the reception of the JSON message in nodeRED is in Text format and sometimes an Object

I uploaded an image.


RE: Text script or JSON creator - iliaslamprou - 04-06-2023

Hi,

you can use the suffix  .date except of the .value
You will get the timestamp of the value.

The app sends the messages as Strings. I don't know why it happens. 
it's strange behavior. Υou can check the values of the variables. They are the only ones who change.


RE: Text script or JSON creator - samxhot - 04-08-2023

Thank you.

the .date suffix is very useful to me.

As for the Text /object representation in nodeRED, I will test it more.
It is not critical for now.

I think this tread must close.