diff --git a/README.md b/README.md index 8b9a3ca..53526ee 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # HannaBox +Manual install of wifi manager download zip in project dir using vs console: + + pio lib install ~/Downloads/WiFiManager-2.0.16-rc.2.zip ## Pins @@ -9,6 +12,8 @@ D4 -> LRC 5V -> Vin GND -> GND +DAC Channel ESP32 = PIN 25 + SD Card: CS -> D1 MOSI -> D7 diff --git a/data/ex.mp3 b/data/ex.mp3 deleted file mode 100644 index e175d0f..0000000 Binary files a/data/ex.mp3 and /dev/null differ diff --git a/data/ex2.mp3 b/data/ex2.mp3 deleted file mode 100644 index e142acf..0000000 Binary files a/data/ex2.mp3 and /dev/null differ diff --git a/platformio.ini b/platformio.ini index eb3a3bf..bc8dc93 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,11 +8,12 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:d1_mini] -platform = espressif8266 -board = d1_mini +[env:d1_mini32] +platform = espressif32 +board = wemos_d1_mini32 framework = arduino lib_deps = - tzapu/WiFiManager@^0.16.0 - earlephilhower/ESP8266Audio@^1.9.7 + esphome/ESP32-audioI2S@^2.0.7 + me-no-dev/AsyncTCP@^1.1.1 + me-no-dev/ESP Async WebServer@^1.2.3 monitor_speed = 115200 diff --git a/src/WebContent.h b/src/WebContent.h new file mode 100644 index 0000000..e02b20f --- /dev/null +++ b/src/WebContent.h @@ -0,0 +1,69 @@ +// HTML web page +const char index_html[] = R"rawliteral( + + + Hanna Box + + + + +

Greenhousino Irrigation System

+ Pump state:

+

+

+

+ + +)rawliteral"; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 015af81..cdc3097 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,46 +1,66 @@ -#include //https://github.com/esp8266/Arduino - // needed for library -#include -#include -#include //https://github.com/tzapu/WiFiManager +#include +#include "ESPAsyncWebServer.h" +//#include //https://github.com/tzapu/WiFiManager + +#include "Audio.h" + +#define I2S_DOUT 26 // connect to DAC pin DIN +#define I2S_BCLK 27 // connect to DAC pin BCK +#define I2S_LRC 25 // connect to DAC pin LCK -#include "AudioFileSourceSPIFFS.h" -#include "AudioGeneratorMP3.h" -#include "AudioOutputI2SNoDAC.h" -#include "AudioFileSourceSD.h" #include #include +#include "WebContent.h" + File root; File mp3File; void printDirectory(File dir, int numTabs); -AudioGeneratorMP3 *mp3; -AudioFileSourceSPIFFS *file; -AudioFileSourceSD *sdFile = NULL; -AudioOutputI2S *out; - unsigned long lastStart = 0; const int startDelay = 250; -void initMp3File() { - file = new AudioFileSourceSPIFFS("/ex2.mp3"); +Audio audio; +// Set web server port number to 80 +AsyncWebServer server(80); + +// Variable to store the HTTP request +String header; + +void playNextMp3() { File next = root.openNextFile(); + if (!next) { root = SD.open("/"); } - if (String(next.name()).endsWith(".mp3")) { - sdFile = new AudioFileSourceSD(next.name()); + + while (!String(next.name()).endsWith(".mp3")) { + next = root.openNextFile(); + if (!next) { + Serial.println("no more files found."); + return; + } + } - out = new AudioOutputI2S(); - mp3 = new AudioGeneratorMP3(); + Serial.print("initialized"); + Serial.print(next.name()); + Serial.print("\n"); + audio.stopSong(); + audio.connecttoSD(next.name()); } +void audio_info(const char *info){ + //Serial.print("info "); Serial.println(info); +} + + + + void setup() { // put your setup code here, to run once: @@ -48,54 +68,49 @@ void setup() pinMode(D3, INPUT_PULLUP); - // WiFiManager - // Local intialization. Once its business is done, there is no need to keep it around - - //WiFiManager wifiManager; - - - // reset saved settings - // wifiManager.resetSettings(); + AsyncWebServer server(80); + //DNSServer dns; + //first parameter is name of access point, second is the password + //AsyncWiFiManager wifiManager(&server,&dns); - // set custom ip for portal - // wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); - - // fetches ssid and pass from eeprom and tries to connect - // if it does not connect it starts an access point with the specified name - // here "AutoConnectAP" - // and goes into a blocking loop awaiting configuration - //wifiManager.autoConnect("AutoConnectAP"); - // or use this for auto generated name ESP + ChipID + //fetches ssid and pass and tries to connect + //if it does not connect it starts an access point with the specified name + //here "AutoConnectAP" + //and goes into a blocking loop awaiting configuration - - // wifiManager.autoConnect(); - + /* + if (!wifiManager.autoConnect()) + { + Serial.println("failed to connect and hit timeout"); + //reset and try again, or maybe put it to deep sleep + //ESP.restart(); + //delay(1000); + } else { // if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); - audioLogger = &Serial; + } + */ + WiFi.begin("heim", "0ggnWLS."); - Serial.print("Initializing SD card..."); + Serial.print("Initializing SD card..."); if (!SD.begin(D1)) { - Serial.println("initialization failed!"); + Serial.println("SD initialization failed!"); while (1); } - Serial.println("initialization done."); + Serial.println("SD initialization done."); root = SD.open("/"); - - //printDirectory(root, 0); + audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); + audio.setVolume(12); // 0...21 - Serial.println("done!"); - - SPIFFS.begin(); - Serial.println("beginning mp3 setup..."); - initMp3File(); - - + // Send web page with input fields to client + server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ + request->send_P(200, "text/html", index_html); + }); } void printDirectory(File dir, int numTabs) { @@ -125,27 +140,19 @@ void printDirectory(File dir, int numTabs) { void loop() { + + audio.loop(); //Serial.print(digitalRead(D2)); if (digitalRead(D3)==LOW) { unsigned long now = millis(); if (now-lastStart>startDelay) { - if (mp3->isRunning()) { - mp3->stop(); - } - initMp3File(); - mp3->begin(sdFile,out); - Serial.print("started."); + playNextMp3(); + Serial.println("mp3 started."); lastStart=now; } } - if (mp3->isRunning()) - { - if (!mp3->loop()) - mp3->stop(); - } - } \ No newline at end of file