TOP
SSV Software Systems Register  Register
Log in to check your private messages  Log in to check your private messages
Startseite FAQ Search Mitglieder Profile  Log in 
SSV Support-Forum
RTDC mit Processing …

 
Post new topic   Reply to topic    SSV-Forum Forum Index >>> Real Time Data Channels (RTDC)
<<< Previous topic - Next topic >>>  
Display posts from previous:   
Author Message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 16.12.2014, 21:39    Post subject: RTDC mit Processing … Reply with quote

Hallo Forum.

Auf RTDC-Datenprojekte lässt sich auch problemlos mit Hilfe der beliebten Programmierumgebung Processing (https://processing.org/) zugreifen. Nehmen wir einfach einmal das folgende Datenprojekt mit dem Namen TEMP und den beiden Daten-Items T_SSV und T_SC als Beispiel:

Code:
01: {
02:     "do": [
03:         {
04:             "id": 10,
05:             "name": "TEMP",
06:             "desc": "Temperaturfuehler",
07:             "property": {},
08:             "item": [
09:                {
10:                     "id": 49,
11:                     "name": "T_SSV",
12:                     "data": [
13:                         1416655631,
14:                         "18.2"
15:                     ],
16:                     "type": "GAUGE",
17:                     "desc": "Temperatur Demo SSV",
18:                     "property": {
19:                         "unit": "C"
20:                     }
21:                 },
22:                 {
23:                     "id": 50,
24:                     "name": "T_SC",
25:                     "data": [
26:                         1416583523,
27:                         "23.6"
28:                     ],
29:                     "type": "GAUGE",
30:                     "desc": "Temperatur Demo SC",
31:                     "property": {
32:                         "unit": "C"
33:                     }
34:                 }
35:             ]
36:         }
37:     ]
38: }


Durch dieses Datenprojekt ergeben sich die folgenden RTDC-REST-API-Links für HTTP-Zugriffe:

Code:
01: http://<SERVER:PORT>/rtdc/v0/?get=do
02: http://<SERVER:PORT>/rtdc/v0/?get=do&do=TEMP
03: http://<SERVER:PORT>/rtdc/v0/?get=data&do=TEMP&item=T_SC
04: http://<SERVER:PORT>/rtdc/v0/?get=data&do=TEMP&item=T_SSV


Mit den ersten beiden Links (Zeilen 01 und 02) lässt sich per REST-API-READ mittels einer HTTP-GET-Abfrage (HTTP GET Request) das komplette Datenprojekt TEMP abfragen – die HTTP Response liefert in diesem Fall die vollständigen JSON-Daten zum RTDC-Datenprojekt. Der Link in Zeile 03 dient zur Abfrage des Daten-Items T_SC, der Link in Zeile 04 bezieht sich auf T_SSV. In beiden Fällen liefert die jeweilige HTTP Response JSON-Daten mit dem betreffenden Item. Hier der Beispiel-Code für ein Processing-Sketch:

Code:
import processing.net.*;
Client myClient;
int dataLen, resync;
String data;
PFont myFont;

void setup() {
  size(300, 130);
  background(#2c223e);
  myFont = createFont("System", 48, true);
  frameRate(1);
  try {
    myClient = new Client(this, "<SERVER>", <PORT>);
    resync = 25;
  }
  catch (Exception e) {
    println("I recognize the SocketException");
  }
}
 
void draw() {
  try {
    myClient.write("<GET REQUEST>\n");
    myClient.write("Host: <SERVER>\n");
    myClient.write("X-RTDC-Auth-Key: <API KEY>\n");
    myClient.write("Accept: application/json; charset=utf-8\n\n"); 
    if (myClient.available() > 0) {
      data = myClient.readString();
      String lines[] = reverse(split(data, "\n"));     
      String jsonFragment = lines[0];
     
      // Extract JSON Object TEMP…
     
      JSONObject jo = JSONObject.parse(jsonFragment);
      JSONArray ja = jo.getJSONArray("do");
     
      // Extract Data Item T_SC
     
      jo = ja.getJSONObject(0);
      ja = jo.getJSONArray("item");

      // Extract Array with Time Stamp and Data …
     
      jo = ja.getJSONObject(0);
      ja = jo.getJSONArray("data");
     
      // Extract Data …
     
      String temp = ja.getString(1);
      println (temp);
             
      background(#2c223e);
      fill(#ffffff);
      textFont(myFont);
      String ndata = temp + "°C";
      text(ndata, 10, height/2+16);
    }
    myClient.clear();
  }
  catch (Exception e) {
    println("I recognize the SocketException");
  }
  resync--;
  if (resync == 0) {
    myClient.stop();
    delay(100);
    myClient = new Client(this, "<SERVER>", <PORT>);
    resync = 25;
    println("Resync TCP link ...");   
  }
}

Speichert man diesen Processing-Code in einer Datei mit dem Namen sketch_RTDC_GET_TD.pde und ersetzt die Platzhalter für <SERVER>, <PORT>, <API KEY> und <GET REQUEST> durch gültige Zeichenfolgen, lässt sich das gewünschte Daten-Item im Datenprojekt TEMP lesen. Für T_SC wird folgende Zeichenfolge als <GET REQUEST> benötigt:

Code:
GET /rtdc/v0/?get=data&do=TEMP&item=T_SC HTTP/1.1


Um im Datenprojekt TEMP den Daten-Item T_SSV zu lesen, wäre die hier folgende Zeichenfolge als <GET REQUEST> erforderlich:

Code:
GET /rtdc/v0/?get=data&do=TEMP&item=T_SSV HTTP/1.1


Gruß KDW
Back to top
View user's profile Send private message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 16.05.2015, 12:13    Post subject: MQTT-Unterstützung … Reply with quote

Hallo Forum.

Mit Processing kann man auch die Paho-MQTT-Bibliotheken nutzen. Siehe hierzu: http://www.element14.com/community/groups/arduino/blog/2014/12/13/part-21-using-mqtt-client-libraries-in-a-processing-sketch

Gruß KDW
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SSV-Forum Forum Index >>> Real Time Data Channels (RTDC) All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

SSV Software Systems GmbH

Dünenweg 5
30419 Hannover

Fon: +49(0)511  ·  40 000-0
Fax: +49(0)511  ·  40 000-40

sales@ssv-embedded.de


Impressum    ·    Datenschutz    ·    AGB

© 2023 SSV SOFTWARE SYSTEMS GmbH. Alle Rechte vorbehalten.

ISO 9001:2015