Feat: add hostname

This commit is contained in:
Bertrand Benjamin 2022-08-11 17:09:39 +02:00
parent 79e712aa20
commit dc739f6408
2 changed files with 42 additions and 20 deletions

View File

@ -10,11 +10,44 @@ Audio audio;
String ssid = WIFI_SSID; String ssid = WIFI_SSID;
String password = WIFI_PASSWD; String password = WIFI_PASSWD;
String hostname = HOSTNAME;
int analogValue;
void setup() { void setup() {
wifi_init();
Serial.println(".");
Serial.println("WiFi connecte");
Serial.println("Adresse IP: ");
Serial.println(WiFi.localIP());
Serial.println(WiFi.RSSI());
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(30);
// audio.connecttohost("http://192.168.2.216:8000/06%20-%20H4dopi.mp3");
audio.connecttohost("http://icecast.radiofrance.fr/franceinter-midfi.mp3");
// audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
}
void loop()
{
audio.loop();
analogValue = analogRead(34);
audio.setVolume(analogValue*30/4095);
}
void wifi_init() {
Serial.begin(115200); Serial.begin(115200);
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.setHostname(hostname.c_str());
WiFi.begin(ssid.c_str(), password.c_str()); WiFi.begin(ssid.c_str(), password.c_str());
Serial.print("Connexion au reseau "); Serial.print("Connexion au reseau ");
@ -26,26 +59,6 @@ void setup() {
} }
WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(192,168,2,1)); WiFi.config(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask(), IPAddress(192,168,2,1));
Serial.println(".");
Serial.println("WiFi connecte");
Serial.println("Adresse IP: ");
Serial.println(WiFi.localIP());
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(5);
// audio.connecttohost("http://192.168.2.216:8000/06%20-%20H4dopi.mp3");
audio.connecttohost("http://icecast.radiofrance.fr/franceinter-midfi.mp3");
// audio.connecttohost("0n-80s.radionetz.de:8000/0n-70s.mp3");
}
void loop()
{
audio.loop();
} }
void audio_info(const char *info) { void audio_info(const char *info) {

9
wifiinfo.h.sample Normal file
View File

@ -0,0 +1,9 @@
#ifndef CREDENTIALS_H
#define CREDENTIALS_H
// Replace with your actual SSID and password:
#define WIFI_SSID "Your SSID here"
#define WIFI_PASSWD "WLAN AP password here"
#define HOSTNAME "hostname"
#endif