LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Temperaturedata from a webserver via http JSON request to LabView

Solved!
Go to solution

Hi everyone,

I already established a Webserver, which contains the temperaturedata from several PT100-Elements. Now I would like to view and save these temperatur data in LabView. Maybe through an http get request I could involve the data via JSON format?

I'm really thankful for any help, I just started using LabView and this task seems pretty complicated to me.

 

Thank you!

0 Kudos
Message 1 of 14
(2,175 Views)

Yes you can do a simple get request with LabVIEW to get you data formated in JSON. A good starting point might be here -> https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/build_web_service/

If you understand the basics it's really no big deal to do this with LabVIEW.

Message 2 of 14
(2,157 Views)

Hi Jens,
thanks a lot for your fast reply. I'm defintly trying to work through the tutorial. By now I found kind of a solution using the JSON format. But I have problems unflatten the JSON into LabView data. I've attached the whole project. Maybe you can take a look at it.
Thank you a lot for your help!
Miriam

0 Kudos
Message 3 of 14
(2,153 Views)

I think I can see what you did wrong.

First of all I would recommend to create a control/ typedef for the data you want to import into LabVIEW. Otherwise you need to create you own parser to extract the data out of the JSON string.

In the snippet I attached you can see the array with some data just as an example. We then flatten it to JSON (your webserver/ web application is doing this) and then we unflatten the JSON string again to demonstrate the way you have done it (top one) and how I would recommend doing it (bottom one). I think this should be very clear why you want to wire some sort of type definition or control into the unflatten from JSON VI.

JSON.png

  
Be aware that JSON only supports some very basic data types but if you webserver can send the data it should be ok.

Message 4 of 14
(2,146 Views)

 Thank you for your helpful answer. I think I can also see what I did wrong. The type and default must match the output type. But for some reasons, I can not find a way fix that problem. In the snippet below I did it obviously wrong, because this error is popping up. But nevertheless the temperaturdata, which I want to display in LabView is shown. If I connect the type and default point of the unflatten JSON function to any other block, the temperaturdata is not shown in the VI. Do you know how I can fix the problem? I really appreciate your help!

Unbenannt3.PNG

Unbenannt.2PNG.PNG

0 Kudos
Message 5 of 14
(2,104 Views)
Solution
Accepted by topic author MiriamLea

Is the attached picture still your VI? If so then you're still not giving the unflatten from JSON VI a proper typedef to interpret the data. Maybe attach the actual VI again and a copy of the JSON data you get from you webserver.

If the "String" in you picture is the data then try this snippet, the cluster should work with the given data. (I assume you know that you can drag this picture into LabVIEW to generate the code you can see?)

vi.png

0 Kudos
Message 6 of 14
(2,101 Views)

Thank you so much for you help! It works now 😍

0 Kudos
Message 7 of 14
(2,092 Views)

I got a second question regarding this topic:

With one webserver the whole thing worked. But now I have multiple webservers, which sends the same amount of temperaturdata. I would like to view all data in the front panel. I tryed to copy the main block diagramm, but I constantly get an error code. I don't know what I'm doing wrong, I increased the amount of time, but it still doesn't work.
Thank you for your answers!

Error Code:

MiriamLea_0-1629274149845.png

 

MultipleWebserver.png

 

0 Kudos
Message 8 of 14
(2,033 Views)

Hi Miriam,

 


@MiriamLea wrote:

With one webserver the whole thing worked. But now I have multiple webservers, which sends the same amount of temperaturdata. I would like to view all data in the front panel. I tryed to copy the main block diagramm, but I constantly get an error code. I don't know what I'm doing wrong, I increased the amount of time, but it still doesn't work.


Where do you set any timeout?

What's the point of that wait function in parallel to your HTTP handling?

Does your 2nd device even send data? Is the IP address correct? Can you access the 2nd device on that IP address?

Is it the same device and is it configured exactly the same (apart from IP address)?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 9 of 14
(2,029 Views)

Hey GerdW and thank you for your reply.

I set a timeout on the left handside to 1000 ms.

And to be honest I don't know what the point of the wait function, I just though I might need to, to run this VI continiously.
And yes the second device sends data, and the IP adresse is correct. It is the same device configured the same as the first one, just with another IP Adresse. 

 

Do you have an idea what I'm doing wrong here?
Greetings, Miriam

0 Kudos
Message 10 of 14
(2,026 Views)