Introduction: Real-time Web Control for Light Decorations (no Server Side Coding)

Picture of Real-time Web Control for Light Decorations (no Server Side Coding)

Arduino Ethernet is an awesome device. This is how to operate your festive seasonal lights from wherever you want:
-by a simple click on your web-page (a few lines of HTML, no javascript, or any other coding is required);
-by entering a simple "http://..." line into any browser on any device like a phone, a computer, or a tablet
-from any other internet enabled device such as another Arduino Ethernet.

Step 1: Gathering Details and Preparation

Picture of Gathering Details and Preparation

The solution utilises a cloud-based real time web publishing tool Partcl.com  that allows you to publish any data with about 0.1 second latency.
First you will need:

Arduino Ethernet (which is in fact is Arduino + Ethernet Shield)
-   NPN transistor, like BC548
- 5.6 kOhm resistor
- wires
- ethernet cable
-power adaptor for Arduino
- Free account on Partcl.com (when registered you will get your publishing and web keys which you will put into Arduino code and in http code on your website)
- seasonal lights themselves (I used what I had, small 100mA chain of leds) - you may need to add an additional resistor for different "led architecture", or even use a relay to power some major decoration )) - up to you.
As a holder for LEDs I used something that was called "Tree" in a  shop. I thought it would look cool. 

Step 2: Soldering It All Together

Picture of Soldering It All Together

You can use a board or just solder the wires together like I did.
Then pack it all in a project box. I placed the transistor outside to cool it down a bit and to prevent the box from overheating.

Step 3: Register on Partcl.com

Picture of Register on Partcl.com

Register an account on Partcl.com.
After registration you will get a publishing key and a web key.  You will need them for the next steps.

Step 4: Upload the Arduino Code

Picture of Upload the Arduino Code

Upload the Arduino code (you need to upgrade your IDE to the latest version 1.0)
Do not forget to Input Mac address of your board into the code
Also substitute the phrase "ENTER_YOUR_WEB_KEY_HERE" by your actual WEB_KEY from your partcl.com account.


--------------------------------------------------------------
The code
--------------------------------------------------------------

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

byte mac[] = {  0x??, 0x??, 0x??, 0x??, 0x??, 0x?? };
char serverName[] = "www.partcl.com";

EthernetClient client;
const int ledPin =  8;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
 
 
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    while(true);
  }
  delay(1000);
  Serial.println("connecting...");
}

void loop()
{
  char statusrec;
  char prevstatus;
  boolean iscon=false;
        for (int i = 0; i < 10; i++){
          boolean clcon=client.connect(serverName, 80);
          if (clcon) {
           iscon=true;
            i=10;
          } else {
            Serial.println("  connection failed");
          }
        }     
    if (iscon){   
        client.print("GET /index/tag?tag=alarm&web_key=ENTER_YOUR_WEB_KEY_HEREHTTP/1.1\nHost: partcl.com\nUser-Agent: Arduino For Teh Win!\nAccept: text/html\nConnection: close\n");
        client.println();              
for (int cc=1; cc<10000; cc++){
  if (client.available()) {
    char c = client.read();
     if (c=='$') {
     c = client.read();
     if (c=='$') {
          c = client.read();
      Serial.print(c);
              if(c=='1') {digitalWrite(ledPin, HIGH);}
              if(c=='0') {digitalWrite(ledPin, LOW);}
      }
   }
  }
  if (!client.connected()) {cc=10000;}
}
  client.stop();
}
}


---------------------------------------------------------------
------------------- unnecessary information ---------
The code below is actually inquiring partcl.com by GET requests and parses responses into commands. So when you send a request to partcl.com with your key, it sends the command to arduino.
You can substitute the word "alarm" in "tag=alarm" in the GET request by any other - just remember to do the same later on your web page in your http requests.

Step 5: Control Your LEDs

Picture of Control Your LEDs

Create the following html page:
(DO NOT FORGET to substitute "ENTER_YOUR_WEB_KEY_HERE" and "ENTER_YOUR_PUBLISHING_KEY_HERE" with a real WEB and PUBLISHING KEYs from your partcl.com home page)

-----------------------------------------------------------

<!DOCTYPE html>
<html>
    <head>
        <script id="partcl_client_script" web_key="ENTER_YOUR_WEB_KEY_HERE" publish_key="ENTER_YOR_PUBLISHING_KEY_HERE" src="http://partcl.com/partcl.full.js"></script>
    </head>
    <body>
<p><button onclick="partcl.publish('alarm','$$0')">off</button> <button onclick="partcl.publish('alarm','$$1')">on</button></p>
    </body>
</html>

-----------------------------------------------------------
Please be aware that the publishing key will be visible to anyone who examines souse of your pages. If you are concerned about this,  it is better to open a separate partcl account for this project to make this publish key different from the keys in your other projects.
Also, in partcl.com, navigate to "My sites" on the right menu and disable Partcl on new sites. Keep the tick on your site though )
Or you can keep the page private if you want.

-----------------------------------------------------------
Alternatively, instead of creating the page, you may open any web browser on any device and enter the following:
(to turn the LED on):  http://partcl.com/publish?publish_key=ENTER_YOR_PUBLISHING_KEY_HERE&id=alarm&value=$$1
(to turn it off):  http://partcl.com/publish?publish_key=ENTER_YOR_PUBLISHING_KEY_HERE&id=alarm&value=$$0

---------------------------------------------------------
I will be happy to guide you through a process to control your lights from a Wordpress blog or from another Arduino Ethernet.

Enjoy!

Comments

Mape9800 (author)2012-11-26

I can not get this project to work!

When I debugg the Arduino code I found that the if statment below never get true becouse 'c' never contains the character '$'.

c = client.read ();
if (c == '$') {
c = client.read ();
...
...

If I log what 'c' contains I will get some html code.

What is wrong?
Have partcl changed anything since you made this tutorial?

Computothought (author)2011-12-20

Cool. Do the same thing with old pc;s all the time.