
Hello sahabat Anak Kendali.
pada kesempatan kali ini saya akan menuliskan artikel tentang Tutorial ESP8266, NodeMcu RFID Kirim Data ke Database, XAMPP.
dimana saya akan mengirimkan ID Card RFID ke Database Local. yang kemudian bisa dikembangkan untuk membuat project E-money ESP8266, seperti alat pembayaran Game Timezone dan game lainya yang biasa ditemukan di Mall.
sebelumnya saya sudah banyak menuliskan tutorial yang berkaitan, dan untuk kamu yang belum bisa membuat database dengan XAMPP, silahkan baca baca terlebih dahulu Artikel tentang Database MySQL
dan untuk yang menggunakan modul Arduino Uno ESP8266 ESP-01 kirim data ke DATABASE. silahkan Baca Artikelnya Arduino Uno ESP8266 ESP-01 kirim data ke Database dan sebenarnya masih banyak lagi artikel terkait, untuk itu saya sarakan supaya membuka bagian daftar isi, dan cari judul artikel yang agan minati.
Menulis Database ESP8266 | Menulis ID CARD RFID Database Local MySQL XAMPP
baiklah pertama kita harus terlebih dahulu untuk menyiapkan alat dan rangkaianya, alat yang dibutuhkan adalah
Modul RFID
ESP8266 Nodemcu / Wemos D1 mini / Modul ESP8266 lainya
kemudian silahkan terlebih dahulu pahami tentang Komunikasi SPI, dan cari tau tentang pin SPI pada modul ESP8266
namun saya akan langsung tunjukan rangkaian untuk Nodemcu dan RFID nya
D1 NodemCu——- RST RFID
D2 NodemCu——- SDA/SS RFID
D5 NodemCu——- SCK RFID
D6 NodemCu——- MISO RFID
D7 NodemCu——- MOSI RFID
3V NodemCu——- 3.3V RFID
GND NodemCu—- GND RFID
selanjutnya sekarang buat terlebih dahulu Databasenya
kemudian buat program PHP nya untuk menghubungkan ke database
berikan nama koneksi.php pada program berikut dan simpan pada directory (“C/xampp/htdocs/esp8266”) esp8266 adalah folder buatan sendiri
<?php
$servername = "localhost";
$database = "monitoring";
$username = "root";
$password = "";
$konek = mysqli_connect ($servername, $username, $password, $database);
if ($konek!=false){
echo "berhasil";
} else {
echo "gagal";}
?>
berikan nama index.php pada program berikut dan simpan di folder yang sama
<?php
include ("koneksi.php");
$var1 = $_GET['data1'];
$var2 = $_GET['data2'];
mysqli_query($konek, "INSERT INTO rfid(idcard,val) VALUES('$var1','$var2')");
?>
selanjutnya membuat program ESP8266 untuk Nodemcu dengan Arduino IDE. pastikan semua library sudah terinstall, dan jika belum bisa download di github.
/*
* visit www.anakkendali.com
* 2018
*
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
WiFiClient client;
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 4
#define RST_PIN 5
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
String request_string;
const char* host = "192.168.1.9";
HTTPClient http;
void setup() {
// put your setup code here, to run once:
WiFi.disconnect();
WiFi.begin("KOST_RAMA","bayardulu500");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300);
}
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
Serial.println("I am waiting for card...");
}
String strID,val;
void loop() {
// put your main code here, to run repeatedly:
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
return;
// Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
// Serial.println(rfid.PICC_GetTypeName(piccType));
// Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Your tag is not of type MIFARE Classic."));
return;
}
//id kartu dan yang akan dikirim ke database
strID = "";
for (byte i = 0; i < 4; i++) {
strID +=
(rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
String(rfid.uid.uidByte[i], HEX) +
(i != 3 ? ":" : "");
}
strID.toUpperCase();
Serial.print("Tap card key: ");
Serial.println(strID);
val = "500"; // nilai kartu yang akan dikirim
koneksi_database();
delay(1000);
}
void koneksi_database()
{
if (!client.connect(host,80)) {
Serial.println("Gagal Konek");
return;
}
request_string = "/esp8266/index.php?data1=";
request_string += strID;
request_string += "&data2=";
request_string += val;
Serial.print("requesting URL: ");
Serial.println(request_string);
client.print(String("GET ") + request_string + "HTTP/1.1rn" + "Host: " + host + "rn" + "Connection: closernrn");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
}
mungkin cukup ini dulu, nanti akan saya lanjutkan tutorialnya, sehingga bisa membaca Data pada database juga, kemudian bisa di buat project E-Money. untuk videonya silahkan tonton di bawah ini.
Selanjutnya Baca : ESP8266, NodeMcu RFID Membaca Database, XAMPP
Keren sekaliiiiii, tolong update donk untuk part selanjutnya untuk project e moneyy.
Thanks in advance
kalau Nodemcu diganti dengan arduino uno r3, kirakira ada tambahan lagi apa engga ya?
ada, esp8266, bebas tipenya
Admin mau nanya. Klo ditambahin lcd 16×2 dan buzzer dan servo untuk outputnya jadi bagaimana ya programnya? Misal idnya terdaftar outputnya aktif ke22nya gitu. Tolong dikasih tau min..
min kalo setelah diupload diserial monitor ga muncul apa" kenapa ya min? thanks
Coba di cek baudrate nya
Atau teken tombol reset nya
Gan knp di serial monitor selalu muncul tulisan gagal konek setial tap rfid ?
salah ip host nya,, atau urlnya
exit status 1
stray ‘\223’ in program
pas di verify keluar error seperti ini gan kenapa ya ?
itu karakter “” atau – di periksa lagi,, ada yang ke rubah karena web nya
kalau boleh tau erornya yg mana ya mas ?
https://pastebin.com/qdJH68Cj tolong dikoreksi ya mas terimakasih
Gan, bisa tolong share file database nya ga? tolong di export gitu, ane bingung bikin databasenya
ada di artikel ini gan
https://www.anakkendali.com/2019/04/esp8266-tutorial-e-money-rfid-database-local/
itu isi database sensornya apa aja ya?
itu di atas ada gambanya gan,, bisa ikutin disitu isi database nya
Arduino: 1.8.6 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 9600”
bismillah:17:1: error: stray ‘\342’ in program
const char* host = “192.168.100.46�;
^
bismillah:17:1: error: stray ‘\200’ in program
bismillah:17:1: error: stray ‘\234’ in program
bismillah:17:23: error: too many decimal points in number
const char* host = “192.168.100.46�;
^
bismillah:17:1: error: stray ‘\342’ in program
const char* host = “192.168.100.46�;
^
bismillah:17:1: error: stray ‘\200’ in program
bismillah:17:1: error: stray ‘\235’ in program
bismillah:22:1: error: stray ‘\342’ in program
WiFi.begin(“JAELANI�,�djaelani″);
^
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\234’ in program
bismillah:22:1: error: stray ‘\342’ in program
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\235’ in program
bismillah:22:1: error: stray ‘\342’ in program
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\235’ in program
bismillah:22:1: error: stray ‘\342’ in program
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\263’ in program
bismillah:29:1: error: stray ‘\342’ in program
Serial.println(“I am waiting for card…�);
^
bismillah:29:1: error: stray ‘\200’ in program
bismillah:29:1: error: stray ‘\234’ in program
bismillah:29:1: error: stray ‘\342’ in program
bismillah:29:1: error: stray ‘\200’ in program
bismillah:29:1: error: stray ‘\246’ in program
bismillah:29:1: error: stray ‘\342’ in program
bismillah:29:1: error: stray ‘\200’ in program
bismillah:29:1: error: stray ‘\235’ in program
bismillah:43:1: error: stray ‘\342’ in program
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
bismillah:43:1: error: stray ‘\200’ in program
bismillah:43:1: error: stray ‘\234’ in program
bismillah:43:1: error: stray ‘\342’ in program
bismillah:43:1: error: stray ‘\200’ in program
bismillah:43:1: error: stray ‘\235’ in program
bismillah:47:1: error: stray ‘\342’ in program
strID = “�;
^
bismillah:47:1: error: stray ‘\200’ in program
bismillah:47:1: error: stray ‘\234’ in program
bismillah:47:1: error: stray ‘\342’ in program
bismillah:47:1: error: stray ‘\200’ in program
bismillah:47:1: error: stray ‘\235’ in program
bismillah:50:1: error: stray ‘\342’ in program
(rfid.uid.uidByte[i] 5000) {
^
bismillah:79:1: error: stray ‘\200’ in program
bismillah:79:1: error: stray ‘\223’ in program
bismillah:80:1: error: stray ‘\342’ in program
Serial.println(“>>> Client Timeout !�);
^
bismillah:80:1: error: stray ‘\200’ in program
bismillah:80:1: error: stray ‘\234’ in program
bismillah:80:1: error: stray ‘\342’ in program
bismillah:80:1: error: stray ‘\200’ in program
bismillah:80:1: error: stray ‘\235’ in program
C:\Users\nopal\Desktop\bismillah\bismillah.ino: In function ‘void setup()’:
bismillah:22:15: error: ‘JAELANI’ was not declared in this scope
WiFi.begin(“JAELANI�,�djaelani″);
^
bismillah:22:29: error: ‘djaelani’ was not declared in this scope
WiFi.begin(“JAELANI�,�djaelani″);
^
bismillah:29:19: error: ‘I’ was not declared in this scope
Serial.println(“I am waiting for card…�);
^
In file included from C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/Arduino.h:261:0,
from sketch\bismillah.ino.cpp:1:
C:\Users\nopal\Desktop\bismillah\bismillah.ino: In function ‘void loop()’:
bismillah:43:21: error: ‘Your’ was not declared in this scope
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:38:76: note: in definition of macro ‘FPSTR’
#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer))
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:39:34: note: in expansion of macro ‘PSTR’
#define F(string_literal) (FPSTR(PSTR(string_literal)))
^
C:\Users\nopal\Desktop\bismillah\bismillah.ino:43:16: note: in expansion of macro ‘F’
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
bismillah:43:26: error: expected ‘)’ before ‘tag’
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:38:76: note: in definition of macro ‘FPSTR’
#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer))
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:39:34: note: in expansion of macro ‘PSTR’
#define F(string_literal) (FPSTR(PSTR(string_literal)))
^
C:\Users\nopal\Desktop\bismillah\bismillah.ino:43:16: note: in expansion of macro ‘F’
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
bismillah:47:15: error: expected primary-expression before ‘;’ token
strID = “�;
^
bismillah:50:47: error: expected primary-expression before ‘)’ token
(rfid.uid.uidByte[i] 5000) {
^
bismillah:80:19: error: expected primary-expression before ‘>>’ token
Serial.println(“>>> Client Timeout !�);
^
bismillah:80:21: error: expected primary-expression before ‘>’ token
Serial.println(“>>> Client Timeout !�);
^
bismillah:80:30: error: expected primary-expression before ‘Timeout’
Serial.println(“>>> Client Timeout !�);
^
exit status 1
stray ‘\342’ in program
bismillah:17:1: error: stray ‘\342’ in program
const char* host = “192.168.100.46�;
^
bismillah:17:1: error: stray ‘\200’ in program
bismillah:17:1: error: stray ‘\234’ in program
bismillah:17:23: error: too many decimal points in number
const char* host = “192.168.100.46�;
^
bismillah:17:1: error: stray ‘\342’ in program
const char* host = “192.168.100.46�;
^
bismillah:17:1: error: stray ‘\200’ in program
bismillah:17:1: error: stray ‘\235’ in program
bismillah:22:1: error: stray ‘\342’ in program
WiFi.begin(“JAELANI�,�djaelani″);
^
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\234’ in program
bismillah:22:1: error: stray ‘\342’ in program
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\235’ in program
bismillah:22:1: error: stray ‘\342’ in program
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\235’ in program
bismillah:22:1: error: stray ‘\342’ in program
bismillah:22:1: error: stray ‘\200’ in program
bismillah:22:1: error: stray ‘\263’ in program
bismillah:29:1: error: stray ‘\342’ in program
Serial.println(“I am waiting for card…�);
^
bismillah:29:1: error: stray ‘\200’ in program
bismillah:29:1: error: stray ‘\234’ in program
bismillah:29:1: error: stray ‘\342’ in program
bismillah:29:1: error: stray ‘\200’ in program
bismillah:29:1: error: stray ‘\246’ in program
bismillah:29:1: error: stray ‘\342’ in program
bismillah:29:1: error: stray ‘\200’ in program
bismillah:29:1: error: stray ‘\235’ in program
bismillah:43:1: error: stray ‘\342’ in program
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
bismillah:43:1: error: stray ‘\200’ in program
bismillah:43:1: error: stray ‘\234’ in program
bismillah:43:1: error: stray ‘\342’ in program
bismillah:43:1: error: stray ‘\200’ in program
bismillah:43:1: error: stray ‘\235’ in program
bismillah:47:1: error: stray ‘\342’ in program
strID = “�;
^
bismillah:47:1: error: stray ‘\200’ in program
bismillah:47:1: error: stray ‘\234’ in program
bismillah:47:1: error: stray ‘\342’ in program
bismillah:47:1: error: stray ‘\200’ in program
bismillah:47:1: error: stray ‘\235’ in program
bismillah:50:1: error: stray ‘\342’ in program
(rfid.uid.uidByte[i] 5000) {
^
bismillah:79:1: error: stray ‘\200’ in program
bismillah:79:1: error: stray ‘\223’ in program
bismillah:80:1: error: stray ‘\342’ in program
Serial.println(“>>> Client Timeout !�);
^
bismillah:80:1: error: stray ‘\200’ in program
bismillah:80:1: error: stray ‘\234’ in program
bismillah:80:1: error: stray ‘\342’ in program
bismillah:80:1: error: stray ‘\200’ in program
bismillah:80:1: error: stray ‘\235’ in program
C:\Users\nopal\Desktop\bismillah\bismillah.ino: In function ‘void setup()’:
bismillah:22:15: error: ‘JAELANI’ was not declared in this scope
WiFi.begin(“JAELANI�,�djaelani″);
^
bismillah:22:29: error: ‘djaelani’ was not declared in this scope
WiFi.begin(“JAELANI�,�djaelani″);
^
bismillah:29:19: error: ‘I’ was not declared in this scope
Serial.println(“I am waiting for card…�);
^
In file included from C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/Arduino.h:261:0,
from sketch\bismillah.ino.cpp:1:
C:\Users\nopal\Desktop\bismillah\bismillah.ino: In function ‘void loop()’:
bismillah:43:21: error: ‘Your’ was not declared in this scope
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:38:76: note: in definition of macro ‘FPSTR’
#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer))
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:39:34: note: in expansion of macro ‘PSTR’
#define F(string_literal) (FPSTR(PSTR(string_literal)))
^
C:\Users\nopal\Desktop\bismillah\bismillah.ino:43:16: note: in expansion of macro ‘F’
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
bismillah:43:26: error: expected ‘)’ before ‘tag’
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:38:76: note: in definition of macro ‘FPSTR’
#define FPSTR(pstr_pointer) (reinterpret_cast(pstr_pointer))
^
C:\Users\nopal\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\cores\esp8266/WString.h:39:34: note: in expansion of macro ‘PSTR’
#define F(string_literal) (FPSTR(PSTR(string_literal)))
^
C:\Users\nopal\Desktop\bismillah\bismillah.ino:43:16: note: in expansion of macro ‘F’
Serial.println(F(“Your tag is not of type MIFARE Classic.�));
^
bismillah:47:15: error: expected primary-expression before ‘;’ token
strID = “�;
^
bismillah:50:47: error: expected primary-expression before ‘)’ token
(rfid.uid.uidByte[i] 5000) {
^
bismillah:80:19: error: expected primary-expression before ‘>>’ token
Serial.println(“>>> Client Timeout !�);
^
bismillah:80:21: error: expected primary-expression before ‘>’ token
Serial.println(“>>> Client Timeout !�);
^
bismillah:80:30: error: expected primary-expression before ‘Timeout’
Serial.println(“>>> Client Timeout !�);
^
exit status 1
stray ‘\342’ in program
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
gan, dari coding diatas, jika menggunakan arduino mega dan esp8266, program bagian mana yang harus diganti ? terimakasih
sketch_may23a:73:1: error: stray ‘\226’ in program
if (millis() – timeout > 500) {
error itu kenapa gan? setelah di verivy
makasih gan
ada beberapa karakter seperti ” atau – kerubah sama html websitenya, coba di replace
if (millis() – timeout > 5000) {
error itunya bang
kenapa pas coba ngirim data string nya ke database selalu Client Timeout ?
butuh solusinya bang, padahal ip & url udah bener
terimakasih ^^
kalo url nya di load lewat browser udah bisa?
maaf mau bertanya pak, kalau ada masalah “Client Timeout!” silap di mana agaknya ya?
load lewat browser gak bisa load juga
berarti salah url nya gan, atau php nya
Arduino: 1.6.9 (Windows 10), Board: “Arduino/Genuino Uno”
In file included from D:\arduino-1.6.9-windows\arduino-1.6.9\libraries\ESP8266WiFi\src/ESP8266WiFi.h:33:0,
from C:\Users\ASUS\Documents\Arduino\RFID_Online\RFID_Online.ino:1:
D:\arduino-1.6.9-windows\arduino-1.6.9\libraries\ESP8266WiFi\src/ESP8266WiFiType.h:26:10: fatal error: queue.h: No such file or directory
#include
^~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
Bang salahnya di library atau gimana? abang makai library yg mana? saya boleh minta gak?
Error ini Gan
>>> Client Timeout !
Kalau kita panggil secara langsung dari web browser url udah bisa sih, cuman ketika RFID Card di Tab muncul >>> Client Timeout ! dan data tdk masuk ke Database