Go Down

Topic: Internet Control of Arduino (Read 6149 times) previous topic - next topic

DCContrarian


As another option (sorry to re-post):

We're creating a free web-service that relays messages through a cloud server.
We'll post more details soon, but the Arduino essentially authenticates and establishes an ongoing connection to the server.

It's great because it does not require any network configuration.
No need to use a local static address, open up your firewall to setup port forwarding, remember your temporary IP address, configure Dynamic DNS, or pay an exorbitant rate for a static IP.

Check out the project:
http://www.kickstarter.com/projects/916146896/customctrl?ref=category


That's pretty much how the IO Bridge works. It connects to their server every few seconds and uploads status and checks for instructions. If you want to send it an instruction you connect to the server and post an instruction, if you want status you download it from their server. As long as the IO Bridge can access the internet and you can access the internet no other configuration is necessary. It supports DHCP so all you have to do is attach it to a network.

One of the variations CustomCTRL is bringing to Arduino is sustaining the connection to the server, so the results happen in a fraction of a second.
When you think about the time it takes to load a webpage, it's still amazing to me that the data can be relayed so rapidly...




Haavard GJ

I have a code that work in the version 22 of the IDE
this code will display a site with options to turn on/off outputs, and show values of analog sernsors =)

Code: [Select]
//*******************************

#include <SPI.h>
#include <Ethernet.h>

/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox

The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* LED connected to GND and digital pin 4 via resistor
By Minde
http://www.sciencprog.com/

**************************************************************
*  Edited by Haavard GJ to work in version 0021              *
*  Thanks to PaulS for the big help on getting this to work  *
**************************************************************
*/


byte    mac[] =     { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };   //physical mac address
byte    ip[] =      { 192, 168, 2, 110 };                     // ip in lan
byte    gateway[] = { 192, 168, 2, 1 };                       // the IP of the router or acsesspoint
byte    subnet[] =  { 255, 255, 255, 0 };                     //subnet mask (i dont think this is neccesary
Server  server(80);                // server port (change this if you are having a local webserver else than the arduino)
int     ledPin = 4;                // LED pin
int     heatpin = 5;               // Heating *relay* (change this if you want)
int     lightpin = 6;              // lights
int     sensorPin = A0;            // analog in 0 for testing
int     sensorValue = 0;           // integer for the analog sensor
String  readString = String(30);   // string for fetching data from address
boolean LEDON = false;             // LED status flag
boolean HEATON = false;            // Heat status flag  (add more status flags if you need more outputs)
boolean LIGHTON = false;           // lights *test*

void setup()
{   
  Serial.begin(57600); //enable serial datada print
  Ethernet.begin(mac, ip, gateway, subnet); //start Ethernet
 
  pinMode(ledPin, OUTPUT); //Set pin 4 to output
  pinMode(heatpin, OUTPUT);
  Serial.print("Starting server"); //for debugging
 
  sensorValue = analogRead(sensorPin);
}

void loop(){

  Client client = server.available();  // Create a client connection
    if (client) {
      while (client.connected()) {
        if (client.available()) {

          char c = client.read();

        if (readString.length() < 30) { //read char by char HTTP request
          readString.concat(c); } //store characters to string
         
        Serial.print(c); //output chars to serial port for debugging
       



        if (c == '\n') { //if HTTP request has ended
       
          Serial.println("");
          Serial.println(readString); // print for debugging
          Serial.println("");
          int Le = readString.indexOf("L="); // led         here is a key component of where
          int He = readString.indexOf("H="); // heat        the status is being read by the arduino
          int V = readString.indexOf("V"); // light
          Serial.print("L= position: ");
          Serial.println(Le);
          Serial.print("H= position: ");
          Serial.println(He);
          Serial.print("V= position: ");
          Serial.print(V);
         
         
         
         
         
         
          //lets check if LED should be lighted
          if (Le > 1){
         
          if (readString.substring(Le,(Le+3)) == "L=1") { //led has to be turned ON
              digitalWrite(ledPin, HIGH); // set the LED on
              Serial.println("ledpin paa"); // debugging
              LEDON = true;
          }

          if (readString.substring(Le,(Le+3))== "L=0") {
            //led has to be turned OFF
            digitalWrite(ledPin, LOW); // set the LED OFF
            Serial.println("ledpin av"); //debugging
            LEDON = false;
           }}
           
           if (He > 1){
             
          if (readString.substring(He,(He+3)) == "H=1") { //heat has to be turned ON
              digitalWrite(heatpin, HIGH); // set the heat on
              Serial.println("heatpin paa");//debug
              HEATON = true;
          }

          if (readString.substring(He,(He+3)) == "H=0") {
            //heat has to be turned OFF
            digitalWrite(heatpin, LOW); // set the heat OFF
            Serial.println("heatpin av"); //debug
            HEATON = false;
           }}
           
            if (V > 1){
             
          if (readString.substring(V,(V+3)) == "V=1") { //light has to be turned ON
              digitalWrite(lightpin, HIGH); // set the heat on
              Serial.println("lys paa pin 6");//debug
              LIGHTON = true;
          }

          if (readString.substring(V,(V+3)) == "V=0") {
            //light has to be turned OFF
            digitalWrite(lightpin, LOW); // set the heat OFF
            Serial.println("lys av"); //debug
            LIGHTON = false;
          }}
           


  client.println("HTTP/1.1 200 OK"); //output HTML data starting with standart header
  client.println("Content-Type: text/html");
  client.println();
  client.print  ("<body style=background-color:white>"); //set background to white

  // HTML Code

  client.println("<font color='red'><h1>Arduino Remote control</font></h1>");//send first heading

  client.println("<font color='blue' size='5?>Analog input 0: "); //print analog in to the browser
 
 
  sensorValue = analogRead(sensorPin);


  client.print(sensorValue);//Analog input.
  Serial.print(sensorValue);

  client.println("<br />");//some space between lines

  //controlling led via checkbox
  client.println("<h1>LED control</h1>");

  // address will look like http://192.168.1.110/?L=1 when submited
  // this line will give the radiobuttons that give the input
  client.println("<form method=get name=LED> <input type='checkbox' name='L' value='1'>LED<br><br><input type='checkbox' name='H' value='1'>HEAT<br><br><input type='checkbox' name='V' value='1'>Light <br><input type=submit value=submit></form>");
  client.println("<br />");
 
  //printing LED status
  client.print("<font size='4?>LED status: ");
  if (LEDON == true) {
     client.println("<font color='green' size='4'>ON</font>");
     Serial.print("led on pin 4");
   }
   else {
    client.println("<font color='red' size='4'>OFF</font>");
    Serial.println("Led off pin 4");
   }

  client.print("<br />");

//printing LED status
  client.print("<font size='4?>Heatpin status: ");
  if (HEATON == true) {
     client.println("<font color='green' size='4'>ON</font>");
     Serial.print("Heat on pin 5");
   }
   else {
    client.println("<font color='red' size='4'>OFF</font>");
    Serial.println("Heat off pin 5");
   }
   client.print("<br />");
   
     client.print("<font size='4?>Light status: ");
  if (LIGHTON == true) {
     client.println("<font color='green' size='4'>ON</font>");
     Serial.print("light on pin 6");
   }
   else {
    client.println("<font color='red' size='4'>OFF</font>");
    Serial.println("light off pin 6");
   }



  client.println("</body></html>");


readString=""; //clearing string for next read

client.stop(); //stopping client

Serial.println("stopped client"); // for debugging

}}}}}

jumpjack


Is this a decent shield
http://www.robotshop.com/arduino-ethernet-shield-4.html

Only if you also need storage, else why spending more?

speemike

Ok so I am going to wait until Arduino puts out their Ethernet Shield again, and then buy it. I am still somewhat confused as to which code goes where? This is the way I think it works, let me know if I am wrong.
PHP or Processing code goes on the Ethernet Shield, this acts like a server and plugs into my router.
Arduino code goes on the Arduino.

But if you do not have an ethernet shield I can load the PHP code or Processing code into a program called Apache on my desktop which simulates a server.

What is the differences between Processing and PHP?

To create a webpage with buttons that will work on my blackberry to trigger LED's I need to write HTML code?
Which software do I use to create buttons on a website, or can it be done in PHP or processing?
I see a lot of people using MySQL in there projects, what is that for?

zoomkat

" Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind."  - Deep Thoughts by Jack Handy
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

PaulS

Quote
I am still somewhat confused as to which code goes where? This is the way I think it works, let me know if I am wrong.
PHP or Processing code goes on the Ethernet Shield, this acts like a server and plugs into my router.

You are wrong. The ethernet shield is a hardware extension to the Arduino. The Arduino code controls what the ethernet shield does. The Arduino with ethernet shield plugs into your LAN and acts like a server or client depending on the code installed.

Quote
But if you do not have an ethernet shield I can load the PHP code or Processing code into a program called Apache on my desktop which simulates a server.

More no. Apache is a web server for the PC. It can serve up pages that include PHP scripting.

Quote
What is the differences between Processing and PHP?

What is the difference between a tree and an alligator? They are completely different applications for different purposes.

Quote
To create a webpage with buttons that will work on my blackberry to trigger LED's I need to write HTML code?

Yes.

Quote
Which software do I use to create buttons on a website

Any software that can output an html file.

Quote
can it be done in PHP or processing?

PHP - Yes. Processing - No.

Quote
I see a lot of people using MySQL in there projects, what is that for?

Its a relational database application.

tkbyd

Quote
Which software do I use to create buttons on a website


Probably best to start with a simple text editor, because then you know EXACTLY what is going into the webpage you've made with a button.

Making the webpage isn't the hard part. Making a webpage with a button, and making the computer serving the webpage deal with responding to a user clicking on the button is the hard part.

Do you know how to create a simple webpage that merely displays "Hello World" when someone goes to it? If not, you need to start there.

Details at...

http://www.arunet.co.uk/tkboyd/hh5.htm

That page assumes that you are going to have someone else host your webpage. In the Arduino world, you will eventually have to master everything at the page above, PLUS set up your Arduino so that it is hosting the page you have written. Not impossible... but a bit of a "journey".

If anyone has a "how to set up your Arduino to serve a "Hello World" webpage" guide, I would love to know where that page (the guide) is....


Jonathan Oxer

Quote
If anyone has a "how to set up your Arduino to serve a "Hello World" webpage" guide, I would love to know where that page (the guide) is....


It's not quite a tutorial / guide, but if you install the Ethernet library (required for the official Ethernet shield) there's always:

Arduino IDE -> File -> Examples -> Ethernet -> WebServer

--
Jon
Ethernet shield with Power-over-Ethernet support and proto area: www.freetronics.com/ethernet-shield

tkbyd

Not quite what I was looking for, but if you are on a similar quest, the code at...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294035237

... might be of interest. Within that is sort of an "Hello world".

tkbyd

Hurrah!

Encouraged by the post I mentioned in the previous post, I looked a little further, and then found what I've been looking for for several years. Took the plunge, bought an ethernet shield (from Nuelectronics... $25, and very good service... but they are in the UK, which will be a factor for some readers)... and now have a webpage up running on $40 of hardware, including the Arduino dedicated to it.

Explained the way I'd hoped someone would explain it to me (Nuelectronics came close) at...

http://sheepdogguides.com/arduino/art5serv.htm

Go Up