Using EthernetShield2 with RC522


hey.
i working on project send uid of magnetcard via udp project on pc. connection itselfs works. able send string arduino software. if want read out uid , send software, doesnt work. me how use udp , rc522 parallel in 1 sketch?
i working exmplesketch (sendandreceivestring).
code: [select]
#include <mfrc522.h>
#include<spi.h>
constexpr uint8_t rst_pin = 5;    
constexpr uint8_t ss_pin = 53;    
mfrc522 mfrc522(ss_pin, rst_pin);

//udp
#include <ethernet2.h>
#include <ethernetudp2.h>
ethernetudp udp;

byte mac[] = {0x90, 0xa2, 0xda, 0x11, 0x2e, 0x46};
ipaddress ip(192, 168, 1, 177);
unsigned int localport = 8888;
char packetbuffer[udp_tx_packet_max_size];
char  replybuffer[] = "uid should in here afterwards.";


void setup() {
  // put setup code here, run once:
 ethernet.begin(mac, ip);
  udp.begin(localport);
  serial.begin(9600);
}

void loop() {
  string content;

  // if there's data available, read packet
  int packetsize = udp.parsepacket();
  if (packetsize)
  {
    serial.print("received packet of size ");
    serial.println(packetsize);
    serial.print("from ");
    ipaddress remote = udp.remoteip();
    for (int = 0; < 4; i++)
    {
      serial.print(remote[i], dec);
      if (i < 3)
      {
        serial.print(".");
      }
    }
    serial.print(", port ");
    serial.println(udp.remoteport());

    // read packet packetbufffer
    udp.read(packetbuffer, udp_tx_packet_max_size);
    serial.println("contents:");
    serial.println(packetbuffer);
    

    //------------------------------------------------------------------------
// new cards
  if ( ! mfrc522.picc_isnewcardpresent()) {
    return;
  }

  // select 1 of cards
  if ( ! mfrc522.picc_readcardserial()) {
    return;
  }
  //----------------------------------------------------------------------
  
  for (byte = 0; < mfrc522.uid.size; i++) {
    content.concat(string(mfrc522.uid.uidbyte[i] <0x10 ? "0" : " "));
    content.concat(string(mfrc522.uid.uidbyte[i],hex));
    }
    content.touppercase();
    string uid= content.substring(1);  
    serial.print(uid);
    // send reply, ip address , port sent packet received
    udp.beginpacket(udp.remoteip(), udp.remoteport());
    udp.write(replybuffer);
    udp.endpacket();
  }
  delay(10);
}

quote
but if want read out uid , send software, doesnt work.
i'm not going @ code until explain does, , how differs want. "it doesn't work" noise. deal in facts here.

code: [select]
    udp.beginpacket(udp.remoteip(), udp.remoteport());
    udp.write(replybuffer);
    udp.endpacket();

replybuffer doesn't contain useful information. uid does.


Arduino Forum > Using Arduino > Programming Questions > Using EthernetShield2 with RC522


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???