IoTaWatt API documentation

I can not find anymore where you mentioned it, but if I remember correctly you told that there is an API that it is not yet documented.
something like this: iotawatt.local/command?deletelog=current

I would like to get values of an inputs or output of a certain moment, is this currently possible and how?


I found those:

in combination with iotawatt.local/feed/list.json I can make the matching.

I would assume thtat the value is the measure number, but no idea to get the maximum value and more important the time of the measure…

I found this iotawatt.local/status?datalogs=1 where I can find the start and the end.
With the interval info I can calculate the timestamp by adding the measureId*interval to the first timestamp.
But it would be nice to include the timestamp to the returned values of inputs and outputs

1 Like

The short answer is that it is possible to get those values. There are two different facilities for extracting data, and it will depend on what you want/need.

I do intend to document the data extraction API, but I have been holding off because what is there now is just a modification of the Emoncms get/feed/data API and maybe could be made more flexible and SQL like. Haven’t had time to think that through, so maybe the way forward is to document the existing APIs and plan to leave them in place if I add newer ones.

But back to your problem. In the subsequent post you are using the status API to get input and output values. That can work but you have already picked up on the problem that input channels are numbered and don’t have the names included in the Json. But the real problem with the status API is that the value is damped, so it is not a true indication of the present measurement. It is intended for use in the status display, not for record keeping. Also, it doesn’t matter what you specify for inputs=, you will get all of the inputs. Same for outputs.

I think the most useful API is the modified feed API’s that are used by the graph program. It can provide accurately timed data for one or more time periods, and for one or more inputs/outputs by name. IoTaWatt has implemented only a subset of those APIs:

feed/list.json will return a Json feed list just as Emoncms does. The difference is in the values for the various Json objects: The “tag” object, which is used by Emoncms to provide node, is used to specify which tab to organize by - Voltage, Power, Energy, Other.

The ID object, used by Emoncms to pass the feed ID, is the ID by which IoTaWatt will identify the input or output. The first character is ‘I’ or ‘O’ to indicate Input or Output. The second character is ‘V’ for Voltage, ‘P’ for Power, ‘E’ for Energy, ‘O’ for Other. The rest of the ID is the same as the “name” object. So if you have an input name “kitchen” the ID to get power (Watts) wouold be “IPkitchen”. To get cumulative kWh use “IEkitchen”.

These feed/data.json requests from Emoncms are supported, with a few modifications:

  • The ID can be a single input/output or it can be a Json array of IDs.
  • The times can be UNIXTIME_MILLISECONDS as specified, or they can be UNIXTIME_SECONDS.
  • Because the ID can be an array, the returned data is a json array of arrays with the inner arrays being an array of the values for the requested IDs at that time.
  • Finally, unlike Emoncms, IoTaWatt does not return the UNIXTIME_MILLISECONDS for each interval. The requester should know what they asked for, and should be able to understand the response. It’s hugely redundant and adds more than 13K to the response. The IoTaWatt graph adaptation does all this easily.

So to use this to get current values, you need to know the current unixtime rounded to a five second interval (ending in 0 or 5). You can ask for one measurement by setting start and end to the same value, and interval to the time period that you want an average value for. So for instance if you are going to request the value every 15 seconds, you would set interval to 15 so that the value returned would be the average for the last 15 seconds.

Sorry if this is a bit rambling, but I wanted to give you something to go on. There is always the code as well. The feed/list.json handler is in module webServer.cpp. It’s pretty straightforward making extensive use of arduinojson.

The feed/data.json handler is the getFeedData.cpp module. It’s maybe a little harder to follow because it rolls it’s own Json and does chunked response, but the setup code in the beginning is pretty easy to follow and that’s what parses the request.


Hi Sorry for the late answer ;-(
This helps me,of course a new interface SQL like would be nice, but for the moment ok with the current one…

I have to find time to make a small program that takes out the data and pushes to a mariadb database…


Why reinvent the wheel? Can you use influxdb, or alternatively push to a local copy of emoncms that you control? That way you can use other tools to query either database.