How do i check if my arduino is connecting to my other arduino!

How do i check if my arduino wifi is connecting to my other arduino wifi?
Its purpose is to turn on a light when a item is in range of my ultrasonic sensor.
This is my code for the sender

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "Netcomm 3240";                     // your network SSID (name)
char key[] = "Ninazoyope";       // your network key
int keyIndex = 0;                                // your network key Index number
int status = WL_IDLE_STATUS;                     // the Wifi radio's status

char server[] = "10.0.1.16";

WiFiClient client;

void setup() {
  
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
}
    while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WEP network, SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, keyIndex, key);
delay(10000);

void loop() {

  // check for the presence of wifi:
  if (WiFi.status() == WL_CONNECTION_LOST) {
    Serial.println("Oops conection lost");
    // don't continue:
    while (true);
     status = WiFi.begin(ssid, keyIndex, key);
  }
  else
{

}
  

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WEP network, SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, keyIndex, key);

    // wait 10 seconds for connection:
    delay(10000);
  }


  // once you are connected :
  Serial.print("You're connected to the network");
}
}

 

And here is my code for the receiver

#include <WiFiNINA.h>
#include <utility/wifi_drv.h>

const int redPin = 25;
const int greenPin = 26;
const int bluePin = 27;


char ssid[] = "NetComm 5926";
char pass[] = "xetajamihe";
IPAddress ip(192, 168, 20, 23);

int status = WL_IDLE_STATUS;
WiFiServer server(80);

String readString;

void setup() {

  Serial.begin(9600);

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }

  digitalWrite(LED_BUILTIN, HIGH);
  
  WiFi.config(ip);
  server.begin();

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  Serial.print("IP Address: ");
  Serial.println(ip);
}

void loop() {

  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");

    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();
        if (readString.length() < 100)
        {
          readString += c;
          Serial.write(c);

          if (c == '\n') {

//URL PARSE CODE FROM HERE ---
            if (readString.indexOf("green") > 0)
            {
               WiFiDrv::analogWrite(redPin,(0,0));
               WiFiDrv::analogWrite(greenPin,(0,0));
               WiFiDrv::analogWrite(bluePin,(0,0));

              delay(1);
            } else if (readString.indexOf("red") > 0) {
               WiFiDrv::analogWrite(redPin, random(0,255));
               WiFiDrv::analogWrite(greenPin, random(0,255));
               WiFiDrv::analogWrite(bluePin, random(0,255));

              delay(1);

            } else {

              Serial.print("PROBLEM:  ");
              Serial.println(readString);

            }
// ------ TO HERE

          
        }
      }
    }
  }
}
}

Thank you :slight_smile:

The easiest way is to check the IP addresses.

| gilshultz
February 24 |

  • | - |

The easiest way is to check the IP addresses.


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click

Do you know how i could do that? I’m a beginner to Arduino

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