Hi,guys
I just an senior school student from china. And i am new to the arduino. i have taken an interest in using the arduino cause it is tons of fun . Anyway I am using it to do a project. My project is to build a home security system.
Now i am using the arduino ethernet shield to control the system from internet with the android mobile phone. And the software on the mobile phone is Domotichome. I can control the arduino with this software. But now i have some problems about it. I have done some research on the ethernet shield but have become really confused on how it works.
I am used the IDE 1.0.5.
Here are my questiones!
- I just want to know how the ethernet shield works.
- I had used two software:Domotichome, Arduino controller. But i was failed! I want to know the difference between them.
3)I had succeed in controlling one LED. But i couldn't control two LED with the arduino.This is the code for one LED:
#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[] = {0x8C,0x21,0x0A,0x35,0xAE,0x85}; //physical mac address
byte ip[] = {192,168,1,4}; //ip
byte gateway[] = {192,168,1,1};
byte subnet[] = {255,255,255,0};
EthernetServer server = EthernetServer(80);
// arduino out
int pinOutPlight = 7;
String readString = String(30); //string for fetching data from address
String ipstr;
// incoming GET command
String r_pinOnLight = "GET /?out=" + String(pinOutPlight) +"&status=1";
String r_pinOffLight = "GET /?out=" + String(pinOutPlight) +"&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;
//ipstr=String(ip[1]);
ipstr=String(ip[0]) + "." + String(ip[1]) + "." + String(ip[2]) + "." + String(ip[3]);
}
void loop(){
current_action = -1;
// 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() < 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\" :");
client.print(ipstr);
client.print("\", \"devices\" : [{ \"type\" : \"light\", \"name\" : \"LED\", \"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();
}
}
}
}
}
- I want to use the DS18B20 Temperature. It must used DallasTemperature.h and OneWire.h. So who has used it. I want to know how to use it!
5)If i just want to control the LED, it shows?"An error has accoured.Check your internet connection.Is arduino alive?" So i had to create one new action about the LED.
Sorry about my English. I am not a native speaker. I am from china! If someone can or want to help me, you can email to me :907400644@qq.com or zhusj110373@hotmail.com. Thank you very much !