Improved Z-Wave message handling in C#

February 6th, 2010 by Henrik Leidecker Jørgensen | Edit this entry 2 comments »

In this article a queue is implemented to allow the device objects to request messages to be send at any time. The messages are enqueued and then send to the Z-Wave controller when possible.
An additional thread is created to decouple the sending and receiving of messages. It will dequeue messages from the SendMessage queue and send them to the Z-Wave controller.
The entire discovery functionality will be moved to the Controller class and a mechanism is provided to allow other objects to subscribe to events concerning updates to the Z-Wave network e.g. added nodes.

class ZWavePort
{
    public delegate void MessageHandler(byte[] sentMessage, byte[] receivedMessage);
 
    ...
 
    private Thread senderThread
 
    ...
 
    private PriorityQueue<zwavemessage , ZWaveMessagePriority> queue = new PriorityQueue</zwavemessage><zwavemessage , ZWaveMessagePriority>();
 
    ...
 
}
 
class Controller : ZWaveNode
{
    public event DiscoveryEventHandler DiscoveryEvent;
 
    ...
 
    private Dictionary<byte , ZWaveNode> devices = new Dictionary</byte><byte , ZWaveNode>();
 
    ...
 
    public void EnqueueMessage(ZWaveMessage message)
    {
        queue.Enqueue(message, message.Priority);
    }
 
    ...
 
}</byte></zwavemessage>

» Read more: Improved Z-Wave message handling in C#

Z-Wave device discovery in C#

January 14th, 2010 by Henrik Leidecker Jørgensen | Edit this entry No comments »

This article will cover the C# implementation of the protocol discussed in ‘Device discovery in Z-Wave‘.
The actual changes caused by the new requests are limited to a reimplementation of the callback id. Not all responses support the callback id and this affects the completion of the message sequences.
The real challenge is connected to the fact that the messages send from Z-Wave controller to the C# client are used for more than completing the message sequences – the content itself is interesting as it reveals information about the devices connected to the Z-Wave network.

The identification of Z-Wave devices basically consists of two new requests.

  • Ask for the node ids in the Z-Wave network (discovery)
  • Ask for the type of each node

A Controller is added to the device classes.

class Controller : ZWaveNode
{
    ....
 
    public void Discovery()
    {
        ...
    }
 
    public void GetNodeTypes(byte nodeId)
    {
        ...
    }
 
    ....
 
}

» Read more: Z-Wave device discovery in C#

Forum at digiWave.dk

January 12th, 2010 by Henrik Leidecker Jørgensen | Edit this entry No comments »

The new forum is now available at digiWave.dk.

The purpose is to centralize the discussion about Z-Wave software development. The idea is to complement sites like ZWave.dk og Domoticaforum.eu.

The forum will be updated as articles about new topics are being published at digiWave.dk.

Device discovery in Z-Wave

January 7th, 2010 by Henrik Leidecker Jørgensen | Edit this entry 2 comments »

It is possible to request a list of connected devices from the Z-Wave controller. This article will take a look at the requests and responses related to device discovery in Z-Wave.
The article is part of a series of articles with focus on the Z-Wave protocol and how to implement it in C#. Reading the previous articles will be an advantage, but it is not mandatory.

It is possible to have 232 Z-Wave devices in one network. Each device is identified by a node id. A number of common attributes are defined for the devices e.g. type. The Z-Wave protocol defines numerous device types but only the Controller, Switch and Dimmer will be addressed in this article.
It is relatively straight forward to identify the devices in the Z-Wave network handled by the Z-Wave controller.

  1. Ask the Z-Wave controller about the registered node ids
  2. Ask the Z-Wave controller about the type linked to each of the node ids

» Read more: Device discovery in Z-Wave

The Z-Wave protocol in C# – Part 3

January 2nd, 2010 by Henrik Leidecker Jørgensen | Edit this entry 5 comments »

In this article the message handling is being improved and a Dimmer is added to the device classes.

The article is building upon a number of other articles previously published on this site. It is highly recommended to read those before proceeding.

A message sequence has to be terminated before a new one can be initiated – in order to comply with the specifications. The current strategy is relying on the device object to determine when a message sequence is completed and to send a notification.
In the previous article only one device was being used and the message sequence for switching on node ‘6′ was looking like the below sequence.

/*
    Message sent: 01 09 00 13 06 03 20 01 FF 05 3B
    Message received: 06
    Message received: 01 04 01 13 01 E8
    Message sent: 06
*/

All the messages coming from the Z-Wave controller were intented for only that specific device object. In this article multiple devices are in play and this adds a complexity in terms of identifying the owner of the messages from the Z-Wave controller. All the device objects will signal ‘message completed’ if they can’t distinguish between messages that they are suppose to react to and those that are not relevant. Remember that all incoming messages are passed on to all the device objects.
The Z-Wave protocol specifies something called a callback id. It can be used to keep track of request/response pairs. A callback id is being defined every time a device object sends a request. » Read more: The Z-Wave protocol in C# – Part 3

The Z-Wave protocol in C# – Part 2

December 27th, 2009 by Henrik Leidecker Jørgensen | Edit this entry 2 comments »

In the previous article the client had to control the timing of the message sending. This responsibility is now moved away from the client. A new set of classes are introduced to represent the Z-Wave devices that the client is communicating with.

The functionality of the implementation remains the same as for the previous article. The Z-Wave device is switched off and then on.

Switch s = new Switch(nodeId, zwavePort)
s.Off();
s.On();

It is important to understand the previous articles to get the most out of this example.

The same devices and configurations are used as in ‘The Z-Wave protocol in C#‘.

The Switch class is responsible for building the messages for switching the Z-Wave device on and off and handling the incoming messages from the Z-Wave controller.

class Switch : ZWaveNode
{
    public void On()
    {
        ...
    }
 
    public void Off()
    {
        ...
    }
 
    public void MessageHandler(byte[] message)
    {
        ...
    }
}

» Read more: The Z-Wave protocol in C# – Part 2

The Z-Wave protocol in C# – Part 1

December 13th, 2009 by Henrik Leidecker Jørgensen | Edit this entry 5 comments »

The example developed in this article will be able to switch on a Z-Wave device and the switch it off again. This requires some of the basic Z-Wave protocol elements to be implemented.

It is important to understand the two previous articles to get the most out of the example shown here.

For this example the same devices and configurations are used as in ‘An introduction to Z-Wave programming in C#

‘.
The ZWavePort class will be responsible for the basic communication and protocol handling.

class ZWavePort
{
    ...
}

» Read more: The Z-Wave protocol in C# – Part 1

An introduction to the Z-Wave protocol

December 8th, 2009 by Henrik Leidecker Jørgensen | Edit this entry 2 comments »

In the first article about Z-Wave programming in C# the program was able to either switch on or switch off a Z-Wave device. In this article some of the basic principles of the Z-Wave protocol will be explored. This will provide the basic understanding for a modification to the code that will be done in a later article. With the modification to the code it will be able to switch the device on and then switch it off . This does not sound like much but it requires the C# program to follow the Z-Wave protocol.

The Z-Wave protocol is based on the following principle.Messaging1

» Read more: An introduction to the Z-Wave protocol

An introduction to Z-Wave programming in C#

November 30th, 2009 by Henrik Leidecker Jørgensen | Edit this entry 3 comments »

Z-Wave is a protocol for wireless communication with home appliances e.g. lamps and sensors. Z-Wave can be used for switching on, switching off, monitoring etc.
It is possible to learn more about Z-Wave by reading one of the previous articles (in Danish) on this site or at Z-Waves.dk.

zwaves-logo-new2

It is easy to get started with Z-Wave programming. One important note here is that the specifications aren’t publicly available. The example in this article can be used for switching a lamp on or off.

» Read more: An introduction to Z-Wave programming in C#