Serial stops sending to raspberry pi when ArduinoCloud.update(); is in the loop()

Maybe somebody can help me out here.

I am using a GSM 1400 with Arduino IoT Cloud. I am using it to communicate with a raspberry pi (that is running my automatic cow feeder). My goal is to relay messages from the pi to the MKR which then tells the MKR what int to send to my IoT Cloud Dashboard.

I can get one to work. Which is sending int variable values from MKR to arduino cloud. But I cannot get communication between the pi and the arduino to work in the same sketch. Just when I request from pi nothing comes back.

I've narrowed it down to the function the IoT Cloud requires to update the Arduino Cloud (ArduinoCloud.update();). When this is set in the loop() the communication between pi and arduino won't work. However, when I comment it out, the communication between the pi and arduino works fine. I even tried putting it into a function I can call at will, it stops communication from working.

Anybody idea what this could be?

Thanks.

#include "thingProperties.h"

String nom = "Arduino";
String msg;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

}

void loop() {
  readSerialPort();
  ArduinoCloud.update();
  Serial.println("Welcome to Arduino");

  if (msg == "open") {
    sendOpen();
  } else if (msg == "closed") {
    sendClosed();
  } else if (msg == "siren") {
    sendSiren();
    delay(3000);
  }

  void readSerialPort() {
    msg = "";
    if (Serial.available()) {
      delay(10);
      while (Serial.available() > 0) {
        msg += (char)Serial.read();
      }
      Serial.flush();
    }
  }

  void sendOpen() {
    Serial.print("Heard - open");
  }

  void sendClosed() {
    Serial.print("Heard - Closed");
  }

  void sendSiren() {
    Serial.print("Heard - Siren");
  }

  void onCommandWriteChange()  {

  }




Hi,

welcome to the forum.

What is a bit uncommon is to define your functions inside function loop.

Defining a function inside another function means this function is only know within this function but not outside (this is called the "scope")

As you use those function only inside loop it does work.
Anyway It is not really clear to me what the situation is.
It would help if you write in more detail what you are trying to do.

I want to descrfibe in my own words what I guess what your description means

You have a Raspi that is controlling a cow-feeder
Your raspi is connected to a Arduino MKR GSM1400

The Raspi is sending messages like "open" , "closed" , "siren" to the Arduino MKR GSM1400

In which way = what are the hardware-connectors how the Arduino MKR GSM1400 is connected to the Raspi?

You coded the standard serial interface which belongs to the USB-connector

not very clear to me what this means
Who is "one" ? and where is the int variable set to what value in your code?

I can't see any int variable beeing set to a value in the code you have posted

I can't see any code that would do a "request from pi"
and it is unclear to me what "request from pi" means.

Which device is doing what?

Do you use some kind of IO-cloud-webinterface to make a request at the Arduino MKR GSM1400?

Your Arduino MKR GSM1400 sends a request to the raspi?

The Raspi is sending a request to the Arduino MKR GSM1400?

How does the request-"message" look like?"

All the posted code does is
if the Arduino MKR GSM1400 receives a "open" print "open" to the serial monitor

So you have to describe in much more details what you want to do

And the functionality you want to have

best regards Stefan