Giter Club home page Giter Club logo

Comments (12)

Apollon77 avatar Apollon77 commented on June 2, 2024 1

Yes, we are currently about to finalize the new Devices High level API which will have full support for this ... I will leave open and poke once we have a nightly to try it

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024 1

All right ... I will also try to simplify the examples code wise a bit to have better focus on the relevant stuff :-)

Main difference is that some examples really work as "cli tools" and so there is more code needed

from matter.js.

seriousme avatar seriousme commented on June 2, 2024 1

It clearly shows how to use the API by putting the CLI stuff at the end.

Nice work!

The CLI stuff feels a bit repetitive, maybe something like

getNumberVar(key, default).{
 return environment.vars.number(key) ?? deviceStorage.get(key, default);
}

const passcode = getNumberVar("passcode", 20202021);
const discriminator = getNumberVar("discriminator", 3840) ;

could help ;-)

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024

PS: If you need it faster then check out what the current device classes do and adopt it for WC ... in fact all clusters are there, just implementation needed.

from matter.js.

seriousme avatar seriousme commented on June 2, 2024

Thanks for the quick reply !

I have time, so I'll wait for the nightly :-)

KInd regards,
Hans

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024

If you like a "pre look" ...will look like that https://github.com/project-chip/matter.js/blob/device-gen/packages/matter-node.js-examples/src/examples/IlluminatedRollerShade.ts

from matter.js.

seriousme avatar seriousme commented on June 2, 2024

Thanks, it looks less complex than the current interface.

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024

compared to what? Ok the other examples have a lot of "boiler plate code" to make anything configurable ... this is completely missing in the example link I sent you ... because this adapter just logs stuff :-) The other examples can be used as CLI tool directly. Or what you mean?

from matter.js.

seriousme avatar seriousme commented on June 2, 2024

When I compare:

const onOffDevice = isSocket ? new OnOffPluginUnitDevice() : new OnOffLightDevice();
onOffDevice.addOnOffListener(on => commandExecutor(on ? "on" : "off")?.());
onOffDevice.addCommandHandler("identify", async ({ request: { identifyTime } }) =>
logger.info(`Identify called for OnOffDevice: ${identifyTime}`),
);
/**
* Create Matter Server and CommissioningServer Node
*
* To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a
* commissioningServer to it and add the just created device instance to it.
* The CommissioningServer node defines the port where the server listens for the UDP packages of the Matter protocol
* and initializes deice specific certificates and such.
*
* The below logic also adds command handlers for commands of clusters that normally are handled internally
* like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands
* are called.
*/
this.matterServer = new MatterServer(storageManager, { mdnsInterface: netInterface });
const commissioningServer = new CommissioningServer({
port,
deviceName,
deviceType: DeviceTypeId(onOffDevice.deviceType),
passcode,
discriminator,
basicInformation: {
vendorName,
vendorId: VendorId(vendorId),
nodeLabel: productName,
productName,
productLabel: productName,
productId,
serialNumber: `node-matter-${uniqueId}`,
},
delayedAnnouncement: hasParameter("ble"), // Delay announcement when BLE is used to show how limited advertisement works
activeSessionsChangedCallback: fabricIndex => {
console.log(
`activeSessionsChangedCallback: Active sessions changed on Fabric ${fabricIndex}`,
commissioningServer.getActiveSessionInformation(fabricIndex),
);
},
commissioningChangedCallback: fabricIndex => {
console.log(
`commissioningChangedCallback: Commissioning changed on Fabric ${fabricIndex}`,
commissioningServer.getCommissionedFabricInformation(fabricIndex)[0],
);
},
});
// optionally add a listener for the testEventTrigger command from the GeneralDiagnostics cluster
commissioningServer.addCommandHandler("testEventTrigger", async ({ request: { enableKey, eventTrigger } }) =>
logger.info(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`),
);
/**
* Modify automatically added clusters of the Root endpoint if needed
* In this example we change the networkCommissioning cluster into one for "Wifi only" devices when BLE is used
* for commissioning, to demonstrate how to do this.
* If you want to implement Ethernet only devices that get connected to the network via LAN/Ethernet cable,
* then all this is not needed.
* The same as shown here for Wi-Fi is also possible theoretical for Thread only or combined devices.
*/
if (hasParameter("ble")) {
// matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.
// To offer e.g. a "Wi-Fi only device" (or any other combination) we need to override the Network Commissioning
// cluster and implement all the need handling here. This is a "static implementation" for pure demonstration
// purposes and just "simulates" the actions to be done. In a real world implementation this would be done by
// the device implementor based on the relevant networking stack.
// The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8
commissioningServer.addRootClusterServer(DummyWifiNetworkCommissioningClusterServer);
}
commissioningServer.addDevice(onOffDevice);
await this.matterServer.addCommissioningServer(commissioningServer);
/**
* Start the Matter Server
*
* After everything was plugged together we can start the server. When not delayed announcement is set for the
* CommissioningServer node then this command also starts the announcement of the device into the network.
*/
await this.matterServer.start();

to:

* Our Matter node.
*/
const node = new ServerNode({
id: "excelsior1000",
productDescription: {},
commissioning: {
passcode: 20202021,
discriminator: 3840,
},
basicInformation: {
vendorName: "Acme Corporation",
productName: "Excelsior 1000 EZ-Niteβ„’",
vendorId: 0xfff1,
productId: 0x8000,
serialNumber: "1234-12345-123",
},
parts: [
{
type: WindowCoveringDevice.with(RollerShade),
id: "shade",
number: 1,
},
{
type: OnOffLightDevice.with(ValanceLight),
id: "valance",
},
],
});
await node.run();

The latter looks more simple, but maybe that is just visual due to the comments sections and the BLE inclusion.
Once I really start coding with it I'll probably have a better feel for it ;-)

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024

I also tried to simplify the examples a bit (beside DevicesFull because it's goal is to show all the fancieness) ... by trying still to show a bit whats possible in practice.

WDYT?

https://github.com/project-chip/matter.js/blob/03ee51b6505407f62f8bf3a1d96310f0d11cef5f/packages/matter-node.js-examples/src/examples/DeviceNode.ts

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024

Thank you, Because the storage key and variable key is not always the same I think I leave it as is ... it was moved "out of sigth" to show that config needs to code from somewhere :-)
If it has the effect for the rest I planned the all fine :-)

from matter.js.

Apollon77 avatar Apollon77 commented on June 2, 2024

0.8 landed also first nightly is available on npm using @dev ... so have fun

from matter.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.