Advertisement
rstx2

New MD

Mar 6th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. //ini hanya pseudocode, eh ngga deng
  2.  
  3. // LIBRARY
  4. #include <WiFi.h>
  5. #include <HTTPClient.h>
  6. #include <Wire.h>
  7. #include "RTClib.h"
  8. #include <NTPClient.h>
  9.  
  10. // PROP
  11. RTC_DS3231 rtc;
  12. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  13.  
  14. // DECLARE
  15. const int a = 35;//sensor : sensor
  16. const int b = 34;//defact light : defact
  17. const int s = 2;//light status
  18.  
  19. int sensor = 0; //sensor state
  20. int defact = 0; //defact light state
  21.  
  22. bool objectDet = false;
  23.  
  24. // Replace with your network credentials
  25. const char* ssid = "guest";
  26. const char* password = "syf-origin";
  27.  
  28. // REPLACE with your Domain name and URL path or IP address with path
  29. const char* serverName = "http://172.16.165.96:49908/api/Sensor/Sensor";
  30.  
  31. // Define NTP Client to get time
  32. WiFiUDP ntpUDP;
  33. NTPClient timeClient(ntpUDP, "id.pool.ntp.org");
  34.  
  35. void setup() {
  36. // put your setup code here, to run once:
  37. pinMode(a, INPUT);//PULL UP (idle is HIGH)
  38. pinMode(b, INPUT);//PULL DOWN (idle is LOW)
  39. pinMode(s, OUTPUT);
  40.  
  41. WiFi.begin(ssid, password);
  42. while(WiFi.status() != WL_CONNECTED) {
  43. delay(150);
  44. digitalWrite(s, HIGH);
  45. delay(150);
  46. digitalWrite(s, LOW);
  47. }
  48. digitalWrite(s, HIGH);
  49. if (! rtc.begin()) {
  50. digitalWrite(s, LOW);
  51. while (1);
  52. }
  53. timeClient.begin();
  54. timeClient.update();
  55. unsigned long epoc = timeClient.getEpochTime();
  56. String formattedDate = timeClient.getFormattedDate();
  57. int yr = formattedDate.substring(0, 4).toInt();
  58. int mn = formattedDate.substring(5, 7).toInt();
  59. int dt = formattedDate.substring(8, 10).toInt();
  60. if (epoc > 200)
  61. {
  62. rtc.adjust(DateTime(yr, mn, dt, timeClient.getHours(), timeClient.getMinutes(), timeClient.getSeconds()));
  63. }
  64. }
  65.  
  66. void loop() {
  67. sensor = digitalRead(a);
  68. defact = digitalRead(b);
  69.  
  70.  
  71. if (digitalRead(sensor)==LOW)
  72. {
  73. objectDet = true;
  74. }
  75. else if (digitalRead(sensor)==HIGH)
  76. {
  77. if (objectDet == true)
  78. {
  79. //post data ...
  80. objectDet = false;
  81. }
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement