I am unable to connect my board to wifi and then to database ssid and password are correct

#include <WiFiNINA.h>

char ssid[] = "SpectrumSetup-D0";    // your network SSID (name)
char pass[] = "stealthlemon381";     // your network password

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // attempt to connect to WiFi network
  Serial.println("Attempting to connect to WiFi...");
  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
    Serial.println("Connection failed! Retrying...");
    delay(3000);
  }

  // you're connected now, print out some status info
  Serial.println("Connected to WiFi");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // your code here
}

i am trying this code but it gives this error

/usr/local/bin/arduino-cli compile --fqbn arduino:renesas_uno:unor4wifi --build-cache-path /tmp --output-dir /tmp/3731771017/build --build-path /tmp/arduino-build-503CEB9A3BD6A8F24491B8E4B7D0265D --library /home/builder/opt/libraries/wifinina_1_8_0 /tmp/3731771017/sketch_apr24a

/home/builder/opt/libraries/wifinina_1_8_0/src/utility/spi_drv.cpp: In static member function 'static void SpiDrv::begin()':
/home/builder/opt/libraries/wifinina_1_8_0/src/utility/spi_drv.cpp:97:15: error: 'NINA_GPIO0' was not declared in this scope
pinMode(NINA_GPIO0, OUTPUT);
^~~~~~~~~~
/home/builder/opt/libraries/wifinina_1_8_0/src/utility/spi_drv.cpp: In static member function 'static int SpiDrv::available()':
/home/builder/opt/libraries/wifinina_1_8_0/src/utility/spi_drv.cpp:581:25: error: 'NINA_GPIO0' was not declared in this scope
return (digitalRead(NINA_GPIO0) != LOW);
^~~~~~~~~~
Multiple libraries were found for "WiFiNINA.h"
Used: /home/builder/opt/libraries/wifinina_1_8_0
Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1
Not used: /home/builder/opt/libraries/wifinina_1_8_14
Not used: /home/builder/opt/libraries/betterwifinina_1_3_0
Multiple libraries were found for "SPI.h"
Used: /home/builder/.arduino15/packages/arduino/hardware/renesas_uno/1.1.0/libraries/SPI
Not used: /home/builder/opt/libraries/eventethernet_1_0_0
Error during build: exit status 1

and i am using online editor

If you're using an R4 then this is the wrong WiFi library. Use "WiFiS3.h"

Please change the title of your topic - your problem is not you unable to connect...
The issue that the code doesn't compile.

By naming a thread incorrectly, you are making it harder for those who might be able to help you.

2 Likes
#include <WiFiS3.h>

const char* ssid = "SpectrumSetup-D0";     // your network SSID (name)
const char* password = "stealthlemon381";  // your network password
const char* serverAddress = "192.168.1.18"; // IP address of your computer running Flask
const int serverPort = 5000; // Port on which your Flask app is running
const int switchPin = 13; // Pin connected to the lights

WiFiSSLClient wifiClient;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect
  }

  Serial.println("Connecting to WiFi network...");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

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

  pinMode(switchPin, OUTPUT); // Initialize pin as output
}

void loop() {
  // Send a simple request to the server to get the status
  int status = getStatus();
  
  // If the status is 1, switch on the lights
  if (status == 1) {
    digitalWrite(switchPin, HIGH); // Switch on the lights
    Serial.println("Lights switched on");
  } else {
    digitalWrite(switchPin, LOW); // Switch off the lights
    Serial.println("Lights switched off");
  }

  delay(5000); // Check status every 5 seconds
}

int getStatus() {
  if (wifiClient.connect(serverAddress, serverPort)) {
    Serial.println("Connected to server");

    // Send a simple request to get status
    wifiClient.println("get_status");

    // Wait for response
    while (wifiClient.connected()) {
      if (wifiClient.available()) {
        String response = wifiClient.readStringUntil('\n');
        return response.toInt(); // Convert response to integer
      }
    }

    wifiClient.stop();
  } else {
    Serial.println("Connection failed");
  }

  return -1; // Return -1 if status couldn't be retrieved
}

now i am trying to connect to database which is running by xampp in my system


from flask import Flask
import mysql.connector

app = Flask(__name__)

# Connect to MySQL database
mydb = mysql.connector.connect(
  host="localhost",
  user="shubh",
  password="Test@123",
  database="gosmart"
)

# Create a cursor object to execute SQL queries
mycursor = mydb.cursor()

# Endpoint to get status from the database
@app.route('/get_status', methods=['GET'])
def get_status():
    try:
        # Execute SQL query to select the status from the allowances table
        mycursor.execute("SELECT status FROM allowences WHERE id = 1")
        result = mycursor.fetchone()

        if result:
            status = result[0]
            return str(status) + "\n"  # Send plain text response
        else:
            return "No record found for id 1.\n"
    except Exception as e:
        return "Error: " + str(e) + "\n"

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

and this code to return result but it gives error

192.168.1.63 - - [26/Apr/2024 16:26:55] "\x16\x03\x01\x01&\x01\x00\x01"\x03\x03\x00\x00\x04\x91n/´®\x056êÅ\x00k\x9a\x00\x11ëÌJ\x8e\x89#­¥z\x16\x8be&Ë\x89\x00\x00\x9aÀ,À0\x00\x9fÀ­À\x9fÀ$À(\x00kÀ" 400 -

after using library wifis3 its working