Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ini hanya pseudocode, eh ngga deng
- // LIBRARY
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include <Wire.h>
- #include "RTClib.h"
- #include <NTPClient.h>
- // PROP
- RTC_DS3231 rtc;
- char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- // DECLARE
- const int a = 35;//sensor : sensor
- const int b = 34;//defact light : defact
- const int s = 2;//light status
- int sensor = 0; //sensor state
- int defact = 0; //defact light state
- bool objectDet = false;
- // Replace with your network credentials
- const char* ssid = "guest";
- const char* password = "syf-origin";
- // REPLACE with your Domain name and URL path or IP address with path
- const char* serverName = "http://172.16.165.96:49908/api/Sensor/Sensor";
- // Define NTP Client to get time
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, "id.pool.ntp.org");
- void setup() {
- // put your setup code here, to run once:
- pinMode(a, INPUT);//PULL UP (idle is HIGH)
- pinMode(b, INPUT);//PULL DOWN (idle is LOW)
- pinMode(s, OUTPUT);
- WiFi.begin(ssid, password);
- while(WiFi.status() != WL_CONNECTED) {
- delay(150);
- digitalWrite(s, HIGH);
- delay(150);
- digitalWrite(s, LOW);
- }
- digitalWrite(s, HIGH);
- if (! rtc.begin()) {
- digitalWrite(s, LOW);
- while (1);
- }
- timeClient.begin();
- timeClient.update();
- unsigned long epoc = timeClient.getEpochTime();
- String formattedDate = timeClient.getFormattedDate();
- int yr = formattedDate.substring(0, 4).toInt();
- int mn = formattedDate.substring(5, 7).toInt();
- int dt = formattedDate.substring(8, 10).toInt();
- if (epoc > 200)
- {
- rtc.adjust(DateTime(yr, mn, dt, timeClient.getHours(), timeClient.getMinutes(), timeClient.getSeconds()));
- }
- }
- void loop() {
- sensor = digitalRead(a);
- defact = digitalRead(b);
- if (digitalRead(sensor)==LOW)
- {
- objectDet = true;
- }
- else if (digitalRead(sensor)==HIGH)
- {
- if (objectDet == true)
- {
- //post data ...
- objectDet = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement