Yayyyyyyy

http://myarduino.info

I decided to take the plunge and spending a whopping $2.95 (Sale on for .info domains right now ) for a .info domain and point it at my little Arduino :slight_smile:

So the lights are off, I gather?

great job :slight_smile: nice to see this working. how does it see if the lights are off? since that's quite strange i think ö

lol it's a cree 3 watt LED (with a power transistor, it does a nice job, but not quite as bright as your 11 watt fluro, but it's close enough), i use +/- from a spare USB port (if the PSU dies or power goes out) that will show 240volts off.

since my PSU is on 24/7, (even when the computer's "off" power still goes out to the arduino and the rest of the attached USB devices.)

  • So yeah not much (yet) going on so I thought i'd give it it's own URL :slight_smile:

could you post the code? i'm interested in how you set up the html formatting :slight_smile:

And make a button that beeps if we press it. Then you'll know how many people are reading your post. :wink:

that's the setup (the computer next to it and router, kinda handy lol)

There's an Arduino Duemonova (can't spell it, i'm not Italian) at the front of the table, and at the back is an Etherten unit.

Works identical to the ethernet shield, same wiznet, same pins used etc.

#include <Wire.h>
//#include <Adafruit_BMP085.h>
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <utility/w5100.h>

#define SBLEDPin 8
#define ComputerPowerPin 9
#define USBPowerPin 5


// The IP address will be dependent on your local network:
byte mac[] = {  0x0C, 0x00, 0x0C, 0xE, 0xA, 0xB };
byte ip[] = { 192,168,1, 253 };
byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask


byte thismsg;
boolean gotAMessage = false; 
EthernetServer server(80);
SoftwareSerial mySerial(6, 7);
//Adafruit_BMP085 bmp;
float p,oldp;
long days=0;
long hours=0;
long mins=0;
long secs=0;
long currentmillis=0;
int visitors = 0;
int sensorvalue;
boolean ledon;
boolean Dimmer;
boolean override;


void setup()
{  
//  bmp.begin();
  Ethernet.begin(mac, ip, gateway, subnet);
  Ethernet.gatewayIP();
  server.begin(); //,gateway,subnet);
  Serial.begin(9600);
  override=false;
  server.begin();
  mySerial.begin(9600);
//  pinMode(ledPinB, OUTPUT);
//  pinMode(ledPinG, OUTPUT);
//  pinMode(ledPinR, OUTPUT);
//  pinMode(SpeakerPin, OUTPUT);
 pinMode(SBLEDPin, OUTPUT);
 pinMode(ComputerPowerPin, OUTPUT);
  pinMode(USBPowerPin, INPUT);
}



void loop()
{

  char c;
  int buttonState;
  currentmillis= millis();
  secs = currentmillis/1000; //convect milliseconds to seconds
  mins=secs/60; //convert seconds to minutes
  hours=mins/60; //convert minutes to hours
  days=hours/24; //convert hours to days
  secs=secs-(mins*60); //subtract the coverted seconds to minutes in order to display 59 secs max
  mins=mins-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
  hours=hours-(days*24); //subtract the coverted hours to days in order to display 23 hours max
  //Display results
 
 buttonState = digitalRead(USBPowerPin);
 if (buttonState == LOW) {     
   delay(1);
   if ((override==false) && (ledon==false))
    {
      digitalWrite(SBLEDPin, HIGH);  
      ledon=true;
    }
  }
  
 

  
//   sensorvalue = analogRead(sensorpin);    
//Serial.print("Sensor Voltage Reading: ");
//    Serial.println(sensorvalue,DEC);
//    delay(150); 

  //if (pressure!=0) delay(1);

   EthernetClient client = server.available();
  
  // when the client sends the first byte, say hello:
  if (client) 
  {
    if (!gotAMessage) 
    {
        char crrip[16];
        byte rip[4];
        int bcount;
        //client.
        visitors++;
        client.getRemoteIP(rip); // where rip is defined as byte rip[] = {0,0,0,0 };     
        sprintf(crrip, "%d.%d.%d.%d", (unsigned char)rip[0], (unsigned char)rip[1], (unsigned char)rip[2], (unsigned char)rip[3]);

    //    client.getRemoteIPAddress(rip);
//        client.write('a',1);
        //    char c = client.read();     
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println();
        client.print("Welcome ");
        client.println(crrip);
        client.println("
");
        client.println("Hello from my <u><b><i>Arduino!</u></b></i>
");
        client.print("Main Power: ");
          if (buttonState == LOW) 
          client.println("<B><I>Main 240 volts OFF</B></I>
");
         if (buttonState == HIGH)
           client.println("Main 240 volts OK
");
        
          client.println("Bedroom Lighting: <B><I>");
          if (ledon==true) 
            client.println("ON!");
             else
            client.println("OFF!"); 
         client.println("</B></I>
");
   
        client.println("Local IP: http://192.168.1.253:1234/WAN IP: http://110.175.97.110:1234 
");

        client.print("Hello Visitor Number: <b>");
        client.println(visitors);
        client.println("
");
        oldp = p;
     if (days>0) // days will displayed only if value is greater than zero
      {
       client.print(days);
       client.print(" days and :");
      }
      client.print(hours);
     client.print("h:");
     client.print(mins);
     client.print("m:");
     client.print(secs);
     client.print("s
 

 - Written By Craig C. (2012)");

         
        //   if (c=='Q') client.stop();
  //      delay(250);
        client.flush();
        client.stop(); 
  //      delay(150);
        //   CheckChar(c);
      }
  }





  if (mySerial.available()) 
  {
    c = (char)mySerial.read();
//    mySerial.print(c);
    CheckChar(c);
    if (c=='v') {
      mySerial.println("Voltage Status: ");
      if (buttonState == HIGH)  mySerial.println("OK");
      if (buttonState == LOW)  mySerial.println("Power OUT!");
    }
  }


}

void uptime()
{
  mySerial.println("Running Time");
  mySerial.println("------------");
    if (days>0) // days will displayed only if value is greater than zero
  {
    mySerial.print(days);
    mySerial.print(" days and :");
  }
  mySerial.print(hours);
  mySerial.print(":");
  mySerial.print(mins);
  mySerial.print(":");
  mySerial.println(secs);
}
//############################################ UPTIME ^^^^  #################################
 


void ToggleLED() {
// digitalWrite(SBLEDPin,HIGH); 
// digitalWrite(SBLEDPin,LOW); 
  
}


void CheckChar(char c) {

// if (c=='t') mySerial.println(bmp.readTemperature());
// if (c=='b') mySerial.println(bmp.readPressure());
// if (c=='a') mySerial.println(bmp.readAltitude());    
  
 if (c=='h') {
    mySerial.println("Help");    
    mySerial.println("p = power button (quick) P = Power Button Long");
    mySerial.println("L = Light On l = Light Off");
    mySerial.println("s = LED Light Status");
    mySerial.println("v = Home Voltage Status (on/off) O(Overide)");    
    mySerial.println("u = Uptime");    
//    mySerial.println("b = barometer pressure t = Temprature a = Altitude");
 }

if (c=='s') {
  mySerial.print("The LED light is: ");
  if (ledon==true) 
     mySerial.println("ON");

  if (ledon==false) 
     mySerial.println("OFF");    
  
}

  if (c=='L') { 
    digitalWrite(SBLEDPin,HIGH); 
    ledon=true;
//   int fade;
 //  for (fade=1; fade++; fade>=1023);
  //  {
   // analogWrite(ASBLEDPin,fade);
   // delay(40);
  //  }
  } 

  if (c=='o') {
    mySerial.print("Override Status: ");
    if (override==false) 
    {
       mySerial.println("ON");
       digitalWrite(SBLEDPin,LOW); 
       override=true;
       ledon=false;
       return;
    }
    
    
    if (override==true) 
    {
      mySerial.println("OFF");        
      digitalWrite(SBLEDPin,HIGH); 
      override=false;
      ledon=true;
      return;
    }
    
  } 
    


  if (c=='l') { 
  //  analogWrite(ASBLEDPin,0); 
   digitalWrite(SBLEDPin,LOW); 
   ledon=false;
  
  } 

  if (c=='u') 
   {
    uptime(); 
   }

  if (c=='p') { 
    digitalWrite(ComputerPowerPin,HIGH); 
    delay(50);
    digitalWrite(ComputerPowerPin,LOW);
  } 
  if (c=='P') {
    digitalWrite(ComputerPowerPin,HIGH); 
    delay(5000);
    digitalWrite(ComputerPowerPin,LOW);
  } 
}

There's also bluetooth code there to switch the cree LED on/off.

be nice with me over the code (please :P), i only started learning C++ a few weeks ago :stuck_out_tongue:

Duemonova (can't spell it, i'm not Italian)

Duemilanove (CAN SPELL it and im not Italian ]:smiley: :P)

looks good, but there one thing i don't understand, it seems there some indentation-based language in it (no C/C+) because you do

if (statement)
    ...
   else
   ...

is that specified for the serverpart of the board? looks nice :slight_smile: i didn't think it was as simple as just printing "Hello from my Arduino!
" xp

can't you use modulus to convert milis to hours/mins/seconds? that's like 10.000 times easier, and it looks cleaner :slight_smile:
just do this:

Hours = Milliseconds / (1000*60*60)
Minutes = (Milliseconds % (1000*60*60)) / (1000*60)
Seconds = ((Milliseconds % (1000*60*60)) % (1000*60)) / 1000

But i'm not sure modulus works on the arduino, but i think it should..i hope so

I'm still learning the language myself after coming from a pascal background so i'm coding the way i would in pascal and adjust it.. Ill fine tune the code and clean it up right now im having too much fun :stuck_out_tongue:

yep a small beep, i might even add a html button so people can buzz me at 5am in the morning.. on second thoughts :stuck_out_tongue:

Due - What bills are.
milan - Italian City
ove - O-V-E

easy........

easy when you're not typing on a phone and can look it up :stuck_out_tongue:

Due - What bills are.
milan - Italian City
ove - O-V-E

easy........

The Easiest is to say "2009" like "I have a Arduino 2009"

ok mr spelling police (geez)