如何解决我怎样才能让 UID RFID 到 Laravel 的文本字段
所以我有一个带有 RFID 的项目 laravel。当我想发布数据时,它需要 UID 形式的 RFID 阅读器。但错误看起来像在服务器上找不到 URL?我怎样才能解决这个问题?有人可以帮我吗?
这是我的 Laravel ManjmhsController
public function create()
{
return view('addmhs');
}
public function store(Request $request)
{
$request->validate([
'uid' => 'required','nim' => 'required|unique:mahasiswa','nama_mhs' => 'required','foto' => 'mimes:jpg,jpeg,png,gif,svg,JPG,PNG,JPEG','tempat_lahir' => 'required','tgl_lahir' => 'required','kelas' => 'required','jurusan' => 'required','alamat' => 'required','email' => 'required|max:50|string|email|max:255','no_telfon' => 'required','saldo' => 'required'
]);
if ($request->hasFile('foto')) {
$foto = $request->file('foto');
$ext = $foto->getClientOriginalExtension();
$fotoName = $request->nama_mhs . date('YmdHis') . '.' . $ext;
$path = public_path('img/');
$foto->move($path,$fotoName);
} else {
$fotoName = 'default.png';
}
$only = $request->only('uid','nim','nama_mhs','tempat_lahir','tgl_lahir','kelas','jurusan','alamat','email','no_telfon','saldo');
$dataFoto = [
'foto' => $fotoName
];
$data = array_merge($only,$dataFoto);
Mahasiswa::create($data);
return redirect('manjmhs');
}
这是我的arduino脚本
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN D2 //--> SDA / SS is connected to pinout D2
#define RST_PIN D1 //--> RST is connected to pinout D1
MFRC522 mfrc522(SS_PIN,RST_PIN); //--> Create MFRC522 instance.
#define ON_Board_LED 2
const char* ssid = "DAVIAN";
const char* password = "gakdipassword";
ESP8266WebServer server(80); //--> Server on port 80
int readsuccess;
byte readcard[4];
char str[32] = "";
String StrUID;
void setup() {
Serial.begin(115200); //--> Initialize serial communications with the PC
SPI.begin(); //--> Init SPI bus
mfrc522.PCD_Init(); //--> Init MFRC522 card
delay(500);
WiFi.begin(ssid,password); //--> Connect to your WiFi router
Serial.println("");
pinMode(ON_Board_LED,OUTPUT);
digitalWrite(ON_Board_LED,HIGH); //--> Turn off Led On Board
//----------------------------------------Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
//----------------------------------------Make the On Board Flashing LED on the process of connecting to the wifi router.
digitalWrite(ON_Board_LED,LOW);
delay(250);
digitalWrite(ON_Board_LED,HIGH);
delay(250);
}
digitalWrite(ON_Board_LED,HIGH); //--> Turn off the On Board LED when it is connected to the wifi router.
//----------------------------------------If successfully connected to the wifi router,the IP Address that will be visited is displayed in the serial monitor
Serial.println("");
Serial.print("Successfully connected to : ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Please tag a card or keychain to see the UID !");
Serial.println("");
}
void loop() {
// put your main code here,to run repeatedly
readsuccess = getid();
if (readsuccess) {
digitalWrite(ON_Board_LED,LOW);
WiFiClient client;
HTTPClient http; //Declare object of class HTTPClient
String UIDresultSend,postData;
UIDresultSend = StrUID;
//Post Data
postData = "getUID=" + UIDresultSend;
http.begin(client,"http://localhost:8000/manjmhs/create/"); //Specify request destination
http.addHeader("Content-Type","application/x-www-form-urlencoded"); //Specify content-type header
int httpCode = http.POST(postData); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(UIDresultSend);
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
delay(500);
digitalWrite(ON_Board_LED,HIGH);
}
}
int getid() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if (!mfrc522.PICC_ReadCardSerial()) {
return 0;
}
Serial.print("THE UID OF THE SCANNED CARD IS : ");
for (int i = 0; i < 4; i++) {
readcard[i] = mfrc522.uid.uidByte[i]; //storing the UID of the tag in readcard
array_to_string(readcard,4,str);
StrUID = str;
}
mfrc522.PICC_HaltA();
return 1;
}
void array_to_string(byte array[],unsigned int len,char buffer[]) {
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i * 2 + 0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i * 2 + 1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len * 2] = '\0';
}
这是我的错误看起来像 error monitor
谁能帮帮我?谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。