Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266HTTPClient.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
- const char *ssid = "ssid";
- const char *password = "password";
- bool isRecording;
- bool muted;
- bool streaming;
- boolean toBool(String value);
- #define mutedLED D8
- #define recordingLED D7
- #define debug true
- String serverName = "http://myip:1880";
- unsigned long lastTime = 0;
- unsigned long timerDelay = 1000;
- void setup()
- {
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- pinMode(mutedLED, OUTPUT);
- digitalWrite(mutedLED, LOW);
- pinMode(recordingLED, OUTPUT);
- digitalWrite(recordingLED, LOW);
- Serial.begin(115200);
- for (int i = 0; i < 10; i++)
- {
- Serial.println("");
- }
- WiFi.begin(ssid, password);
- String connectingTo = {"Connecting to: "};
- connectingTo += ssid;
- Serial.println(connectingTo);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println("Connected!\n\n\n");
- }
- void loop()
- {
- if ((millis() - lastTime) > timerDelay)
- {
- if (WiFi.status() == WL_CONNECTED)
- {
- HTTPClient http;
- http.useHTTP10(true);
- String path = serverName + "/muted";
- http.begin(path.c_str());
- int httpResponseCode = http.GET();
- if (httpResponseCode > 0)
- {
- String response = http.getString();
- unsigned int valueIndex = response.indexOf(":") + 1;
- response = response.substring(valueIndex);
- muted = !toBool(response);
- digitalWrite(mutedLED, muted);
- }
- http.end();
- path = serverName + "/isRecording";
- http.begin(path.c_str());
- httpResponseCode = http.GET();
- if (httpResponseCode > 0)
- {
- String response = http.getString();
- unsigned int valueIndex = response.indexOf(":") + 1;
- response = response.substring(valueIndex);
- isRecording = toBool(response);
- digitalWrite(recordingLED, isRecording);
- http.end();
- }
- }
- else
- Serial.println("WiFi Disconnected");
- lastTime = millis();
- }
- }
- boolean toBool(String value)
- {
- value.toLowerCase();
- if(value == "true" || value == "TRUE" || value == "True") return true;
- if(value == "false" || value == "FALSE" || value == "False") return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement