lifeemotions / knx.net

KNX.net provides a KNX API for .NET
MIT License
102 stars 47 forks source link

How to connect to KNX/IP router with desktop application? #10

Closed AnaKatarina closed 9 years ago

AnaKatarina commented 9 years ago

Hello everybody :)

First of all, I'm sorry if my english is bad. I'm Ana Katarina from Croatia and I really, really need solution for my problem. I would be very thankful if you could help me :)

My task is to make a desktop application that will be able to connect with the KNX / IP router and receive telegram from weather station and save that parameters to database. I'm using Schneider knx router and ETS 3 software. What should I do? I have no one to ask, KNX is in Croatia still unknown, and I promise that I'm just a student who is stuck with this problem.

I'm using Visual Studio 2013 pro and these classes of Mr. David. I'm sending you guys how I wrote code for that solution, but it doesn't work.

using KNXLib; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

namespace zavrsni { public partial class Form1 : Form { string IPadresa; string Port;

private static KnxConnection _connection;

public Form1()
{
    InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

}

private void btnPotvrda_Click(object sender, EventArgs e)
{
    IPadresa = txtIPadresa.Text;
    Port = txtPort.Text;

    int port = Convert.ToInt32(Port);

    try
    {
        _connection = new KnxConnectionRouting(IPadresa, port);
        _connection.Connect();

        _connection.KnxEventDelegate += new KnxConnection.KnxEvent(Event);
        _connection.KnxStatusDelegate += new KnxConnection.KnxStatus(Event);

        _connection.Action("4/1/1", _connection.ToDataPoint("9.001", 24.0f));
    }
    catch (Exception es)
    {
        txtStatus.Text = es.Message;
    }
}

private void Event(string address, string state)
{
    float temp = (float)_connection.FromDataPoint("9.001", state);
    txtStatus.Text = "Temperature: " + temp;          
}      

} }

abelsilva commented 9 years ago

If you have an IP router I would advise you to connect using the KNXConnectionRouting constructor without any arguments, as you probably have the IP router with the defaults loaded. Make sure you are connected on the same network as the IP router (check if you can ping it).

You need also to configure the IP router using ETS to forward everything between IP<->TP in order to receive the events from the weather station.

I don't understand why you would send the Action to 4/1/1, if you only want to receive events you don't need to send this action.

I also don't understand why you would convert every event to a temperature in the Event function, make sure you only convert what you want based on the address you configured using ETS.

Finally, I don't know which datapoints you want from the weather station, you will need to see what kind they are, e.g., 9.001 for temperature? 9.001 is implemented The datapoint for wind isn't.

AnaKatarina commented 9 years ago

I can ping it and I configure router to route all telegrams from weather station. My station sends rain as a bit- rain/no rain, temperature, brightness value-lux, is it morning or evening also as bit and wind speed in meters per second. Yes, I only want to receive events. How should I fix this line? So, in that case I can't use these classes for my project? :/ If I can't, do you know if anybody have similar library with all that datapoint?

AnaKatarina commented 9 years ago

image

abelsilva commented 9 years ago

With this library you could receive:

wind speed and brightness you need to check the weather station specs, but they are probably special datapoints and not generic byte values

You have the option to receive the values as byte and convert them, but you need to see the datapoint specs in order to know how to convert.

Regarding your code, you only need to remove the Action call and the FromDataPoint call. This will allow you to start seeing something.

I've seen other libraries but I've never used any of them.

abelsilva commented 9 years ago

9.005 is not implemented in this library at the moment

AnaKatarina commented 9 years ago

Can you maybe link me or recommend some libraries which can work with all datapoints I need? Maybe here on github?

abelsilva commented 9 years ago

The only one I recall is Calimero but is in Java, this one should have everything you need (i.e., all datapoints available) http://calimero-project.github.io/

In .net I've stumbled upon some but I don't recall the names, a simple search should show them

AnaKatarina commented 9 years ago

Well, then I'll try with Java. Thank you very much for your help :)

abelsilva commented 9 years ago

no problem! good luck!

AnaKatarina commented 9 years ago

In my university, LAN network is unicast, so it's really confusing to me because in every library I' ve been seen multicast address. On this picture below is shown multicast for routing, and unicast for tunneling. So my question is can I on the second IP address (picture below) write for example 192.168.2.125, and configure IP address on my laptop as 192.168.2.126 and then use that second unicast address for routing? Will that work? So at the application I will write that second address and default port 3671 and application will be connected to KNX/IP router? Is it enough to use only classes for connect to router and routing to receive telegrams?

If you have time I would love to if you can explain to me this procedure because you are an expert and it would be great hear your expert opinion, please

image

AnaKatarina commented 9 years ago

At my university*

abelsilva commented 9 years ago

That is only for the multicast address, check if the IP-Configuration 2 is to set the IP address

image

AnaKatarina commented 9 years ago

I see, but what is below Mulitcast address? Ip address for what? Unicast? At IP-Configuration 2 is subnet mask and gateway

What really bothers me is can I do an application for receiving telegrams if I use unicast?

image

abelsilva commented 9 years ago

Please send a screenshot of the configuration of the IP router from ETS, instead of a screenshot from a PDF

Different devices have different configuration menus

AnaKatarina commented 9 years ago

image

image

image

abelsilva commented 9 years ago

I missed this in the first screenshot

Change the IP address here and connect using Tunneling (unicast mode)

image

abelsilva commented 9 years ago

Sorry

Wrong image image