Announcement

REXYGEN forum has been moved. This one is closed.
Head over to the new REXYGEN Community Forum at https://forum.rexygen.com.

Looking forward to meeting you there!
 

#1 2016-12-13 15:24:25

scoobsalamander
Member
From: Belgium - Hulshout
Registered: 2015-10-27
Posts: 217

JSON - String formatting

I would like to use a HTTP API to send some data to another application, this data should be placed in the body of the POST url.

The data string (JSON like) looks something like this...

[
  {
    "name" : "temperatures",
    "columns" : ["bedRoom", "kitchen", "bathRoom"],
    "points" : [
      [sensor0, sensor1, sensor2]
    ]
  }
]

How do I get my my data (sensor0, sensor1, sensor3) inside this string? Can I accomplish this in the REXLANG function block?

Offline

#2 2016-12-15 15:46:05

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: JSON - String formatting

Hi scoobsalamander,

thank you for your question about our new feature - Strings. If I understood correctly, the function block you are looking for is "CONCAT" from "STRING" library. This block concatenates input strings according to given pattern. The functionality you would like to achieve is shown in REST API example on our GitHub.

There is also suitable function in REXLANG called "strcat(dest,src)", which appends "src" string to "dest" string.

Hope that I answered your question. If you require any further information, feel free to contact me.

Cheers, Tomas

Offline

#3 2016-12-15 23:44:56

scoobsalamander
Member
From: Belgium - Hulshout
Registered: 2015-10-27
Posts: 217

Re: JSON - String formatting

...thanks for the link. My locally stored Github forked files of the examples seemed to be outdated......ok now. :-)

I'm trying to send some sensor data to an external storage engine (influxdb running on the same device). With node-red it is working fine but now I would like to send it straight from REXcontrols to this time series database.

I tried already a lot but I always get an error....the parser on influx' side is throwing errors all the time.

If someone has an idea how I should format the data (4 floats) to get it into my database???

I already tried with single points and multiple.....tried also a string which I found on their website but only errors are being send back.
Is it because it is not real Json (they are using line protocol now instead of Json)?

https://docs.influxdata.com/influxdb/v1 … ting_data/

Offline

#4 2016-12-16 09:44:54

scoobsalamander
Member
From: Belgium - Hulshout
Registered: 2015-10-27
Posts: 217

Re: JSON - String formatting

....after a good sleep I had some success with storing values directly into a Influx DB.

2016-12-16-09_32_07-REX.png

2016-12-16-09_33_32-REX.png


(Only the conversion of the values I still have to check because something has gone wrong .....see for example the values 2,3 & 5...they do not correspond)
** EDIT : changed settings of RTOS function blocks inside the Subsystem. Now the values are OK. (corrected in example as well...)

Example :
InfluxDB.zip

Influx database used in example : REXmeas
IP-address of InfluxDB : localhost

Influx info - data format --> 'line protocol' is used instead of JSON (deprecated as of InfluxDB 0.9.1), if you use Node-RED then you still can use JSON.

Last edited by scoobsalamander (2016-12-16 14:18:03)

Offline

#5 2016-12-16 14:11:27

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: JSON - String formatting

Hi scoobsalamander,

thank you for sharing your project with the community - it can be valuable source for someone else. Your pace is incredible wink Keep up!

Cheers, Tomas

Offline

#6 2017-11-17 03:10:51

100m@modbus_asic
Member
Registered: 2017-11-17
Posts: 1

Re: JSON - String formatting

Is there possible to implement Jason on Modbus protocol ?
In that way, it might send both control command and data at the same time.
Most importantly, using Jason to define tags for others undefined devices of automation and IoTs.

Offline

#7 2017-11-18 20:08:52

scoobsalamander
Member
From: Belgium - Hulshout
Registered: 2015-10-27
Posts: 217

Re: JSON - String formatting

Json is a text string which contains the data. So for automation I would opt for Modbus..... With Json you need the convert your integers and booleans first into a string and afterwards another conversion is needed.....not so efficient.

In this topic I was just showing how you can use it to store some data in a database every few seconds/minutes.....

Do you have an example of the data which you would like to send? This might give us a better idea what you are trying to achieve....

Offline

Board footer

Powered by FluxBB