-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP8266_Wifi-Radio.ino
290 lines (233 loc) · 7.64 KB
/
ESP8266_Wifi-Radio.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
Copyright (c) 2020 Peter Siepe. All rights reserved.
See the bottom of this file for the license terms.
do8pgg@do8pgg.de
*/
/*
Wifi-TEA5767 Controller with OTA (Over The Air)-Update
*/
#include <TEA5767.h>
#include <ESP8266WiFi.h> //Wifi
// Enable oder disable OTA, maybe it works.
// #define OTA
#ifdef OTA
#include <ESP8266mDNS.h> //OTA
#include <WiFiUdp.h> //OTA
#include <ArduinoOTA.h> //OTA
#endif
// Enable oder Disable Serial-Output
// #define serial
// Local Frequencys
float einslive = 106.7; // EinsLive
float wdr2 = 99.20; // WDR2
float wdr3 = 95.10; // WDR3
float wdr4 = 101.30; // WDR4
float wdr5 = 88.80; // WDR5
float cosmo = 103.30; // Cosmo
float radioen = 105.70; // WDR4
// SSID and Password from your Wireless Network
const char* ssid = "SSID";
const char* password = "PASSWORD";
String MuteState = "off";
TEA5767 radio = TEA5767();
WiFiServer server(80); // Listen http-Port
void setup() {
Wire.begin();
// Enable or disable Serial-Output
#ifdef serial
Serial.begin(115200);
#endif
radio.setFrequency(wdr4); // Startup-Station
WiFi.mode(WIFI_STA); //OTA
delay(10);
// Connect to network...
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250); // Print dots while waiting for connection :-)
Serial.print(".");
}
Serial.println("");
Serial.print("Connectet to: ");
Serial.println(ssid);
// Start the server
server.begin();
Serial.println("Server started successfully!");
// Print IP-Address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
#ifdef OTA
ArduinoOTA.begin(); //OTA
#endif
}
void loop() {
#ifdef OTA
ArduinoOTA.handle(); //OTA
#endif
// New Client
WiFiClient client = server.available();
if (!client) {
return;
}
// Waiting...
Serial.println("Client Connected:");
while (!client.available()) {
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// requests...
if (request.indexOf("/einslive") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(einslive);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/wdr2") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(wdr2);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/wdr3") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(wdr3);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/wdr4") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(wdr4);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/wdr5") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(wdr5);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/cosmo") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(cosmo);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/radioen") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setFrequency(radioen);
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/stumm") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setMuted(true);
MuteState = "on";
server.stop();
delay(10);
server.begin();
}
if (request.indexOf("/normal") != -1) {
Serial.print("Requested from: ");
Serial.print(client.remoteIP());
Serial.println(" ");
radio.setMuted(false);
MuteState = "off";
server.stop();
delay(10);
server.begin();
}
// Build the "WebInterface"
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // Must be important!...
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<title>Bad-Radio</title>");
// Should still be tidied up a little and sorted. But ... it works for me :-)
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
client.println("<style>html { font-family: Helvetica; background-color: grey; display: inline-block; margin: 0px auto; text-align:}");
client.println(".button { background-color: #1C91FF; border: none; color: white; padding: 25px 80px;");
client.println("text-decoration: none; font-size: 50px; margin: 2px; cursor: pointer;}");
client.println(".buttoncosmo {background-color: #1C91FF; padding: 25px 59px;}");
client.println(".buttonmuteon {background-color: #FF0000; padding: 25px 86px;}");
client.println(".buttonmuteoff {background-color: #1C91FF; padding: 25px 78px;}");
client.println(".buttonlive {background-color: #1C91FF; padding: 25px 67px;}");
client.println(".buttonren {background-color: #1C91FF; padding: 25px 62px;}");
client.println("</style></head>");
// Einslive
client.println("<p><a href=\"/einslive\"><button class=\"button buttonlive\">Eins Live</button></a></p>");
// WDR 2
client.println("<p><a href=\"/wdr2\"><button class=\"button\">W D R 2</button></a></p>");
// WDR3
client.println("<p><a href=\"/wdr3\"><button class=\"button\">W D R 3</button></a></p>");
// WDR4
client.println("<p><a href=\"/wdr4\"><button class=\"button\">W D R 4</button></a></p>");
// WDR5
client.println("<p><a href=\"/wdr5\"><button class=\"button\">W D R 5</button></a></p>");
// WDR Cosmo
client.println("<p><a href=\"/cosmo\"><button class=\"button buttoncosmo\">C o s m o</button></a></p>");
// Radio EN
client.println("<p><a href=\"/radioen\"><button class=\"button buttonren\">Radio EN</button></a></p>");
// Muter
if (MuteState == "off") {
client.println("<p><a href=\"/stumm\"><button class=\"button buttonmuteoff\">Ton aus</button></a></p>");
} else {
client.println("<p><a href=\"/normal\"><button class=\"button buttonmuteon\">Ton ein</button></a></p>");
}
client.println();
delay(1);
short lvl = radio.getSignalLevel();
Serial.println("Client disconnected");
client.println("<br>");
delay(250);
client.print(" Signalstärke: ");
client.print(lvl);
client.println("<a href=\"/\"\"></a>");
client.println("</html>");
}
/*
Copyright (c) 2020 Peter Geher
This Code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this Code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/