arduino and www

is it possible to implement arduino data in a homepage on a server?

something like a webcam server. getting data every x-minutes and sending them to a webserver. but how? flash could refresh every x-minutes and read a textfile. so it could be possible to view progress of perhaps temperature or humidity in milano while sitting in timbuktu.

anybody out here in the knowledge of how to doing this?

to view progress of perhaps temperature or humidity in milano while sitting in timbuktu.

anybody out here in the knowledge of how to doing this?

yes, very easily, and without an Arduino!

http://www.wunderground.com/global/stations/16066.html

Sorry.. I'm sure there is a real answer in here somewhere, but sometimes I can't resist stating the obvious :)

D

Remembering that I am but a simple cave programmer that does not know about fancy tools…

I access some Arduinos over the WWW using cgi bins that are simply shell scripts that echo strings to the serial ports and read back the results.

I suppose slightly more evolved programmers might use PHP or something similar.

If you knew the URL to this and sent an ‘R’ in the query string you would set off my corporate “compromised server” alert and send me into a panic.

#!/bin/sh


echo "Content-type: text/html"
echo ""
echo "<HTML><HEAD><TITLE>Set Lights</TITLE></HEAD>"
echo "<BODY>"

echo "$QUERY_STRING" > /dev/usb/tts/0

echo "
You have just set the lights."
echo "</BODY></HTML>"

I saw an Ethernet Arduino on tinker.it. As soon as I find an FTDI chip, I'll be working on a network device. Maybe I can help you write some PHP :)

@Daniel: Why i’ve known that somebody will do this joke while i was writing about the example with the weather data?
:slight_smile:

@jims: ok. you acces the serial ports directly over cgi by executing shell-script? wow.
perhaps this is the way in php. but i don’t know nothing about php at the moment.

@Johntron: this is fancy!!! wanna have some!

the guys from the “remote project” are getting arduino data in vvvv and sending this data via OSC to php and flash.
this is a long chain of technologies.
http://tobias.zachl.at/daten/remote.pdf

so i need a php-file wich is possible to receive Arduino Data via OSC, or directly getting data from the serial port?
But I still don’t understand how to get the standing serverconnection between the php-file and the serial port.
hough? think i have to ckeck out php.

So I’m new here (“hello”), my Arduino NG board arrived last week, I’ve done the “hello world” & (KnightRider) tests. All’s working fab :slight_smile:

But, for the life of me, I can’t find a straight-up way to turn a LED, on and off, over the www.

So I just want to use an html form button to post data to a php script, and for that script to tell the board to toggle the state of the LED.

How simple is that?

Well, after days of scanning through sites and downloading pdf’s and examples and scripts and wot nots - I discovered it’s not simple at all :-[

I have mac’s and pc’s, the boards currently plugged into a notebook, so I’m interested in an “any” platform solution if anyone’s got any idea’s that might help.

I have a fully decked out linux server, so I can run server side scripts.

Any clues?

Hi

@john_ryan, as you found out, connecting to the web is actually a fairly complicated proposition, as you need to go from the web page >host machine> connected arduino. The biggest problem seems to be getting the Arduino to make a network connection. Tom Igoe has one solution on his site, using a Lantronix model to connect to a PHP web scraper script, which already scraped the appropriate web page info you want to use as a trigger.

D

Hi Daniel

Thanks for that, yes that was one of the pages I toiled over.

So, www to Arduino isn't possible without a Lantronix Xport direct?

Can any usb to ethernet adaptor be used? I can probably hack Tom's code and produce a simplified script for a www "hello world" that does the following:-

1/ monitoring a button state on a web page 2/ switching a LED on and off via html form button post via php

That's basically a starting point for anyone wanting to use Arduino over the internet, and I'm surprised it hasn't already been done as there seems to be enough people out there asking similar questions.

So, the Lantronix I couldn't find anything USB or cheap, but there's a bunch of others like:-

  • Intellinet Act/Link .. 20 bucks
  • EDIMAX USB to ethernet converter ... 40 bucks

What do you think? Perhaps I should email Tom?

hi

yes you obviously need some hardware to do this... it is more complicated than you make it out to be, as there is the whole issue of having some hardaware somehwere that is connected to the net, doing the tcp/ip etc. This means you have two options: host machine, or network interface like the Lantronix. I guess you could also use an ArduinoBT with a cell phone as the host/network interface.

Have a look at jims' post at the top...

D

PS: maybe you should just wait for Tom's book... look on Amazon for "Making Things Talk"

Thanks, so it's not possible to use an off-the-shelf usb to ethernet and simply plug it into a dsl router?

The Arduino "ethernet" over at tinker.it uses the OSC messaging protocol, would a Arduino plugged into a usb to ethernet adapter be any different? or using Jim's code where the URL is known?

And is there a difference between the Lantronix, and say a D-Link DSB-650TX? Or, is the deal strictly Lantronix ?

Ignore the d-link, not a relevant example.

So I need a Lantronix & xport, I've got that part figured - are there any known alternatives ?

So I found this

http://www.modtronix.com/

Seems more like an integrated solution for my html/php/LED 'hello world' test - I emailed tinker.it about their Ethernet Arduino, but no reply :(

You have a linux server handy, can you just have the PHP script run there and send serial commands down to the Arduino? It really is 20x easier than making a dedicated ethernet front end. There is a class that might help... http://phpclasses.promoxy.com/browse/package/3679.html. Unfortunately PHP Developer's Network is apparently designed to annoy visitors and they have worn out my patience with redirects and asinine policies before I managed to get the code downloaded.

Here is a serial to ethernet module I have used with arduino. I've not done any web interfacing, but it can do both tcp and udp.

Thanks for the info I really appreciate it.

Yes, I have Linux server and I do php but I haven’t worked with hardware like this before. It looks promising, if I can set up the ‘hello world’ then I’ll post the html source with the php script. I was wondering if you’d mind doing a quick test to see if the EG-SR-7150MJ module works over the internet before I go buy one?

Also, if you can briefly explain the physical relationship between the Arduino and EG-SR-7150MJ - is there a cable required to connect both devices? RJ12 cable?

I’m a newbie at this but I learn fast :slight_smile:

Here’s the example script

<?php
require_once "php_serial.class.php";

// Let's create the object
$serial = new phpSerial();

// Now we set the device
$serial->setDevice("/dev/ttyS0");

// And finaly we send a message
$serial->sendMessage(chr(0x1B) . chr(0x40));

// The device is auto-freed when shutdown, so you may not need to free it
// by yourself. Written here (but commented) for the example

// $serial->freeDevice();
?>

and
php_serial.class.php

<?php
/**
* Serial port control class
*
* @author Rémy Sanchez <thenux@gmail.com>
* @copyright under GPL 2 licence
*/
class phpSerial
{
    var $_device = null;
    var $_dHandle = null;
    var $_buffer = "";
    
    /**
     * This var says if buffer should be flushed by sendMessage (true) or manualy (false)
     *
     * @var bool
     */
    var $autoflush = true;
    
    /**
     * Constructor. Perform some checks about the OS and setserial
     *
     * @return bool
     */
    function phpSerial ()
    {
        setlocale(LC_ALL, "en_US");
        
        $sysname = php_uname();
        
        if (substr($sysname, 0, 5) === "Linux")
        {
            $version = exec("setserial -V 2>&1");
            if (substr($version, 0, 19) === "setserial version 2")
            {
                register_shutdown_function(array($this, "freeDevice"));
                return true;
            }
            else
            {
                trigger_error("Invalid (!= 2) or inexistant setserial detected", E_USER_ERROR);
                exit();
                return false;
            }
        }
        else
        {
            trigger_error("Host OS is not linux, unable tu run.", E_USER_ERROR);
            exit();
            return false;
        }
    }
    
    /**
     * Sets the serial device (something like /dev/ttyS0), tests if valid and open it.
     *
     * @param string $device address of the device
     * @return bool
     */
    function setDevice ($device)
    {
        $test = exec("setserial " . $device . " 2>&1");
        
        if (substr($test, 0, strlen($device)+1) === $device . ",")
        {
            $this->_device = $device;
            $this->_dHandle = fopen($this->_device, "wb");
            return true;
        }
        else
        {
            trigger_error("Specified serial port not valid", E_USER_WARNING);
            return false;
        }
    }
    
    /**
     * Closes the device file
     *
     * @return bool
     */
    function freeDevice ()
    {
        if ($this->_device !== null)
        {
            if (fclose ($this->_dHandle))
            {
                $this->_dHandle = null;
                $this->_device = null;
                return true;
            }
        }
        
        return false;
    }
    
    /**
     * Sets a setserial parameter (cf man setserial)
     *
     * @param string $param parameter name
     * @param string $arg parameter value
     * @return bool
     */
    function setParam ($param, $arg = "")
    {
        if ($this->_device === null)
        {
            trigger_error("Device must be specified", E_USER_WARNING);
            return false;
        }
        
        $return = exec ("setserial " . $this->_device . " " . $param . " " . $arg . " 2>&1");
        
        if ($return{0} === "I")
        {
            trigger_error("setserial: Invalid flag", E_USER_WARNING);
            return false;
        }
        elseif ($return{0} === "/")
        {
            trigger_error("setserial: Error with device file", E_USER_WARNING);
            return false;
        }
        else
        {
            return true;
        }
    }
    
    /**
     * Sends a string to the device
     *
     * @param string $str string to be sent to the device
     */
    function sendMessage ($str)
    {
        $this->_buffer .= $str;
        
        if ($this->autoflush === true) $this->flush();
    }
    
    /**
     * Flushes the buffer
     *
     * @return bool
     */
    function flush ()
    {
        if ($this->_device === null)
        {
            trigger_error("Device must be specified", E_USER_WARNING);
            return false;
        }

        if (fwrite($this->_dHandle, $this->_buffer) !== false)
        {
            $this->_buffer = "";
            return true;
        }
        else
        {
            $this->_buffer = "";
            trigger_error("Error while sending message", E_USER_WARNING);
            return false;
        }
    }
}
?>

I’ve posted this here because it wasn’t easy finding it. You can edit copy paste this into a text editor and save as the file names

1/ example.php
2/ php_serial.class.php

Create a directory on the linux server eg. /test

Upload the two php files to the directory, changing the parameters of the example script that I’ll get back to once I’ve got it figured.

The script is accessed by:-
www.yourserver.com/test/example.php

I can verify the device works over the internet, but can't really help you with html/php side of it. For my uses I am using Visual Basic to establish a Winsock connection to the device to send and receive data. I really wouldn't know where to start in getting a TCP or UDP connection in php and then sending data. Google shows several hits on the topic though.

Looking at the code you supplied it seems this is for connecting the Arduino to the serial port of the server. If you want to go that direction you do not need the serial to ethernet adapter. Will you be able to connect each Arduino to a server in your application?

For my application I did not want to have a computer tied to each Arduino.

The physical connection between the Arduino and EG-SR-7150MJ is simply two wires (RX TX). The EG-SR-7150MJ does require 3.3V so I have a regulator for that.

Hey thanks for that. If I don't need an ethernet adaptor that certainly makes it cheaper. I'll go read the links in the google search you supplied :)

No problem. Keep in mind the google search will only help you if you decide to use the ethernet module.

Hi, thanks. I think I've got to the point where the economies of time versus the economies of buying a modtronix, are now favoring the modxtronix. The SBC65EC does everything I'm attempting to do, and more, and it's plug n play so I won't be wasting time attempting to find work-a-rounds (about 12 hours all up now and I've got too much work on at the moment to afford it).

And I've tested their web interface 'live' so I can see for myself the various relationships between I/O's and GET & POST commands. And it's got a relay board add-on which makes for a nice integrated system.

So I've got my Arduino board and I guess have at least eliminated one possibility, I'm sure I'll find a use for it one day but for now it's not an easily adaptable solution for what I'm needing.

I'm disappointed to have not heard anything back from tinker.it - but I guess they're busy like everyone else.

Anyway - thanks again for your time, best of luck with your own projects :)

For anyone else looking to use Arduino via web based control, here's an excellent example using Xampp and php over at instructables:-

http://www.instructables.com/id/EXKBV8BZBKEY6DCICU/

I only recently discovered instructables, the example appears to have been tested and works - I would expect the example to work with BT and when I get a chance to test it I'll update the post.

It would have been nice to have found that example "somewhere" at arduino back in May.