char* getAddress() const {
return address;
}
and use
strcpy(charbuffer, sensors[i]->getAddress());
It not work.
Any ideas what could affect this problem? (all other things works fine and return method has no problems. Seems that strcpy not work but also I m not sure how could i put this char const* value to char array[30]). It not also help if I use %s, not '%s'.
You are simply trying to load this array:
char charbuffer[30]
with a value that is in, or is pointed at by, sensor[1] ?
Can you post the code which includes the definition of sensor and, if sensor is an array of structures, the definition of that structure, and the code which updates sensor.
Serial monitor: (it puts only the first value). I used '%s' for query.
Connected to server version 5.6.21 (this print is from mysql-connector-library that connection is ok)
0 (for loop for sensors) - Serial.println(i);
28 A8 FB 13 5 0 0 B0 - Serial.println(charbuffer);
28 A8 FB 13 5 0 0 B0 - Serial.println(charbuffer)(before sql-query)
28 A8 FB 13 5 0 0 B0 - Serial.println(charbuffer)(after all)
1
28 2B 4F 13 5 0 0 53
28 2B 4F 13 5 0 0 53 (before sql-query)
Error: 156 = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[' at line 1.
28 2B 4F 13 5 0 0 53
Now it puts only the first value to a database but gets problems after that. It works fine (puts data all time to the database) if I determine char charbuffer[30] = "whatevervalue";
tolerance_zero:
I figured out what was a problem. Was thinking about this why it gives error about '['. Then I was thinking that there was not enough space for query.
So when I changed
char sqlquery[200];
it started working. All examples with mysql-connector have char sqlquery[128];
You'd do well to have a define of the max size somewhere so you can change all your character arrays at once if you need to in the future....
#define SQL_SIZE_MAX 200
char Query1[SQL_SIZE_MAX+1] ; // +1 for terminating zero
char AQuery[SQL_SIZE_MAX+1] ;
etc...
So if you ever have to change the size again all you need to do is change 200 to, for example, 250...