Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. Adding IP Connectivity To Arduino Gurux Server Example

Adding IP connectivity to Arduino Gurux server example

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By bhatiasidharth.89 , 6 September, 2021
Forums
General discussion

Hi Mikko,

I wish to add IP connectivity to Arduino Gurux server example and read/write the demo meter over an IP connection with the Gurux DLMS Director software. My meter can connect to WiFi. Could you please guide my as to how I can proceed with this?

Regards
Sidharth

Profile picture for user Kurumi

Kurumi

4 years 9 months ago

Hi,

Hi,

If you want only support TCP/IP connection then it's easy.
You need to modify loop()-method. Replace Serial.available, Serial.readBytes and Serial.write with appropriate TCP/IP methods like: EthernetClient.available, EthernetClient.read and EthernetClient.write.

BR,
Mikko

bhatiasidharth.89

4 years 9 months ago

In reply to Hi, by Kurumi

Hi Mikko,

Hi Mikko,

Thanks. Do you have any sample for this?

Regards
Sidharth

bhatiasidharth.89

4 years 9 months ago

Hi Mikko,

Hi Mikko,

I tried to add WiFi to the Gurux sample Arduino code and as soon as I include the header file WiFi.h I get the following errors:

In file included from /Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi/src/WiFi.h:32:0, from /Users/sidharthbhatia/Documents/gurux_esp32_new/server/server.ino:36:
/Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi/src/WiFiSTA.h:43:101: error: conversion from 'long unsigned int' to 'IPAddress' is ambiguous
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
^
In file included from /Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/Arduino.h:150:0, from sketch/server.ino.cpp:1:
/Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/IPAddress.h:51:5: note: candidate: IPAddress::IPAddress(const uint8_t*)
IPAddress(const uint8_t *address);
^
/Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/IPAddress.h:50:5: note: candidate: IPAddress::IPAddress(uint32_t)
IPAddress(uint32_t address);
^
In file included from /Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi/src/WiFi.h:32:0, from /Users/sidharthbhatia/Documents/gurux_esp32_new/server/server.ino:36:
/Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi/src/WiFiSTA.h:43:140: error: conversion from 'long unsigned int' to 'IPAddress' is ambiguous
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
^
In file included from /Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/Arduino.h:150:0, from sketch/server.ino.cpp:1:
/Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/IPAddress.h:51:5: note: candidate: IPAddress::IPAddress(const uint8_t*)
IPAddress(const uint8_t *address);
^
/Users/sidharthbhatia/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/IPAddress.h:50:5: note: candidate: IPAddress::IPAddress(uint32_t)
IPAddress(uint32_t address);
^

exit status 1
Error compiling for board ESP32 Dev Module.

Regards
Sidharth

Profile picture for user Kurumi

Kurumi

4 years 9 months ago

Hi,

Hi,

WiFi.h was added and ESP32 Dev Module board is selected but this error can't be repeated.
There are some improvements for Arduino. Get the latest version and let me know if you have problems.

BR,
Mikko

bhatiasidharth.89

4 years 9 months ago

Hi Mikko,

Hi Mikko,

I tried with the latest code and also another PC but the issue still persists. I installed a fresh copy of Arduino IDE 1.0.6 and the latest ESP32 boards package using this link (https://dl.espressif.com/dl/package_esp32_index.json) and compiled it for the ESP32 Dev Module board as you have done. Please advise if you feel anything should be done differently to get this to work.

Regards
Sidharth Bhatia

Profile picture for user Kurumi

Kurumi

4 years 9 months ago

Hi,

Hi,

This was tested with this package:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/pack…

This is tested with your link and I let you know the results tomorrow.

BR,
Mikko

bhatiasidharth.89

4 years 9 months ago

Hi Mikko,

Hi Mikko,

Were you able to test this?
Also, I tested with both the packages, the one that you shared above and the one that I shared. It's the exact same issue with both the packages.

Regards

Profile picture for user Kurumi

Kurumi

4 years 8 months ago

Hi,

Hi,

Both work without problems. Is there a reason why you are using Arduino IDE 1.0.6? I was using the latest version 1.8.51.0. Maybe that is the reason.

BR,
Mikko

bhatiasidharth.89

4 years 8 months ago

Hi,

Hi,

I mistakenly wrote the Arduino IDE version as 1.0.6. It's actually 1.8.13. I am not able to understand what the issue is. I have tested with both ESP32 Arduino packages on 2 different computers by installing fresh copy of Arduino on both the computers but the issue is still there. Please advice as to what should be done.

Regards
Sidharth

Regards

Profile picture for user Kurumi

Kurumi

4 years 8 months ago

Hi Sidharth,

Hi Sidharth,

What I did is this:
1. Update board manager to https://dl.espressif.com/dl/package_esp32_index.json
2. Select "ESP32 Dev Module" as the board.
2. Added #include <WiFi.h> before #include <EEPROM.h>
3. Combile board.

I used the server example from GitHub as the template.

BR,
Mikko

bhatiasidharth.89

4 years 8 months ago

Hi Mikko,

Hi Mikko,

The compile errors issue is now solved. Thanks. I was including the #include <WiFi.h> line after #include "GXDLMSServer.h" which was creating the issue. After I added #include <WiFi.h> before #include <EEPROM.h> this issue got resolved.

But now I have another issue. Since I am using a WiFi connection to connect to the meter with TCP/IP I replaced Serial.available, Serial.readBytes and Serial.write with appropriate TCP/IP methods like: client.available, client.readBytes and client.write as you had suggested. To connect to the meter from DLMS Director I use the same configuration as with the serial connection except the following:
Media: Net
Host name: 192.168.101.11 (local IP of the ESP32 dev board)
Port: 80 (Port assigned in the code)
Protocol: Tcp

When I initiate connection from DLMS director I can see in the debug logs of the ESP32 dev board that a new client has connected and these debug logs -> :svr_isTarget...:Connecting using Low authentication...
By printing debug information I could also see that the code tries to send a reply to the client of size 32 bytes. But the connection on the DLMS director does not succeed and times out. Please help me with this. Please let me know if you need any other information in this regard.

To use the TCP/IP connection I am using following code in loop():
void loop() {
static unsigned char tmp[50];
uint32_t start = time_current();
int available;
//Execute invokes when needed.
if (executeTime <= start)
{
Server.run(start, &executeTime);
}

WiFiClient client = server.available(); // Listen for incoming clients

if (client)
{
GXTRACE("New Client.", NULL);
if (client.connected())
{
delay(1000); // If this delay is not there the data from client is not received completely
available = client.available();
if (available > 0)
{
if (available > sizeof(tmp))
{
available = sizeof(tmp);
}

available = client.readBytes(tmp, available);
GXTRACE_INT("Bytes read = ", available);
if ((available = Server.handleRequest(tmp, available, &reply)) != 0)
{
GXTRACE_INT(PSTR("handleRequest failed:"), available);
bb_clear(&reply);
}
if (reply.size != 0)
{
//Send reply.
GXTRACE("Sending reply to client.", NULL);
client.write(reply.data, reply.size);
client.flush();
bb_clear(&reply);
}
}
else
{
GXTRACE("available = 0", NULL);
}
}
else
{
GXTRACE("Client not connected.", NULL);
}

// Close the connection
client.stop();
GXTRACE("Client disconnected.", NULL);
}
}

Regards
Sidharth

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin