I'd like the arduino to write to a file whenever an ajax call is made. The ajax works, but it doesn't write to the file. All other code inside the ajax handler does execute.
void handle_ajax() {
int startUrlIndex = HTTP_req.indexOf("button");
int endUrlIndex = HTTP_req.indexOf(" HTTP");
String url = HTTP_req.substring(startUrlIndex, endUrlIndex);
int startButtonIndex = url.indexOf("device-") + 7;// 7 is length of device-, I really just want the number.
int endButtonIndex = url.indexOf("&");
String button = url.substring(startButtonIndex, endButtonIndex);
int startStateIndex = url.indexOf("state=") + 6; // 6 is length of state=, I really just want the number.
String state = url.substring(startStateIndex);
int device = button.toInt();
int newState = state.toInt();
dim_light(device, newState * 12);
write_config("", "text");
}
bool write_config(String line, String text) {
configFile = SD.open("config.ini", FILE_WRITE);
if (configFile) {
configFile.write("Dipshit");
}
configFile.close();
Serial.println("Works.");
return true;
}
setup()
? 2. Can you expand your code snippet to include the parts where you configure the SD card?SD
andconfigFile
? The statementconfigFile.close();
belongs into the{}
just after the line withconfigFile.write("Dipshit");
.