Struct array wrong data

Hello guys i have problem with my code :

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include "OS.h"
#include "PubSubClient.h"
#include "mqtt_handler.h"
#include "feed_item.h"
#include <Preferences.h>
#include "ESP32Time.h"

#define INIT_PIN 15

extern Preferences drive;
extern WebServer server;
extern const char *mqtt_server;
extern PubSubClient client;
extern Servo feed_servo;

ESP32Time rtc(3600);
feed_item times[3] = {};

const char *SERIAL_NUMBER = "TWR876";

bool setup_wifi = false;

void IRAM_ATTR rst()
{
  ESP.restart();
}

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

  // setup
  pinMode(INIT_PIN, INPUT);

  feed_servo.attach(FEED_SERVO_PIN);

  feed_servo.write(0);

  // init system

  if (digitalRead(INIT_PIN) == LOW)
  {
    unsigned long time = millis();
    while (digitalRead(INIT_PIN) == LOW)
    {
    }
    unsigned long now = millis();
    if (now - time >= 6000)
    {
      clear_times_data();
    }
    else if (now - time >= 4999)
    {
      drive.begin("wifi", false);
      drive.clear();
      drive.end();
      delay(200);
    }
  }

  drive.begin("feed_system", true); // Open namespace for reading
for (int i = 0; i < 3; i++) {
    feed_item it = load_times_data(i);
    Serial.printf("Loaded from load_times_data %d: %02d:%02d:%02d\n", i, it.H, it.M, it.S);
    times[i] = it;  // Direct assignment to times[i]
    Serial.printf("Assigned Time for %d: %02d:%02d:%02d\n", i, times[i].H, times[i].M, times[i].S);
}

  drive.end();

  attachInterrupt(digitalPinToInterrupt(15), rst, FALLING);
  // end init system

  // get wifi data
  drive.begin("wifi", false);
  String ssid = drive.getString("ssid", "");
  delay(200);
  String pass = drive.getString("pass", "");
  delay(200);
  drive.end();

  rtc.setTime(30, 24, 14, 17, 1, 2021);

  if (ssid == "")
  {
    setup_wifi = true;
    // wifi setup
    WiFiSetup();
    server.begin();
  }
  else
  {
    // connect wifi
    WiFi.softAPdisconnect(true);
    WiFiConnect(ssid, pass);
  }

  // mqtt setup
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void loop()
{
  // iot system check

  if (setup_wifi)
  {
    server.handleClient();
  }
  else if (!WiFi.isConnected())
  {
    WiFi.reconnect();
  }
  else if (!client.connected())
  {
    reconnect();
    delay(1000);
    client.publish("fed1", "online");
  }
  else
  {
    client.loop();
  }
  Serial.println(rtc.getTime());
  Serial.printf("%d:%d:%d\n", times[0].H, times[0].M, times[0].S);
}

my output is wrong output:

Feed item 0 loaded: Time: 13:12:00, Play Sound: 0, Delay: 20, Work: 1
Loaded from load_times_data 0: 13:12:00
Assigned Time for 0: 13:12:00
Feed item 1 loaded: Time: 13:12:00, Play Sound: 0, Delay: 20, Work: 1
Loaded from load_times_data 1: 13:12:00
Assigned Time for 1: 13:12:00
Feed item 2 loaded: Time: 13:12:00, Play Sound: 0, Delay: 20, Work: 1
Loaded from load_times_data 2: 13:12:00
Assigned Time for 2: 13:12:00
..
192.168.100.18
Attempting MQTT connection...connected
15:24:35
620773686:-1306523032:172156192

feed Item :

struct feed_item {
    int H;
    int M;
    int S;
    bool play_sound;
    int delay;
    bool work;
};

ok, and what is expected?

13:12:00 instead 620773686:-1306523032:172156192

it is definitely not type int.

maybe try first

  Serial.println(rtc.getTime());
  Serial.println(times[0].H);
  Serial.println(times[0].M);
  Serial.println(times[0].S);

and/or

  Serial.println(rtc.getTime());
  byte b = times[0].H
  Serial.println(b);
  b = times[0].M
  Serial.println(b);
  b = times[0].S
  Serial.println(b);

im sorry for miss information i just want when I load 13:12:00 the code show that instead of 620773686:-1306523032:172156192
its simple code I want to work :

struct feed_item {
    int H;
    int M;
    int S;
    bool play_sound;
    int delay_time;
    bool work;
};

feed_item times[3] = {{12,13,14,false,1000,true},{12,15,34,false,3000,true},{18,23,54,false,2000,true}};
void setup() {
  Serial.begin(115200);

    for (int i = 0; i < 3; i++) {
    Serial.print("Item ");
    Serial.print(i);
    Serial.print(": time = ");
    Serial.printf("%d:%d:%d",times[i].H,times[i].M,times[i].S);
    Serial.print(", flag = ");
    Serial.println(times[i].play_sound ? "true" : "false");
  }
}

void loop() {

}

my out put is :

Item 0: time = 620773686:-1306523032:172156192, flag = true
Item 1: time = -1306523034:549662752:1415906525, flag = true
Item 2: time = -266470525:201343286:15736066, flag = true

I want to get :
item 0:time = 12:13:14 , ...........

i check the byte it was 54 idk why and how to fix that

this simple code i show you didnt work too

try

struct feed_item {
    int32_t H;
    int32_t M;
    int32_t S;
    int32_t delay_time;
    int32_t BoolFlags;
};
feed_item times[3] = {
 {12,13,14,1000, (false<<1) | (true<<0)},
 {12,15,34,3000, (false<<1) | (true<<0)},
 {18,23,54,2000, (false<<1) | (true<<0)}
};

maybe you will need to modify other piece of your code, like this

Serial.println(times[i].play_sound ? "true" : "false");
to
Serial.println(times[i].BoolFlags&0x02? "true" : "false");

steel i got :

Item 0: time = 620773686:-1306523032:172156192, flag = true
Item 1: time = -452968138:-1306523034:549662752, flag = true
Item 2: time = 240:553664822:-266470525, flag = true

can you shorting the code that i can test it in simulator?

yes :

struct feed_item {
    int32_t H;
    int32_t M;
    int32_t S;
    int32_t delay_time;
    int32_t BoolFlags;
};
feed_item times[3] = {
 {12,13,14,1000, (false<<1) | (true<<0)},
 {12,15,34,3000, (false<<1) | (true<<0)},
 {18,23,54,2000, (false<<1) | (true<<0)}
};
void setup() {
  Serial.begin(115200);

    for (int i = 0; i < 3; i++) {
    Serial.print("Item ");
    Serial.print(i);
    Serial.print(": time = ");
    Serial.printf("%d:%d:%d",times[i].H,times[i].M,times[i].S);
    Serial.print(", flag = ");
    Serial.println(times[i].BoolFlags ? "true" : "false");
  }
}

void loop() {

}

That may be an unfortunate choice of names. times appears to be unusable as an array name (don't know why ... reserved word, function name, who knows). When I changed it to something else, your code worked.

no way dude thanks a lot you saved me thanks dude
and thanks other tried to help :heart_eyes:

mark his answer as solution