You’ll want to create an Adapter
class and use the handleDeviceSaved
callback to get a list of all saved devices.
You can create your views with an Extension
and an APIHandler
.
You’ll want to create an Adapter
class and use the handleDeviceSaved
callback to get a list of all saved devices.
You can create your views with an Extension
and an APIHandler
.
Some screenshots to show the progress so far
The basic extension
I’ve created all the screens so far starting from the example-extension.
Would the Adapter
class be in the same package or a separate package? If separate, how would they communicate?
The Adapter
runs on the server. You’ll want to create an Adapter
that is owned by the APIHandler
, or vice versa, so that the Adapter
can share the device info with the APIHandler
.
The example-adapter actually uses this pattern, although it uses the adapter for much more than you’ll need to. You won’t need to create any devices of your own.
I’ve done this and it’s working, thank-you for your quick response.
I’ve completed the basics of a platform to setup groups of things and the structure behind pages. I’ll spend some time to go through to ensure all the components are working and that all the code is fairly clean and documented. Then I’ll publish on GitHub.
Before anyone gets excited: This doesn’t do anything for anyone yet.
I have not even created any display of the new pages. The hard graft will be to see how to to chop up the basic Things page and FloorPlan page, then see how to get the devices displaying and updating on the new pages that will eventually appear.
I’ve published the extension so far at https://github.com/chas-iot/pages-extension
It is not ready to be added to the of published addons. So far, it is only some internal infrastructure and the UI to manage that infrastructure - it does not create pages that display updating things.
If you want to test, please note that the path to the database is hard-coded to /home/pi/.mozilla-iot/pages/pages.sqlite3
- make sure that path exists or edit src/db.js
Hi,
can anyone advise why this code leaves me with config === undefined ?
class PagesAPIHandler extends APIHandler {
constructor(addonManager) {
super(addonManager, manifest.id);
addonManager.addAPIHandler(this);
let pages_db_location = '/home/pi/.mozilla-iot/pages'; // hard-coded fallback
const db = new Database(manifest.id);
db.open().then(() => {
db.loadConfig();
}).then((config) => {
if (config && config.dblocation) {
pages_db_location = config.dblocation;
} else {
console.error(`pages-api-handler (B): "dblocation" is not in extension configuration ${JSON.stringify(config)}`);
}
PagesDB.open(pages_db_location);
}).then(() => {
I’ve lightly edited from the actual code to remove some not relevant initialisation.
I just added the code to load the config and it is failing. With the fallback hard-coded location, the extension otherwise runs OK.
config
will only be defined there after the user has configured the add-on via the UI. Defaults can be accessed from the manifest
object.
How does the Floorplan page work?
I started to look at the Gateway code but got lost. From what I can work out from watching the Gateway HTML, the Floorplan redirects from the Things page. I would like to replicate that.
I assume there is some MVC or similar pattern used to do this. What should I research so I can do the same thing?
Thanks in advance
Generally speaking, the UI is a single page app. The navigation just hides/unhides appropriate sections.
There is a loose MVC framework that manages the WebSocket connection to /things
, e.g. property updates and such. The thing bubbles are all custom web components.
With that said, I’m not sure how much of it is directly accessible from an extension, so you’ll probably just have to play with it. The main logic you’ll want to look at (and probably attempt to replicate) is in thing.js.
If possible, I’d like to achieve this at the browser level rather than reproduce a large chunk of the gateway.
Alternative approaches being researched:
id
s on the Things page and I can magically display each one separately as I please on as many different pages as I please.My question regarding the Floorplan page vs the Things page. Are both being separately being updated in the DOM, even when one (or both) is hidden? Or do they do some variant of one of the approaches I mentioned. I did start looking but this will take me many hours over several days to familiarise myself enough with the code to work it out for myself.
If you can give me an idea of exactly which things you’d need access to, I can potentially extend the Extension class (or elsewhere) to give developers a bit more access. I wonder if, instead, it would be simpler to just have a basic link for each device that takes you to the individual thing pages, though?
What I am trying to do is create additional pages that look like the Things page or the Floorplan page but with different sets of Things visible. Use case: I have a lot of non-physical Things (timers, intervals,email etc) that clutter up those two pages, and I’m not usually interested in seeing.
Where possible, I don’t want to rebuild existing functionality. Which is why I’d like to re-use the existing mechanisms that display Things.
I have further steps in mind.
So, as I said before, it’s probably easiest to just use text links at this point, given the current set of constraints.
Another option is to build this into the gateway itself. I’d love to have that feature and would gladly review a pull request…
I’d love to build it into the gateway. I’ve been thinking about an approach. Here are my notes. Criticism is needed
container
name
rowid
(primary key)rowtype
– D for Display, G for Groupsettings
– a JSON string where a link to a floorplan image, etc may be placedlink
container
and a thing
may be set uprowid
(primary key)container
-> container.rowid
contained
-> things.id
rowtype
– T for Thing, U for usersettings
– contains a JSON string of settings, such as the x,y co-ordinates of the placement on a Floorplanorder
– the sequence to display on a page (JSON handling is not yet built into sqlite3, so this is too painful to put into the settings column)contained
could point to users.id
as part of permissions (shame that the id has different types in the two tables)<div class="thing connected" draggable="true" id="thing-zb-14b457fffe4f65ce" data-layout-index="4">
Wow, this is thorough! Some thoughts:
containers
table containing id
, name
, etc., then the description in things
could be amended to add a containers
array. This is essentially what we do for the floorplan and positioning on the main Things page.Thanks for the response @mstegeman
No problem, that’s far and distant.
I’d like to have a Floorplan with some Things left off (e.g. virtual things like timers, email and weather). I’d like to have a larger scale partial Floorplan showing some Things in more detail.
Wouldnt groups be also suitable for a multiples things device ?
probably not.
Without a further explanation of what you mean, I can’t provide a more meaningful explanation.