Okay, here is the deal:
Working on an RFID scanner mod that will take the resulting RFID code, send it as a GET request to a PHP script that will process the RFID and the time the RFID was scanned (or roughly the time it is scanned), log it to the MySQL database, do some calculations, send back a few string-based values and display them on a 16x2 LCD module.
I have looked at a bunch of example code, and can get most of this working individually, but not exactly in tandem as i would like. These are...
- Display information on the LCD
- Read the code from an RFID and turn it into a String.
- Send a GET HTTP request to an Apache2 web server running on a local Raspberry Pi AND get the web server to use the data as it needs
- Read the returned data from the web server and, via substring, capture data that is enclosed within <> or {} or [] or ()
I do have a few issues, those being...
- making the UNO wait within a function for a response from the web server
- disconnecting and reconnecting to the web server only when i need to send and receive data
here is the code i am using on the arduino as of right now. not complete, obviously, but if anyone could point out in my code the best place to connect and reconnect that would be great.
i dont need help with the PHP side of things, i have been working with PHP and/or MySQL for about 5-10 years now so I can figure out any issues in that area, and as of right now I dont have any issues there.
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
boolean debugMode = true;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x14, 0xE8 };
byte ip[] = { 10, 0, 1, 142 };
byte gateway[] = { 10, 0, 1, 1 };
byte dns[] = { 10, 0, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
byte localServer[] = { 10, 0, 1, 175 };
EthernetClient client;
boolean waitingForResponse = false;
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
String readString, readString1;
void setup() {
Ethernet.begin(mac,ip,dns,gateway,subnet); // start up Ethernet
Serial.begin(9600); // enable Serial
if (debugMode) Serial.println("Starting Time Management System");
if (debugMode) Serial.println();
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
if (debugMode) Serial.println("Analog Pins set to OUTPUT");
if (debugMode) Serial.println();
lcd.begin(16,2); // start up 16x2 LCD Module
if (debugMode) Serial.println("LCD Module Enabled");
if (debugMode) Serial.println();
// Attempt to make an Ethernet connection
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Testing Ethernet");
if (debugMode) Serial.print("Testing Ethernet: ");
lcd.setCursor(0,1);
if (client.connect(localServer,80)) {
lcd.print("Successful!");
if (debugMode) Serial.println("Successful!");
if (debugMode) Serial.println();
client.stop();
client.flush();
} else {
lcd.print("Failed!");
if (debugMode) Serial.println("Failed!");
if (debugMode) Serial.println();
}
}
void loop() {
checkScanner();
}
void checkScanner() {
String txtMsg = "";
if (Serial.available() == 16) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (int(inChar) > 31) {
txtMsg += inChar;
}
}
Serial.println(txtMsg);
Serial.println();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Card Scanned!");
lcd.setCursor(0,1);
lcd.print("Processing...");
client.print("GET /monarch-time-tracker/test.php?rfid=");
client.print(txtMsg);
client.println(" HTTP/1.0");
client.println();
waitingForResponse = true;
awaitScanResponse();
}
}
void awaitScanResponse() {
while (true) {
if (client.available()) {
char c = client.read();
readString += c;
}
if (!client.connected()) {
client.stop();
client.flush();
int d1 = readString.indexOf('<');
int d2 = readString.indexOf('>');
readString1 = (readString.substring(d1+1,d2));
}
}
}