I have the small project to monitor the level of water. I designed the webserver to get AJAX input from Arduino Mega. I want to enable alarm sound when the water level signal over alarm value. I used audio tag in html to read file.mp3 on the SD Card of arduino, but could not enable the audio on the web. Please, give me some advise to resolve this problem, bros. Thanks very much!
that seems to be an HTML question, not an Arduino question
post your code (with code tags)
2 Likes
This my arduino code:
else if (StrContains(HTTP_req, "GET /alarm.mp3")) {
webFile = SD.open("alarm.mp3");
delay(100);
if (webFile) {
client.println();
byte clientBuf[64];
int clientCount = 0;
while(webFile.available())
{
clientBuf[clientCount] = webFile.read();
clientCount++;
if(clientCount > 63)
{
// Serial.println("Packet");
client.write(clientBuf,64);
clientCount = 0;
}
}
//final <64 byte cleanup packet
if(clientCount > 0) client.write(clientBuf,clientCount);
// close the file:
webFile.close();
Serial.println("close audio");
}
delay(1);
}
beside, HTML code:
<audio controls autoplay>
<source src="alarm.mp3">
</audio>
print something in the else of if (webFile) {
(do you know for sure the file could be open?)
can you post the whole code? (Snippets R Us!)
PS: also do you send something like this
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
before the
client.println();
and do you have a
client.stop(); // close the connection
you seem to be missing type of source data
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.