Arduino as I/O device for RaspberryPi web server

I've advanced my noob status to now having three Uno's controlling various things around the house.
I've been frustrated by using the arduino as web server due to the combination of writing html code as print statements, and what appears to be a rapid consumption of memory with the web page, and what becomes undesirable behavior when you exceed the memory.

So... the new chapter: I've purchased a RaspberryPi to be the web server. I have it now loaded with Apache and PHP, and have recreated one of my Arduino web pages in the new server. My next step, which I'm stumped by, is something that should be simple, but I don't know where to start:

The project is my garage door controls. The current Uno has sensors for door position, temperature and humidity.
It serves a webpage accessible from my home network that provides that data, and allows user to check boxes to open/close the doors.

How can I write PHP code on the Pi that will query the Uno, get the sensor data to complete the web page, and then also write data back to the Uno to cause actions to be taken?

It was simple on the Uno, but how can I accomplish this over ethernet, using PHP code on the Pi? I assume much of the code on the UNO remains the same (basic web server?, I/O read/write), but it doesn't have to serve pages any more, just data streams.
Likewise on the Pi, I don't know how to access another IP address to retrieve the data, or to send data back to it.

ANY pointers would be greatly appreciated!!!
Tim

There are so many ways. I'll enumerate some.

-arduinos with wifi shield (or arduino yun) connected to the web server via ip. In this case you'll have to learn on php to receive data from other ip adresses.

-arduinos over xbee reporting to central arduino connected to raspi via usb.
Here you'll have to learn how to use the serial library on php.

-arduinos connected to rs485 network with rpi as the rs485 master. Again, learning on php to use the serial com library.

I've been frustrated by using the arduino as web server due to the combination of writing html code as print statements, and what appears to be a rapid consumption of memory with the web page, and what becomes undesirable behavior when you exceed the memory.

Most people with a lot of html text put it on an SD card so that it does not have to be generated within the arduino code.

I'm with zoomkat, most Ethernet shields come with an SD card slot for exactly this reason. Alternatively, you can store your strings in PROGMEM if there aren't too many of them. Also, be sure to use strings (lowercase 's'), NOT the String class (uppercase S).

Still, if you're set on a Pi+PHP, I'd take a look here:

http://elinux.org/RPi_Serial_Connection

and just use TTL RS232 to make the Pi and the Arduino talk, assuming they are situated fairly closely to each other physically. If you have a long distance to cross, then there are other options.

For those suggesting methods to connect, that isn't what I am focused on.... I already have ethernet on all of my arduinos and also my RaspPi. I ultimately want to consolidate all my arduino control pages into one web portal (security, cameras, music controls, lighting controls etc). This would be the Pi responsibility, and it would talk to each of the arduinos via the ethernet network.

I just don't know the proper data transfer method now between Uno and Pi. Because of this, the html on the pi is something I'd like to fix with on board SDRAM for a future project perhaps, but it isn't the real issue for me now.

See the response from @tylernt

just use TTL RS232 to make the Pi and the Arduino talk

i.e he suggests that you connect the PI and Arduino via RS232

You will need to write PHP to communicate with the Arduino via RS232 and write code on the Arduino to understand the requests (from the serial) and send back appropriate data to the PI

If you search on PHP Serial Comms there are plenty of pages that describe how to do this.

You will need to write your own command set and Arduino code, depending on what you are doing i.e what data is required from the Arduino

One simple way to do this if you are only sending commands and not data, just send

0x01 for command 1 e..g read door position
0x02 close door
0x03 open door

Other people have done more complex data transfers, there are plenty of examples on the web if you look

gowfster:
Pi responsibility, and it would talk to each of the arduinos via the ethernet network.

I just don't know the proper data transfer method now between Uno and Pi.

Good news, you get to make up your own! :slight_smile:

Seriously though. I'd make the Arduinos web servers. But instead of worrying about HTML, I'd define a layer of communication on top of HTTP. PHP has commands for acting as a HTTP client. You might use PHP to request an URL that consists of nothing more than a single character. An URL of 'a' might mean open a door, an URL of 'b' might mean close it, an URL of 'c' might be a query for the humidity, and so on. The code on the Arduino side is then just a simple switch/case construct. In response, the Arduino can return an "HTML" page that contains nothing more than one or a handful of characters -- 'a' for success, 'b' for failure, or whatever itoa() returns for the humidity percentage, etc.

Or come up with your own scheme. Check out the SMTP RFC for inspiration on a client/server protocol.

yep, I'm there: use the Arduino web server, but simply use a /?xxxxx as my data exchange protocol, to be decoded by the arduino into an action.

BUT.... here's my very simple level of confusion:
If it was arduino to arduino - no problem I have plenty of code that does just that. But my lack of knowledge on PHP/LINUX leaves me not knowing how to push data out the ethernet port to the arduino to read. It is probably such a noob question that I apologize! I haven't tried to figure out how to read the response from UNO yet either.
on the good side... I just ordered a book on PHP and MySQL in hopes of learning more.

Any help in the meantime is greatly appreciated!
Tim

But my lack of knowledge on PHP/LINUX leaves me not knowing how to push data out the ethernet port to the arduino to read.

Why are you trying to communicate between the boards using ethernet? Use the serial ports on the boards.

My design intent:
I am controlling 120 lighting control relays around my house. They are consolidated in 5 locations, with 24 in each location.
I have ethernet between those 5 locations. these locations are about 100 feet apart on three floors. In addition, I would connect my home audio and security system (also run on arduinos on ethernet), so I really have a consolidated home automation concept.

I could write a separate web page / server for each location, accessible via unique IP addresses (what i do now), but what I really want is one very nice web page/server that is the GUI for my lighting controls. One-stop-shop for all controls, and the ability to have "macros' that turn on sets of lights (e.g. all exterior lights) through that server.

I'm really struggling with this - ethernet and IP on the UNO has been great and reliable. When I started on the Raspberry Pi as the consolidation server, I keep running into my lack of understanding. Exhaustive web searches only spin me in circles, because everyone has their opinion on the 'best' way to communicate: UDP, HTTP, Mosquito, MTP etc... but they all expect a >>Novice level of knowledge to understand what they are saying, no less how to do it. Surprisingly, I haven't found the simple example of an Arduino sketch, and a PHP/HTML script that work together between Pi and Arduino. I was expecting to find many, but have found none, and I've been looking for 2 weeks.

I know what I'm trying to do is really quite simple, but I've failed to accomplish it. I'm hoping someone has something that they can share as an example to get me started.

Prolly because there is no one 'best' way... so many ways to skin this cat.

UDP is prolly the most 'lightweight' as far as memory and CPU on the Arduino goes, but you don't need to go that far. HTTP is 'light' enough and you already have experience with it. If this were a corporate project I might suggest SOAP but here I think it's overkill.

This application begs for SNMP but implementing the full SNMP protocol may, again, be overkill (but would be super cool). So I still vote for a custom protocol over HTTP based on SMTP or SNMP.

I could write a separate web page / server for each location, accessible via unique IP addresses (what i do now), but what I really want is one very nice web page/server that is the GUI for my lighting controls. One-stop-shop for all controls, and the ability to have "macros' that turn on sets of lights (e.g. all exterior lights) through that server.

Generally what is done for a setup like you want is serve the main control page from one server, and in that page have the control links for other servers embedded. Probably the majority of control web pages are made. Look at the below web page which is served from a main web server. if you look at the page source, you will see the control links embedded which connect to an apache web server and web cam application on an old computer I have. You could do the same for a bunch of arduino servers.

http://web.comporium.net/~shb/wc2000-PT-script.htm