Pages: [1] 2   Go Down
Author Topic: Yayyyyyyy  (Read 1793 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley




http://www.dynonames.com/
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18819
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So the lights are off, I gather?
Logged


Belgium
Offline Offline
Full Member
***
Karma: 0
Posts: 187
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Belgium
Offline Offline
Full Member
***
Karma: 0
Posts: 187
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18819
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



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. 

http://www.freetronics.com/collections/all-products/products/etherten

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

Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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("<br>");
        client.println("Hello from my <u><b><i>Arduino!</u></b></i><br>");
        client.print("Main Power: ");
          if (buttonState == LOW)
          client.println("<B><I>Main 240 volts OFF</B></I><BR>");
         if (buttonState == HIGH)
           client.println("Main 240 volts OK<BR>");
       
          client.println("Bedroom Lighting: <B><I>");
          if (ledon==true)
            client.println("ON!");
             else
            client.println("OFF!");
         client.println("</B></I><BR>");
   
        client.println("Local IP: http://192.168.1.253:1234/WAN IP: http://110.175.97.110:1234 <br>");

        client.print("Hello Visitor Number: <b>");
        client.println(visitors);
        client.println("<br>");
        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<br> <BR><BR> - 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.
Logged

Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

be nice with me over the code (please smiley-razz), i only started learning C++ a few weeks ago smiley-razz
Logged

ਪੰਜਾਬ
Offline Offline
Edison Member
*
Karma: 12
Posts: 1601
Another year! Alone! :(
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Duemilanove (CAN SPELL it and im not Italian  smiley-twist smiley-razz)
Logged

"Real Men can Accomplish  Anything"
-  Website  
- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੂਂ !

Belgium
Offline Offline
Full Member
***
Karma: 0
Posts: 187
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
if (statement)
    ...
   else
   ...

is that specified for the serverpart of the board? looks nice smiley i didn't think it was as simple as just printing "Hello from my <u><b><i>Arduino!</u></b></i><br>" xp

can't you use modulus to convert milis to hours/mins/seconds? that's like 10.000 times easier, and it looks cleaner smiley
just do this:
Code:
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
Logged


Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :p
Logged

Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

easy........
Logged


Offline Offline
Edison Member
*
Karma: 29
Posts: 2457
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

easy when you're not typing on a phone and can look it up smiley-razz
Logged

Pages: [1] 2   Go Up
Jump to: