Show Posts
Pages: [1] 2
1  Topics / Home Automation and Networked Objects / Re: controlling servo motor over internet using erduino ethernet shield on: June 30, 2012, 10:44:56 am
Hi,

Are you hosting the web server on the Arduino itself? In such case you need to parse the data from the client (web browser). The web page buttons shall post some variables to the server, and the server shall parse the incoming data from the client and move the servos.

Check this http://www.instructables.com/id/ServDuino-Arduino-Webserver/

Also, the following code will probably work for you:
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString, servo1, servo2;

Servo myservo1; 


void setup(){

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
myservo1.attach(7);

}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

        //store characters to string
        readString += c;
        }

        //if HTTP request has ended
        if (c == '\n') {
          Serial.println(readString);

          //readString looks like "GET /?-1500 HTTP/1.1"

          if (readString.length() >0) {
              Serial.println(readString);
              servo1 = readString.substring(7, 11);
              Serial.println(servo1);
              int n1;
              char carray1[6];
              servo1.toCharArray(carray1, sizeof(carray1));
              n1 = atoi(carray1);
              myservo1.writeMicroseconds(n1);
              readString="";
            }
           client.stop();

           readString="";

          }
        }
      }
    }
}s
2  Topics / Home Automation and Networked Objects / Re: Using wireless sensors with your arduino on: June 13, 2012, 06:13:07 am
too difficult, you probably need to hack it and figure out what communication protocol it uses. Why don't you use a cheap IR sensor, interface it with Arduino and use whatever RF communication you like?
3  Topics / Home Automation and Networked Objects / Re: Send XML-File over HTTP-Request to Arduino board on: June 13, 2012, 06:09:36 am
Can't you just use POST from the library to read values? If you have to send the whole XML then, most likely you need to get it through POST and parse it manually in your code!
4  Topics / Home Automation and Networked Objects / Re: Arduino + Wifly RN-XV + Processing on: June 01, 2012, 07:14:35 am
Sorry, previous post contains server code for the WiFly, but you need the Client code to connect to the Processing sketch (which is creating a server).

Code:

#include "WiFly.h"
#include "Credentials.h"

byte server[] = { 192,168,1,1 }; // Your PC IP

Client client(server, 1234);


void setup() {
 
  Serial.begin(9600);

  WiFly.begin();
 
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  } 

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("Hello World!\n");
    client.println();
  } else {
    Serial.println("connection failed");
  }
 
}

void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  while (Serial.available() > 0) {
          char inChar = Serial.read();
            if (client.connected()) {
              client.print(inChar);
            }
    }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}


5  Using Arduino / Networking, Protocols, and Devices / Re: SoftwareSerial What did I do wrong? on: May 29, 2012, 03:16:37 am
How about some debugging using the Serial Monitor? Since your default Rx/Tx ports are free, print whatever comes from the ZigBee sender to make sure you got the characters arriving properly!
6  Topics / Home Automation and Networked Objects / Re: Arduino and PHP on: May 28, 2012, 04:12:25 am
Hi,

are you trying to just store values from the Arduino on MySQL or send values to the Arduino from the html page as well?

If it is only the first care, all you need is the php script that will receive values directly from the Arduino. It is more easy to use GET instead of POST, so here is your php code slightly modified:

Code:
<?php
$con 
mysql_connect("my_webhost","username","password");
if (!
$con)
   {
   die(
'could not connect: ' .mysql_error());
   }
   
mysql_select_db("my_database"$con);

$sql="INSERT INTO Automation (arduino,pin2,pin3,pin4,pin5,pin6)
VALUES ('
$_GET[arduino]','$_GET[pin2]','$_GET[pin3]','$_GET[pin4]','$_GET[pin5]','$_GET[pin6]')";

if (!
mysql_query($sql,$con))
   {
   die(
'Error: ' mysql_error());
   }
echo 
"1 record added";

mysql_close($con);
?>



Here is an Arduino sketch that connects to the php script and sends pin2, pin3, ...variables through POST:
Code:

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,1,1); // YOUR SERVER'S IP ADDRESS

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;


int pin2, pin3, pin4, pin5, pin6;

//String representations of the pin values
String spin2, spin3, spin4, spin5, spin6;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
 
}

void loop()
{
 
  //read pin values:
  pin2 = analogRead(0);
  //...
 
  spin2 = String(pin2, DEC);
 
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /arduinoInsert.php?arduino=arduino&pin2="+spin2+"&pin3="+spin3+"&pin4="+spin4+"&pin5="+spin5+"&pin6="+spin6+" HTTP/1.0");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
 

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}


7  Topics / Home Automation and Networked Objects / Re: Help with SMS controlling the relay shield on: May 28, 2012, 03:41:47 am
Sure smiley-wink
8  Topics / Science and Measurement / Re: urgent! build pulse oximeter using arduino.. on: May 28, 2012, 03:38:38 am
Hi,

I have built this http://blog.buildinginternetofthings.com/2012/05/13/my-heart-rate-on-the-cosm-cloud/ based on a product by seeedstudio, but I am sure you can find similar code for your project in http://pulsesensor.myshopify.com/pages/code-and-guide
9  Using Arduino / Networking, Protocols, and Devices / Re: Interfacing multiple Arduinos on: May 28, 2012, 03:34:45 am
I would go with an Ethernet over Power solution (if putting Eth cables all around is an issue), ethernet shields, and use a simple web server on the PC (or a pluggable pc solution) with a REST interface for receiving and sending data to the Arduinos
10  Topics / Home Automation and Networked Objects / Re: Arduino + Wifly RN-XV + Processing on: May 22, 2012, 05:48:27 am
Hi,

You have misplaced some of the code in your sketch, check the following code. Have not tested if it runs properly but I least it compiles smiley

Code:
#include "WiFly.h"
#include "Credentials.h"

Server server(80);

void setup() {
  // start the WiFly connection:
  WiFly.begin();
 
  if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      // Hang on failure.
    }
  }

  Serial.begin(9600);
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
 
  server.begin();

  // give the WiFly shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
 
  //------rest shall be implemented inside loop()
 
  // if you get a connection, report back via serial:
  //if (client.connect(server, 1234)) {
  // 
  //  Serial.println("connected");
  //}
  //else {
  //  // if you didn't get a connection to the server:
  //  Serial.println("connection failed");
  //}
}

void loop() {
  Client client = server.available();
 
  //If client has been instantiated
  if (client) {
    //check for client connection
    while (client.connected()) {
      //if client has connected
      if (client.available()) {
        //The following code will simply send characters for Terminal input to the server - use it as a test
        while (Serial.available() > 0) {
          char inChar = Serial.read();
            if (client.connected()) {
              client.print(inChar);
            }
        }
      }
    }
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}
11  Topics / Home Automation and Networked Objects / Re: Help with SMS controlling the relay shield on: May 16, 2012, 04:19:54 am
What are the problems you are facing? building the circuit? programming it?

I have made a similar project that activates a relay by SMS but using an Android phone instead, it is one of my projects listed here http://www.buildinginternetofthings.com/list-of-projects/
12  Topics / Home Automation and Networked Objects / Monitoring my pulse rate over the web on: May 14, 2012, 01:16:22 pm
Hello,

I'd like to share my arduino-based (clone-based actually) project that logs my pulse rate on cosm (former pachube) https://cosm.com/feeds/59362. Full project details and code here:
http://blog.buildinginternetofthings.com/2012/05/13/my-heart-rate-on-the-cosm-cloud/
13  Topics / Home Automation and Networked Objects / Re: Arduino + Wifly RN-XV + Processing on: May 07, 2012, 10:11:40 am
I suggest you implement your own server in Processing and talk to it through the Arduino

check the following code:
Code:

import processing.net.*;
Server myServer;

void setup() {
  size(200, 200);
  // Starts a myServer on port 1234, change this to whatever suits you!
  myServer = new Server(this, 1234);
}

void draw() {
  // Get the next available client
  Client thisClient = myServer.available();
  // write the output of the client
  if (thisClient !=null) {
    String whatClientSaid = thisClient.readString();
    if (whatClientSaid != null) {
      println(thisClient.ip() + "t" + whatClientSaid);
    }
  }
}


and the Arduino code (for Ethernet example, easy to adopt):
Code:

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Enter the IP address of the server you're connecting to:
IPAddress server(192,168,1,1);

// Initialize the Ethernet client library
// with the IP address and port of the server
EthernetClient client;

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  // start the serial library:
  Serial.begin(9600);
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 1234)) {
    Serial.println("connected");
  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
 
  //The following code will simply send characters for Terminal input to the server - use it as a test
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}

14  Community / Products and Services / Re: Building Internet of Things with the Arduino on: March 29, 2012, 02:22:48 am
You can also check the ToC with the Amazon "Look inside" feature:

www.amzn.com/1470023431
15  Community / Products and Services / Re: Looking for beta testers on: March 27, 2012, 01:37:58 am
Hello Joe,

nice initiative and concept, I am sure you are also aware of http://labs.ideo.com/2012/03/15/arduino-tool-that-connects-each-board-to-its-own-source/.

Is there any beta release data available?

Best,
Charalampos
Pages: [1] 2