Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <WiFiServer.h>
- #include <WiFiUdp.h>
- WiFiServer server(80);
- char serialString[10];
- void setup() {
- pinMode(14,OUTPUT);
- Serial.begin(9600);
- Serial.end();
- Serial.begin(9600);
- Serial.println("Starting up");
- WiFi.begin("Fane Home", "fararestante");
- Serial.print("Connecting...");
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.print("Connected ");
- Serial.print(WiFi.localIP());
- server.begin();
- }
- void loop() {
- WiFiClient client = server.available();
- if(client){
- String req = client.readStringUntil('\r');
- client.flush();
- Serial1.println(req);
- if (req.indexOf("/bpm/") != -1) {
- strcpy(serialString,"bpm");
- String bpmString = req.substring(req.indexOf("/bpm/")+5,req.indexOf("/bpm/")+8);
- char bpmChar[10] = "";
- bpmString.toCharArray(bpmChar,10);
- strcat(serialString,bpmChar);
- Serial.write(serialString,10);
- }
- else if (req.indexOf("/brg/") != -1) {
- strcpy(serialString,"brg");
- String brgString = req.substring(req.indexOf("/brg/")+5,req.indexOf("/brg/")+8);
- char brgChar[10] = "";
- brgString.toCharArray(brgChar,10);
- strcat(serialString,brgChar);
- Serial.write(serialString,10);
- }
- else if (req.indexOf("/muz/1") != -1) {
- strcpy(serialString,"muz1");
- Serial.write(serialString,4);
- }
- else if (req.indexOf("/muz/2") != -1) {
- strcpy(serialString,"muz2");
- Serial.write(serialString,4);
- }
- else if (req.indexOf("/eco/") != -1){
- strcpy(serialString,"eco");
- Serial.write(serialString,4);
- }
- else if (req.indexOf("/clr/") != -1){
- strcpy(serialString,"clr");
- Serial.write(serialString,4);
- }
- else if (req.indexOf("/col/") != -1){
- strcpy(serialString,"col");
- String colString = req.substring(req.indexOf("/clr/")+5,req.indexOf("/clr/")+7);
- char colChar[10] = "";
- colString.toCharArray(colChar,10);
- strcat(serialString,colChar);
- Serial.write(serialString);
- }
- else if (req.indexOf("/bth/") != -1){
- strcpy(serialString,"bth");
- String bthString = req.substring(req.indexOf("/bth/")+5,req.indexOf("/bth/")+8);
- char bthChar[10] = "";
- bthString.toCharArray(bthChar,10);
- strcat(serialString,bthChar);
- Serial.write(serialString);
- }
- else if (req.indexOf("/bhh/") != -1){
- strcpy(serialString,"bth");
- String bthString = req.substring(req.indexOf("/bhh/")+5,req.indexOf("/bhh/")+8);
- int bhhInt = bthString.toInt();
- bhhInt = 2400/bhhInt;
- char bthChar[10] = "";
- itoa(bhhInt, bthChar, 10);
- strcat(serialString,bthChar);
- Serial.write(serialString);
- }
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement