How to set and get DNS-Server on new rpcWiFi lib for Wio Terminal?

Hello,
I’m working with the new rpcWiFi Api but I can’t set or get the DNS-Server. After having called WiFi.begin() WiFi.dnsIp returns with ‘0.0.0.0’ and it cannot be changed with WiFi.config().

Since my example App (https://wiki.seeedstudio.com/Wio-Terminal-Reading-Github/) reaches the selected selected server (api.github.com) there must be a DNS-Server assigned internally, but I could not yet find out were this is done.

IPAddress presetIp(192, 168, 1, 83);
IPAddress presetGateWay(192, 168, 1, 1);
IPAddress presetSubnet(255, 255, 255, 0);

WiFi.begin(ssid, password);

// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {     
    lcd_log_line(itoa((int)WiFi.status(), buf, 10));        
    // wait 1 second for re-trying
    delay(1000);
}

WiFi.config(presetIp, presetGateWay, presetSubnet, presetGateWay, presetGateWay);

IPAddress localIpAddress = WiFi.localIP();
IPAddress gatewayIp =  WiFi.gatewayIP();
IPAddress subNetMask =  WiFi.subnetMask();
IPAddress dnsServerIp = WiFi.dnsIP();

Any advise would be appreciated.
Best regards
RoSchmi

1 Like

Hi @RoSchmi

We have found a bug in our current firmware that it also runs dnsserver on the 8720. We are fixing this bug right now and will keep you updated.

2 Likes

Hi @ansonhe97, are there any updates on DNS Server Bug fix?

DNS issue should be solved please update to the latest firmware. But we have recently encouter some bottom layer of TLS issue regards to realteks SDK(which they are fixing now). Please test your environment and feedback so we can also work on it :smiley:

Hi @ansonhe97 I had already tested yesterday before writing with the realteks firmware release v2.0.3 and the following source code but it still doesn’t work the DNS returns 0.0.0.0. I also wanted to point out that in the examples the WiFiClientStaticIP.ino file has errors and does not work. It includes the WiFi.h library as well as rpcWiFi.h, but other than that it doesn’t matter if I put the line “if (! WiFi.config (local_IP, gateway, subnet, primaryDNS, secondaryDNS))” before the line "WiFi.begin (ssid, password); ", as written in the example, the connection fails.
I also wanted to ask you why the release is never updated in the library.properties file of the libraries? In this way it is not possible to manage the projects correctly by entering with which release of the library it must be compiled.
Maybe I didn’t quite understand how the release works. Can you explain it to me?
Thanks
Moreover I have continued the tests today and there is still an incompatibility of the new WiFi library with writing to SD card. If I load the new library writing to SD fails

Click to see the code

/*
Example of connection using Static IP
by Evandro Luis Copercini
Public domain - 2017
*/
#include <rpcWiFi.h>
//#include <WiFi.h>

const char* ssid = “xxxxxxxxxx”;
const char* password = “xxxxxxxxxx”;
const char* host = “example.com”;
const char* url = “/index.html”;

IPAddress local_IP(192, 168, 0, 87);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

void setup()
{
Serial.begin(115200);
while (!Serial)
{
};

Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))
{
Serial.println(“STA Failed to configure”);
}

Serial.println("");
Serial.println(“WiFi connected!”);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("ESP Mac Address: ");
Serial.println(WiFi.macAddress());
Serial.print("Subnet Mask: ");
Serial.println(WiFi.subnetMask());
Serial.print("Gateway IP: ");
Serial.println(WiFi.gatewayIP());
Serial.print("DNS: ");
Serial.println(WiFi.dnsIP());
}

void loop()
{
delay(5000);

Serial.print("connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println(“connection failed”);
return;
}

Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server
client.print(String(“GET “) + url + " HTTP/1.1\r\n” +
“Host: " + host + “\r\n” +
“Connection: close\r\n\r\n”);
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(”>>> Client Timeout !”);
client.stop();
return;
}
}

// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil(’\r’);
Serial.print(line);
}

Serial.println();
Serial.println(“closing connection”);
}

We have targeted the problem and will solve this in the next release.

Currently Software is under frequent development which means that it gets more and more stable. Once it becomes stable it will tag with a stable version and will not change dramatically.

Hi @Gianfry60

We have just updated the firmware:

and Please update rpcWifi and rpcUnified to the latest:

I can confirm that with firmware v2.0.4 the command WiFi.dnsIP() now returns the address of the DNS Server.
However I have the issue that when I call WiFi.config() before WiFi.begin() the WiFi.status() stays 0 (WL_IDLE_STATUS) and doesn’t reach staus 3 (WL_CONNECTED).
Is this the correct behavior? In an example for the ESP32 I saw code where WiFi.config is called before WiFi.begin().
When I call WiFi.config() after WiFi.begin() everything seems to be as expected.

Hi @ ansonhe97, I confirm that now the DNS is managed correctly even if the WiFi.begin () declaration sequence remains, which must be put before the WiFi.config () altriminti does not work. However, I also found a problem with the management of the WiFiClient. It seems that it does not respond correctly or in any case with a long time. If I try to use it to query MySQL the call times out. The same code used with an Ethernet shield works fine. I am attaching the code I used and the display of the serial monitor.

Code

Click to see the code

#include <WiFi.h>

#include “defines.h”

#include “Credentials.h”

#include <rpcWiFiClient.h>

#include <MySQL_Generic_Connection.h>

#include <MySQL_Generic_Query.h>

const char QUERY_TEST[] = “SELECT ATH50.Device.ChangeCFG FROM ATH50.Device WHERE ATH50.Device.idDevice = 1”;

WiFiClient client;

MySQL_Connection conn((Client *)&client);

#define WIFI_USE_SAMD

#define SEEED_WIO_TERMINAL

#define USING_WIFI_CUSTOM

void runQuery(void)

{

Serial.println("====================================================");

Serial.println("> Running SELECT with dynamically supplied parameter");

// Initiate the query class instance

MySQL_Query query_mem = MySQL_Query(&conn);

// Execute the query

// KH, check if valid before fetching

if (!query_mem.execute(QUERY_TEST))

{

Serial.println("Querying error");

return;

}

// Fetch the columns and print them

column_names *cols = query_mem.get_columns();

for (int f = 0; f < cols->num_fields; f++)

{

Serial.print(cols->fields[f]->name);

if (f < cols->num_fields - 1)

{

  Serial.print(",");

}

}

Serial.println();

// Read the rows and print them

row_values *row = NULL;

do

{

row = query_mem.get_next_row();

if (row != NULL)

{

  for (int f = 0; f < cols->num_fields; f++)

  {

    Serial.print(row->values[f]);

    if (f < cols->num_fields - 1)

    {

      Serial.print(",");

    }

  }

  Serial.println();

}

} while (row != NULL);

}

void setup()

{

Serial.begin(115200);

while (!Serial)

;

WiFi.begin(ssid, pass);

if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS))

{

Serial.println("STA Failed to configure");

}

Serial.print("Connecting to ");

Serial.println(ssid);

while (WiFi.status() != WL_CONNECTED)

{

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.println(“WiFi connected!”);

Serial.print("IP address: ");

Serial.println(WiFi.localIP());

Serial.print("ESP Mac Address: ");

Serial.println(WiFi.macAddress());

Serial.print("Subnet Mask: ");

Serial.println(WiFi.subnetMask());

Serial.print("Gateway IP: ");

Serial.println(WiFi.gatewayIP());

Serial.print("DNS: ");

Serial.println(WiFi.dnsIP());

Serial.print("Connecting to SQL Server @ ");

Serial.print(server_addr);

Serial.println(String(", Port = ") + server_port);

//Serial.println(String("User = “) + user + String(”, PW = “) + password + String(”, DB = ") + default_database);

}

void loop()

{

Serial.println(“Connecting…”);

if (conn.connect(server_addr, server_port, user, password))

{

delay(500);

runQuery();

conn.close(); // close the connection

}

else

{

Serial.println("\nConnect failed. Trying again on next iteration.");

}

Serial.println("\nSleeping…");

Serial.println("================================================");

delay(10000);

}

Serial Monitor

Click to see the code

Connecting to D-Link-GR 2.4 Gz

WiFi connected!
IP address: 192.168.0.87
ESP Mac Address: 2c:f7:f1:1b:47:a9
Subnet Mask: 255.255.255.0
Gateway IP: 192.168.0.1
DNS: 8.8.8.8
Connecting to SQL Server @ 5.150.142.221, Port = 3306
Connecting…
[SQL] Connecting to Server: 5.150.142.221 , Port = 3306
[SQL] Connect OK. Try reading packets
[SQL] MySQL_Packet::wait_for_bytes: OK, Num bytes= 102
[SQL] MySQL_Packet::read_packet: packet_len= 98
[SQL] MySQL_Packet::read_packet: First time allocate buffer, size = 102
[SQL] MySQL_Packet::read_packet: exit
[SQL] Try parsing packets
[SQL] Try send_authentication packets
[SQL] MySQL_Packet::wait_for_bytes: OK, Num bytes= 11
[SQL] MySQL_Packet::read_packet: packet_len= 7
[SQL] MySQL_Packet::read_packet: exit
[SQL] MySQL_Packet::get_packet_type: packet type= 0
[SQL] MySQL_Packet::get_packet_type: packet type= MYSQL_OK_PACKET
[SQL] Connected. Server Version = 5.5.5-10.1.47-MariaDB-0+deb9u1

Running SELECT with dynamically supplied parameter
[SQL] MySQL_Query::execute: Reuse allocated buffer, conn->largest_buffer_size = 102 > 84
[SQL] MySQL_Query::execute: query = SELECT ATH50.Device.ChangeCFG FROM ATH50.Device WHERE ATH50.Device.idDevice = 1
[SQL] MySQL_Query::execute_query: query = SELECT ATH50.Device.ChangeCFG FROM ATH50.Device WHERE ATH50.Device.idDevice = 1
[SQL] MySQL_Packet::wait_for_bytes: client->stop
[SQL] MySQL_Packet::wait_for_bytes: OK, Num bytes= 0
[SQL] MySQL_Packet::read_packet: ERROR: Timeout waiting for client.
Querying error

Hi,

Currently the software only supports adding WiFi.config() after WiFi.begin(). We will fix the behavior in a later firmware release.
For the MySQL, I will test and get back to you

Best Regards,
Lakshantha

Hi @Gianfry60 Thanks for your contributions,
I’m very interested to learn more about your experiences with an ethernet shield. I would like to test my application, where I’m loading sensor data to Azure Storage Tables (-https://github.com/RoSchmi/AzureDataSender_Wio_Terminal) with an ethernet shield to test if some long term stability issues I’m still seeing are caused by bugs in my code or by bugs in the RTL8720 firmware. Which Ethernet shield are you using? Can you post some code how you use an ethernet shield with Wio Terminal.
Thanks in advance.
RoSchmi

Hi @RoSchmi. I just noticed that you are interested in using an Ethernet Shield with the Wio Terminal. I would suggest you to use the ENC28J60 OVERLAYS HAT for Raspberry Pi and we have prepared a getting started tutorial for it as well.

Best Regards,
Lakshantha

1 Like

Hi @RoSchmi, I used a shied HR911105A - ENC28J60, and with the code that I am attaching it works perfectly I hope it is useful for you. If you need more details please ask me and I will be happy to help you.

Click to see the code

#include <Arduino.h>

#include “defines.h”

#include <MySQL_Generic_Ethernet.h>

#define SEEED_WIO_TERMINAL

char user[] = “xxxxx”; // MySQL user login username

char password[] = “xxxxx”; // MySQL user login password

IPAddress server_addr(xxx, xxx, xxx, xxx); // MySQL IpAddress

uint16_t server_port = 3306; // MySQL port

char default_database[] = “ATH50”;

char default_table[] = “Device”;

IPAddress local_IP(192, 168, 0, 87);

IPAddress gateway(192, 168, 0, 1);

IPAddress subnet(255, 255, 255, 0);

IPAddress primaryDNS(8, 8, 8, 8); //optional

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

const char QUERY_TEST[] = “SELECT ATH50.Device.ChangeCFG FROM ATH50.Device WHERE ATH50.Device.idDevice = 1”;

MySQL_Connection conn((Client *)&client);

void setup()

{

Serial.begin(115200);

while (!Serial)

    ;

Serial.println("\nStarting Complex_Select_WiFi on " + String(BOARD_NAME));

Ethernet.init(USE_THIS_SS_PIN);

//Use Static IP

Ethernet.begin(mymac, local_IP, primaryDNS, gateway, subnet);

Serial.print("Connected! IP address: ");

Serial.println(Ethernet.localIP());

// print out info about the connection:

Serial.print("Connecting to SQL Server @ ");

Serial.print(server_addr);

Serial.println(String(", Port = ") + server_port);

Serial.println(String("User = ") + user + String(", PW = ") + password + String(", DB = ") + default_database);

}

void runQuery(void)

{

Serial.println("====================================================");

Serial.println("> Running SELECT with dynamically supplied parameter");

// Initiate the query class instance

MySQL_Query query_mem = MySQL_Query(&conn);

// Execute the query

// KH, check if valid before fetching

if (!query_mem.execute(QUERY_TEST))

{

    Serial.println("Querying error");

    return;

}

// Fetch the columns and print them

column_names *cols = query_mem.get_columns();

for (int f = 0; f < cols->num_fields; f++)

{

    Serial.print(cols->fields[f]->name);

    if (f < cols->num_fields - 1)

    {

        Serial.print(",");

    }

}

Serial.println();

// Read the rows and print them

row_values *row = NULL;

do

{

    row = query_mem.get_next_row();

    if (row != NULL)

    {

        for (int f = 0; f < cols->num_fields; f++)

        {

            Serial.print(row->values[f]);

            if (f < cols->num_fields - 1)

            {

                Serial.print(",");

            }

        }

        Serial.println();

    }

} while (row != NULL);

}

void loop()

{

Serial.println("Connecting...");

if (conn.connect(server_addr, server_port, user, password))

{

    delay(500);

    runQuery();

    conn.close(); // close the connection

}

else

{

    Serial.println("\nConnect failed. Trying again on next iteration.");

}

Serial.println("\nSleeping...");

Serial.println("================================================");

delay(10000);

}

1 Like

Thanks @lakshan and @Gianfry60,
I’ll try it in the next days. Did you try ssl secured transmission? I found -https://github.com/khoih-prog/EthernetWebServer_SSL which I want to try. Any other recommendation?