Inspired by @Timbones’s nice work over on the dashboard I’ve been looking at ways to explore the data.
I know that at the moment each data source also has it’s own EmonCMS wrapped around it and that’s what we’re using to render the data. However, seeing as the data is openly exposed then we could arguably use another user interface.
ofc I was looking at using my MMSP experimentation app. Partly because of @TrystanLea’s comment about analyzing the space and DHW heating separately which I’ve already coded.
So, I came up with a cunning plan to simply have my app use a different server when asking for data.json
. That sorta worked, but it’s based on my feedId
s so that’s bad. Next up I ran with my app calling out to the remote feed.json
which then allows you to request the right data.json
parameters and away you go.
If you imagine doing this with a query string so you can send hyperlinks to it then you end up with code a bit like this to branch on finding the feed.json
:
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
// See if a custom datasource is specified
const datasource_value = params.datasource;
if (datasource_value)
feed_list_url=datasource_value
else
feed_list_url="../feed/list.json"
console.log("Using feeds from " + feed_list_url)
// Load the available feeds for this user's system so we can configure the application
config.feeds = await (await fetch(feed_list_url)).json()
and so on.
Now, ofc the first feed I tried was from this one which I know is much like mine:
http://emon.cryosphere.co.uk/ashp
However, this fell over because I’m hosting my app on an HTTPS server and browsers have become really strict about not loading HTTP content into HTTPS pages.
Next I tried:
That showed another problem, CORS is set and returned from OPTION
pre-flight requests to emoncms.org but when you make the subsequent GET
request the Access-Control-Allow-Origin
header is missing so the browser’s CORS logic blocks you seeing the result.
Then I side-stepped that using the ridiculous cors-anywhere
so I have a request like this:
This now gives me the other datasources list of feeds and now I need to work out what to render. Clearly the next problem will be that the name of the feeds in their EmonCMS doesn’t match mine. We normally handle this by having it stored as application configuration, but clearly that only covers a single datasource (the "local one). Anyway, I hacked that too so it uses the names from the heatgeek feed.
As a result I can now review other people’s data in my instance of EmonCMS using my custom apps in there. Here’s me looking at the heatgeek
feed for example:
Clearly I’ve only done a little bit of mapping. That’s mainly because the request limit through cors-anywhere is 50 per hour so I very quickly use them up.
Q1. Is this a good idea?
Then, if we decide it is we have some problems to sort out:
Q2. HTTP-based data and HTTPS-based apps don’t get along (but the other way round would be OK)
A2. There are no magic fixes, needs a proxy or some other hack
Q3. CORS setup on emoncms.org needs enhancing
A3. emoncms.org admins would need to decide to do that (for example)
Q4. Feed mapping differs per datasource because of different feed names
A4. I have no idea how to approach this. I can concoct things, but none are very appealing