Reading meters using Dynamic IP addresses in GPRS connection
If you want to read your meters using GPRS connection you must have static IP addresses on your meters (SIM card). If you have dynamic IP addresses, your meter must always start the connection to the server. This means that your meter can send example scheduled push messages, but you can't read your meter when you want to. In public GPRS networks, connections are always established from modem to GPRS network, and never from GPRS network to modem. It is not possible for a client application to open a connection.- Static IP address: Meter or reading system can start the connection.
- Dynamic IP address: Meter always starts the connection.
Note! All meters do not support this. In this simple example server waits TCP/IP connections from the meters and when new TCP/IP connection is established it will start to act like DLMS Client. In this example I only show how to establish connection to the meter after meter has made TCP/IP connection. We have used meter that only makes connection to the server. Some meters are first sending some initializing information. Because this is manufacturer depending, I do'y go it through here.
Build
If you want to build source codes you need Nuget package manager for Visual Studio. You can get it here.Simple example
First we create TCP/IP server what listens given port. We are using GXNet as TCP/IP server.GXNet server = new GXNet(NetworkType.Tcp, 1234); server.OnClientConnected += OnClientConnected; server.Open();
GXNet server = new GXNet(NetworkType.TCP, 1000); GXListener listener = new GXListener(); server.addListener(listener); server.open(); //implement listener class public class GXListener extends Thread implements IGXMediaListener, IGXNetListener { }
/// <summary>New client is connected. </summary> /// <param name="sender">Server component.</param> /// <param name="e">Connection parameters,</param> private static void OnClientConnected(object sender, Common.ConnectionEventArgs e) { Console.WriteLine("Client {0} is connected.", e.Info); GXNet server = (GXNet)sender; try { using (GXNet cl = server.Attach(e.Info)) { GXDLMSReader cl = new Net.GXDLMSReader(media); cl.ReadAll(); //Create own thread for each meter if you are handling multiple meters simultaneously. //new Thread(new ThreadStart(cl.ReadAll)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
@Override public void onClientConnected(Object sender, ConnectionEventArgs e) { System.out.println(String.format("Client '%1$s' is connected.", e.getInfo())); GXNet server = (GXNet) sender; try { try (GXNet cl = server.attach(e.getInfo())) { readMeter(cl); } } catch (Exception ex) { System.out.println(ex.getMessage()); } }
Thats it. If you have any questions or ideas how to improve Gurux.DLMS component let us know or ask question in a Forum