API magic: what else beyond query?

What else can the API do, beyond query (which is well documented)?

I remember saving this one I found in one post in this community:


I’m thinking a periodic retrieval of the message log (for a pseudo syslog’ing), a check of the date/time, retrieval of the config.txt for automated backups, status statistics (just noticed my IoTaWatt has only been up 10 days…that seems curious), etc.

MOAR PLEASE! :slight_smile:

Most of that is possible, but you would need to look at the code in GitHub for how to use.

The message log is just a file. You can download it in its entirety, or add the textpos= Query to the URL to get retrieve fixed size segments from the beginning or end of the file.

No way to do that, but I have been meaning to add that to the status query.

Again, it’s just a file, you can download it directly from the web server or using the file manager.

The status API accepts queries for inputs, outputs, WiFi, datalogs, uploadersl, statistics. Response is json. You can see the various handlers in the code, or just turn on your browser debugger and look at the requests and responses as you open the various tabs in the status display.

Maybe as you peruse the code, @zipzap, you could semi-document what you find as a kind of community-contributed reference for others who are similarly interested. Even if it’s just a “when I query the following, here’s the results I get”, that would be of huge value if there isn’t yet a verbatim API documentation outside the codebase.
That might even serve as a good starting point for an official API documentation page in the IoTaWatt documentation, if there is enough interest and it serves enough value for Bob to spend some time on it. Of course, depending on how much is there, a pinned community-written guide could be all that is needed! :slight_smile:

@Tony, yes, I am planning on “showing my work”! I would be glad to contribute to the official doc if @overeasy thinks it appropriate to put this level of esoteric detail in there. (I am a little familiar with git but not at all familiar with the ReStructuredText documentation format.)

Important note: These low-level API calls may be firmware specific and are not guaranteed to work from release to release. The officially supported method of accessing this data is via the IoTaWatt GUI.

So far I have examined the HTML output from my IoTaWatt and discovered these (firmware 02_05_12.bin):

To check wifi status:

curl http://iotawatt.localdomain/status?wifi

(connecttime in UNIX epoch time)

Reset wifi (to change SSID):

curl http://iotawatt.localdomain/command?disconnect=yes

(then power cycle the IoTaWatt and reconnect as new for wifi)

Datalog info:

curl http://iotawatt.localdomain/status?datalogs

(times in UNIX epoch time)

config.txt download (e.g., for scripting an automated backup):

curl http://iotawatt.localdomain/config.txt

“format”: 2,
“timezone”: “-5”,
“update”: “MINOR”,
“device”: {

messages file download (for sort of syslog’ing, the last 10,000 lines):

curl http://iotawatt.localdomain/iotawatt/iotamsgs.txt\?textpos=-10000 > iotamsgs-10000.txt

(redirected to the file “iotamsgs-10000.txt”)

UNIX epoch time converter example

I want to note that all of these have a higher level interface through the config AP port he file manager app. The low level transactions are not documented because I reserve the right to change them as needed. Since the documentation is release specific, it’s fine to detail them there, but using them for anything important risks future incompatibility. That would need to be clear.

Thanks for the clarification @overeasy. I have edited my previous post to add a disclaimer (in case that one in particular is pinned, bookmarked, etc.). I will add a disclaimer as well to any follow-up posts as I discover more.