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?
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.
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.
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.
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.
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.
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.
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.
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);
}
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
Hi Mikko,
Hi Mikko,
Thanks. Do you have any sample for this?
Regards
Sidharth
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
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
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
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
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
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
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
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
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