Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Two ethernet client connections in one loop on: October 15, 2013, 05:49:08 pm
While it would have been interesting to see the results you get with the repaired crystal ball, here it is - in all its glory.

Code:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xAA, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 39 };
byte serverName[] = { 192, 168, 0, 105 };

EthernetClient client;

///////////////////////////
// THINGS TO ADD
//
// Trigger EventGhost via HTTP get request
// Lights on if dim, heating on if cold, fan on if hot?
//



//tmp36 storage
float temperatureC;

//ldr storage
int photocellPin = 1;     // the cell and 10K pulldown are connected to a0
int photocellReadingA;     // the analog reading from the analog resistor divider
int photocellReadingB;


void setup()
{
 
   pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
 
    Ethernet.begin(mac, ip);
   
     // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
   
    delay(1000);
    Serial.begin(9600);
}

void loop()
{
       //ethernet connect
        if(client.connect(serverName, 8033))
        {
       
       
         
         digitalWrite(5, HIGH);
 
         //LDR SENSOR
         
          photocellReadingA = analogRead(photocellPin); 
  Serial.print("LightA: ");
  Serial.println(photocellReadingA);     // the raw analog reading
       
        //let the sensor recover
        delay(1000);
       
         
         //TEMP SENSOR
         //getting the voltage reading from the temperature sensor
 int reading = analogRead(0); 
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 3.3;
 voltage /= 1024.0;
 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;
 Serial.print("Temp1: "); Serial.print(temperatureC); Serial.println(" C");
 
 if (temperatureC >= 22) {
   Serial.println("It's warm!");
 }
 else
 {
   Serial.println("It's cold!");
 }
 
   delay(1000);
   digitalWrite(5, LOW);
     
         //ethernet stuff
            Serial.println("Connected to server.");
            digitalWrite(6, HIGH);
            Serial.println("Writing to MySQL DB");
            client.print("GET /envmon/tempwrite.php?temp1=");
            client.print(temperatureC);
            client.print("&light1=");
            client.print(photocellReadingA);
            client.println(" HTTP/1.1");
            client.println("Host: localhost");
            client.println();
           
                      client.flush();         
                      client.stop();
   
            Serial.println("Server connection closed.");
   delay(2000);
   
          photocellReadingB = analogRead(photocellPin); 
          Serial.print("LightB: ");
          Serial.println(photocellReadingB);     // the raw analog reading
           
          Serial.print("Difference: "); 
          Serial.println(photocellReadingA - photocellReadingB);
           
         
          if ((photocellReadingA - photocellReadingB) <= 10) {
            Serial.println("Lighting indifferent.");
          }
 
          else if ((photocellReadingA - photocellReadingB) <= 100) {
            Serial.println("Sudden lighting change!");
       
         boolean suddendark = true;
          }
 

        else
        {
            Serial.println("connection failure");
        }
         client.flush();
         
           if(client.connect(serverName, 8033))
             
        {
            delay(1000);
            digitalWrite(6, LOW);
            delay(3000);
           
            //light switching test
            Serial.println("Doing lighting stuff!");
            //ethernet stuff
            Serial.println("connected for lights...");
            digitalWrite(6, HIGH);
            Serial.println("ARDUINO: forming HTTP request message");
            client.print("GET /envmon/EGAP.php?turnon=books1");
            //finish off the ethernet code
            client.println(" HTTP/1.1");
            client.println("Host: localhost");
            client.println();
           
                      client.flush();     
                   client.stop();   
           
        }
       
}}

2  Using Arduino / Networking, Protocols, and Devices / Two ethernet client connections in one loop on: October 15, 2013, 05:37:59 pm
I've got a couple of LDR's and a TMP36 happily sending data to a MySQL server running on my network using the ethernet shield. I have some PHP scripts which control my LightwaveRF WiFi module, in order to turn lights on and off.

I want to add an action to turn the lights on when an LDR is below a certain value, i.e. it's dark. Controlling the lights is also done via a client connection to the same server the SQL DB is running on. Testing a sketch with this on its own worked very well and created an impromptu disco mode which I may keep in.

Anyway, when I combine the MySQL sketch with the lighting control sketch, I get MySQL database updates, but I don't get any lighting control.

My question is, do I need to do anything special in order to 'visit' another web page in order to send another GET? Do I close the ethernet client connection from the mysql writing part, and then open another connection for the lighting control part? I've tried both and no joy. I've also tried it with the lighting control bit just at the end of the rest of the code, so without any conditions to trigger it - and still nothing. Try the lighting control sketch on its own again and it works fine. What am I missing? I haven't been able to find any examples of code where there are multiple connections to pages.

I can post the code, but I'll warn you - it's a mess.

Thanks for any help!
3  Topics / Home Automation and Networked Objects / UK Home Easy socket control with 433Mhz transmitter and PIR sensors on: September 25, 2013, 07:18:37 pm
I've finally managed to get the receiver example working, from the Arduino Home Easy hacking library (https://github.com/bruce33/homeeasyhacking/tree/master/Arduino) but now that I have the sender code I'm not sure how that helps me to control my remote sockets. I have the older style Home Easy sockets, where you set an ID using a rotary selector on the socket itself rather than 'learning' the socket with a remote. I am using trying to use the Home Easy PIR's to trigger things to happen, including then sending a signal to turn on a specific socket. The only code I've found  - as far as I can see - refers to the newer style sockets.

I can see a lot of posts about the Home Easy gear so it seems a lot of people have got it working, am I the only one with the old style sockets?

Cheers for any help!
4  Using Arduino / Networking, Protocols, and Devices / Detect if a device is present on the network via MAC address on: February 06, 2013, 02:39:46 pm
I've built a lighting controller, based on a Lightwave RF web module, an arduino uno and an ethernet shield. There are a number of sensors on the arduino, the data from which is logged via the ethernet shield on a mysql database running on a server. Depending on data from the sensors (i.e. light) the arduino sends UDP strings to the Lightwave RF module in order to turn lights on or off.

What I want to do now, is detect if my, or my girlfriends phone is on the network (by it auto-connecting to the wifi at home) and then turning on lights accordingly.

How could I achieve this? Setting static IP's on the phone is an option if that would be easier than detecting by MAC.

Any help would be greatly received!

Thanks in advance!  smiley-mr-green
5  Forum 2005-2010 (read only) / Exhibition / Re: First project: Laser tripped flash gun on: July 23, 2010, 02:56:28 pm
Did you say you powered the laser diode directly from the arduino? I've been looking some info on this for ages, as I like you haven't played with electronics for a good while and would very much like to build a trippy laser light show too! smiley
Pages: [1]