SHARE
TWEET

Untitled

Mamp123 Mar 29th, 2019 (edited) 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define nama_wifi "Wifi"
  2. #define pass_wifi "1gakada123"
  3. #define ip_host "https://domain.com"
  4. #include <SPI.h>
  5. #include <MFRC522.h>
  6. #include <Wire.h>
  7. #include <LiquidCrystal_I2C.h>
  8. #define RST_PIN 8
  9. #define SS_PIN 9
  10.  
  11. LiquidCrystal_I2C lcd(0x27, 16, 2);
  12. MFRC522 rfid(SS_PIN, RST_PIN);
  13.  
  14. //PIN INFRARED              
  15. #define isObstaclePin1 2
  16.  
  17. #define EMPTY true
  18. #define FILLED false
  19.  
  20. //STATUS SENSOR IR TO DATABASE
  21. int isObstacle1 = HIGH; //HIGH MEANS NO OBSTACLE (TIDAK ADA BARANG)
  22. byte readCard[4];
  23. String NEW_DATA_READ = "";
  24. String strID;
  25. char setID[50];
  26. int successRead;
  27. boolean connected = false;
  28.  
  29.  
  30. void setup() {
  31.   Serial.begin(9600);
  32.   Serial1.begin(9600);
  33.   Serial1.begin(115200);
  34.   pinMode(isObstaclePin1, INPUT);
  35.   SPI.begin();
  36.   rfid.PCD_Init();
  37.  
  38.  
  39. Serial1.setTimeout(5000);
  40. Serial.println("CHECK ESP8266");
  41. delay (1000);
  42. Serial1.println("AT+RST");
  43. delay(1000);
  44. if(Serial1.find("WIFI GOT IP"))
  45. {
  46.   Serial.println("ESP8266 SIAP");
  47. }
  48. else {
  49.   Serial.println(" Tidak Ada Response dari ESP8266 ");
  50.   while(1);
  51. }
  52. delay(1000);
  53.  
  54. for (int i=0; i<5; i++){
  55.   connect_to_wifi();
  56.   if (connected){
  57.     break;
  58.   }
  59. }
  60.   if (!connected){
  61.     while(1);
  62.   }
  63.   delay(5000);
  64.   Serial1.println("AT+CIPMUX=0");
  65.   delay(1000);
  66.   Serial.println("Selamat Datang");
  67.   delay(3000);
  68. }
  69.  
  70.  
  71. void loop(){
  72.  
  73.   isObstacle1 = digitalRead(isObstaclePin1);
  74.   infra1();
  75. }
  76.  
  77.   //LOKER1
  78.   void infra1(){
  79.    if (isObstacle1 == HIGH){
  80.     Serial.println("LOKER 1 KOSONG");
  81.     tap();
  82.     Serial.println("TIMER START");
  83.     }
  84.  
  85.    else if (isObstacle1 == LOW)
  86.   {
  87.     Serial.println("LOKER 1 BERISI");
  88.    
  89.     }
  90.   }
  91.  
  92. void senddataid(String x)
  93. {
  94. sendcommand();
  95. String cmd2 = "GET /index2.php?data7=";
  96. cmd2 +=x;
  97. cmd2 +="\r\n";
  98. cmd2 +="HTTP/1.1\r\n";
  99. Serial1.print("AT+CIPSEND=");
  100. Serial1.println(cmd2.length());
  101. if (Serial1.find(">")){
  102.   Serial.print(">");
  103. } else {
  104.   Serial1.println("AT+CIPCLOSE");
  105.   Serial.println("Koneksi Timeout");
  106.   delay(1000);
  107.   return;
  108. }
  109. Serial1.print(cmd2);
  110. delay(2000);
  111.  
  112. while(Serial1.available())
  113. {
  114.   char c =Serial1.read();
  115.   Serial.write(c);
  116.   if (c=='\r') Serial.print('\n');
  117. }
  118. Serial.println("-----end");
  119. delay(10000);
  120. }
  121.  
  122. void connect_to_wifi()
  123. {
  124.   Serial1.println("AT+CWMODE=1");
  125.   String cmd = "AT+CWJAP=\"";
  126.   cmd+=nama_wifi;
  127.   cmd+="\",\"";
  128.   cmd+=pass_wifi;
  129.   cmd+="\"";
  130.   Serial1.println(cmd);
  131.   Serial.println(cmd);
  132.   if (Serial1.find("OK")){
  133.     Serial.println("Berhasil Terkoneksi ke internet");
  134.   connected=true;
  135.   } else {
  136.     Serial.println("Gagal Terkoneksi");
  137.   connected=false;
  138.   }
  139. }
  140.  
  141. void sendcommand()
  142. {
  143.   String cmd = "AT+CIPSTART=\"TCP\",\"";
  144. cmd+= ip_host;
  145. cmd+="\",80";
  146. Serial1.println(cmd);
  147. Serial.println(cmd);
  148. if (Serial1.find("Error")){
  149.   Serial.println("Koneksi eror");
  150.   return;
  151. }
  152. }
  153.  
  154. int getID()
  155. {
  156.  
  157.   if ( !rfid.PICC_IsNewCardPresent())
  158.   {
  159.     return 0;
  160.   }
  161.   if ( !rfid.PICC_ReadCardSerial())
  162.   {
  163.     return 0;
  164.   }
  165.   for (  int i = 0; i < 4 ; i++)
  166.   {
  167.     readCard[i] = rfid.uid.uidByte[i] ;
  168.     Serial.print(readCard[i], HEX);
  169.     NEW_DATA_READ += String(readCard[i], HEX);
  170.   }
  171.   NEW_DATA_READ.trim();
  172.   Serial.println("");
  173.   rfid.PICC_HaltA();
  174.   return 1;
  175.  }
  176.  
  177. void tap()
  178. {
  179.   Serial.println("TAP RFID ANDA");
  180.   do{
  181.     delay(2000);
  182.       successRead = getID();
  183.       }while(!successRead);
  184.       sprintf(setID, "%02X:%02X:%02X:%02X", readCard[0], readCard[1], readCard[2], readCard[3]);
  185.   senddataid(setID);
  186.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top