sendUpdate if different, but update not different

Hello,
I have this code that is supposed to monitor 7 pins for state change and all six analog pins, which eventually will be monitored for variation change. Anyway, the inputs are supposed to call the sendUpdate function which sends a GET request as a client. The remote web server then takes and stores the information to a database. I am having a problem that I am not sure how to solve the best way with the most accuracy. Quite often I will look through the database records and see many updates that were sent, but there is no change in the logic input states. So I assume that at the point of evaluation, there was a change but by the time it got sent to the sendUpdate function, it was back to the original state. Does that make sense? Here is my code...

void loop(){
  
  if(Serial.available() > 0){
    char c = Serial.read();
    
    if(c == 'u'){
      sendUpdate();
    }
  }
  
  if(minute() == 0 || minute() == 15 || minute() == 30 || minute() == 45){
    if(minute() != lastMinute){
      sendUpdate();
      lastMinute = minute();
    }
  }
  
  dRead0 = digitalRead(2);
  if(dRead0 != digitalRead(2)){
    sendUpdate();
  }
  
  dRead1 = digitalRead(3);
  if(dRead1 != digitalRead(3)){
    sendUpdate();
  }
  
  dRead2 = digitalRead(5);
  if(dRead2 != digitalRead(5)){
    sendUpdate();
  }
  
  dRead3 = digitalRead(6);
  if(dRead3 != digitalRead(6)){
    sendUpdate();
  }
  
  dRead4 = digitalRead(7);
  if(dRead4 != digitalRead(7)){
    sendUpdate();
  }
  
  dRead5 = digitalRead(8);
  if(dRead5 != digitalRead(8)){
    sendUpdate();
  }
  
  dRead6 = digitalRead(9);
  if(dRead6 != digitalRead(9)){
    sendUpdate();
  }
  
  aRead0 = analogRead(0);
  aRead1 = analogRead(1);
  aRead2 = analogRead(2);
  aRead3 = analogRead(3);
  aRead4 = analogRead(4);
  aRead5 = analogRead(5);
 
}

void sendUpdate(){
 
 // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    //Serial.println("connected");
    // Make a HTTP request:
    client.print("GET /ktvl/telemetry/telemetry.php?key=");
    client.print(authKey);
    client.print("&id=test");
    client.print("&d0=");
    client.print(dRead0);
    client.print("&d1=");
    client.print(dRead1);
    client.print("&d2=");
    client.print(dRead2);
    client.print("&d3=");
    client.print(dRead3);
    client.print("&d4=");
    client.print(dRead4);
    client.print("&d5=");
    client.print(dRead5);
    client.print("&d6=");
    client.print(dRead6);
    client.print("&a0=");
    client.print(aRead0);
    client.print("&a1=");
    client.print(aRead1);
    client.print("&a2=");
    client.print(aRead2);
    client.print("&a3=");
    client.print(aRead3);
    client.print("&a4=");
    client.print(aRead4);
    client.print("&a5=");
    client.print(aRead5);
    client.print("&ip=");
    client.print(Ethernet.localIP());
    client.println(" HTTP/1.1");
    client.println("Host: www.example.com");
    client.println("Connection: close");
    client.println();
    client.stop();
    Serial.println("Update sent to server...");
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

Thanks for any help...

Jeremy-arduino:
Quite often I will look through the database records and see many updates that were sent, but there is no change in the logic input states. So I assume that at the point of evaluation, there was a change but by the time it got sent to the sendUpdate function, it was back to the original state.

Updates without changes or
changes without updates?

Can't you log the cause (state change) of the updating?

The analogRead function is a long one.
With an oscope, or maybe an LED -- if you digitalWrite pin 13 HIGH, do your six analogReads, and then digitalWrite pin 13 LOW, you can get an idea of how long that's taking.

Make a boolean variable, flagBit --

void setup {}
{
  boolean flagBit = false;
}

void loop(){
  
  if(Serial.available() > 0){
    char c = Serial.read();
    
    if(c == 'u'){
      sendUpdate();
    }
  }
  
  if(minute() == 0 || minute() == 15 || minute() == 30 || minute() == 45){
    if(minute() != lastMinute){
      flagBit = true;
      lastMinute = minute();
    }
  }
  
  dRead0 = digitalRead(2);
  if(dRead0 != digitalRead(2)){
    flagBit = true;
  }
  
  dRead1 = digitalRead(3);
  if(dRead1 != digitalRead(3)){
    flagBit = true;
  }
  
  dRead2 = digitalRead(5);
  if(dRead2 != digitalRead(5)){
    flagBit = true;
  }
  
  dRead3 = digitalRead(6);
  if(dRead3 != digitalRead(6)){
    flagBit = true;
  }
  
  dRead4 = digitalRead(7);
  if(dRead4 != digitalRead(7)){
    flagBit = true;
  }
  
  dRead5 = digitalRead(8);
  if(dRead5 != digitalRead(8)){
    flagBit = true;
  }
  
  dRead6 = digitalRead(9);
  if(dRead6 != digitalRead(9)){
    flagBit = true;
  }
  
  aRead0 = analogRead(0);
  aRead1 = analogRead(1);
  aRead2 = analogRead(2);
  aRead3 = analogRead(3);
  aRead4 = analogRead(4);
  aRead5 = analogRead(5);
  
  if (flagBit == true)
  {
    sendUpdate();
  }
}

void sendUpdate(){
  flagBit = false;
 // if you get a connection, report back via serial:  
  if (client.connect(server, 80)) {
    //Serial.println("connected");
    // Make a HTTP request:
    client.print("GET /ktvl/telemetry/telemetry.php?key=");
    client.print(authKey);
    client.print("&id=test");
    client.print("&d0=");
    client.print(dRead0);
    client.print("&d1=");
    client.print(dRead1);
    client.print("&d2=");
    client.print(dRead2);
    client.print("&d3=");
    client.print(dRead3);
    client.print("&d4=");
    client.print(dRead4);
    client.print("&d5=");
    client.print(dRead5);
    client.print("&d6=");
    client.print(dRead6);
    client.print("&a0=");
    client.print(aRead0);
    client.print("&a1=");
    client.print(aRead1);
    client.print("&a2=");
    client.print(aRead2);
    client.print("&a3=");
    client.print(aRead3);
    client.print("&a4=");
    client.print(aRead4);
    client.print("&a5=");
    client.print(aRead5);
    client.print("&ip=");
    client.print(Ethernet.localIP());
    client.println(" HTTP/1.1");
    client.println("Host: www.example.com");
    client.println("Connection: close");
    client.println();
    client.stop();
    Serial.println("Update sent to server...");
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

It checks (goes through) everything and then, it updates if anything warranted updating.

  dRead0 = digitalRead(2);
  if(dRead0 != digitalRead(2)){
    sendUpdate();
  }

You have less than a microsecond resolution in which the change must occur in, so the liklihood this catches the change is fairly slim.

Using arrays and for loops to process the inputs would reduce the size of your code by roughly a factor of five.

The posted code seems to be incomplete - it's always best to post a complete sketch.

The technique used to detect input changes is unlikely to be effective (unless you have floating inputs, which would give you a whole other set of problems).

If you adopt arrays and for loops, you can address this easily by reading each input into a temporary variable and comparing with the previous stored value for that input before saving it. Here's the sort of thing I mean:

boolean readInputs()
{
    inputChanged = false;
    for(int i = 0; i < PIN_COUNT; i++)
    {
        int newValue = digitalRead(inputPins[i]);
        if(newValue != values[i])
        {
            inputChanged = true;
            values[i] = newValue;
        }
    }
    return inputChanged;
}

@ Runaway Pancake
Actually I have both issues. Updated records without change, and changes with up the update function running. I tried the flagbit, but that did not seem to fix anything.

@Arrch
That's what I would have thought too, and that's why I was almost too embarrassed to make this post, but I can't argue with the results.

@PeterH
That looks good, but as I'm not using consecutive pins, I am unsure how to implement that code.

Ideas on any of this anyone? If the full sketch is needed, I will post it...

I have measured the voltage at the pins and it is definitely going between 0-5 volts but the sendUpdate function is not running. How else can I troubleshoot this? I am using external pull up resistors...

Jeremy-arduino:
That looks good, but as I'm not using consecutive pins, I am unsure how to implement that code.

I'm not sure how that's relative; PeterH's code uses an array of pin numbers; you can put non-consecutive numbers in an array.

Take a look at the StateChangeDetection example to see how to properly detect the signal edge of a digital input.

OK, I looked at the StateChangeDetection and found what I was missing... I forgot to save the current to another "lastKnownState" variable. Doing that, fixed the problem and all works very well now... Thank you Arrch!!!