· 7 years ago · Apr 20, 2018, 09:32 AM
1<?php
2
3$connect = mysqli_connect("127.0.0.1","root","","db_coba");
4//120.0.0.1=ip adress, root=user database, ""=password,user=nama database
5
6$nfc=$_REQUEST['nfc'];
7//$jenis=$_REQUEST['jenis'];
8
9
10mysqli_query($connect,"insert into tabel_nfc(id_nfc)
11values($nfc)");
12echo "success";
13
14
15mysqli_close($connect);
16?>
17
18#include <ESP8266WiFi.h>
19#include <WiFiClientSecure.h>
20
21const char* ssid = "RESLab";
22const char* password = "reslabsk";
23
24const char* host = "192.168.1.122";
25const int httpsPort = 443;
26
27#if 0
28#include <SPI.h>
29#include <PN532_SPI.h>
30#include <PN532.h>
31#include <NfcAdapter.h>
32
33PN532_SPI pn532spi(SPI, 10);
34NfcAdapter nfc = NfcAdapter(pn532spi);
35#else
36
37#include <Wire.h>
38#include <PN532_I2C.h>
39#include <PN532.h>
40#include <NfcAdapter.h>
41
42PN532_I2C pn532_i2c(Wire);
43NfcAdapter nfc = NfcAdapter(pn532_i2c);
44#endif
45
46String x;
47
48void setup()
49{
50 //WiFi.mode(WIFI_STA);
51 x = " ";
52 Serial.begin(115200);
53 nfc.begin();
54}
55
56void loop()
57 {
58 if(WiFi.status() != WL_CONNECTED)
59 conek();
60 scan_nfc();
61 delay(500);
62 }
63
64void conek()
65{
66 WiFi.begin(ssid, password);
67 while (WiFi.status() != WL_CONNECTED)
68 {
69 delay(500);
70 Serial.print(".");
71 }
72}
73void db_update()
74{
75 String y = "";
76 x += " ";
77 int i = 0;
78 while(i<x.length())
79 {
80 if (x.substring(i,i+1)==" ")
81 y += "%20";
82 else
83 y += x.substring(i,i+1);
84 i++;
85 }
86
87 WiFiClientSecure client;
88 Serial.print("connecting to ");
89 Serial.println(host);
90
91 if (!client.connect(host, httpsPort))
92 {
93 Serial.println("connection failed");
94 return;
95 }
96 String url = "/nfcinsert.php?nfc=%27";
97 url += y;
98 url += "%27";
99 Serial.print("requesting URL: ");
100 Serial.println(url);
101 client.print(String("GET ") + url + " HTTP/1.1rn" +
102 "Host: " + host + "rn" +
103 "User-Agent: BuildFailureDetectorESP8266rn" +
104 "Connection: closernrn");
105 Serial.println("request sent");
106}
107
108void scan_nfc()
109{
110 if (nfc.tagPresent())
111 {
112 NfcTag tag = nfc.read();
113 x = tag.getUidString();
114 Serial.println(x);
115 db_update();
116 delay(5000);
117 //tag.print();
118 }
119}