Hello!
I experience a problem, also occuring within ArduinoBLE, that the client board does not see the server AP (signal??). I tried switching roles & try to just scan networks, but it sees every AP except the one the server board is supposed to send. Can you help me?
The server code:
#include <SPI.h>
#include <WiFiNINA.h>
char ssid[] = "ArduinoAP"; // SSID of the Access Point
char pass[] = ""; // No password for the Access Point
WiFiServer server(100); // Create a server instance
void setup() {
Serial.begin(9600);
while (!Serial);
// Create an Access Point
Serial.println("Creating Access Point...");
WiFi.beginAP(ssid);
IPAddress ip = WiFi.localIP();
Serial.print("AP IP address: ");
Serial.println(ip);
// Start the server
server.begin();
Serial.println("Server started");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (client) {
Serial.println("Client connected");
// Read the request
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
}
}
// Send a response
client.println("Hello from Arduino #1!");
client.stop();
Serial.println("Client disconnected");
}
}
The client code:
//client
#include <SPI.h>
#include <WiFiNINA.h>
char ssid[] = "ArduinoAP"; // SSID of the Access Point
char pass[] = ""; // No password for the Access Point
WiFiClient client; // Create a WiFi client instance
void setup() {
Serial.begin(9600);
while (!Serial);
// Connect to the Access Point
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
// Print local IP address
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// If not connected, attempt to reconnect
if (!client.connected()) {
Serial.println("Connecting to server...");
if (client.connect("192.168.4.1", 100)) { // Replace "ServerIPAddress" with the IP address of Arduino #1
Serial.println("Connected to server");
client.println("Hello from Arduino #2!"); // Send a message to the server
} else {
Serial.println("Connection failed");
delay(5000); // Wait before retrying
}
}
// Wait a bit before sending another message
delay(5000);
}