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