I had following setup earlier:
String INSERT_SQL = "";
// inserting to sql database on mysql server
INSERT_SQL = "";
INSERT_SQL.concat("INSERT INTO arduinoSensorData.sensorLog (out_temperature, out_humidity, ");
INSERT_SQL.concat(" drwngRoom_temperature, drwngRoom_humidity, pot1_soilMoisture, pot1_avg_SoilMoisture,");
INSERT_SQL.concat(" wateringPot1) VALUES ('");
INSERT_SQL.concat(outdoorTempInC);
INSERT_SQL.concat("', '");
INSERT_SQL.concat(outoorHumidity);
INSERT_SQL.concat("', '");
INSERT_SQL.concat(indorTempinC);
INSERT_SQL.concat("', '");
INSERT_SQL.concat(h);
INSERT_SQL.concat("', '");
INSERT_SQL.concat(val);
INSERT_SQL.concat("', '");
INSERT_SQL.concat(avgVal);
INSERT_SQL.concat("', '");
if (wateringBasedOnAlarm){
waterMsg = "water based on alarm";
} else waterMsg = soilMsg;
INSERT_SQL.concat(waterMsg);
INSERT_SQL.concat("');");
And later, I was converting it to char like this:
const char *mycharp = INSERT_SQL.c_str();
Which I realised wrong approach as in every iteration of the loop function of arduino MCU this will consume more memory!
So, I decided to change INSERT_SQL
to char instead of declaring it as String
at first place.
I initialised INSERT_SQL as char like this:
char INSERT_SQL[295];
Because I realised the total length would not be more than 295,
But when compiler reaches the line:
INSERT_SQL = "";
I got an error saying:
incompatible types in assignment of 'const char [1]' to 'char [295]'
So, this is the first thing I need is to fix it and secondly, I think I cannot use concat
with char datatype, so in that case how do I populate values to sql query using sprintf
?