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

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