of course, some basic programming skills are needed to better understand it, let me know!
Hi there, with this sample you should be able to turn on/off a light, i'm posting this beacuse an user of this forum asked me how to make it and i thought it was nice sharing this with all the people.
#include <SPI.h>
#include <Ethernet.h>
#define action_none -1
#define action_out_all 0
#define action_on_light 1
#define action_off_light 2
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBE }; //physical mac address
byte ip[] = { 192, 168, 1, 16 }; // ip address
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 pinOutPlight = 4;
// incoming GET command
String r_pinOnLight = "GET /?out=4&status=1";
String r_pinOffLight = "GET /?out=4&status=0";
String r_out_all = "GET /?out=all";
// current action
int current_action;
void setup(){
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
delay(1000);
pinMode(pinOutPlight, OUTPUT);
digitalWrite(pinOutPlight, 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_pinOnLight))
{
Serial.print("\n ON UP \n");
current_action = action_on_light;
}
else if(readString.startsWith(r_pinOffLight))
{
Serial.print("\n OFF UP \n");
current_action = action_off_light;
}
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.16\", \"devices\" : [{ \"type\" : \"light\", \"name\" : \"your name\", \"out\" : \"");
client.print(pinOutPlight);
client.print("\"}");
client.print("]}");
break;
case action_on_light:
digitalWrite(pinOutPlight, HIGH);
client.print("{\"status\" : \"1\" , \"out\" : \"");
client.print(pinOutPlight);
client.print("\"}");
break;
case action_off_light:
digitalWrite(pinOutPlight, LOW);
client.print("{\"status\" : \"0\" , \"out\" : \"");
client.print(pinOutPlight);
client.print("\"}");
break;
default:
current_action = action_none;
}
// ****************************************************
//clearing string for next read
readString="";
//stopping client
client.stop();
}
}
}
}
}
you have to change your ip in the sketch. It's just a demo, any improvement are welcome.
If someone has downloaded my app and played a bit with arduino and this stuff you should vote my project on MAKE
Thanks!
This post started out with the premise that other home automation systems are too expensive. Aren't X10 systems pretty cheap ($99 for controller and software)?
One issue with X10 is that they require a computer with X10 controller on 24/7. The computer provides a web interface and can turn devices on/off at scheduled times. For example, you may want to switch an outside light on automatically at 7 PM every day.
Have you given any thought to a server solution, i.e. leaving an android device at home and on 24/7 that can be connected to remotely?
Hello!
I try to get this to work with the 28J60 Ethernet Shield.
But i get error in the android APP "An error has accoured, check your internet connection. Is Arduino Alive?"
It all works, i get "my item" and i can controll the arduino output from the app.
The only problem seems to be with the JSON from the arduino to the android app. When i test in my web browser its look like this:
//arduinoIP/?out=5&status=0
-> {"status" : "0" , "out" : "5"}
//arduinoIP/?out=5&status=1
-> {"status" : "1" , "out" : "5"}
What can be wrong?
if (strcmp(params, "?out=all") == 0)
{
e.print("{\"ip\" : \"192.168.0.15\", \"devices\" : [{ \"type\" : \"plug\", \"name\" : \"LAMPA\", \"out\" : \"");
e.print("5\"}");
e.print("]}");
e.respond();
Serial.println("OUTALL!!");
}
if (strcmp(params, "?out=5&status=0") == 0)
{
digitalWrite(pinOutRelay, LOW);
Serial.println("OUT LOW!!");
e.print("{\"status\" : \"0\" , \"out\" : \"");
e.print("5\"}");
e.respond();
Serial.println("LOW!!");
}
if (strcmp(params, "?out=5&status=1") == 0)
{
digitalWrite(pinOutRelay, HIGH);
Serial.println("OUT HIGH!!");
e.print("{\"status\" : \"1\" , \"out\" : \"");
e.print("5\"}");
e.respond();
Serial.println("HIGH!!");
}
Edit: I found the error ![]()
I had a old DomoticHome APP installed . It work perfect with the app from market.
Can we also make an automated 'assisstant robot'? I need it to complete my homework ![]()
I think it can be used for this too, if you use as "type" something like "plug" or "light" you'll have 2buttons (on/off). let me know
I had lot of mail last months, all with the same question: "how can i write the code for arduino?" down here the answer ![]()
Just deployed a web app to generate automatically the code for arduino
http://domotichome.heroku.com/masters
it's in beta, please don't link it in other site because it will be moved from there.
Hope it will be helpful!
Please report bugs.
This is some fantastic stuff that you're doing and I really hope you continue to develop it.
I had a bit of trouble with the code that your creator made. It didn't seem to work, I couldn't get my Android to sync.
When I used that simpler light one that you posted on the 2nd or 3rd page that worked well. At least, I could switch the light on but not off.
The Android app is a little buggy and needs some work but it's a solid start. I've had a little bit of experience with electronics, I'm an avid Arduino user and a beginner with the programming. Keep up the good work, this will be a great project to follow.
Thanks.
@Arduino-Idea you are totally right i just fixed some stuff, try again please you can see what it's generated by the sync command typing in your browser
http://yourip/?out=all
let me know
Hi there, thanks for that.
I have tested it again and your code generator seems to work for me now.
I am using a Nexus One over 3G and can sync your app with my Arduino which listed the test LED for me.
The only issue I'm having is that when I try and use the lock or unlock buttons (LED on/off I'm assuming), I get an error saying:
"An error has occurred, check your internet connection. Is Arduino alive?"
(nothing appears in the serial monitor)
I can create an action using the LED which allows me to switch the LED on successfully but I can't see anyway to turn it off. The following appears in the serial monitor each time I press the action button in the app.
GET /?out=5&status=1 HTTP/1.1
5 HIGH
I have confirmed that everything is working by using the URL's to switch the LED on and off through my browser both locally on my PC and also over 3G on the phone browser.
I can see so much potential with this project, thank you so much for sharing it and spending so much time on it.
I'm getting confused
@Arduino-Idea thanks for testing it, i'll check the code generation for type "light", maybe the problem is in the android app, need to test. Stay tuned
@Divyanshu it's normal ![]()
Thanks mate, I'm happy to test apk's etc for you if need be. Keep up the good work!
@Divyanshu - you are not alone mate, I am often banging my head against the wall but I learn tiny bit each day which keeps me going!
I added the support for:
- temperature sensor MCP9700A
- CT sensor using the code of open energy monitor guys
bb
Hello bl4d3,
at first let me say: Its a great job what you have done! I am watching for a few month to this side and now i am really lucky to see, that you still developing this cool system ![]()
The new function to generate the arduino code is very good and easy. I tried it and it works (right now, only in the browser).
Now i have two questions:
What do you think, how secure is this system when i integrate some arduinos with the code to my house and control them via my phone trough the internet (connect them to my route with dyndns)? Is it possible and good to add a function like &key=xyzXYZ or something like that?
The second question is, what does the checkbox "Send data to remote server?" do (in the arduino-code-generator)?
Thanks a lot and keep going on ![]()
On weekend i will try the Android app ![]()
Poldi
Great, good work bl4d3.
If you get around to it, support for the DS18B20 One-wire temperature sensor would be a great addition!
As always, keep up the good work.
BT
@Poldi I know it is not a best practice open you front door through http call without encryption, in my mind i have this 2 solutions:
- embed a passowrd in each request and arduino will check it, but it always goes in clear...
- set a MAC address filter on your router plus WPA-PSK2 key it should be quite safe
if anyone has a best idea I'm here!
@Arduino-Idea I'll do it no problem, could you provide me a little sketch about to read data from DS18B20? I don't have it here and I can test the code but, if you have time, you should do it ![]()
EDIT
I forget a piece, tha "Send data to remote server" is used to upload automatically data read from sensors, the result is this
I'm looking for a cheap RoR hosting now
Hi bl4d3,
Here is all the information about the one wire protocol for the DS18B20 including a sketch and libraries. I have no idea when it comes to programming in C so can't help any further with that but everything you need should be on that page.
There are a couple of different models of these sensors but the above one is the newest one and they are pretty much the same anyway, this is all detailed at that link.
http://www.arduino.cc/playground/Learning/OneWire
With the security side of things. Personally, I think the risk is low and both those suggestions used together would work fine.
Another thought, with your remote server stuff, have you considered including the ability to send a feed to pachube to monitor and graph reading from the sensors?
Keep up the good work mate. Don't work too hard though, I think if you get a good, stable base product working and build on it from there this could become very popular!
Cheers,
BT
Hey bl4d3,
thanks for your reply!
Because i work in electronics, i can´t really say, which way is secure. I´ve learned programming by myself with the work with arduino. But I found something with QR-Codes we can check for this:
Another question:
Do you want to add more different Sensor an actors the people want to use, or do you thing it is possible to add a kind of "open format". I mean a "device" which shows values from the arduino. Then the users can program their own code with many sensors - or what ever they use - and in your Android-App you can define a field from type int etc...