This is so weird, even if I add this
unsigned long long B = 2291061678ul;
//long long B = atol(str.c_str());
unsigned long A = (long) strtol(str.c_str(),NULL,0);
Serial.println("this is A");
Serial.println(A);
Serial.println("this is B");
Serial.println(B);
I get the same, by the way it a Arduino pro mini
From the trigger
2291061678
this is A
2147483647
this is B
2147483647
working string
2147483647
and A
7FFFFFFF
7FFFFFFF