Pages: 1 [2] 3 4 5   Go Down
Author Topic: home automation with arduino and android  (Read 54796 times)
0 Members and 2 Guests are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for this great idea!
Can you share android code please?
Regards,
eZar.
« Last Edit: September 25, 2010, 03:08:11 pm by ezar » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any chance of getting your entire sketch? I have an app inventor program that I would like to use but need to program my arduino correctly to recognize web commands and I think this would work.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok guys enjoy:
http://github.com/bl4d3/DomoticHome
it's my first time on github, hope all work fine, if someone will find bugs (nad I think there are on it) or needs some customizations let me know, of course, forking the project is welcome!
Logged

France
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey, i like your project smiley

I have downloaded the android app, but can we have the .pde sktech ? I don't know how to send the JSON reponse with my Arduino
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can find an example at the first page of this thread smiley
Logged

France
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah ! Sorry, i had not seen smiley

Thanks, and sorry for my english, i'm french .

And good work for this ^^
Logged

France
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mhh, I have an error line 45 when I try to compile :

In function 'void loop()':
erreur: 'class String' has no member named 'append'


Do you know why ?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that sketch was for Arduino2009 and maybe you have an Arduino one, Am i wrong?
By the way i wrote a quick example that show how to activate/deactivate a digital out.
To activate the pin you have to make this http call
http://yourip/?out=5&status=1
to deactivate
http://yourip/?out=5&status=0
to get the list of the pins used by arduino
http://yourip/?out=all
last one is used to sync arduino with the domotichome app

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

// define actions
#define action_none -1
#define action_out_all 0
#define action_mypin_up 1
#define action_mypin_down 2

// define network config
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBE }; //physical mac address
byte ip[] = { 192, 168, 1, 20 };                  // ip in lan -> cambialo pure
byte gateway[] = { 192, 168, 1, 1 };                  // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask
Server server(80);                                      //server port
String readString = String(30); //string for fetching data from address

// arduino out
int pinOutRelay = 5;

// incoming GET command  
String r_pinOutRelay_down = "GET /?out=5&status=0 HTTP/1.1";
String r_pinOutRelay_up = "GET /?out=5&status=1 HTTP/1.1";
String r_out_all = "GET /?out=all HTTP/1.1";

// current action
int current_action;

void setup(){
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  
  pinMode(pinOutRelay, OUTPUT);    
  digitalWrite(pinOutRelay, LOW);
  //enable serial datada print  
  Serial.begin(9600);
  current_action = -1;
}
void loop(){
  current_action = -1;
  // Create a client connection
  Client client = server.available();
    if (client) {
      while (client.connected()) {
       if (client.available()) {
        char c = client.read();
        //read char by char HTTP request
        if (readString.length() < 30)
        {
          //store characters to string
          readString = readString + c;
        }  
        //output chars to serial port
        //Serial.print(c);
        //if HTTP request has ended
        if (c == '\n') {
      
         Serial.print(readString);
         // ****************************************************
          if(readString.startsWith(r_pinOutRelay_up))
          {
          Serial.print("\n HIGH\n");
          current_action = action_mypin_up;
          }
          else if(readString.startsWith(r_pinOutRelay_down))
          {
           Serial.print("\n LOW\n");
           current_action = action_mypin_down;              
          }
          else if(readString.startsWith(r_out_all))
          {
            Serial.print("\n ALL\n");
            current_action = action_out_all;
          }
          else
          {
            Serial.print("\n None \n");  
            current_action = action_none;
          }
         // ****************************************************  
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
         char buf[12];              
         switch(current_action)
         {
         case action_out_all:
           client.print("{\"ip\" : \"192.168.10.20\", \"devices\" : [{ \"type\" : \"gate\", \"name\" : \"caldaia\", \"out\" : \"");          
           client.print(pinOutRelay);
           client.print("\"}");            
           client.print("]}");                      
           break;
         case action_mypin_down:
           digitalWrite(pinOutRelay, LOW);
           client.print("{\"status\" : \"low\" , \"out\" : \"");
           client.print(pinOutRelay);
           client.print("\"}");                          
           break;          
         case action_mypin_up:
           digitalWrite(pinOutRelay, HIGH);
           client.print("{\"status\" : \"high\" , \"out\" : \"");
           client.print(pinOutRelay);
           client.print("\"}");                
           break;
         default:
           current_action = action_none;        
         }
        

         // ****************************************************            
        
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
        }
      }
    }
  }
}    

Logged

France
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank for reply,
I have the Arduno Duemilanove, and i've try your example, and is work fine with my Desire smiley

The error was because I have the Arduino0017 instead of Arduino0021
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm really glad to hear that!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey I've toyed a little with this stuff now but I can only turn thing´s on and not off again Can anyone help me?

it is as if the app on the fon do not know the code:? out = 5 & status = 0
what can it be?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change gate to light in the code.... yess, I was crazy too  ;D
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes you are right, a short list of the type available:

plug
light
door
gate
temperature
humidity
wattmeter
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello bl4d3, I have a question:

How I do to read from analog 0 and from digital otput 0??

String r_pinOutRelay_up_0 = "GET /?out=0&status=1 HTTP/1.1";
String r_pinAnalog0 = "GET /?out=0&status=1 HTTP/1.1";

?¿? Thanks!!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice shot smiley i know this limitation and right now I can't implement a solution for it (no time), I can suggest you to send

out=10&status=1

to refer at analogic pin 0 and strip out the first char if the out paramenter is composed by 2 char, I know it's a workaround and I have to fix it on android side.

Thank you!
Logged

Pages: 1 [2] 3 4 5   Go Up
Jump to: