mr-markus / zigbeenet Goto Github PK
View Code? Open in Web Editor NEWA .NET Standard library for working with ZigBee
License: Eclipse Public License 1.0
A .NET Standard library for working with ZigBee
License: Eclipse Public License 1.0
To get an overview of existing badges take a look at https://github.com/dwyl/repo-badges. I don’t know if they are all available for a C# project but I‘ll check it out if you want.
I think it would be a good possibility to present the quality of the code.
But we have to discuss which badges we want to use first.
Regards.
Set up a test project so unit testing can begin.
A end user should probably only need to do:
var zigbeeInt = ZigbeeNet.CC2531(); // Static function to initialize the interface
zigbeeInt.PacketReceived += MyPacketHandler;
zigbeeint.Send(amazing stuff);
Originally posted by @eiaro in #6 (comment)
Hi there,
do you plan to support the digi Xbee device too? Looking at #29 you will. But is there a timeline when you will begin implementing it?
Really great work so far guys!
Let me know if you need help.
There are many clusters and commands in the ZigBee standard which have all the same structure and methods.
So it should be possible to create them by a code generator and a ressource file.
As an existing resource file it could be used this file from zsmartsystems
The generated code should be outputted here: ZigbeeNet/ZigBeeNet/ZCL/Clusters/
At the moment there are already some clusters which were written by hand, but they can be overwritten with generated code.
It would be important that the documentation will be generated as XML comments, too.
Use Threadsafe enumeration for the queue
ZigbeeNet/src/ZigbeeNet.CCZnp/CCZnp.cs
Line 28 in 12d61ee
We need your help!
Do you already have tested some devices with ZigbeeNet? Please let us know which devices and which clusters or functionality you have tested so that we can create a "supported devices" section in our README
Thanks!
Currently we are working with ShareProjects, so that we are able to create different targets.
But because this project should be a netstandard library there is no reason to do this. All referencing projects should be at version that support netstandard 2.0 as minimum.
For the serialport class you have to implement the IZigBeePort class in your project (see ZigBeeNetPlayground example)
If there is a preferred code style, please set up a ReSharper rules file for it and I will follow.
ZigbeeNet/ZigbeeNet/CC/CCZnp.cs
Line 407 in f78f6e5
ZigBeeDiscoveryExtension.StartScheduler only runs the task once, it should start the task periodically instead.
To make the work with each other easier I suggest to get closer to GitFlow for this project.
At least a separation of master (deployed) and develop (current alpha) is useful and advisable. Especially with regard to issue #33 and possible auto builds of the nuget packages.
For better logging experience it would be great if the caller of ZigbeeNet could choose his own logger library.
So an interface with common Methods like Log(LogLevel level) could be a possible solution.
Ideas are wellcome at all time :-)
I have a Nortek Security Control (https://www.amazon.com/GoControl-CECOMINOD016164-HUSBZB-1-USB-Hub/dp/B01GJ826F8/ref=asc_df_B01GJ826F8/?tag=hyprod-20&linkCode=df0&hvadid=193989831776&hvpos=1o1&hvnetw=g&hvrand=11729360482103299148&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9031961&hvtargid=pla-312424172362&psc=1). What do I need to get this running? Can I just treat this as a serial port? I have some programming experience if we need to build some sort of adapter for this, though I'd probably need a little help to get started as I don't do much hardware programming.
This code need to be fixed so the CC protocol is implemented correct. My assumptions when writing it was more than slightly off, but should be a good basis.
Reading and parsing
ZigbeeNet/ZigbeeNet/CC/CCZnp.cs
Lines 386 to 412 in 0d06cf9
Sending and waiting for response
ZigbeeNet/ZigbeeNet/CC/CCZnp.cs
Lines 509 to 514 in 0d06cf9
Code does now allow the Cmd1
ZigbeeNet/ZigbeeNet/CC/CCZnp.cs
Lines 494 to 507 in 0d06cf9
Currently there are two Meta classes (ZpiMeta and ZclMeta) that parse JSON files and provide Methods to get instances for ZpiObject and ZclCommand.
ZpiMeta
public static ZpiObject GetCommand(SubSystem subSystem, byte cmdId)
{
return ZpiObjects[subSystem].SingleOrDefault(cmd => cmd.CommandId == cmdId);
}
ZclMeta
public static ZclGlobalCommand GetGlobalCommand(byte cmdId)
{
return GlobalCommands.Single(fc => fc.Id.Equals(cmdId));
}
public static ZclClusterCommand GetClusterCommand(string cluster, string cmd)
{
return ClusterCommands.Single(fc => fc.Cluster.Equals(cluster) && fc.Name.Equals(cmd));
}
This was just a first solution to get an object with correct and typed Parameters as a ArgumentCollection.
As next step a code generation with T4 template could be a possible solution. Code in meta classes for parsing JSON file can be reused.
But i think that we still need the posibillity to dynamically create an instance of an object because we do not know the type if an message is incomming. At this point we have to parse the object and ist arguments into the right type.
The comparison of AssociatedDevices, BindingTable, Neighbors and Routes in UpdateNode() always return false because we use the default Object.Equals method which just compares the references.
We should compare the actual content of the list with something like this:
http://msdn.microsoft.com/en-us/library/bb348567%28v=vs.110%29.aspx
Also why are they List whereas in the java project they are HashSet
Does it make sense, for example, to expand the autogenerated ZclCluster classes in derived classes?
Currently I am testing with an Ikea-Tradfi bulb. Here the imprinted Model Id is stored in the ZclBasic cluster under the vendor-specific attribute 0x000a. Currently I am expanding the cluster in my own code.
https://github.com/Mr-Markus/ZigbeeNet/blob/develop/libraries/ZigBeeNet/ZCL/ZclCluster.cs#L352
We should avoid to call Task.Result. Instead we should use async/await.
currently most ZDO and ZCL request/response do not handle well properties that are list. They rely on the Object.ToString() method that just print the type of the list:
[14:21:10 DBG] RX CMD: NetworkAddressResponse [20978/0 -> 0/0, cluster=32768, transId=, status=SUCCESS, ieeeAddrRemoteDev=17880104E15812, nwkAddrRemoteDev=20978, startIndex=0, nwkAddrAssocDevList=System.Collections.Generic.List`1[System.Int32]]
we need to see the content of the list
For ZCL that means the code generator need to be modified to handle lists
Any plan or anyone currently working on supporting Ember stack?
I may need this in a near future, so I wanted to ask before I start trying to add it myself.
Since the project is a port of zsmartsystems, which is equivalent to a copy in the broadest sense, the copyright and also the license must be respected.
zsmartsystems/com.zsmartsystems.zigbee uses the EPL-1.0.
This is a CopyLeft license so the notes as well as the license of the original project have to be taken over. MIT in this form is not allowed.
I recommend a quick customization so you don't get into legal trouble as the owner ;)
There have to be a solution for NetworkStateSerialization, which means that if network is shutdown or startup all known devices should still be there
Instead of using reflection to create the ZclCluster instances we should consider using factory functions.
Like here https://github.com/Mr-Markus/ZigbeeNet/blob/develop/libraries/ZigBeeNet/ZigBeeNetworkManager.cs#L992 we should avoid to call "return await" if possible as the compile will generate a state machine. Just return the Task direcly. In most cases it is not necessary to call await when there is nothing to do after awaiting the task. (It might by when combined with using)
Actually the implementation for Texas Instruments CC2531 hardware is within the ZigBeeNet shared project.
If there will be more implementations the target assembly will always contain all hardware implementations even if you only use one of it.
To minimize the assembly file and make development easier it will be better to create seperate project files for each hardware. Also creation of NuGet packages will be simplified and correct target platform can be choosed.
Following structure:
The base library ZigBeeNet should always be netstandard, but CC2531 needs System.IO.Ports.SerialPort which is only possible on full framework or .NET Core 3.0 and newer or with explicit reference with it's package from NuGet.
For this case we need seperate assemblies and NuGet packages
Hi All,
Does the current XBee support work for a ConBee II dongle please?
Thanks,
Jim
This might be resolved with a TaskCompletionSource. This might be a breaking change because we have to change the Start() method to return a Task instead of void.
Here is an example of a refactored while loop with a TaskCompletionSource:
https://github.com/zigbeenet/ZigbeeNet/blob/master/src/ZigBeeNet/Transaction/ZigBeeTransaction.cs#L82
ZigBeeTransaction.CommandReceived(ZigBeeCommand) gets called more than once in case of a transaction match. This should not happen I think. Maybe the ZigBeeNetworkManager has to deal with it by removing the Transaction/CommandListener earlier.
I'm trying to configure attribute reporting on a light bulb, so that the value is automatically reported to my program when on/off status change or every 10 seconds:
var cluster = endpoint.GetInputCluster(ZclOnOffCluster.CLUSTER_ID);
if (cluster != null)
{
var result = await cluster.Bind(networkManager.LocalIeeeAddress, 1);
if (result.IsSuccess())
{
result = await ((ZclOnOffCluster)cluster).SetOnOffReporting(1, 10);
if (result.IsSuccess())
{
}
}
}
but I always get the following response:
[11:21:46 DBG] RX APS: ZigBeeApsFrame [sourceAddress=20978/11, destinationAddress=0/1, profile=260, cluster=6, addressMode=0, radius=0, apsCounter=0, payload=24 14 7 140 0 0 0]
[11:21:46 DBG] RX ZCL: ZclHeader [frameType=ENTIRE_PROFILE_COMMAND, manufacturerSpecific=False, direction=SERVER_TO_CLIENT, disableDefaultResponse=True, manufacturerCode=0, sequenceNumber=14, commandId=7]
[11:21:46 DBG] RX CMD: ConfigureReportingResponse [On/Off: 20978/11 -> 0/1, cluster=6, transId=14, Status=SUCCESS, Records=[Attribute Status Record: status=UNREPORTABLE_ATTRIBUTE, direction=False, attributeIdentifier=0,]]
first I don't know if I need to bind? I'm not clear what a bind request does and when I should send it?
I tried with or without bind, I tried with different attributes but I always get status=UNREPORTABLE_ATTRIBUTE
any idea? have you ever tested reporting?
Note: see my PR #77 for some fixes needed for bind and config reporting command
There should be NuGet packages for the ZigBeeNet libraries on nuget.org
They should be provided with lowest possible version
See #32 which have to be done first
Following packages should be created first:
Creating NuGet packages should be done with AppVayor as part of CI
Reference to local projects will make project hard to maintain. Either include it in the project, or separate it out as a own project and publish a Nuget for it.
Avoid while (true) { .. } during TI CC2531 startup
ZpiObject.cs(120,26): error CS0246: The type or namespace name 'DEBUG' could not be found (are you missing a using directive or an assembly reference?) [/home/pi/src/ZigbeeNet/src/ZigbeeNet.CCZnp/ZigbeeNet.CC.csproj]
ZpiSREQ.cs(80,24): error CS0246: The type or namespace name 'DEBUG' could not be found (are you missing a using directive or an assembly reference?) [/home/pi/src/ZigbeeNet/src/ZigbeeNet.CCZnp/ZigbeeNet.CC.csproj]
Currently ZigbeeNet is not 100 % netstandard, because it references unpi-net which uses SerialPort
class that is not availible in netstandard.
A solution for ZigbeeNet is needed, that it is not necessary to reference unpi-net directly
Any idea?
For example:
Log.Error("Synchronous command send failed due to unexpected exception.", ex);
will not log the exception as there is no parameter in the message template. So we should replace it with:
Log.Error("Synchronous command send failed due to unexpected exception. {Exception}", ex);
or I saw that Serilog also have methods that takes an exception as the first parameter:
public static void Error(Exception exception, string messageTemplate);
but I'm not sure how it works.
ZigbeeNet/ZigbeeNet/CC/CCZnp.cs
Line 403 in 0d06cf9
At this Point it can happen that a packet with type AREQ can be read from InputStream. This is defined by TI in UNPI
Asynchronous Request transfer initiated by Host Asynchronous Indication – transfer initiated by NP. Both types of asynchronous messages use the same message type bit field (0x02). The type of message (request/indication) depends on which processor initiated the transaction.
Two Scenarios:
You send an SREQ and will return a SRSP with Status. But as second Response you receive an AREQ packet, too.
Example: nodeDescReq which is send as SREQ but awaits a SRSP with Status if it was sent correct and a second AREQ that contains device info
This is an AREQ packet that is send from client-to-server (Server = end device)
An end device in yout Network (e.g. Thermostat) is sending you new Information because Temperatur changed.
This is also an AREQ packet. But is is send from server-to-client (Server = end device)
For Scenario 1 i already created a JSON mapping file zdo_ReqRspMap.json that defines which SREQ awaits which AREQ packet, too. In class file ZpiObject the property public ZpiObject IndObject
holds the Information if there is an AREQ Response awaited
I think this Information have to be used here
I think most of the code is already there, it just a matter of testing it and fixing potential problems.
When a node is first added NodeAdded is called, but the node passed as parameter has an empty Endpoints dictionary, which I guess is expected?
Then ZigBeeDiscoveryExtension does its job and queries the node for its capabilities. The Endpoints dictionary is populated, but NodeUpdated is never called.
I think ZigBeeNetworkManager.RefreshNode() is supposed to trigger the NodeUpdated callback for all the listeners but it never does because it always returns here:
// Return if there were no updates
if (!currentNode.UpdateNode(node))
{
Log.Debug("{IeeeAddress}: Node {NwkAddress} is not updated", node.IeeeAddress, node.NetworkAddress);
return;
}
I don't understand how it is supposed to work: currentNode.UpdateNode(node) always returns false because here currentNode and node are the same reference so UpdateNode correctly says they are equal.
I'm testing with the PlayGround sample
Hi,
is anyone able to help me to get device Information (model) from that type of bulb?
The "manufacturer id" is already discovered but i cant get more Information.
thx
Setup a CI to avoid code that cannot compile to enter master branch.
Because LibLog often creates errors if you reference the library in your project we would replace it with serilog
Hello,
I saw your code last week and have implemented the level/brightness cluster.
(pull request is coming when the remaining problems are solved)
The 'only' problem is that I can't seem to get it working.
I believe I have to bind my device (Ikea Tradfri lamp), before it accepts the commands I send to it.
With debug logging enabled, I can see incoming DeviceAnnounce messages. But I think its not enough to just process this message and let the device be added to my nodes.
In the cluster class I also found a Bind method, but this also doesn't seem to work.
Maybe it's a problem with the Zigbee link key, but the cc2531 has no support for it? (at least the current code doesn't)
Is there a possibility you could help me with this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.