calaos / calaos_base

Calaos server
https://calaos.fr
GNU General Public License v3.0
160 stars 37 forks source link

Dev/nae/charts #151

Open naguirre opened 3 years ago

naguirre commented 3 years ago

Fix bug and bad log + add new HTTP API for charts/datalogger points retrieval.

This api act as a proxy for influxdb database. If datalooger is disable, this api return "success" : "false" otherwise, the content of the q key of the json request is send to influxdb. Influxdb output is then returned as json payload.

Example of json payload (get 1hour of points for Calaos IO named "Outside Temperature")

{ "cn_user": "USERNAME", "cn_pass": "PASSWORD", "action": "datalogger", "q": "SELECT  \"value\" from \"Outside Temperature\" WHERE time >= now() - 1h" }

Example of json returned :

{
    "results": [
        {
            "statement_id": 0,
            "series": [
                {
                    "name": "Outside Temperature",
                    "columns": [
                        "time",
                        "value"
                    ],
                    "values": [
                        [
                            "2020-09-19T14:25:30.148879183Z",
                            29.2
                        ],
                        [
                            "2020-09-19T14:30:30.148224696Z",
                            29.2
                        ],
                        [
                            "2020-09-19T14:35:30.146235282Z",
                            29.2
                        ],
                        [
                            "2020-09-19T14:40:30.147027598Z",
                            29.2
                        ],
                        [
                            "2020-09-19T14:45:30.149729178Z",
                            29.2
                        ],
                        [
                            "2020-09-19T14:48:32.524887511Z",
                            29
                        ],
                        [
                            "2020-09-19T14:50:30.147821093Z",
                            29
                        ],
                        [
                            "2020-09-19T14:55:30.148496147Z",
                            29
                        ],
                        [
                            "2020-09-19T15:00:30.150516343Z",
                            29
                        ],
                        [
                            "2020-09-19T15:05:30.150021941Z",
                            29
                        ],
                        [
                            "2020-09-19T15:10:30.150139142Z",
                            29
                        ],
                        [
                            "2020-09-19T15:15:30.152617019Z",
                            29
                        ],
                        [
                            "2020-09-19T15:20:30.153415413Z",
                            29
                        ]
                    ]
                }
            ]
        }
    ]
}