Go Down

Topic: web server (Read 25009 times) previous topic - next topic

84billy

Arduino YUN can be used as a web server interactive?
with which library?

federicofissore

The Yun comes with a web server that's able to

  • serve static files (html, js...)

  • execute cgi-bin scripts (lua, python, whatever)

  • forward urls starting with /arduino/ to the running sketch, thus allowing the creation of custom APIs: take a look at the Bridge and TemperatureWebPanel examples


rapturedbyrobots

That's great, but there are no examples for actually serving a file.  How do you serve a static html file stored on the SD?  Trying to use the File IO but having no luck sending anything to the Yunclient.

federicofissore

Take a look at TemperatureWebPanel example: the sketch folder contains a www folder with files that are copied to the yun sd card as soon as you upload the sketch via WIFI

At the lower level, /www folder (on linino side) is the so called "document root" of the web server, thus whatever file is stored there is served by it

rapturedbyrobots

Thanks.  That helped a lot!

rapturedbyrobots

One last question.  I have the Yun serving a static html file now.  Thanks!  And I also have it reading and processing urls to control pins and such.  But I would like to have it redirect to the served home page after sending a command.  I tried printing the header as follows but no luck:

client.println("<head>");
client.println("<meta http-equiv=\"refresh\" content=\"1; URL=http://arduino1.local/arduino/control/ledoff\">");
client.println("</head>");

Should I be using the curl command or something?

Thanks again!

Franxoois


The Yun comes with a web server that's able to

  • serve static files (html, js...)

  • execute cgi-bin scripts (lua, python, whatever)

  • forward urls starting with /arduino/ to the running sketch, thus allowing the creation of custom APIs: take a look at the Bridge and TemperatureWebPanel examples




Is PHP possible on the Yun ?

federicofissore

Yes, there are both php4 and 5

84billy

I installed php

A minimal php5 installation includes

php5
php5-cgi
In /etc/php.ini ensure that the doc_root is empty if you are using multiple uhttpd instances (each on its own port). This enables the uhttpd 'home' variable to work for you.

Ensure that you uncomment the extension interpreter line for PHP in the main section of the uHTTPd config file:

list interpreter ".php=/usr/bin/php-cgi"


http://wiki.openwrt.org/doc/uci/uhttpd

cammer

I have served up a couple static html pages but I am still having problems getting the script to communicate to the arduino code. I have tried to configure my sd card and yun as per the guides and:

http://scuola.arduino.cc/courses/lessons/cover/b4EoRkV
http://scuola.arduino.cc/courses/lessons/cover/xzLgKRa

I think I am misunderstanding the file structure because any get command from the script can't access /arduino.

My SD card is configured with an /arduino/www path at the root.

root@cammer:/mnt/sda1/arduino/www# ls

TemperatureWebPanel   msg     betta     test

all of my sketch folders have a /www folder in them housing site files.

What I still don't understand, is where the /arduino directory in the URL and script is getting pulled from

ex. $.get('/arduino/msg/')

My files can only be accessed in the browser with

cammer.local/sd/msg/

cammer.local/arduino/msg
returns permission denied.

I also cannot cd into /arduino from the sd from terminal, have I configured something incorrectly?

federicofissore

#10
Sep 26, 2013, 09:26 am Last Edit: Sep 26, 2013, 10:24 am by Federico Fissore Reason: 1
Hi @cammer, you've configured everything the right way, it's just that the /arduino/ url is not for serving files.

/arduino/ is not a physical folder somewhere on the yun or on your sd card. It's a special url that the webserver uses to make your browser talk directly with your sketch

If your sketch is using YunServer and YunClient (as those tutorials do) and you call a url such as "/arduino/msg/hello", everything from the "m" of "msg" to the "o" of "hello" is sent to the sketch as a string.

A part is missing from the tutorial, however: it doesn't tell you that, in order to keep things simple, you need to open the rest api from the yun web panel. I've asked Angelo to update it asap

As a general introduction to how the bridge works, you'd want to read a blog post we've written some days ago
http://blog.arduino.cc/2013/09/05/hands-on-the-arduino-yuns-bridge/

cammer

Ok thank you for clarifying. I have noticed that the yunServer and YunClient are nowhere to be found in my bridge library and are only referenced in the bridge example itself. They also do not light up (turn orange) in the includes. Is it possible I have just downloaded a version of the bridge library that is incomplete? However I have tried to find the code online but have not been able to, which makes me more unsure.

federicofissore

In folder libraries/Bridge/src (under the folder in which you installed the IDE) there are YunClient.* and YunServer.*


They also do not light up (turn orange) in the includes.


Ah we missed those: thank you for pointing out

trushk

This might help. I used buttons on a web browser to turn the on board led on/off.  This has the details:
http://tkmaker.blogspot.com/2014/01/arduino-yun-introduction-controlling.html

thermalintegration

Something that appears obvious to everyone except me is..

How EXACTLY do you edit  uHTTPd config file, as per instructions below.

The aim is to get PHP5 running.
I have a simple php file sitting in www folder on sd card, and I have installed PHP5 and -cgi using opkg, and they show as installed, however php page doesnt open as a parsed php page in a browser, but rather tries to download.

Given all this has been done via YunSerialTerminal, and it isnt exactly a text editor, what tool or method does one use to actually edit the config files. Is it edited in place, or does one have to somehow obtain the contents of "/etc/config/uhttpd", edit, and somehow load back onto Yun ?

Any help much appreciated.

---------
A minimal php5 installation includes

    php5
    php5-cgi

In /etc/php.ini ensure that the doc_root is empty if you are using multiple uhttpd instances (each on its own port). This enables the uhttpd 'home' variable to work for you.

Ensure that you uncomment the extension interpreter line for PHP in the main section of the uHTTPd config file:
list interpreter ".php=/usr/bin/php-cgi"
-------------

Go Up