Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #include <TimeLib.h>
- #include <WidgetRTC.h>
- #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
- char auth[] = "2352ec27045e49dcb33abe409b255d71";
- char ssid[] = "SmartHome";
- char pass[] = "Blacksmith...098";
- String currentTime =" TUGAS AKHIR";
- String currentDate =" M.PRASUCI R.";
- BlynkTimer timer;
- WidgetRTC rtc;
- WidgetLED led1(V3);
- WidgetLED led2(V5);
- //WidgetMap myMap(V4);
- int relay1 = 0;
- int relayVButton1 = 0;
- int relay2 = 2;
- int relayVButton2 = 2;
- boolean relayState1 = 1;
- boolean relayState2 = 1;
- /*void mapp()
- {
- int index = 1;
- float lat = 0.125897;
- float lon = 117.488487;
- myMap.clear();
- //0.125897, 117.488487
- //myMap.location(index, lat, lon, "Lampu 2");
- //Blynk.virtualWrite(V4, index, lat, lon, "Lampu 2");
- Blynk.virtualWrite(V4, index, lat, lon, "Lampu 1");
- }*/
- void clockDisplay()
- {
- //currentTime = String(hour()) + ":" + minute() + ":" + second();
- //currentDate = String(day()) + " " + month() + " " + year();
- //Serial.print("Current time: ");
- //Serial.print(currentTime);
- //Serial.print(" ");
- //Serial.print(currentDate);
- //Serial.println();
- Blynk.virtualWrite(V0, currentTime);
- Blynk.virtualWrite(V1, currentDate);
- }
- void setup()
- {
- Serial.begin(9600);
- auto_konek();
- pinMode(relay1,OUTPUT);
- Blynk.virtualWrite(V2, LOW);
- relayVButton1 = 1;
- digitalWrite(relay1, LOW);
- led1.on();
- pinMode(relay2,OUTPUT);
- Blynk.virtualWrite(V4, LOW);
- relayVButton2 = 1;
- digitalWrite(relay2, LOW);
- led2.on();
- Blynk.begin(auth, ssid, pass);
- while (Blynk.connect()==false){ESP.restart();}
- Blynk.syncAll();
- rtc.begin();
- // timer.setInterval(60000L, mapp);
- clockDisplay();
- }
- void somefunction()
- {
- if (relayVButton1 == 1)
- {digitalWrite(relay1, HIGH);
- led1.off();}
- else
- {digitalWrite(relay1, LOW);
- led1.on();}
- }
- void somefunction2()
- {
- if (relayVButton2 == 1)
- {digitalWrite(relay2, HIGH);
- led2.off();}
- else
- {digitalWrite(relay2, LOW);
- led2.on();}
- }
- void auto_konek()
- {
- //wifiManager.resetSettings();
- wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,254), IPAddress(10,0,1,1), IPAddress(255,255,255,0)};
- wifiManager.autoConnect("Smart Home Lamp");
- Blynk.config(auth);
- }
- }
- BLYNK_WRITE(V2)
- {relayVButton1 = param.asInt();}
- BLYNK_WRITE(V4)
- {relayVButton2 = param.asInt();}
- void loop()
- {
- Blynk.run();
- // clockDisplay();
- somefunction();
- somefunction2();
- timer.run();
- }
Add Comment
Please, Sign In to add comment