I use this code to gather data from sensors and send it do mysql database.
I raised char query[128] to 255 but I need to send much longer string in variables sumPM25=",10,10,10,10";sumPM10=",10,10,10,10";
If I put such a long string I got Exception and program stops after the first loop. These long strings are saved correctly to mysql database.
What should I do to send long strings without getting exception and stopping the program? There is a lot of dynamic memory to use variables. So this is not a problem.
char INSERT_DATA[] = "INSERT INTO sh177864_alberts.ruchLog (ruch1, hum, pres, pm25, pm10) VALUES (%s,%s,%s,'%s','%s')";
char query[255];
String sumPM25, sumPM10;
void setup(){...}
void loop() {
printBME280Data(&Serial);
//delay(500);
}
void printBME280Data
(
Stream* client
)
{
float temp(NAN), hum(NAN), pres(NAN), tempAVG, humAVG, presAVG;
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_hPa);
tempAVG=0; humAVG=0;presAVG=0;
sumPM25=",10,10,10,10";sumPM10=",10,10,10,10"; // here is problem!!!
for (int a=0; a<10; a++)
{
bme.read(pres, temp, hum, tempUnit, presUnit);
client->print("Temperatura: ");
client->print(temp);
client->print("°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
client->print("\t\tWilgotność: ");
client->print(hum);
client->print("% RH");
client->print("\t\tCiśnienie: ");
client->print(pres);
client->println(" hPa\t\t");
tempAVG+=temp;
humAVG+=hum;
presAVG+=pres;
//for (int b=0; b<12; b++)
// {
if(Serial.find(0x42))
Serial.readBytes(bufor,N);
if(bufor[0] == 0x4d){
if(sprawdzLancuch(bufor,N)){
PM25=wartoscPM25(bufor);
PM10=wartoscPM10(bufor);
}
}
sprintf(linia1,"%d",PM25);
sprintf(linia2,"%d",PM10);
delay(5000);
//}
}
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Save
dtostrf(tempAVG/10, 1, 3, temperature);
dtostrf(humAVG/10, 1, 3, wilgotnosc);
dtostrf(presAVG/10, 1, 2, cisnienie);
sprintf(query, INSERT_DATA, temperature, wilgotnosc, cisnienie, sumPM25.c_str(), sumPM10.c_str());
cur_mem->execute(query);
delete cur_mem;
Serial.println("Data saved.");
delay(1000);
}