Interfacing with a fuel pump, RFID and FTP server

Hi All,

I have used Arduino's in the past and i'm fairly familiar on how to get up and running. I am also a C# developer so I have that side covered but I have a project at work that I would appreciate some advice on.

We have a fuel pump (like at a garage) and our electritian has rigged it up to relays and other electrical items so that it can be controlled externally by a device like an Arduino. I also wish to use the Parralax RFID reader so that people can swipe a card to start the fuel pump and I want to add a keypad and LCD read out so that people can punch a number in instead of swiping an RFID.

I should be able to get the interface with the pump and RFID to work but I also need to be able to interface with an external data source (text files or db) to check that persons fuel allowance
and also write back how much they took.

In brief, this is my thoughts on flow logic:

Arduino sits there awaiting RFID card swip
Card swiped or number punched in, Arduino connects to FTP server on local network and reads data from a file to check fuel allowance
Arduino turns pump on and counts PWM (the pump send a pulse to PWM per 10th or a ltr) - when limit reached, shuts down pump
Arduino writes a file back to FTP server recording delivery

I'm thinking of running a Mega with the ethernet shield and a parralx RFID sensor.

Any sugestions of links to similar projects would be greatly received!

I'm thinking of running a Mega with the ethernet shield

Unless you are doing other things, the Mega is overkill. The rest of the project is quite do-able. Just take it one step at a time.

Ok - my first head scratcher is communication. I am trying to decide the best way to talk to a mssql (of mysql if I have to) database, web service or ftp server - I just cant decide?!?!?

I need a fairly robust method to be able to send and receive data from one of the above sources - does anyone have any recommendations?

UPDATE I like the idea of using UDP to communicate with an app that I can write in C# that will sit on my windows server and handle all of the logic there, but, I need to send and receive and it's my understanding that UDP id really a 1 way protocol.

Can I set up a listener in 1 socket and a sender on another all on the Arduino with 1 ethernet shield?

UDP transmission is designed for communications that don't really matter is they succeed or not. Sending messages to every workstation that the system is coming down, for example. Sending VOIP data is another example. Packets are small. If you miss 10 microseconds of a stream of voice data, is that critical?

Your packets ARE critical. I wouldn't bee looking at using UDP in your case.

You want the redundancy and retry capabilities that are integral to TCP/IP.

You need some application running on the PC at all times. Web servers fill that role. You want to be able to send information, and know that it will get to the PC, and that the PC will do something with it.

A PUT, POST, or GET request to a server will generate a response. Not necessarily the one you want, but a response nonetheless. The server handles generating the response.

Making the PC generate the right request is then pretty easy. Make sure that the correct program is in the correct place, with the correct permissions, and the response will come from the application, with a 200 return code, rather than the server generating a response with a 404 return code.

Making the application on the PC actually do what it needs to do is not trivial, but lots of the infrastructure for communication, via ethernet, between the Arduino and the PC (server) is already in place (or easily put in place).

C# and ASP.NET make great tools for doing the hard work, on the PC, of parsing the GET, PUT, or POST requests and interacting with the database.

Thank you for your reply - I appreciate your advice.

I think I need more info back from my server to the Arduino.

The logic needs to be along the lines of:

-User swipes RFID
-Arduino sends RFID # to server program (what ever that will be) and the server queries the DB to see what the allowance and fuel type is and sends to the Arduino a message confirming that it's ok to dispence fuel, what type of fuel and maximum ammount
-Arduino goes away and does its thing
-When finished, Arduino sends back to the server the ammount delivered

Based on the above - what do you now suggest would be a good communication approach?

Suppose that the Arduino was your PC, instead.

Suppose that the PC ran a browser, showing a web page from a server somewhere.

Now, suppose you think about those questions again. In this context, would you have any problem answering them?

The Arduino will make a GET request. That does more than tell the server to get off it's derriere and do something. It expects a reply.

The server executes the GET request, and streams whatever response it gets back to the client.

That request can then be parsed by the client, which can then make intelligent (or not) decisions based on the data in the reply.

When the Arduino detects that the fuel has been dispensed, it makes another GET request, with different inputs, or to a different server application, or both, to notify the server that the transaction is complete.

Hmm - OK I see where your going with this.

I can set up a 'website' that take parameters in the header and returns data and also write data to the DB where need be.

Is there a limit to the length of data that can be transfered this way? I would of course keep it to 1 line and keep it simple.

So a GET request can be used for both incoming and outgoing data?

Is there a limit to the length of data that can be transfered this way?

There is. If I remember correctly, though, it's like 2048 characters.

I would of course keep it to 1 line and keep it simple.

The one line is necessary. Carriage returns in the input will cause a number of issues. Basically, don't do it.

Keeping it simple is always a good idea.

So a GET request can be used for both incoming and outgoing data?

Think of how a google search works. You type a value in a form. When you press the submit button, a GET request is performed.
http://www.google.com/search?q=max232&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
The URL defines the server (you'll define it separately on the Arduino), the application (search) and the arguments (q=max232, etc.) This is a GET request.

You know that google's search application returns a reply, and that the browser (the Arduino will take on this role) parses the reply, and reacts accordingly.

In the google search case, the reply is an html file full of hyperlinks. When a hyperlink is selected, another GET request is made.

You'll be doing the same thing. Think of the Arduino as a web browser (that's what a client does). How would you structure the server application if it was being driven by a browser, instead of the Arduino?

That, by the way, is how you can test the application that you are building. Have your browser execute the same kind of request that the Arduino is going to. When the request results in the proper behavior in the browser application, you can then submit the same request(s) from the Arduino, and expect the same response(s).

Again - thank you for taking the time to reply, cleared things up for me greatly!

Final question regards data returned by the server - should I be returning data in the header or in a body tag (for example)?

The usual response to a GET request is an html file. But, it doesn't have to be an html file. The response could be an xml file, or plain text.

Return from the GET application whatever makes the most sense. That would generally be whatever is easiest to parse.

For the first request, that could be as simple as "Y" or "N", along with the server generated wrapper that contains the 200 return code (or other return code, if the server can't find the application to run, or can't access it).

For the second request, no response is needed, but one will be sent, with a 200 return code and no body (or other code...), if you don't supply one. You could simply look for the appropriate return code, after the second request.

I feel a weekend of coding coming on..... ;D

Just playing around with ASP.Net and I can easily get the following output:

test_data_returned
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
 
</title></head>
<body>
</body>
</html>

Although it's not acceptable for a conventional web page, you can see that I can get my data in to line 1.

I assume that the Arduino will be able to read this data ok?

I assume that the Arduino will be able to read this data ok?

Yes, it will. If you add some specific delimiters, it could be even easier.

Instead of

test_data_returned

...

Have the program return

<test_data_returned>

...

Then, you can quit parsing the returned data, and simply flush the buffer, when the end of packet marker (>) arrives.

Good idea - didn't think of that.

I presume that when the Arduino receives all of the data from the server, there will be a few extra lines prior to the section I need?

If this is the case, is it quite easy to go through the text to find the start of my data that I need? Do you have any recomendations?

I presume that when the Arduino receives all of the data from the server, there will be a few extra lines prior to the section I need?

Typically, yes.

If this is the case, is it quite easy to go through the text to find the start of my data that I need?

Depends on how easy it is to identify your data. That's why I like start of packet and end of packet markers. They make it easy to identify my data.

Although very early in my project, I'm thinking ahead. At the moment, all of what we have discussed is triggered by the Arduino and not the server.
If I had a need in the future to trigger events on the Arduino from the server, only using Ethernet, what are my options, if any?

Typically, the Arduino with ethernet shield acts as either a server or a client. All the stuff we've talked about so far has had the Arduino acting as a client, requesting information from the server.

It is theoretically possible to have the Arduino act as both client and server, so that clients can ask the Arduino to do stuff.

What kinds of things are you thinking that a client might ask of the Arduino-as-server?

I don't have a specific requirement at present but I can see users losing thier cards and then ringing me up expecting me to sort it there and then.
I suppose having a facility to remotely control the pumps would be a bonus I'd be interested in exploring.