#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
}
/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
#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)