roblans / ZWave4Net

ZWave4Net is a .NET library that interfaces with the Aeotec / Aeon Labs Z-Stick.
MIT License
41 stars 33 forks source link

Get raw data from the sensor #24

Closed OsvaldoVallati2 closed 6 years ago

OsvaldoVallati2 commented 6 years ago

Hi, I have an Aeon MultiSensor 6 and the Z-stick connected to my PC and I would like to read the sensor’s measurement (Hum/temp/Lux) every 5 minutes. I followed this https://github.com/roblans/ZWave4Net/issues/12 and I am able to connect to the sensor and change the configuration with the code.

At this point, how can I get all the measurements and display them on the console?

I am very new on this and I really appreciate some help. Thanks!

roblans commented 6 years ago
            // create a multiSensor6 for the node
            var multiSensor6 = new ZWave.Devices.Aeon.MultiSensor6(node);

            // subscribe to events
            multiSensor6.HumidityMeasured += (s, e) => Console.WriteLine($"Humidity: {e.Meassure}");
            multiSensor6.LuminanceMeasured += (s, e) => Console.WriteLine($"Luminance: {e.Meassure}");
            multiSensor6.TemperatureMeasured += (s, e) => Console.WriteLine($"Temperature: {e.Meassure}");
            multiSensor6.UltravioletMeasured += (s, e) => Console.WriteLine($"Ultraviolet: {e.Meassure}");
            multiSensor6.VibrationDetected += (s, e) => Console.WriteLine($"VibrationDetected");
            multiSensor6.MotionDetected += (s, e) => Console.WriteLine($"MotionDetected");
            multiSensor6.MotionCancelled += (s, e) => Console.WriteLine($"MotionCancelled");
            multiSensor6.WakeUp += (s, e) => Console.WriteLine($"WakeUp");

            // wait
            Console.ReadLine();
OsvaldoVallati2 commented 6 years ago

Thanks for the help! it worked.

Next step will be to connect more than one sensor in the network and synchronise the readings. I will let you how it goes!

Thanks Osvaldo

OsvaldoVallati2 commented 6 years ago

Hi, I am trying to read my Multisensors 6 using the zWaveChannel with the the script below.

var channel = new ZWaveChannel ("COM5");
channel.Open();                     
controller.Channel.Log = Console.Out;

I configured the sensors to wake up and read every 4 minutes, and on the console I get those lines for each node:

Event: NodeID:003 Command:[Class:SensorMultiLevel, Command:5, Payload:01-22-01-11] Event: NodeID:003 Command:[Class:SensorMultiLevel, Command:5, Payload:05-01-2B] Event: NodeID:003 Command:[Class:Battery, Command:3, Payload:64] Event: NodeID:003 Command:[Class:SensorMultiLevel, Command:5, Payload:03-0A-00-73] Event: NodeID:003 Command:[Class:SensorMultiLevel, Command:5, Payload:1B-01-00]

I assume that my readings are inside the Payload.. How can I get the data from those strings?

Thanks Osvaldo

roblans commented 6 years ago

Hi Osvaldo

Don't use the ZWaveChannel class, this class is only used for low-level communication with the Z-Stick, use the ZWaveController class instead.

This is a complete sample how to use the Multisensors 6:

    private static async Task MultiSensor6Sample()
    {
        // create the controller
        var controller = new ZWaveController("COM5");

        // open the controller
        controller.Open();

        // get all nodes
        var nodes = await controller.GetNodes();

        // get the node for the MultiSensor6 (NodeID = 3)
        var node = nodes[3];

        // create a MultiSensor6 Device for the node
        var multiSensor6 = new ZWave.Devices.Aeon.MultiSensor6(node);

        // subscribe to events
        multiSensor6.HumidityMeasured += (s, e) => Console.WriteLine($"Humidity: {e.Meassure}");
        multiSensor6.LuminanceMeasured += (s, e) => Console.WriteLine($"Luminance: {e.Meassure}");
        multiSensor6.TemperatureMeasured += (s, e) => Console.WriteLine($"Temperature: {e.Meassure}");
        multiSensor6.UltravioletMeasured += (s, e) => Console.WriteLine($"Ultraviolet: {e.Meassure}");
        multiSensor6.VibrationDetected += (s, e) => Console.WriteLine($"VibrationDetected");
        multiSensor6.MotionDetected += (s, e) => Console.WriteLine($"MotionDetected");
        multiSensor6.MotionCancelled += (s, e) => Console.WriteLine($"MotionCancelled");
        multiSensor6.WakeUp += (s, e) => Console.WriteLine($"WakeUp");

        // wait for keypress
        Console.ReadLine();

        // close the controller
        controller.Close();
    }

Regards,

Rob.

OsvaldoVallati2 commented 6 years ago

Thanks for the suggestion! Iit worked, I just changed a bit to have indication of the nodeID and the time stamp of the readings. Thanks again, Osvlado

                    // subscribe to events
                    multiSensor6.HumidityMeasured += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_"+ $"Humidity: {e.Meassure} " + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));
                    multiSensor6.LuminanceMeasured += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_" + $"Luminance: {e.Meassure}" + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));
                    multiSensor6.TemperatureMeasured += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_" + $"Temperature: {e.Meassure}" + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));
                    multiSensor6.UltravioletMeasured += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_" + $"Ultraviolet: {e.Meassure}" + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));
                    multiSensor6.VibrationDetected += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_" + $"VibrationDetected" + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));
                    multiSensor6.MotionDetected += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_" + $"MotionDetected" + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));
                    multiSensor6.WakeUp += (s, e) => Debug.WriteLine("MultiSensor_" + SensorID + "_" + $"WakeUp" + " _Time_" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss"));