Personal tools

Difference between revisions of "Data storage example"

From PhotoVoltaic Logger new generation

Jump to: navigation, search
m (Insert data)
m (Insert data)
Line 26: Line 26:
 
         --output /tmp/pvlng.curl \
 
         --output /tmp/pvlng.curl \
 
         --header "X-PVLng-key: a10d3cca-370c-121e-b79c-2f0a58030a01" \
 
         --header "X-PVLng-key: a10d3cca-370c-121e-b79c-2f0a58030a01" \
         --data data=23.45 \
+
         --data-binary {"data":"23.45"} \
         <nowiki>http://your.domain.here/api/r3/data/87fd-cc15-cb33-71a8-6b78-3855-4c11-a79e.txt</nowiki>)
+
         <nowiki>http://your.domain.here/api/r3/data/87fd-cc15-cb33-71a8-6b78-3855-4c11-a79e.json</nowiki>)
  
 
To get readable error messages back, request content type text/plain (triggered by file extension <tt>.txt</tt>).
 
To get readable error messages back, request content type text/plain (triggered by file extension <tt>.txt</tt>).

Revision as of 09:51, 27 August 2014

Data

As example we will store a temperature.

Parameter Value since
API key a10d3cca-370c-121e-b79c-2f0a58030a01 r1
Channel GUID 87fd-cc15-cb33-71a8-6b78-3855-4c11-a79e r1
Temperature 23.45 °C r1

Insert data

To store data we send a PUT request from a console with curl.

The API key must be send as a Header field named X-PVLng-key

Interesting is the HTTP code returned and the response body for error analysis in case of HTTP code is not 200 or 201.

$ set $(curl --request PUT \
        –-write-out %{http_code} \
        --output /tmp/pvlng.curl \
        --header "X-PVLng-key: a10d3cca-370c-121e-b79c-2f0a58030a01" \
        --data-binary {"data":"23.45"} \
        http://your.domain.here/api/r3/data/87fd-cc15-cb33-71a8-6b78-3855-4c11-a79e.json)

To get readable error messages back, request content type text/plain (triggered by file extension .txt).

Simple check

$ test $1 -eq 200 -o $1 -eq 201 || echo "Error ($1): $(</tmp/pvlng.curl)" && exit 1