Guest User

Untitled

a guest
Jan 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <ESP8266WebServer.h>
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6. LiquidCrystal_I2C lcd(0x27, 16, 2);
  7.  
  8. const char* ssid = "Be Happy";
  9. const char* password = "1234567890";
  10.  
  11. ESP8266WebServer server(80);
  12. String page = "";
  13. int data, data1;
  14. int counter;
  15. int currentState = 0;
  16. int previousState = 0;
  17. String data2 = "NULL";
  18. void setup() {
  19. pinMode(D2, INPUT);
  20. pinMode(D3, INPUT);
  21. Wire.begin(2, 0);
  22. lcd.init();
  23. lcd.backlight();
  24. lcd.print("Pulse Counter");
  25. delay(1000);
  26. Serial.begin(115200);
  27. WiFi.begin(ssid, password);
  28. Serial.println("");
  29. while (WiFi.status() != WL_CONNECTED) {
  30. delay(500);
  31. Serial.print(".");
  32. }
  33. Serial.println("");
  34. Serial.print("Connected to ");
  35. Serial.println(ssid);
  36. Serial.print("IP address: ");
  37. Serial.println(WiFi.localIP());
  38. lcd.clear();
  39. lcd.setCursor(0, 0);
  40. lcd.print("Connected to ");
  41. lcd.setCursor(0, 1);
  42. lcd.print(ssid);
  43. delay(1000);
  44. lcd.clear();
  45. lcd.setCursor(0, 0);
  46. lcd.print("IP address: ");
  47. lcd.setCursor(0, 1);
  48. lcd.print(WiFi.localIP());
  49. delay(1000);
  50. if (data1==1)
  51. data2 = "ON";
  52. if (data1 ==0)
  53. data2 = "OFF";
  54. server.on("/", []() {
  55. page = "<h1>Unit-II</h1><h2>Status:</h2> <h4>" + data2 + "</h4><h3>Pulse:</h3> <h4>" + String(counter) + "</h4><script>location.reload();</script>";
  56. server.send(200, "text/html", page);
  57. });
  58. server.begin();
  59. Serial.println("Web server started!");
  60. }
  61.  
  62. void loop() {
  63. data1 = digitalRead(D3);
  64. data = digitalRead(D2);
  65. if (data1 == HIGH) {
  66. if (data == HIGH) {
  67. currentState = 1;
  68. }
  69. else {
  70. currentState = 0;
  71. }
  72. if (currentState != previousState) {
  73. if (currentState == 1) {
  74. counter = counter + 1;
  75. Serial.print("Unit-II ");
  76. Serial.println("ON");
  77. Serial.print("Pulse= ");
  78. Serial.println(counter);
  79. lcd.clear();
  80. lcd.setCursor(0, 0);
  81. lcd.print("Unit-II");
  82. lcd.setCursor(9, 0);
  83. lcd.print("ON");
  84. lcd.clear();
  85. lcd.setCursor(0, 1);
  86. lcd.print("Pulse= ");
  87. lcd.setCursor(7, 1);
  88. lcd.print(counter);
  89. }
  90. }
  91. previousState = currentState;
  92. }
  93. else {
  94. Serial.print("Unit-II ");
  95. Serial.println("OFF");
  96. lcd.clear();
  97. lcd.setCursor(0, 0);
  98. lcd.print("Unit-II ");
  99. lcd.setCursor(9, 1);
  100. lcd.print("OFF");
  101. }
  102. server.handleClient();
  103. }
  104.  
  105. <!DOCTYPE html>
  106. <html lang="en">
  107. <head>
  108. <meta charset="UTF-8">
  109. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  110. <meta name="viewport" content="width=device-width, initial-scale=1">
  111. <link rel="stylesheet" href="stylesheet.css">
  112. <title>Machine Data</title>
  113. </head>
  114. <body>
  115. <iframe src="http://192.168.43.XXX">
  116. </iframe>
  117. <iframe src="http://192.168.43.XXX">
  118. </iframe>
  119. </body>
  120. </html>
Add Comment
Please, Sign In to add comment