Controlling Automower

However after some time (typically hours) I get weird messages:

Sounds like you're running out of memory slowly. Get rid of the usage of the String class. Although the worst memory leaking bug was fixed in version 1.0.5 of the IDE it still makes excessive use of dynamic memory allocation which fragments the memory and at some point it cannot allocate enough memory. At that point things get weird and unpredictable. Convert the complete string handling to C strings (character arrays).

Also use the F() macro for all constant string calls to print() and println() methods.

How can I implement something that checks if the start bit is correct?

You can parse the message and react on each byte instead of reading 5 bytes and checking for complete combinations. Although if the mower is only sending data if you sent a command before, this shouldn't be necessary.

(deleted)

client.print("Stop");

gets

client.print(F("Stop"));

and

String command = client.readStringUntil('/');

maybe written as

#define BUFFERSIZE 40
uint8_t buffer[BUFFERSIZE];
uint8_t i = 0;
while (i < BUFFERSIZE) {
  if (client.available()) {
    uint8_t c = client.read();
    if (c == '/') break;
    buffer[i++] = c;
  }
}

you can then use strncmp() to compare the string to a fixed String and there is also a strncmp_P() version to hold the compare string in flash only and save some RAM. This code misses a timeout handling and other error handling (what if buffer overflows?).

(deleted)

(deleted)

(deleted)

The other command was used in the bridge example and I use it in another sketch as well without issues.

That was the case with the print() calls without the F() macro too. Just because it works for some time doesn't mean that it cannot be responsible for the problems after running a while. You're using the String class and that class fragments the available memory after some time. Once there isn't enough memory to fulfill the next allocation request, the program starts to react unpredictably.

Status returns 14392 instead of 56.

Provide the whole 5 bytes of output (best is to post it in hexadecimal format) not just a single part of it.

Also please post the current code you're working with, I guess you changed some stuff in the meantime.

Btw. is there a code way to restart the sketch?

Sure there is, but you should get the code to run reliably and not to restart it every other second.

Do you expect issues withe the compare functions I use?

Do you mean the "memcmp()" function? No, that works very well.

(deleted)

(deleted)

Change

if (strcmp (buffer, "digital") == 0)

to

if (strcmp ((char *)buffer, "digital") == 0)

and it compiles for me.

Problem happens if Automower has low battery. So I have to restart Arduino because it is probably not an issue of the code. How can I do this?

What happens if the mower is low on battery? Does the voltage that powers the Arduino drop? How much voltage do you have with a full battery? How much if it's getting empty? Where do you feed the Arduino with this voltage (Vin, 5V, power connector)?

You can restart the Arduino by pushing the reset button. You probably meant how to do it in software: that doesn't make sense because your software is already not running correctly, so don't expect it to reset itself.

(deleted)

I can read the Sensors so the issue might be in the Automower side.

Why do you want to restart the Arduino then? What do you expect that this should fix?

(deleted)

Automower.ino (9.24 KB)

I can only guess, but it might be possible that the Automower gives feedback that has more than 5 Bytes and therefore I have the issue. In that case the script is not in sync anymore.

That's no reason to reset the Arduino. If you're unsure clear the serial buffer from time to time.

However I have a new issue with your code:

Why do you think this has anything to do with "my" code?
Your code formatting is still horrible. Please take the time to use the AutoFormatter in the IDE at least.

Although it should make a significant difference, change the code

#define BUFFERSIZE 40
uint8_t buffer[BUFFERSIZE];
uint8_t i = 0;
while (i < BUFFERSIZE) {
  if (client.available()) {
    uint8_t c = client.read();
    if (c == '/') break;
    buffer[i++] = c;
  }
}

to

#define BUFFERSIZE 40
uint8_t buffer[BUFFERSIZE];
uint8_t i = 0;
while (i < BUFFERSIZE) {
  if (client.available()) {
    uint8_t c = client.read();
    if (c == '/') break;
    buffer[i++] = c;
  }
}
if (i < BUFFERSIZE) buffer[i] = 0;

In digitalCommand() and analogCommand() you're still using the String class. Why?

(deleted)

Hello Dawiinci,

Great project you did! I own the same automower and was looking for exactly this. How is it working for you now?
Do you have this project documented somewhere, or would you like to post the code and instructions?
That would be awesome :slight_smile:

Thanks
Sam

hi dawincii

i am also interested in the whole project description

off course with a please and thank you

mario

Hi dawincii,

this seems to be quite interesting, because iown a 220 :slight_smile:
So I am also interested in the whole project.

Greetings

mike

Hello,

also intrested!

kr
Sam