Unable to connect Arduino to server through Wifi.

Good day everybody,

I am currently trying to use my Arduino MKR1000 Wifi to send data (IP Address and Signal Strength) to a database (MyPHP through XAMPP). It works find if I use a localhost to send a data to it.

I am able to connect my router and get an IP but is not able to connect the database/server itself.

Arduino MKR1000 version: 19.4.4 (https://store.arduino.cc/usa/arduino-mkr1000)
Arduino IDE version: 1.8.5
XAMPP version: 3.2.2

Arduino’s Code:

#include <SPI.h>
#include <WiFi101.h>

char ssid = “Alfatech Vestasia”; // your network SSID (name)
char pass = “password”; // your network password
int status = WL_IDLE_STATUS;

WiFiServer server(80); //port 80

void setup() {
// Serial.begin starts the serial connection between computer and Arduino
Serial.begin(9600);

// 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);
}
server.begin();
// you’re connected now, so print out the status:
printWifiStatus();
//Serial.println(Ethernet.localIP());
}

void loop() {
WiFiClient client = server.available();
//Serial.print(client);
while (client.connected()){
IPAddress ip1 = WiFi.localIP();
long rssi = WiFi.RSSI();
client.print(“GET /write_data.php?”); // This
client.print(“IPAdds=”); // This
client.print(ip1); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
client.print("&SignalStrength=");
client.print(rssi);
client.println(" HTTP/1.1"); // Part of the GET request
client.println(“Host: 192.168.3.118”); // using XAMPP (Therefore, IP address of your computer)
client.println(“Connection: close”); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop(); // Closing connection to server
}
Serial.println("–> connection failed\n");
// Give the server some time to recieve the data and store it. I used 10 seconds here.
//Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
delay(10000);
}

void printWifiStatus() {
Serial.print(“SSID: “);
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print(“IP Address: “);
Serial.println(ip);
// print the MAC address of the router you’re attached to:
byte mac[6];
WiFi.macAddress(mac);
Serial.print(“MAC address: “);
Serial.print(mac[5], HEX);
Serial.print(”:”);
Serial.print(mac[4], HEX);
Serial.print(”:”);
Serial.print(mac[3], HEX);
Serial.print(”:”);
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.println(mac[0], HEX);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.println(rssi);

// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print(“Encryption Type:”);
Serial.println(encryption, HEX);
Serial.println();
}

PHP Code:

<?php $dbconnect = mysqli_connect('localhost', 'root', '' , 'help'); //my structure is named 'help' with my table (named wifi) in it if(!$dbconnect) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO wifi (IPAdd, SignalStrength ) VALUES ('".$_GET["IPAdd"]."','".$_GET["SignalStrength"]."' )"; if (mysqli_query($dbconnect, $sql)) { echo "good"; } else { echo "Error: " . $sql . " " . mysqli_error($dbconnect); } ?>

Output:

SSID: Alfatech Vestasia
IP Address: 192.168.3.97
MAC address: F8:F0:5:F7:E4:6D
signal strength (RSSI):-63
Encryption Type:2

→ connection failed

I checked the value of client and it is always 0.

Not sure what I am doing wrong and will appreciate all help given.