Serial print a State Machine cycle, but only it differs from the previous cycle?

Hello

I wrote a litte State Machine, and for debugging purposes, I (serial) print if a new state is reached:

void loop() {
  
  if (device_state != prev_device_state) {
    Serial.print("device state:\t\t");
    Serial.println(device_state);
  }

  .
  .
  .
}

That works very well and I get get this (example) output on serial monitor:

[2018-10-01 18:28:20]  
[2018-10-01 18:28:20]  Connecting ......
[2018-10-01 18:28:27]  
[2018-10-01 18:28:27]  Connected to:Mercury
[2018-10-01 18:28:27]  IP address:192.168.1.62
[2018-10-01 18:28:27]  device state:1
[2018-10-01 18:28:27]  device state:2
[2018-10-01 18:28:27]  device state:3
[2018-10-01 18:28:27]  device state:4
[2018-10-01 18:28:27]  device state:5
[2018-10-01 18:28:27]  device state:6
[2018-10-01 18:28:28]  device state:7
[2018-10-01 18:28:28]  device state:8
[2018-10-01 18:28:28]  device state:9
[2018-10-01 18:28:28]  device state:10
[2018-10-01 18:28:28]  cycle time:8189 mSecs
[2018-10-01 18:28:28]  device state:11
[2018-10-01 18:28:28]  device state:60
[2018-10-01 18:28:28]  device state:62
[2018-10-01 18:28:28]  device state:63
[2018-10-01 18:28:28]  device state:64
[2018-10-01 18:28:28]  device state:65
[2018-10-01 18:28:28]  device state:66
[2018-10-01 18:28:28]  device state:67
[2018-10-01 18:28:28]  device state:80
[2018-10-01 18:28:28]  device state:81
[2018-10-01 18:28:28]  device state:82
[2018-10-01 18:28:28]  device state:10
[2018-10-01 18:28:28]  cycle time:25 mSecs
[2018-10-01 18:28:28]  device state:11
[2018-10-01 18:28:28]  device state:60
[2018-10-01 18:28:28]  device state:62
[2018-10-01 18:28:28]  device state:63
[2018-10-01 18:28:28]  device state:64
[2018-10-01 18:28:28]  device state:80
[2018-10-01 18:28:28]  device state:81
[2018-10-01 18:28:28]  device state:82
[2018-10-01 18:28:28]  device state:10
[2018-10-01 18:28:28]  cycle time:25 mSecs
[2018-10-01 18:28:28]  device state:11
[2018-10-01 18:28:28]  device state:60
[2018-10-01 18:28:28]  device state:62
[2018-10-01 18:28:28]  device state:63
[2018-10-01 18:28:28]  device state:64
[2018-10-01 18:28:28]  device state:80
[2018-10-01 18:28:28]  device state:81
[2018-10-01 18:28:28]  device state:82
[2018-10-01 18:28:28]  device state:10
[2018-10-01 18:28:28]  cycle time:25 mSecs
...

As soon as the State Machine went into operation and as long there are no "commands" to it, every printed cycle is exactly equal the previous cycle.

Now, I wish to omit print outs from cycles with the same content as the previous cycle. I only want to print out a cycle if it differs from the previous cycle. I imagined to somehow concatinate all states from one cycle to a string and compare this string with the saved string from the previous cycle. (In my case, every new cycle starts with state 10.)

But my C knowlege is obviously to week, to handle this data type changes, string arrays and concatinating...

Is there a C crack here that has a solution for this (for me) tricky problem?

Kind regards
Roman

What property of a cycle is different from every other cycle?

The state numbers do immediately change, because in case of a command to the state machine, it enters different states.

Here an example where my state machine gets a command and you can see that a cylce has more and partial different states:

[2018-10-06 10:13:33]  cycle time:25 mSecs
[2018-10-06 10:13:33]  device state:11
[2018-10-06 10:13:33]  device state:60
[2018-10-06 10:13:33]  device state:62
[2018-10-06 10:13:33]  device state:63
[2018-10-06 10:13:33]  device state:64
[2018-10-06 10:13:33]  device state:80
[2018-10-06 10:13:33]  device state:81
[2018-10-06 10:13:33]  device state:82
[2018-10-06 10:13:33]  device state:10
[2018-10-06 10:13:33]  cycle time:25 mSecs
[2018-10-06 10:13:33]  device state:11
[2018-10-06 10:13:33]  device state:20
[2018-10-06 10:13:33]  device state:22
[2018-10-06 10:13:33]  device state:23
[2018-10-06 10:13:33]  device state:24
[2018-10-06 10:13:33]  device state:25
[2018-10-06 10:13:33]  device state:26
[2018-10-06 10:13:33]  device state:27
[2018-10-06 10:13:33]  device state:28
[2018-10-06 10:13:33]  device state:60
[2018-10-06 10:13:33]  device state:62
[2018-10-06 10:13:33]  device state:63
[2018-10-06 10:13:33]  device state:64
[2018-10-06 10:13:33]  device state:65
[2018-10-06 10:13:33]  device state:66
[2018-10-06 10:13:33]  device state:67
[2018-10-06 10:13:33]  device state:68
[2018-10-06 10:13:33]  device state:69
[2018-10-06 10:13:33]  device state:70
[2018-10-06 10:13:33]  device state:80
[2018-10-06 10:13:33]  device state:81
[2018-10-06 10:13:33]  device state:82
[2018-10-06 10:13:33]  device state:10
[2018-10-06 10:13:33]  cycle time:49 mSecs
[2018-10-06 10:13:33]  device state:11
[2018-10-06 10:13:33]  device state:60
[2018-10-06 10:13:33]  device state:62
[2018-10-06 10:13:33]  device state:63
[2018-10-06 10:13:33]  device state:64
[2018-10-06 10:13:33]  device state:80
[2018-10-06 10:13:33]  device state:81
[2018-10-06 10:13:33]  device state:82
[2018-10-06 10:13:33]  device state:10
[2018-10-06 10:13:33]  cycle time:26 mSecs

So one state has - concatinated - this states:

116062636480818210

One state later, its this:

1120222324252627286062636465666768697080818210

But this is only one of many possible state cycles. So simply do an mathematical addition an compare the result is not enough to "compare" different cycles. And only compare the number of states of one cylce does not work as well, because even the single states in one cycle can differ, the total number of states can be equal.

I wrote a litte State Machine, and for debugging purposes, I (serial) print if a new state is reached:

The normal way to print such a message when using a state machine would be to print it when you leave a state to go to a new one, but you have not posted your program so it is difficult to see what you are doing

Please post your complete program