I am having a strange issue (probably just dont understand and cant find other topics) regarding sending info to a mySQL database. I can send integers to multiple fields but don't understand what I am doing wrong that I cannot send the date up to a datetime field.
I also cannot send a string like a name. The field just gets a single charachter or some random integer depending on what I have the placeholder set to.
could the issue be that I cant get the dtostrf to work as the board we are using is the MKR1000?
here is some of my code of the cloud update void:
void cloudUpload() {
String dateStamp="";
String timeStamp="";
dateStamp += "20";
dateStamp += (rtc.getYear());
if (rtc.getMonth() < 10) {
dateStamp += "0";
}
dateStamp += (rtc.getMonth());
if (rtc.getDay() < 10) {
dateStamp += "0";
}
dateStamp += (rtc.getDay());
if (rtc.getHours() < 10) {
timeStamp += "0";
}
timeStamp += (rtc.getHours());
//timeStamp += ":";
if (rtc.getMinutes() < 10) {
timeStamp += "0";
}
timeStamp += (rtc.getMinutes());
//timeStamp += ":";
if (rtc.getSeconds() < 10) {
timeStamp += "0";
}
timeStamp += (rtc.getSeconds());
//Serial.println(timeStamp);
//Serial.println(cardName);
String cardName = "Dandy";
char INSERT_DATA[] = "INSERT INTO tek.access (timedateStamp, custSerial, cardCode, facilityCode, readerNum, accessGranted, cardName, timeStamp) VALUES ('%d','%d','%d','%d','%d','%d','%S','%d')";
char query[128];
WiFiClient client;
MySQL_Connection conn((Client *)&client);
//Serial.println("db Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(500);
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
//dtostrf(50.125, 1, 1, custSerial); // this does not seem to work on the MKR1000
sprintf(query, INSERT_DATA, dateStamp.toInt(), custSerial, cardCode, facilityCode, readerNum, accessGranted, cardName, timeStamp.toInt());
// Execute the query
cur_mem->execute(query);
delete cur_mem;
}
else
Serial.println("db Connection failed.");
conn.close();
}
Any help or pointing in the correct direction would be good and thanks!
Andrew