i'm trying use hanrun ehternet hr911105a module + mfrc522 "rfid" card number , send website , reply website thats all, rfid works fine when alone , ethernet works fine when alone , when put them both , when scan rfid tag response website once no response response no response , on..., , noticed each time set cs rfid high , cs ethernet low toggles right away there forcing rfid's cs low , ethernet's cs high
my wiring following :
for both rfid , ethernet :
mosi > pin11
miso > pin12
sclk > pin13
rst > pin9
for rfid :
cs > pin7
for ethernet module
cs > pin8
input button > pin2 use try send request server manually without scanning rfid tag
my website works fine, , tried response google.com , same not server problem.
here code , works , have attached :
#include <spi.h>
#include <mfrc522.h>
#include <ethercard.h>
#define rst_pin 9
#define rfid_cs_pin 7
#define ether_cs_pin 8
#define interrupt_pin 2
byte mymac[] = { 0x74,0x69,0x69,0x2d,0x30,0x31 };
const char website[] progmem = "promedianz.com";
static byte session;
stash stash;
const char* reply;
byte ethernet::buffer[700];
boolean lastbtnstate = low;
mfrc522 mfrc522(rfid_cs_pin, rst_pin);
void setup () {
serial.begin(57600);
pinmode(ether_cs_pin,output);
pinmode(rfid_cs_pin,output);
pinmode(interrupt_pin,input);
digitalwrite(ether_cs_pin,high);
digitalwrite(rfid_cs_pin,low);
spi.begin();
mfrc522.pcd_init();
showreaderdetails();
serial.println(f("scan picc see uid, type, , data blocks..."));
digitalwrite(ether_cs_pin,low);
digitalwrite(rfid_cs_pin,high);
if (ether.begin(sizeof ethernet::buffer, mymac,ether_cs_pin) == 0)
serial.println(f("failed access ethernet controller"));
if (!ether.dhcpsetup())
serial.println(f("dhcp failed"));
ether.printip("ip: ", ether.myip);
ether.printip("gw: ", ether.gwip);
ether.printip("dns: ", ether.dnsip);
if (!ether.dnslookup(website))
serial.println(f("dns failed"));
ether.printip("srv: ", ether.hisip);
}
void loop () {
if ( mfrc522.picc_isnewcardpresent()) {
if(mfrc522.picc_readcardserial()){
string readcard = "";
(int = 0; < mfrc522.uid.size; i++) {
if(mfrc522.uid.uidbyte==0){readcard += "00";}
else{readcard += string(mfrc522.uid.uidbyte,hex);}
}
if(readcard != ""){
serial.println("cardid sent : " + readcard);
requesfromserver(readcard);
}
}
}
boolean pin2 = debounce(lastbtnstate,interrupt_pin);
if(pin2 == high){
serial.println("interrpt btn click !!");
requesfromserver("interrupt cardid");
}
}
void requesfromserver(string cardid){
serial.println("sending cardid : " + cardid);
byte sd = stash.create();
stash.print("cardid=");
stash.print(cardid);
stash.save();
int stash_size = stash.size();
// compose http post request, taking headers below , appending
// created stash in sd holder.
stash::prepare(pstr("post http://$f/trials/arduino/ http/1.0" "\r\n"
"host: $f" "\r\n"
"content-length: $d" "\r\n"
"content-type: application/x-www-form-urlencoded" "\r\n"
"\r\n"
"$h"),
website, website, stash_size, sd);
// send packet - releases stash buffers once done
// save session id can watch in main loop.
session = ether.tcpsend();
unsigned long lasttime = millis();
reply = 0;
while (!reply){
digitalwrite(ether_cs_pin,low);
digitalwrite(rfid_cs_pin,high);
ether.packetloop(ether.packetreceive());
reply = ether.tcpreply(session);
if (reply != 0) {
serial.println("got response!");
serial.println(reply);
}
if((millis() - lasttime) > 1000){
serial.println("request timed out !!");
break;
}
}
}
boolean debounce(boolean last,int inputbutton){
boolean current = digitalread(inputbutton);
if(current != last){
delay(50);
current = digitalread(inputbutton);
}else{
current = low ;
}
return current;
}
void showreaderdetails() {
// mfrc522 software version
byte v = mfrc522.pcd_readregister(mfrc522.versionreg);
serial.print(f("mfrc522 software version: 0x"));
serial.print(v, hex);
if (v == 0x91)
serial.print(f(" = v1.0"));
else if (v == 0x92)
serial.print(f(" = v2.0"));
else
serial.print(f(" (unknown)"));
serial.println("");
// when 0x00 or 0xff returned, communication failed
if ((v == 0x00) || (v == 0xff)) {
serial.println(f("warning: communication failure, mfrc522 connected?"));
}
}
my wiring following :
for both rfid , ethernet :
mosi > pin11
miso > pin12
sclk > pin13
rst > pin9
for rfid :
cs > pin7
for ethernet module
cs > pin8
input button > pin2 use try send request server manually without scanning rfid tag
my website works fine, , tried response google.com , same not server problem.
here code , works , have attached :
#include <spi.h>
#include <mfrc522.h>
#include <ethercard.h>
#define rst_pin 9
#define rfid_cs_pin 7
#define ether_cs_pin 8
#define interrupt_pin 2
byte mymac[] = { 0x74,0x69,0x69,0x2d,0x30,0x31 };
const char website[] progmem = "promedianz.com";
static byte session;
stash stash;
const char* reply;
byte ethernet::buffer[700];
boolean lastbtnstate = low;
mfrc522 mfrc522(rfid_cs_pin, rst_pin);
void setup () {
serial.begin(57600);
pinmode(ether_cs_pin,output);
pinmode(rfid_cs_pin,output);
pinmode(interrupt_pin,input);
digitalwrite(ether_cs_pin,high);
digitalwrite(rfid_cs_pin,low);
spi.begin();
mfrc522.pcd_init();
showreaderdetails();
serial.println(f("scan picc see uid, type, , data blocks..."));
digitalwrite(ether_cs_pin,low);
digitalwrite(rfid_cs_pin,high);
if (ether.begin(sizeof ethernet::buffer, mymac,ether_cs_pin) == 0)
serial.println(f("failed access ethernet controller"));
if (!ether.dhcpsetup())
serial.println(f("dhcp failed"));
ether.printip("ip: ", ether.myip);
ether.printip("gw: ", ether.gwip);
ether.printip("dns: ", ether.dnsip);
if (!ether.dnslookup(website))
serial.println(f("dns failed"));
ether.printip("srv: ", ether.hisip);
}
void loop () {
if ( mfrc522.picc_isnewcardpresent()) {
if(mfrc522.picc_readcardserial()){
string readcard = "";
(int = 0; < mfrc522.uid.size; i++) {
if(mfrc522.uid.uidbyte==0){readcard += "00";}
else{readcard += string(mfrc522.uid.uidbyte,hex);}
}
if(readcard != ""){
serial.println("cardid sent : " + readcard);
requesfromserver(readcard);
}
}
}
boolean pin2 = debounce(lastbtnstate,interrupt_pin);
if(pin2 == high){
serial.println("interrpt btn click !!");
requesfromserver("interrupt cardid");
}
}
void requesfromserver(string cardid){
serial.println("sending cardid : " + cardid);
byte sd = stash.create();
stash.print("cardid=");
stash.print(cardid);
stash.save();
int stash_size = stash.size();
// compose http post request, taking headers below , appending
// created stash in sd holder.
stash::prepare(pstr("post http://$f/trials/arduino/ http/1.0" "\r\n"
"host: $f" "\r\n"
"content-length: $d" "\r\n"
"content-type: application/x-www-form-urlencoded" "\r\n"
"\r\n"
"$h"),
website, website, stash_size, sd);
// send packet - releases stash buffers once done
// save session id can watch in main loop.
session = ether.tcpsend();
unsigned long lasttime = millis();
reply = 0;
while (!reply){
digitalwrite(ether_cs_pin,low);
digitalwrite(rfid_cs_pin,high);
ether.packetloop(ether.packetreceive());
reply = ether.tcpreply(session);
if (reply != 0) {
serial.println("got response!");
serial.println(reply);
}
if((millis() - lasttime) > 1000){
serial.println("request timed out !!");
break;
}
}
}
boolean debounce(boolean last,int inputbutton){
boolean current = digitalread(inputbutton);
if(current != last){
delay(50);
current = digitalread(inputbutton);
}else{
current = low ;
}
return current;
}
void showreaderdetails() {
// mfrc522 software version
byte v = mfrc522.pcd_readregister(mfrc522.versionreg);
serial.print(f("mfrc522 software version: 0x"));
serial.print(v, hex);
if (v == 0x91)
serial.print(f(" = v1.0"));
else if (v == 0x92)
serial.print(f(" = v2.0"));
else
serial.print(f(" (unknown)"));
serial.println("");
// when 0x00 or 0xff returned, communication failed
if ((v == 0x00) || (v == 0xff)) {
serial.println(f("warning: communication failure, mfrc522 connected?"));
}
}
its possible libraries driving cs pin.
according docs can choose different pin ether cs - possible can try that?
otherwise can try narrow problem down:-
do see connection attempt @ webserver end when connection fails?
does program print debug strings when connection fails?
have tried extending timeout? increase 1000 10000 perhaps?
does connection fail same way if press button rather swipe card?
if add code main loop sends request @ set interval (as waiting events) every second 1 fail?
according docs can choose different pin ether cs - possible can try that?
otherwise can try narrow problem down:-
do see connection attempt @ webserver end when connection fails?
does program print debug strings when connection fails?
have tried extending timeout? increase 1000 10000 perhaps?
does connection fail same way if press button rather swipe card?
if add code main loop sends request @ set interval (as waiting events) every second 1 fail?
Arduino Forum > Topics > Home Automation and Networked Objects > Hanrun ehternet Module + MFRC522 can't get website reponse
arduino
Comments
Post a Comment