hi, have problem program. program reads rfid tag next send request server , waits response. if response true, program open door. have problem receiving server response. , have no idea how search in response true.
reciving request server doesn't work. , have no idea how serch true in response.
code: [select]
#include <wiegand.h>
#include <uipethernet.h>
wiegand wg;
int door = 1;
byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
ipaddress ip(192, 168, 1, 179);
byte server[] = { 192, 168, 1, 18 }; // ip serwera
ethernetclient client;
void setup() {
wg.begin();
pinmode(7, output);
pinmode(8, output);
pinmode(9, output);
serial.begin(9600);
}
void loop() {
if(wg.available()){
ethernet.begin(mac, ip);
unsigned long cardid = wg.getcode(); //kod karty
serial.print(cardid);
string = gethttpheader(cardid,door); //string z get
serial.println("connecting...");
if (client.connect(server, 80)) {
serial.println("connected");
client.println(a);
client.println();
boolean result = serverrequest();
if(result == true){
accessgranted();
}
else{
accessdenied();
}
}
else {
serial.println("connection failed");
loop();
}
}
}
boolean serverrequest(){ //zosta ta funkcja
if (client.available()) {
char c = client.read();
serial.print(c);
}
if (!client.connected()) {
serial.println();
serial.println("disconnecting.");
client.stop();
for(;;);
}
}
void accessdenied() { //zamykanie
delay(100);
digitalwrite(8, high);
delay(100);
digitalwrite(8, low);
delay(100);
digitalwrite(8, high);
delay(100);
digitalwrite(8, low);
loop();;
}
void accessgranted() { //otwieranie
digitalwrite(7, high);
digitalwrite(9, high);
delay(5000);
digitalwrite(9, low);
digitalwrite(7, low);
loop();
}
string gethttpheader(unsigned long cardid, word door) { //tworzenie zapytania get
string getbegin = f("get /auth/door.php");
string getid = f("?id=");
string getdoor = f("&door=");
string getend = f(" http/1.1\r\nhost: 10.0.0.22\r\n\r\n");
return getbegin + getid + cardid + getdoor + door + getend;
}
reciving request server doesn't work. , have no idea how serch true in response.
code: [select]
ethernet.begin(mac, ip);
this belongs in setup(), not loop(). start communication ethernet shield once!
code: [select]
string getbegin = f("get /auth/door.php");
string getid = f("?id=");
string getdoor = f("&door=");
string getend = f(" http/1.1\r\nhost: 10.0.0.22\r\n\r\n");
nonsense. f() macro can not used way. there no sense trying keep string literals out of sram while simultaneously pissing away resources on string class.
code: [select]
return getbegin + getid + cardid + getdoor + door + getend;
how adding bunch of string instances , long , word (whatever f**k is) supposed work?
quote
reciving request server doesn't work.almost because haven't gotten valid request server. stop nonsense strings. send pieces 1 @ time server, or use sprintf() construct single statement.
Arduino Forum > Using Arduino > Programming Questions > Server response problem!
arduino
Comments
Post a Comment