Hello! So I have been trying different things with this problem but I thought this seemed the easiest way; however, I need some help figuring out the right syntax.
I want to have my arduino do things (like spin a motor) when it finds a txt file that is produced by the website in SD card.
Here is the part of the sd code that tries (i guess ) to create a txt file inside the SD card
<script type="text/javascript">
var jsalarm={
padfield:function(f){
return (f<10)? "0"+f : f
},
showcurrenttime:function(){
var dateobj=new Date()
var ct=this.padfield(dateobj.getHours())+":"+this.padfield(dateobj.getMinutes())+":"+this.padfield(dateobj.getSeconds())
this.ctref.innerHTML=ct
this.ctref.setAttribute("title", ct)
if (typeof this.hourwake!="undefined"){ //if alarm is set
if (this.ctref.title==(this.hourwake+":"+this.minutewake+":"+this.secondwake)){
clearInterval(jsalarm.timer)
countdowntimer()
PrintWriter writer = new PrintWriter("alarm.txt", "UTF-8");
}
}
},
So this website that runs from the sd card creates a text file in itself and then I have the arduino look for it to do things.
So basically I have a nested SD finder: Here is the part of the code im trying to debug.
void setup()
{
Ethernet.begin(mac,ip);
pinMode(9,OUTPUT);
server.begin();
Serial.begin(9600);
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
return; // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
}
void loop()
{
EthernetClient client = server.available();
if (client){
boolean currentLineIsBlank = true;
while(client.connected()) {
if(client.available()){
char c = client.read();
if (c== '\n' && currentLineIsBlank) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
//web page
webFile = SD.open("index.htm"); // open web page file
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
if (SD.exists("alarm.txt"));
void functions();
SD.remove("alarm.txt");
}
webFile.close();
}
break;
}
Any help would be gracefully apreciated!