Suggestion on protocols to connect Arduino Mega to a server.

Hello everybody! :slight_smile:

I started using Arduino some years ago and I made a lot of project but nobody of them used the Internet. Now is time to make a project with an Arduino Mega that communicate with a server on Internet to send state information and to recive commands from it. I will probably use an Ethernet shield to provide phisical connection to a router.

My project:

It is like a storage cabinet with electronic locks. I will connect the locks (more or less 8 ) with the Mega.
Users will be able to unlock a cabinet using an App from the mobile phone that not communicate directly to the cabinet but to the server that will tell the Arduino Mega to unlock a specific lock. My partner will setup the server and the App.
Also the locks are able to understand when thay are manually locked and I want the Arduino will advise the server in this case.
The network will consist on a server and multiple Arduino Mega with Ethernet shield of course.

What I ask you:

I have just started to inquire with web guides on web communication protocols and to understand differences among Data format, Application, Web transfer, Internet and Network, although I noticed some confusion about the separation of the layers, or at list I have some :confused: .
Anyway, I need some suggestions from you to understand which are the best protocols to use in my case considering that:

  • my cabinet will not use a battery, so energy saving is not strictly necessary
  • I need the communication is highly reliable as the TCP is
  • both the server and Arduino will be able to start the communication because the server will tell the lock to unlock and the Arduino will tell the server whrn a lock is manually locked
  • The protocol should be easy to use and implement on Arduino Mega
  • What about cryptography? I would like cabinet will be safe from hackers (if it is not too complicated on an Arduino Mega). What do you think about it?

I hope this discussion is interesting and a matter of comparison between all of us!

Thank you,

Simone

Hello,
I am realizing a similar project with RFID chips relays and a database. I use a TCP connection established by the server to control the arduinos. Except for a small problem with reconnecting what I'm trying to solve here in the forum it works very well.
That both sides can start the communication I consider difficult. I would establish a connection and then both sides can receive and transmit.
There is a ready-to-use TCP library for the ethernet shields of the arduinos.
Cryptography I wouldn't know how to implement it because it needs performance that arduino doesn't have. or I haven't found it yet.
The question is in which language you want to program the server?
Penner 42

First, cryptography on a Mega is probably a no-go - there's just not enough room for it.

HTTP is relatively easy to implement on a Mega, you can easily have a web-server running on it (to receive commands), and sending HTTP requests to your server is also easy. Then it boils down to can your server be programmed to respond to HTTP requests like GET and POST to update state variables (so it would know when a lock is opened manually).

I implemented a driveway gate controller this way - a Mega runs a web server, and the gate can be controlled by any web browser. It's not exposed to the internet, so I didn't worry about security much beyond "how do I control access to my own network". BUT, since it's all HTTP, I can control the gate without visiting the web-page first - just post the form data directly, so I can control it programmatically no problem.

For very basic security, you could run the web server on a different port (so it's harder to find), and you could implement white-listing - there's no need to accept commands from anything unless it has the IP of your server. Maybe also add the local sub-net, so you can talk to it directly if needed.

You might want to look at home automation projects, they operate in a similar fashion. Have you read the Arduino cookbook by Michael Margolis? Also on line there are many videos etc showing the Arduino and how to do what you want. This additional information will go a long way in getting your problem solved.

Thank you all for helping me!

The question is in which language you want to program the server?

Well, I didn't decide yet, I think it depend on what protocol I choose to implement, isn't it?

Anyway you gave me a lot of suggestions, I will start to study from them and let you know!