Some more developments regarding this project:
I managed to get the the response from my home automation system (Homeseer) to go trough the Gateway Moteino back to the RFID node and the sketch on the RFID node reads the data correctly and blinks the local led for 5 seconds as a response. So now, as I approach the RFID tag to the RFID antenna after a very brief moment of about 1/2 a second the local LED starts blinking, showing that the whole circuit was processed.
I spent the whole week looking for ways to correctly read the data from the home automation computer serial port. The problem was quite simple to solve but only after I tried all the wrong ways of doing it.
Why was it hard? Well, for once I know nothing about C++. So I had to read all the stuff I could get my eyes on to try to figure this out. Of course I could just ask around and I'm sure I wouldn't waste so much time if I did, but by not doing it the easy way I now have a much better know-how to tackle my other Moteino projects.
So what was my solution, you ask?
Well, the whole projects goes like this:
[RFID ANTENA] --> [RFID MOTEINO NODE] ))))(airwaves)(((([GATEWAY MOTEINO]-->[USB PORT]-->[HOME AUTOM SOFT]-->[VB SCRIPT - CHECK TAG NUMBER LIST...
...IF TAG EXIST ON LIST SEND PROTOCOL #2/1/]-->[HOME AUTOM SOFT]-->[USB PORT]-->[GATEWAY MOTEINO]))))(airwaves)(((([RFID MOTEINO NODE]-->[DOOR LOCK]
The biggest problem to solve was how to handle variable types conversion form String to char to int to whatever. I guess for someone with experience in C++ that wouldn't be a problem but for me it drove me on a path of discovery reading everything I could get my eyes on.
The simple solution was to make my home automation software lookup the tag number it received trough the serial port (USB) on a txt file and if it is on that list sends a preset protocol phrase to the serial port to be picked up by the Serial.read() of the gateway Moteino and passed on to the RFID node.
The protocol e very simple: #2/3/
The '#' marks the beginning of the message. The '2' is the node number to which this message will be sent to and the '/' marks the end of the node number. This is important because the node number may have more than one digit and the gateway must know where to stop reading the node number. Next is a data package, an unsigned long int (a bit overkill since it may hold a number as big as 4.294.967.295), which will be interpreted by the RFID Moteino node and act upon according to the loaded sketch. In this case that '1/' means blink the local led and flip flop some digital output to drive the electric lock. So this means I can send 4.294.967.295 different instructions to any node as a response to a RFID Tag. Maybe I'll turn them into an int later on
.
This is where the parsing and interpretation of the protocol message is done on the gateway:
if (Serial.available()>0)
{
inbyte = Serial.read();
if (inbyte == '#')//É o início de um packet?
{
serialdata = 0;
while (inbyte != '/')
{
inbyte = Serial.read();
if (inbyte > 0 && inbyte != '/')
{
serialdata = serialdata * 10 + inbyte - '0';
}
}
inbyte = 0;
destinationNode = serialdata;//Atribui o numero do node a destinationNode
Serial.print("destinationNode:");Serial.println(destinationNode);
serialdata = 0;
while (inbyte != '/')
{
inbyte = Serial.read();
if (inbyte > 0 && inbyte != '/')
{
serialdata = serialdata * 10 + inbyte - '0';
}
}
inbyte = 0;
data = serialdata;//Atribui o numero do node a destinationNode
Serial.print("Data:");Serial.println(data);
}
Serial.flush();
if (radio.sendWithRetry(destinationNode, (const void*)&data, 5, 5, ACK_TIME))
{
Serial.println("ACK Received!");//If the sent packet was delivered and an ACK received, send this message to the serial monitor
delay(3);// Allow the the radio to switch to receive mode
}
destinationNode = 0;
data = 0;
Serial.flush();
}
I still have to do some tuning on the code to prevent the gateway to get mad and lost if the protocol message is broken midway for some reason.
I'll be updating the code I posted previously and add some more as soon as I have more time.
The last thing I did was to connect an optocoupler that will drive the electric door lock. I'll make a video of the whole thing soon.
Happy Motoining