32�5�2 json interfaces – Solare Datensysteme Solar-Log User Manual

Page 237

Advertising
background image

237

Appendix

32�5�2 JSON Interfaces

The JavaScript Object Notation (JSON) is a compact data format to transmit data between applications.

The objects documented here can be used in connection with other programs.

The current data can be accessed via HTTP protocol. To do this an HTTP Post Inquiry needs to be sent to

the Solar-Log™. The object requested has to be in the body:

POST /getjp HTTP/1.1

Host: solar-log-xxxx

...

Content Length: 20

Connection: keep-alive

Pragma: no-cache

Cache Control: no-cache

{„801“:{„170“:null}}

The reply contains a JSON object as a character string in the body:

HTTP/1.1 200 OK

Date: Mon, 31 Mar 2014 10:42:32 GMT

Server: IPC@CHIP

Content-Type: text/plain

Transfer-Encoding: chunked

{„801“:{„170“:{„100“:“31.03.14 10:42:15“,“101“:0,“102“:0,“103“:0,“104“:0,“105“:0,“106“:0,“107“:3527647,

“108“:0,“109“:0,“110“:0,“111“:0,“112“:0,“113“:1132434,“114“:0,“115“:0,“116“:45000}}}

The JSON character sting needs to be converted to an object first before it can be data can be processed

in a Java script. For example, when the JSON character string contains the variable "tdata" the conversa-

tion looks like this:

var LiveDaten=JSON.parse(tdata)[801][170];

After that the individual data fields can be accessed via the indexes specified in the following table.

For example, the current P

AC

output is displayed as follows:

alert(„The current AC output is: „ + LiveDaten[101] + „ W“);

Advertising