KRITSADA

Esp8266

Jan 3rd, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BLYNK_PRINT Serial
  2. #include <ESP8266WiFi.h>
  3. #include <BlynkSimpleEsp8266.h>
  4. #include <TimeLib.h>
  5. #include <WidgetRTC.h>
  6. #include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
  7.  
  8. char auth[] = "2352ec27045e49dcb33abe409b255d71";
  9. char ssid[] = "SmartHome";
  10. char pass[] = "Blacksmith...098";
  11. String currentTime ="  TUGAS AKHIR";
  12. String currentDate ="  M.PRASUCI R.";
  13. BlynkTimer timer;
  14. WidgetRTC rtc;
  15. WidgetLED led1(V3);
  16. WidgetLED led2(V5);
  17. //WidgetMap myMap(V4);
  18.  
  19. int relay1 = 0;
  20. int relayVButton1 = 0;
  21. int relay2 = 2;
  22. int relayVButton2 = 2;
  23.  
  24. boolean relayState1 = 1;
  25. boolean relayState2 = 1;
  26.  
  27. /*void mapp()
  28. {
  29.   int index = 1;
  30.   float lat = 0.125897;
  31.   float lon = 117.488487;
  32.   myMap.clear();
  33.   //0.125897, 117.488487
  34.   //myMap.location(index, lat, lon, "Lampu 2");
  35.   //Blynk.virtualWrite(V4, index, lat, lon, "Lampu 2");
  36.   Blynk.virtualWrite(V4, index, lat, lon, "Lampu 1");
  37. }*/
  38.  
  39. void clockDisplay()
  40. {
  41.   //currentTime = String(hour()) + ":" + minute() + ":" + second();
  42.   //currentDate = String(day()) + " " + month() + " " + year();
  43.   //Serial.print("Current time: ");
  44.   //Serial.print(currentTime);
  45.   //Serial.print(" ");
  46.   //Serial.print(currentDate);
  47.   //Serial.println();
  48.   Blynk.virtualWrite(V0, currentTime);
  49.   Blynk.virtualWrite(V1, currentDate);
  50. }
  51.  
  52. void setup()
  53. {
  54.   Serial.begin(9600);
  55.   auto_konek();
  56.   pinMode(relay1,OUTPUT);
  57.   Blynk.virtualWrite(V2, LOW);
  58.   relayVButton1 = 1;
  59.   digitalWrite(relay1, LOW);
  60.   led1.on();
  61.   pinMode(relay2,OUTPUT);
  62.   Blynk.virtualWrite(V4, LOW);
  63.   relayVButton2 = 1;
  64.   digitalWrite(relay2, LOW);
  65.   led2.on();
  66.   Blynk.begin(auth, ssid, pass);
  67.  while (Blynk.connect()==false){ESP.restart();}
  68.   Blynk.syncAll();
  69.   rtc.begin();
  70.  
  71. //  timer.setInterval(60000L, mapp);
  72.   clockDisplay();
  73. }
  74.  
  75. void somefunction()
  76. {
  77.   if (relayVButton1 == 1)
  78.     {digitalWrite(relay1, HIGH);
  79.     led1.off();}
  80.     else
  81.     {digitalWrite(relay1, LOW);
  82.     led1.on();}
  83. }  
  84.  
  85. void somefunction2()
  86. {
  87.   if (relayVButton2 == 1)
  88.     {digitalWrite(relay2, HIGH);
  89.     led2.off();}
  90.     else
  91.     {digitalWrite(relay2, LOW);
  92.     led2.on();}
  93. }  
  94.  
  95. void auto_konek()
  96. {
  97.  //wifiManager.resetSettings();
  98.  wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,254), IPAddress(10,0,1,1), IPAddress(255,255,255,0)};
  99.  wifiManager.autoConnect("Smart Home Lamp");
  100.  Blynk.config(auth);
  101.  }
  102. }  
  103.  
  104. BLYNK_WRITE(V2)
  105. {relayVButton1 = param.asInt();}
  106. BLYNK_WRITE(V4)
  107. {relayVButton2 = param.asInt();}
  108.  
  109. void loop()
  110. {
  111.   Blynk.run();
  112.  // clockDisplay();
  113.   somefunction();
  114.   somefunction2();
  115.   timer.run();
  116. }
Add Comment
Please, Sign In to add comment