I am doing a project that logs data onto MySQL using and Arduino MKR WiFi 1010 via an HTTP request with the aid of XAMPP. I have tried the following code below and I can not get a response on the serial monitor to confirm connection with the web server. The code was initially for an Ethernet connection but I tried to modify it to a Wifi connection. I already have a php script (insert_temp.php) that logs the data onto MySQL and it works ok, I'm just struggling with the communication between the Arduino and the web server. I would really appreciate any help. Apologies if I haven't followed most of the guidelines required when posting, it is my first time posting on the forum.
Code:
#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)
WiFiClient client;
int HTTP_PORT = 80;
String HTTP_METHOD = "GET";
char HOST_NAME[] = "10.0.0.249"; // change to your PC's IP address
String PATH_NAME = "/insert_temp.php";
String queryString = "?temperature=29.1";
void setup() {
Serial.begin(9600);
// initialize the Ethernet shield using DHCP:
if (WiFi.begin(ssid, pass) == WL_CONNECTED) {
Serial.println("Failed to obtaining an IP address using DHCP");
while(true);
}
// connect to web server on port 80:
if(client.connect(HOST_NAME, HTTP_PORT)) {
// if connected:
Serial.println("Connected to server");
// make a HTTP request:
// send HTTP header
client.println(HTTP_METHOD + " " + PATH_NAME + queryString + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println(); // end HTTP header
while(client.connected()) {
if(client.available()){
// read an incoming byte from the server and print it to serial monitor:
char c = client.read();
Serial.print(c);
}
}
// the server's disconnected, stop the client:
client.stop();
Serial.println();
Serial.println("disconnected");
} else {// if not connected:
Serial.println("connection failed");
}
}
void loop() {
}