Open whatislove23 opened 6 months ago
uint8_t btn_prev; char ssid[] = "Home"; // your network SSID (name) char pass[] = "23042002"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status char server[] = "192.168.31.160"; const int CHUNK_SIZE = 64; // Adjust the chunk size as needed char mybuffer[CHUNK_SIZE]; WiFiEspClient client; SoftwareSerial Serial1(3, 2); // RX, TX
void setRGBColor(int mode) { switch (mode) { case 0: analogWrite(R_PIN, 0); analogWrite(G_PIN, 0); analogWrite(B_PIN, 0); break; case 1: // Set color for mode 1 (e.g., red) analogWrite(R_PIN, 255); analogWrite(G_PIN, 0); analogWrite(B_PIN, 0); break;
case 2:
// Set color for mode 2 (e.g., green)
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 255);
analogWrite(B_PIN, 0);
break;
case 3:
// Set color for mode 3 (e.g., blue)
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 255);
break;
// Add more cases as needed for different modes
case 4:
// Set color for mode 4 (e.g., purple)
analogWrite(R_PIN, 255);
analogWrite(G_PIN, 0); // Adjust green value for orange
analogWrite(B_PIN, 255);
break;
default:
// Default case (e.g., turn off)
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 0);
break;
} }
void setup() { setRGBColor(3); pinMode(R_PIN, OUTPUT); pinMode(G_PIN, OUTPUT); pinMode(B_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); Serial.begin(115200); Serial1.begin(9600); Serial.print("Initializing SD card..."); if (!SD.begin(4)) { Serial.println("initialization failed!"); while (true) setRGBColor(1); } Serial.println("initialization done."); WiFi.init(&Serial1); if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); while (true) setRGBColor(1); } while (status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, pass); } setRGBColor(2); }
void saveAudioToFile() { File audioFile = SD.open("audio.wav", FILE_WRITE );
if (audioFile) { while (client.available()) { int bytesRead = client.readBytes(mybuffer, CHUNK_SIZE); audioFile.write(mybuffer, bytesRead); Serial.print("."); } Serial.println("Audio saved to SD card."); audioFile.close(); setRGBColor(2);
} else { Serial.println("Error opening audio file for saving!"); } } void loop() { uint8_t btn = digitalRead(BUTTON_PIN);
if (btn == LOW && btn_prev == HIGH) { setRGBColor(4); / RECORD SPEECH/ SAVE TO SD/ SEND FROM SD TO SERVER TO DO / if (client.connect(server, 5000)) { Serial.println("Connected to server"); int value = 2.5; // an arbitrary value for testing String content = "{\"JSON_key\": " + String(value) + "}"; client.println("POST /post HTTP/1.1"); client.println("Host: 192.168.31.160:5000"); client.println("Accept: /"); client.println("Content-Length: " + String(content.length())); client.println("Content-Type: application/json"); client.println(); client.println(content); } if (client.connect(server, 5000)) { Serial.println("Connected to server"); client.println("GET / HTTP/1.1"); client.println("Host: 192.168.31.160:5000"); client.println("Connection: close"); client.println(); } } if(client.available()){ Serial.println(1); saveAudioToFile(); } btn_prev = digitalRead(BUTTON_PIN); }
Hello. Im trying to download wav file from server and store them to sd card. This part of code is working but when im trying to add library #include to play audio ESP starts behave like this (see screenshoot) without the line everything is okay. Maybe someone has idea how to solve this because im not really good into this. Thanks