hi,
I am having a arduino due which connects to rn-171 wifly shield, and a 125khz rfid reader . I am using softwareserial to connect with both wifly and rfid reader to arduino, the rfid is connected to 10,11 and the wifly is connected to 8,9 gpio of arduino. my idea is a simple tcp client which reads the data from rfid and sends to the server , the server reverts back with a text based on that led will glow. I am using wiflyhq library and softwareserial library, the tcp client is a complete rip off from wifly hq sample ![]()
the issue is when i connecting it to the server it gets connected and sends the data to the server but it does not receives the back the data. if I disable the rfid and uses some hard coded value it sends the data as well as capture the return message from server. I am struck , any ideas.
for reference, the partially completed code , I suspect that listen() property of softwareserial, if i use rfid.listen it listens to the input but if i tried to use wiflyserial.listen() it is not working.
/*
* WiFlyHQ Example tcpclient.ino
*
* This sketch implements a simple TCP client that connects to a
* TCP server, sends any serial monitor input to the server and any
* data received from the server to the TCP monitor, and disconnects
* after 10 seconds.
*
* This sketch is released to the public domain.
*
*/
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(8,9);
SoftwareSerial RFID(10,11);
//#include <AltSoftSerial.h>
//AltSoftSerial wifiSerial(8,9);
#include <WiFlyHQ.h>
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
/* Change these to match your WiFi network */
const char mySSID[] = "MYssid";
const char myPassword[] = "abcdefghijkl";
const char server[]="10.168.10.100";
int counter=0;
char val;
char code[10];
int bytesread=0;
int readbytes=0;
char tagid[10];
WiFly wifly;
void setup()
{
char buf[64];
Serial.begin(115200);
Serial.println("Starting");
Serial.print("Free memory: ");
Serial.println(wifly.getFreeMemory(),DEC);
RFID.begin(9600);
wifiSerial.begin(9600);
if (!wifly.begin(&wifiSerial, &Serial)) {
Serial.println("Failed to start wifly");
wifly.terminal();
}
/* Join wifi network if not already associated */
if (!wifly.isAssociated()) {
/* Setup the WiFly to connect to a wifi network */
Serial.println("Joining network");
wifly.setSSID(mySSID);
wifly.setPassphrase(myPassword);
//wifly.enableDHCP();
if (wifly.join()) {
Serial.println("Joined wifi network");
}
else {
Serial.println("Failed to join wifi network");
wifly.terminal();
}
}
else {
Serial.println("Already joined network");
}
Serial.println("WiFly ready");
wifly.setIpProtocol(WIFLY_PROTOCOL_TCP);
if (wifly.isConnected()) {
Serial.println("Old connection active. Closing");
wifly.close();
}
if( wifly.open("192.168.1.100",8042)){
Serial.println("Connected");
}else{
Serial.println("Connected");
}
RFID.listen();
//Serial.println(F("Sending Hello World"));
//send("Hello, World!");
}
void loop()
{
// wifiSerial.listen();
if (wifly.isConnected()){
}else{
wifly.open("192.168.1.100",8042);
}
dispMsg();
//wifly.close();
delay(10);
//RFID.listen();
readCard();
delay(10);
}
void send(const char *data)
{
wifly.write((uint8_t)0);
wifly.write(data);
wifly.write((uint8_t)255);
}
void dispMsg(){
if(wifly.available() > 0) { // if data available from reader
Serial.println("test");
//if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread < 10) { // read 10 digit code
if( wifly.available() > 0) {
val = wifly.read();
code[bytesread] = val;
} // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("Server returned: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
delay(1);
//}
}
}
void readCard(){
//Serial.println("Inside read card method");
if(RFID.available() > 0) { // if data available from reader
//if((val = Serial.read()) == 10) { // check for header
readbytes = 0;
while(readbytes < 10) { // read 10 digit code
if( RFID.available() > 0) {
counter = RFID.read();
// Serial.println(counter);
if((counter == 10)||(counter == 13)) { // if header or stop bytes before the 10 digit reading
// break; // stop reading
} else{
tagid[readbytes] = counter; } // add the digit
readbytes++; // ready to read next digit
}
}
if(readbytes == 10) { // if 14 digit read is complete
// Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(tagid); // print the TAG code
//write2txt(code);
send(tagid);
}
readbytes = 0;
delay(1);
//}
}
}