Pages: 1 [2]   Go Down
Author Topic: Controlling Arduino from an exernal (nice) webpage  (Read 2331 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 5
Posts: 181
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found some code in the feof manual page to handle feof blocking.
Code:
<?php
function safe_feof($fp, &$start NULL) {
 
$start microtime(true);

 return 
feof($fp);
}

/* Assuming $fp is previously opened by fsockopen() */

$start NULL;
$timeout ini_get('default_socket_timeout');

while(!
safe_feof($fp$start) && (microtime(true) - $start) < $timeout)
{
 
/* Handle */
}
?>
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Heyy!

I’ve working on it, and until now I’ve only implemented the Zoomcat approach (communication over the URL), but this one only works in one way, so I can send commands from my hosted webpage to the Arduino. I would like to do something with AJAX so I could have bi directional communication. I was thinking to implement a web client on the Arduino that would connect to my hosted web page, and thru Javascript handle the request in some way, does someone know how to implement this?

Other way could be using UDP, but this have I big inconvenience because I nedd to open ports in wherever I want to connect the Arduino, and it cant not be hadeled with javasrcipt, maybe TCP would be much better…


Thank you for your support!
« Last Edit: February 23, 2013, 07:02:52 am by jmdiscovery » Logged

Tasmania - Australia
Offline Offline
Sr. Member
****
Karma: 14
Posts: 306
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If I understand you correctly, I believe what you wish to do can be done.
Firstly, did you take a look at BitLash as suggested by BillRoy, as it might be a good and suitable solution for you?

I have spent the past months learning and developing a system where by my Arduino monitors my renewable energy system and makes it availible for viewing on the web.
What I do, is have the Arduino use a http POST, to send data to my hosted site where a php script either stores the data in a SQL database or in a file.
Then, when a web browser points to the host site, another php script retrieves the data from sql database or file and again uses the POST method to send it back to the client, the javascript on your computer.
You need to know what structure you wish to use to transfer the data, I use json format.
Javascript then displays it in the way you wish on your screen.

Then, for the other way, to send data back to the Arduino, you can use a reverse path, that is, using a server between you and the Arduino, or you can send directly back to the Arduino, which is what I have been doing at present. If you use a hosted site, the you can use php or whatever language of you choice and is available on your host site, eg. perl or python, to communicate data back to your Arduino. If you decide to go from browser to Arduino, then you more likely write in javascript or a cleint-side language to send the data back to your Arduino. Either way, your Arduino needs to be able to accept requests, so it needs to be set up as a server, I use http not UDP and use the WebDuino library to provide this functionality.

Data that I want to go back to the Arduino, I hide and I make it so this function is not available from the web-page normally, as in my case, it is not something I would normally want anybody to be able to do from the webpage. But you can make possible from the web page by using an authorisation system.

I am no expert, and still learning myself, with a lot of reading and trying things out and help from other clever programmers e.g. http://www.cs.helsinki.fi/u/ljlukkar/iot/.
The web page is basically all writen in javascript and uses backbone.js as the MVC (model view controller) to keep a lot of the ajax code tidy and give it better structure.
To have an idea, you could look at my devolpments in my signature.
« Last Edit: February 23, 2013, 07:57:56 am by rockwallaby » Logged


0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
does someone know how to implement this?

https://github.com/billroy/bitlash/blob/master/examples/ethernetcommander/ethernetcommander.ino

- As a server: accepts Bitlash commands in the HTTP POST body, returns the text of whatever Bitlash prints out whilst executing the commands

- As a client: POSTs asynchronous updates to the Bitlash Commander server or perhaps an Apache/PHP server as rockwallaby has laid out.

You asked about Ajax.  Ajax is downstream of all the above, in the line that connects the browser(s) to the server.  Your server listens for AJAX requests (another type of POST, usually) and returns update data to the javascript running in your browser.  That javascript updates the web page it's running in by manipulating the DOM.

Commander, for exaple, uses Ajax to distribute control value updates to all the connected browsers.


-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey!,

- Yes, of course I've cheking BitLash, it’s really powerful, I was trying to code some example using the ethernetcomander.ino What I’d like to do is to be able to call my own functions coded in the Arduino as I’ve seen I’d just need to customize the runWebserver function in order to call my own functions, great! smiley Now, where I need some more help is in the Web part, billroy, do you have some simple example of a web to send/receive commands/info to/from the Arduino (I look at the herokuapp panels but they are quite complex for the basic needs of my webpage..)

- rockwallaby, reading you I feel like what you say is exactly what I think I want!! But how did you implement all this?! smiley I’ve seen your website but everything related to the Arduino/web part will be written soon (u hope) hehe smiley-grin, can’t wait! Will you advance some of the code pls...?



I’m learning a lot here, THANK YOU for your support and patient!!
Logged

Pages: 1 [2]   Go Up
Jump to: