1 master WiFi R4 UNO that listens over Wifi 1 slave WiFi R4 UNO, gathers all info and sends the status to the cloud

I have two rooms, that yhey are far away from each other, there are no cables or any other way to connect them. Only Wifi is the same.

Inside those 2 rooms i have 8 refrigerators. 5 in one room and 3 to the other. Those refidgerators have an NO contact that trigers whenever there is an alarm ( door open, high temperature, ect).

I would like to pass DI & GND of my arduino UNO Wifi through those NO contacts and sent to the cloud the status of every refrigerator.

The problem comes to the other room. I can only connect those 2 arduinos though WiFi.
My serial monitors tells me that that they connect to wifi. I don't have any transfer of info.

Here is my master code :

#include "thingProperties.h"
#include <WiFi.h>
#include <WiFiClient.h>
//#include <ArduinoIoTCloud.h>
//#include <Arduino_ConnectionHandler.h>

// WiFi credentials
const char* ssid = "ssidname"; //here i write the ssid that i want to connect
const char* password = "password"; // here i write the password of the ssid

// Static IP details for the master Arduino
IPAddress local_IP(192, 168, 1, 50);   // Desired static IP address
IPAddress gateway(192, 168, 1, 1);     // Typically your router's IP address
IPAddress subnet(255, 255, 255, 0);    // Subnet mask
IPAddress primaryDNS(8, 8, 8, 8);      // Google's primary DNS
IPAddress secondaryDNS(8, 8, 4, 4);    // Google's secondary DNS (optional)

// Create a server on port 80
WiFiServer server(80);

// Local refrigerator pins (for master Arduino)
const int fridge1Pin = 2;
const int fridge2Pin = 3;
const int fridge3Pin = 4;
const int fridge4Pin = 5;
const int fridge5Pin = 6;

// Variables to hold alarm states for all refrigerators
bool fridge1_alarm = false;
bool fridge2_alarm = false;
bool fridge3_alarm = false;
bool fridge4_alarm = false;
bool fridge5_alarm = false;
bool fridge6_alarm = false;  // From the slave Arduino
bool fridge7_alarm = false;  // From the slave Arduino
bool fridge8_alarm = false;  // From the slave Arduino


void setup() {
  Serial.begin(115200);

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

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  // Print the static IP address
  Serial.println("Connected to WiFi.");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

  // Set up the local fridge pins as inputs with pull-up resistors
  pinMode(fridge1Pin, INPUT_PULLUP);
  pinMode(fridge2Pin, INPUT_PULLUP);
  pinMode(fridge3Pin, INPUT_PULLUP);
  pinMode(fridge4Pin, INPUT_PULLUP);
  pinMode(fridge5Pin, INPUT_PULLUP);

  // Initialize Arduino Cloud
  initProperties();
  
  // Manually establish the connection to the Arduino Cloud
  ArduinoCloud.begin();

  // Wait for cloud connection
  while (!ArduinoCloud.connected()) {
    delay(500);
  }

  // Start the server to receive data from the slave Arduino
  server.begin();
}

// Initialize Arduino Cloud properties
void initProperties() {
  ArduinoCloud.addProperty(fridge1_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge2_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge3_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge4_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge5_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge6_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge7_alarm, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(fridge8_alarm, READ, ON_CHANGE, NULL);
}

void loop() {
  // Monitor local refrigerators (directly connected to master Arduino)
  fridge1_alarm = digitalRead(fridge1Pin) == LOW;
  fridge2_alarm = digitalRead(fridge2Pin) == LOW;
  fridge3_alarm = digitalRead(fridge3Pin) == LOW;
  fridge4_alarm = digitalRead(fridge4Pin) == LOW;
  fridge5_alarm = digitalRead(fridge5Pin) == LOW;

  // Listen for incoming data from the slave Arduino
  WiFiClient client = server.available();
  if (client) {
    Serial.println("Client connected.");
    while (client.connected()) {
      if (client.available()) {
        // Read the incoming data from the slave Arduino
        String data = client.readStringUntil('\n');
        Serial.println("Received: " + data);

        // Parse the data from the slave (expected format: "1,0,1")
        fridge6_alarm = (data.charAt(0) == '1');
        fridge7_alarm = (data.charAt(2) == '1');
        fridge8_alarm = (data.charAt(4) == '1');

        // Close the connection after reading the data
        client.stop();
      }
    }
  }

  // Send all 8 refrigerators' statuses to the Arduino Cloud
  ArduinoCloud.update();  // Sync with Arduino Cloud

  // Optional: Print alarm statuses to the serial monitor for debugging
  Serial.println("Fridge1: " + String(fridge1_alarm));
  Serial.println("Fridge2: " + String(fridge2_alarm));
  Serial.println("Fridge3: " + String(fridge3_alarm));
  Serial.println("Fridge4: " + String(fridge4_alarm));
  Serial.println("Fridge5: " + String(fridge5_alarm));
  Serial.println("Fridge6: " + String(fridge6_alarm));
  Serial.println("Fridge7: " + String(fridge7_alarm));
  Serial.println("Fridge8: " + String(fridge8_alarm));

  delay(1000);  // Update every second
}

this is what i get in serial monitor from my master :

Connected to WiFi.
IP Address: 192.168.1.50

========================================================
And this is my slave code :

#include <WiFi.h>
#include <WiFiClient.h>

// WiFi credentials
const char* ssid = "ssidname"; //here i write the ssid that i want to connect
const char* password = "password"; // here i write the password of the ssid

// IP address of the master Arduino (static IP)
const char* host = "192.168.1.50";  // Replace with the static IP of the master

// Pin definitions for refrigerators connected to the slave Arduino
const int fridge6Pin = 2;
const int fridge7Pin = 3;
const int fridge8Pin = 4;

WiFiClient client;

void setup() {
  Serial.begin(115200);

  // Set up refrigerator pins as inputs with pull-up resistors
  pinMode(fridge6Pin, INPUT_PULLUP);
  pinMode(fridge7Pin, INPUT_PULLUP);
  pinMode(fridge8Pin, INPUT_PULLUP);

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  Serial.println("Connected to WiFi.");
}

void loop() {
  // Gather alarm states for the refrigerators connected to the slave
  bool fridge6_alarm = digitalRead(fridge6Pin) == LOW;
  bool fridge7_alarm = digitalRead(fridge7Pin) == LOW;
  bool fridge8_alarm = digitalRead(fridge8Pin) == LOW;

  // Format the data as a string: "1,0,1" (for example)
  String dataToSend = String(fridge6_alarm) + "," + 
                      String(fridge7_alarm) + "," + 
                      String(fridge8_alarm);
  
  // Connect to the master Arduino and send the data
  if (client.connect(host, 80)) {
    client.println(dataToSend);
    client.stop();  // Close the connection after sending
    Serial.println("Data sent to master: " + dataToSend);
  }

  delay(1000); // Send data every second
}

this is what i get from serial monitor from my slave arduino :

Connected to WiFi.

can any one help ? I think that my problem is in libraries conflict .... but my knowledge is up to that !

I am not familiar with Arduino cloud. But why does one Arduino need to connect to the other Arduino? Can they not both update the cloud independently? That would make the project simpler.

Also, you need to learn to use arrays. Your code is many times longer than it should be. Any time you have a bunch of variables with the same name expect for a number, that should be an array.

Can I connect more that 1 device to 1 thing ?

Can you phrase the question more precisely?

Hi @kourpetis.

I'm not sure I understood correctly what you mean by this. Please provide a more detailed description of what you mean by this in a reply on this forum thread to help us to understand it.

No, but you can display data from more than one Arduino Cloud IoT Thing in a single IoT dashboard.