Arduino Uno R4 WiFi cannot connect to Server

I am currently having a problem on my Arduino Uno R4 Wifi in which the original code works perfectly on Arduino Uno Rev2 Wifi, Nano IOT33

Program: Sending Temperature data to Xampp Server
Problem: Cannot connect to SQL Server

Please refer to attached txt file for the error on serial monitor

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#include "WiFiS3.h"
#include <SPI.h>
#include <max6675.h>


#ifndef STASSID
#define STASSID "redacted"
#define STAPSK  "redacted"
#endif

void(* resetFunc) (void) = 0;


LiquidCrystal_I2C  lcd = LiquidCrystal_I2C(0x27, 20, 4);

// Select I2C BUS

  const char* ssid     = STASSID;
  const char* password = STAPSK;

  int status = WL_IDLE_STATUS;     // the WiFi radio's status
  WiFiClient client;

  // if you don't want to use DNS (and reduce your sketch size)
  // use the numeric IP instead of the name for the server:
  IPAddress server(192, 168, 0, 104);  // numeric IP for Google (no DNS)
  //char server[] = "www.google.com";    // name address for Google (using DNS)

  unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
  const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milli



  // Temperature Sensor1
  int thermo1D0 = 1; // so
  int thermo1CS = 2;
  int thermo1CLK = 3; // sck
  float chh1 = 0;
  MAX6675 thermocouple1(thermo1CLK, thermo1CS, thermo1D0);

  // Temperature Sensor2
  int thermo2D0 = 4; // so
  int thermo2CS = 5;
  int thermo2CLK = 6; // sck
  float chh2 = 0;
  MAX6675 thermocouple2(thermo2CLK, thermo2CS, thermo2D0);


  // Temperature Sensor3
  int thermo3D0 = 7; // so
  int thermo3CS = 8;
  int thermo3CLK = 9; // sck
  float chh3 = 0;
  MAX6675 thermocouple3(thermo3CLK, thermo3CS, thermo3D0);


  

  float ch1 = 0;
  float ch2 = 0;
  float ch3 = 0;

  void setup()
  {
    Wire.begin();
    Serial.begin(9600);
    
    
    lcd.init();
    lcd.backlight();
     
    lcd.print("Initializing...");

    // check for the WiFi module:
    if (WiFi.status() == WL_NO_MODULE) {
      Serial.println("Communication with WiFi module failed!");
       
       lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Module Error");
      // don't continue
      while (true);
    }

    String fv = WiFi.firmwareVersion();
    if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
      Serial.println("Please upgrade the firmware");
    }

    

    // attempt to connect to WiFi network:
    while (status != WL_CONNECTED) {
      Serial.print("Attempting to connect to WPA SSID: ");
      Serial.println(ssid);
      // Connect to WPA/WPA2 network:
      status = WiFi.begin(ssid, password);
      
    
    lcd.setCursor(0, 1);
    lcd.print("Connecting to Router");
      
      // wait 10 seconds for connection:
      delay(5000);


    }


    
    lcd.setCursor(0, 1);
    lcd.print("WiFi Connected      ");

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    
   
   
    Serial.println("initialization done.");
     
   
  }

  void loop()
  {
    //ch1 = thermcouple1.readCelsius();

    //ch2 = thermocouple2.readCelsius();

    //ch3 = thermocouple3.readCelsius(); // read temperature

    chh1 = thermocouple1.readCelsius();

    chh2 = thermocouple2.readCelsius();

    chh3 = thermocouple3.readCelsius(); // read temperature


    ch1 = chh1 + 1;
    ch2 = chh2 + 1;
    ch3 = chh3 + 1;

    while (client.available()) {
      char c = client.read();
      Serial.write(c);
    }

    // if ten seconds have passed since your last connection,
    // then connect again and send data:
    if (millis() - lastConnectionTime > postingInterval) {
       client.stop();
    Serial.println("\nStarting connection to server...");
    
    lcd.setCursor(0, 1);
    lcd.print("Connecting to Server");
    // if you get a connection, report back via serial:
    if (client.connect(server, 80)) {

      Serial.println("Connected to server");
     
      lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("Connected to server ");
    lcd.setCursor(0, 0);
    lcd.print("    Mino Oven 08    ");
      // Make a HTTP request:
      client.print("GET /mino08/data1.php?"); //Connecting and Sending values to database
      client.print("ch1=");
      client.print(ch1);
      client.print("&ch2=");
      client.print(ch2);
      client.print("&ch3=");
      client.println(ch3);
      client.println(" HTTP/1.1"); // Part of the GET request
      client.println("Host: 192.168.0.104"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
      // note the time that the connection was made:
      lastConnectionTime = millis();
    }
    else {

      // if you didn't get a connection to the server:
      Serial.println("connection failed");

    lcd.setCursor(0, 1);
    lcd.print("Connection Failed    ");
    resetFunc();
    }
    }




    Serial.print("ch1=");
    Serial.print(ch1);
    Serial.print("=");
    Serial.print(chh1);
    Serial.print("&ch2=");
    Serial.print(ch2);
    Serial.print("=");
    Serial.print(chh2);
    Serial.print("&ch3=");
    Serial.print(ch3);
    Serial.print("=");
    Serial.println(chh3);

    
  
    lcd.setCursor(0, 2);
    lcd.print(" ");
 lcd.print("Ch1");
 
  lcd.print("    ");
   lcd.print("Ch2");
  
  lcd.print("    ");
   lcd.print("Ch3");
  
  
    
    lcd.setCursor(0, 3);
 
  lcd.print(ch1);
  lcd.print("  ");
  
  lcd.print(ch2);
  lcd.print("  ");
   
  lcd.print(ch3);
 
 
    
 
    delay(5000);

    // if the server's disconnected, stop the client:

  
  }
  


 
  

error code.txt (2.4 KB)

so the crash report is because of the reserFunction.

is the port open on firewall on PC?

There is no problem on my firewall.

There are currently 4 devices connected on my SQL server

2 units of Arduino Uno Rev2 Wifi
1 Unit Nano IOt33
1 unit Nano RP2040 connect

I am only having problem with my newly delivered Arduino Uno R4 Wifi

is the problem already at first connection or only at a reconnection?

the problem occurs at first connection --->after successful connection to wireless network

try to put while (client.available()) { into if (client.connected())
it is a new library it can have problems like that

I already inserted above instruction still the same
image

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#include "WiFiS3.h"

#include <SPI.h>
#include <max6675.h>


#ifndef STASSID
#define STASSID "webServer"
#define STAPSK  "smkandon"
#endif

//void(* resetFunc) (void) = 0;


LiquidCrystal_I2C  lcd = LiquidCrystal_I2C(0x27, 20, 4);

// Select I2C BUS

  const char* ssid     = STASSID;
  const char* password = STAPSK;

  int status = WL_IDLE_STATUS;     // the WiFi radio's status
  WiFiClient client;

  // if you don't want to use DNS (and reduce your sketch size)
  // use the numeric IP instead of the name for the server:
  IPAddress server(192, 168, 0, 104);  // numeric IP for Google (no DNS)
  //char server[] = "www.google.com";    // name address for Google (using DNS)

  unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
  const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milli



  // Temperature Sensor1
  int thermo1D0 = 1; // so
  int thermo1CS = 2;
  int thermo1CLK = 3; // sck
  float chh1 = 0;
  MAX6675 thermocouple1(thermo1CLK, thermo1CS, thermo1D0);

  // Temperature Sensor2
  int thermo2D0 = 4; // so
  int thermo2CS = 5;
  int thermo2CLK = 6; // sck
  float chh2 = 0;
  MAX6675 thermocouple2(thermo2CLK, thermo2CS, thermo2D0);


  // Temperature Sensor3
  int thermo3D0 = 7; // so
  int thermo3CS = 8;
  int thermo3CLK = 9; // sck
  float chh3 = 0;
  MAX6675 thermocouple3(thermo3CLK, thermo3CS, thermo3D0);


  

  float ch1 = 0;
  float ch2 = 0;
  float ch3 = 0;

  void setup()
  {
    Wire.begin();
    Serial.begin(9600);
    
    
    lcd.init();
    lcd.backlight();
     
    lcd.print("Initializing...");

    // check for the WiFi module:
    if (WiFi.status() == WL_NO_MODULE) {
      Serial.println("Communication with WiFi module failed!");
       
       lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Module Error");
      // don't continue
      while (true);
    }

    String fv = WiFi.firmwareVersion();
    if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
      Serial.println("Please upgrade the firmware");
    }

    

    // attempt to connect to WiFi network:
    while (status != WL_CONNECTED) {
      Serial.print("Attempting to connect to WPA SSID: ");
      Serial.println(ssid);
      // Connect to WPA/WPA2 network:
      status = WiFi.begin(ssid, password);
      
    
    lcd.setCursor(0, 1);
    lcd.print("Connecting to Router");
      
      // wait 10 seconds for connection:
      delay(5000);


    }


    
    lcd.setCursor(0, 1);
    lcd.print("WiFi Connected      ");

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    
   
   
    Serial.println("initialization done.");
     
   
  }

  void loop()
  {
    //ch1 = thermcouple1.readCelsius();

    //ch2 = thermocouple2.readCelsius();

    //ch3 = thermocouple3.readCelsius(); // read temperature

    chh1 = thermocouple1.readCelsius();

    chh2 = thermocouple2.readCelsius();

    chh3 = thermocouple3.readCelsius(); // read temperature


    ch1 = chh1 + 1;
    ch2 = chh2 + 1;
    ch3 = chh3 + 1;

    
   

    // if ten seconds have passed since your last connection,
    // then connect again and send data:
    if (millis() - lastConnectionTime > postingInterval) {
       
    Serial.println("\nStarting connection to server...");
    
    lcd.setCursor(0, 1);
    lcd.print("Connecting to Server");

    while (client.available()) {
      char c = client.read();
      Serial.write(c);
    // if you get a connection, report back via serial:
    if (client.connect(server,80)) {

      Serial.println("Connected to server");
     
      lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("Connected to server ");
    lcd.setCursor(0, 0);
    lcd.print("    Mino Oven 08    ");
      // Make a HTTP request:
      client.print("GET /mino30/data1.php?"); //Connecting and Sending values to database
      client.print("ch1=");
      client.print(ch1);
      client.print("&ch2=");
      client.print(ch2);
      client.print("&ch3=");
      client.println(ch3);
      client.println(" HTTP/1.1"); // Part of the GET request
      client.println("Host: 192.168.0.104"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
      // note the time that the connection was made:
      client.stop();
      lastConnectionTime = millis();
    }
    else {

      // if you didn't get a connection to the server:
      Serial.println("connection failed");

    lcd.setCursor(0, 1);  
    lcd.print("Connection Failed    ");
   // resetFunc();
    }
    }

 }


    Serial.print("ch1=");
    Serial.print(ch1);
    Serial.print("=");
    Serial.print(chh1);
    Serial.print("&ch2=");
    Serial.print(ch2);
    Serial.print("=");
    Serial.print(chh2);
    Serial.print("&ch3=");
    Serial.print(ch3);
    Serial.print("=");
    Serial.println(chh3);

    
  
    lcd.setCursor(0, 2);
    lcd.print(" ");
 lcd.print("Ch1");
 
  lcd.print("    ");
   lcd.print("Ch2");
  
  lcd.print("    ");
   lcd.print("Ch3");
  
  
    
    lcd.setCursor(0, 3);
 
  lcd.print(ch1);
  lcd.print("  ");
  
  lcd.print(ch2);
  lcd.print("  ");
   
  lcd.print(ch3);
 
 
    
 
    delay(5000);

    // if the server's disconnected, stop the client:

  
  }
  


 
  

is there ANY documentation to that library WiFiS3.h?
I cannot find one...

all WiFi libraries are almost the same, because they follow the Arduino WiFi library (which follows the Ethernet library).

For the reason provided by Juraj, most of the information in the "WiFiNINA" reference page should be relevant to the "WiFiS3" library as well:

I'm aware that Wifi libraries are all the same-->
So please explain to me why I cannot connect my Uno R4 wifi on my Xampp SQL server?

My server have currently different clients connected, Uno Rev2 Wifi, Nano IOT33, NanoRp2040 all of this are WifiNina

I just changed WifiNina to WifiS3-->It should work properly but not

Even Arduino Support cannot give me concrete explanation on this one

try to update the firmware in the esp32 S3

I already updated its firmware

I will not post here in the forum nor seek help if I can solve this problem on my own I have been doing IoT integration for a living,

I'm sure there is somewhat issue with this new board, I bought 3 units of Uno R4 Wifi and all of them cannot connect on my Xampp SQL server,

There is a lot of code in your sketch that isn't related to the networking that is causing you the problem. I recommend you simplify the sketch down the the absolute minimum amount of code that is required to connect to the server.

I also recommend you to disconnect any external circuitry/modules/shields from the board.

This will eliminate all those as variables. If the problem goes away, then you know one of those things was the cause. If the problem persists, then you and the helpers here can focus your attention on the remaining system.

As requested, please see below simplified code

Conclusion: Connection failed
image

/*
  Repeating WiFi Web Client

 This sketch connects to a a web server and makes a request
 using a WiFi equipped Arduino board.

 created 23 April 2012
 modified 31 May 2012
 by Tom Igoe
 modified 13 Jan 2014
 by Federico Vanzati

 http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating
 This code is in the public domain.
 */

#include "WiFiS3.h"


#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Initialize the WiFi client library
WiFiClient client;

// server address:
//char server[] = "example.org";
IPAddress server(192,168,0,104);

unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
int sensorValue = 0;
/* -------------------------------------------------------------------------- */
void setup() {
/* -------------------------------------------------------------------------- */  
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    //delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();
}

/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_request() {
/* -------------------------------------------------------------------------- */  
  uint32_t received_data_num = 0;

  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    /* print data to serial port */
    Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if(received_data_num % 80 == 0) { 
      
    }
    
  }  
}

/* -------------------------------------------------------------------------- */
void loop() {


  sensorValue = analogRead(A0);
/* -------------------------------------------------------------------------- */  
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  read_request();
  
  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }

}

// this method makes a HTTP connection to the server:
/* -------------------------------------------------------------------------- */
void httpRequest() {
/* -------------------------------------------------------------------------- */  
  // close any connection before send a new request.
  // This will free the socket on the NINA module
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP GET request:
    client.print("GET /analogread/data1.php?");
    client.print("sensorValue=");
    client.println(sensorValue);
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.0.104");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
    // note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

/* -------------------------------------------------------------------------- */
void printWifiStatus() {
/* -------------------------------------------------------------------------- */  
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
1 Like

I tried the same code on my Nano RP2040
I just changed Wifi library to WifiNina

Result is OK

image


/*
  Repeating WiFi Web Client

 This sketch connects to a a web server and makes a request
 using a WiFi equipped Arduino board.

 created 23 April 2012
 modified 31 May 2012
 by Tom Igoe
 modified 13 Jan 2014
 by Federico Vanzati

 http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating
 This code is in the public domain.
 */

#include <WiFiNINA.h>


#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key index number (needed only for WEP)

int status = WL_IDLE_STATUS;

// Initialize the WiFi client library
WiFiClient client;

// server address:
//char server[] = "example.org";
IPAddress server(192,168,0,104);

unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
int sensorValue = 0;
/* -------------------------------------------------------------------------- */
void setup() {
/* -------------------------------------------------------------------------- */  
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    //delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();
}

/* just wrap the received data up to 80 columns in the serial print*/
/* -------------------------------------------------------------------------- */
void read_request() {
/* -------------------------------------------------------------------------- */  
  uint32_t received_data_num = 0;

  while (client.available()) {
    /* actual data reception */
    char c = client.read();
    /* print data to serial port */
    Serial.print(c);
    /* wrap data to 80 columns*/
    received_data_num++;
    if(received_data_num % 80 == 0) { 
      
    }
    
  }  
}

/* -------------------------------------------------------------------------- */
void loop() {


  sensorValue = analogRead(A0);
/* -------------------------------------------------------------------------- */  
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  read_request();
  
  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }

}

// this method makes a HTTP connection to the server:
/* -------------------------------------------------------------------------- */
void httpRequest() {
/* -------------------------------------------------------------------------- */  
  // close any connection before send a new request.
  // This will free the socket on the NINA module
  client.stop();

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP GET request:
    client.print("GET /analogread/data1.php?");
    client.print("sensorValue=");
    client.println(sensorValue);
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.0.104");
   // client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
    // note the time that the connection was made:
    lastConnectionTime = millis();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

/* -------------------------------------------------------------------------- */
void printWifiStatus() {
/* -------------------------------------------------------------------------- */  
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

this issue is not yet resolved

is there any update regarding on its WifiS3 library?

this issue is now fixed

Solution-->link

Thanks to

Juraj

3 Likes

I have the problem as you, but the solution you mentioned didn't help me.
I getting this error message

...trying...
ERROR: Timeout waiting for client.
Error: -1 = ERROR: Class requires connected server.
ERROR: Class requires connected server.

Can someone help me with this issue?