// Program Di Arduino IDE (Counter Berbasis IOT)
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "Username WIFI Kamu"; //masukkan ssid
const char* password = "Kata Sandi Wifi Kamu"; //masukkan password
const int infrared = 13;
boolean Object = false;
int hitung = 0;
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
pinMode(infrared, INPUT);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
if(WiFi.status() == WL_CONNECTED){
Serial.println("Connected!!!");
}
else{
Serial.println("Connected Failed!!!");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
int readSensor = digitalRead(infrared);
//Ganti dengan ipaddress komputer anda
http.begin("http://192.168.43.75/counter/proses.php?hitung=" + String(hitung));
int httpCode = http.GET();
if (httpCode > 0) {
char json[100];
String payload = http.getString();
payload.toCharArray(json, 100);
//StaticJsonDocument<200> doc;
DynamicJsonDocument doc(JSON_OBJECT_SIZE(2));
// Deserialize the JSON document
deserializeJson(doc, json);
int batas = doc["batas"];
String Reset = doc["Reset"];
if (readSensor == 0 && Object == false){
if(hitung < batas || batas == 0){
hitung++;
Object = true;
Serial.print("hitung = ");
Serial.println(hitung);
}
else{
}
}
else if(readSensor == 1 && Object == true){
Object = false;
}
delay(10);
}
http.end();
}
}
0 Comments