Closed cimba007 closed 7 years ago
@cimba007 I guess you are using an old version. In the SNAPSHOT version, we have added a friendly metric query for any application.
Currently you are using MyController specific graphical API, which is moved to /stats
>> /nvd3data
you can use as follows,
https://192.168.1.100:8443/mc/rest/metrics/stats?resourceId=152&resourceType=Sensor variable×tampFrom=1486141273860&bucketDuration=2h
Result:
[
{
"start": 1486217987274,
"end": 1486225187274,
"empty": false,
"min": 28.5,
"max": 29.1,
"avg": 28.99666666666666,
"samples": 240
},
{
"start": 1486225187274,
"end": 1486232387274,
"empty": false,
"min": 27.8,
"max": 28.9,
"avg": 28.700836820083694,
"samples": 239
}
]
supported inputs: https://github.com/mycontroller-org/mycontroller/blob/development/modules/core/src/main/java/org/mycontroller/standalone/api/jaxrs/MetricsHandler.java#L142~L147
related queries: http://forum.mycontroller.org/topic/85/monitoring-electricity-consumption http://forum.mycontroller.org/topic/79/temperature-min-max-avg/2
Very nice, I will give it a try tomorrow .. today I spent too much time to figure out how to get chunked-http-responses to work:
https://github.com/esp8266/Arduino/issues/2872
Edit: I check your related two links to the forum. They both deal with other ways of displaying data in mycontroller (this is really nice too!) .. but I wan't to display the data (temperature over last 24 hours) as a graph on one of those fancy SPI-TFTs:
I will have a closer look at "https://192.168.1.100:8443/mc/rest/metrics/stats?"
@cimba007 ok, I use MyControllerDevice library(MQTT) with ESP8266 to display data on OLED 128x64 I2C communication. It works great!
I check your related two links to the forum. They both deal with other ways of displaying data in mycontroller
Yes, it is dealing with direct API. You can access same way from REST API for external device.
I tried the new "stats"-api and am very impressed so far. The only thing that is giving me a headache is the timestamp:
https://192.168.1.100:8443/mc/rest/metrics/stats?resourceId=152&resourceType=Sensor variable×tampFrom=1486141273860&bucketDuration=2h
Would it be possible to introduce negative timestamps? e.g. -6000000 for the "last 100 minutes" ? This would make stuff much easier on embedded systems and would not break any current APIs.
@jkandasa: You got any input on the idea of "negative"-timestamp or extension of the api? Getting the current timestamp to calculate start-end is not "that" easy on mobile microcontrollers.
You mind adding an option to calculate startTimestamp as offset from current timestamp?
e.g. to show the data of the last 12hours? (no absolute timestamp)
Thanks in advance ;_)
@cimba007 the fix, I have added will address as follows,
https://192.168.1.100:8443/mc/rest/metrics/stats?resourceId=3&resourceType=Sensor variable&bucketDuration=1h&duration=12h
When you specify start
or end
values with duration
, calculation will be done as follows,
When you specify start
and end
, duration
will be ignored.
You mind adding an option to calculate startTimestamp as offset from current timestamp? e.g. to show the data of the last 12hours? (no absolute timestamp)
Do you want only values with comma separated? to draw a graph on an embedded device?
@jkandasa: I am pretty happy with your latest implementation of duration. There is an pretty nice json-library which I use to parse the json returned by your api.
Just a sneak-preview of what I want to use it for:
Notice the little graph at the bottom, data fresh pulled from mycontroller .. last 12hours in 30minute steps .. it is pretty rough for now .. no x-axis .. but this will be my work for next weekend.
PS: Did you already add documentation for the "new" api? I think it is awesome and might help other fellow hackers out there a lot ;-)
@cimba007 No, I do not have any document for REST API. I have to do. We have an issue very long time for this https://github.com/mycontroller-org/mycontroller/issues/24
I will try to close this when I do release 0.0.3.Final
@cimba007
Nice looking hardware/software in the picture. Care to share more details?
@Redferne
I will just list the components I used and some libs, should give you a decent start if you want to look further into things:
Hardware:
Librarys:
Oh yes! Thanks for the details. I'm planning a similar project using a MoteinoMega (https://lowpowerlab.com/shop/product/138) I'm hoping that 128kbyte + 512kbyte flash is enough to hold all graphics.
Hi,
I am just trying to connect an esp8266 to mycontroller to get the latest data of the current day:
http://raspi:8443/mc/rest/metrics/stats?sensorId=234×tampFrom=1486141273860
This is working so far .. I even found a nice json streaming library: https://github.com/squix78/json-streaming-parser
For an microcontroller with constrained memory etc. it would be really nice to know how many items are in the response and what timespan is covered. The current response is like this:
I suggest adding from-timestamp, to-timestamp and number of items