Unable to connect between Arduino and my browser

Apple Mac OS
Arduino IDE 2.2.1
Arduino Uno WiFi rev 2
Arduino Motor Shield rev3
WiFiNINA.h version 1.8.14
Arduino C++
TCP-IP

// commoncMacros.h

#ifndef serverAddress
#define serverAddress "192.168.1.143"
#endif

#ifndef whos_there_rows
#define whos_there_rows 16  // adjust rows as needed
#endif

#ifndef serial_comms_speed
#define serial_comms_speed 9600
#endif

#ifndef STD_BUFFER_SIZE
#define STD_BUFFER_SIZE 0xFF
#endif

#ifndef serverPort
#define serverPort 8080
#endif

#ifndef UniversalTimer
#include <UniversalTimer.h>
// UniversalTimer delay10sTimer(10000, false); 
// Create a timer with 10,000ms and non-repeating
#endif

#ifndef arduino_secrets
#include <arduino_secrets.h>
#endif

#ifndef WiFiNINA
#include <WiFiNINA.h>
#endif

#ifndef WiFiClient
#include <WiFiClient.h>
#endif

#ifndef WiFiServer
#include <WiFiServer.h>
#endif

#ifndef WebSocketClient
#include <WebSocketClient.h>
#endif

#ifndef debug
extern bool debug = true;
#endif



#include <commonMacros.h>
//#include <WiFiNINA.h>

IPAddress ip(192, 168, 1, 143);  // Static IP
IPAddress gateway(192, 168, 1, 1);  // Gateway IP
IPAddress subnet(255, 255, 255, 0);  // Subnet mask

WiFiServer server(serverPort);

void setup() {
  // Initialize serial communication
  Serial.begin(serial_comms_speed);

 // Connect to WiFi
  if (!WL_CONNECTED) {
    WiFi.begin(wifi_ssid, wifi_password);
    //delay(1000);
    if (debug) Serial.println("Connecting to WiFi...");
  } //if (!WL_CONNECTED)

  // Configure static IP
  WiFi.config(ip, gateway, subnet);

  // Print local IP address
  if (debug) Serial.println("Connected to WiFi. IP address: " + WiFi.localIP());

  // Start the server
  server.begin();

} //void setup()





void loop() {
// Check for a client connection
  WiFiClient client = server.available();
  if (client) {
    if (debug) Serial.println("New client connected");

    // Read the request
    String request = client.readStringUntil('\r');
    client.flush();

    // Send a response
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println();
    client.println("<html><body>");
    client.println("<h1>Hello, Arduino HTTP Server!</h1>");
    client.println("</body></html>");

    // Close the connection
    client.stop();
    if (debug) Serial.println("Client disconnected");
  } //if (client)

} //void loop()




This set of code compiles and loads onto the Arduino. Upon booting, I find the server address 192.168.1.143 when I run arp -a (arduino-61f8.localdomain (192.168.1.143) at 78:21:84:7a:61:f8 on en1 ifscope [ethernet]). Having done this, when I type http://192.168.1.143/8080 into the browser, I get "The connection has timed out". As you can see, in commonMacros debug is true, yet when I run the program, what I get from the serial output is: ���. The browser baud rate is set to 9600, and you can see for yourself, commonMacros sets the Arduino baud rate to the same.

How do I get my Arduino and my browser to communicate? What am I missing?

first config then begin.
read the complete request before sending the replay. (flush doesn't read RX. it is a TX function)
a quick way to read the rest of the GET request is client.find("\r\n\r\n");

If that code is not generating any readable serial output, then address that first.
Your macros have an odd look to them, for example:

#ifndef debug 
extern bool debug = true; 
#endif

To be consistent I'd have expected something like:

#ifndef debug 
#define debug true
#endif

EDIT

and maybe see here for the correct use of the C++ keyword extern. variable declaration - When to use extern in C++ - Stack Overflow

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.