EMBEDDED SYSTEM WITH PHP
OVERVIEW
This Ethernet Breakout-Module is simplest
way to add LAN connectivity to your microcontroller based products and
projects. Use this module to enable Ethernet interface for your product. It
works with any microcontroller operating at 3.3V or 5V. This module works at
3.3V and is compatible with 5V interface lines.
FEATURES
- Brand new and high quality.
- Chip board ENC28J60-I/SO.
- The board 25MHZ crystal.
- The network interface board HR911105A.
- 3.3 V power supply pin.
- Size: 6cm x 3.2cm - 2.4inch x 1.28inch.
- High quality PCB FR4 Grade with FPT Certified
APPLICATION DIAGRAM
CIRCUIT DIAGRAM
PIN CONNECTION
INTERFACE
LIBRARY
(add this library on your arduino folder in program files)
https://drive.google.com/file/d/0BzrGD4zr88GnZFRRalNjU1E0UmM/view
CODE
- With Arduino
- ADD hello world example from Examples
3.relay interface(Web Remote)
code:
#include "etherShield.h"
#include "ETHER_28J60.h"
int outputPin1 = 2;
int outputPin2 = 3;
int outputPin3 = 4;
int outputPin4 = 5;
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
// so unless you have more than one of these boards
// connected, you should be fine with this value.
static uint8_t ip[4] = {192, 168, 1, 15}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
char flag1=0,flag2=0,flag3=0,flag4=0;
void setup()
{
e.setup(mac, ip, port);
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(outputPin3, OUTPUT);
pinMode(outputPin4, OUTPUT);
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print("<H1>Web Remote</H1>");
e.print("<A HREF='?cmd1=off'>RDL</A></BR>");
// dispaly();
if (strcmp(params, "?cmd1=on") == 0)
{
digitalWrite(outputPin1, HIGH);
flag1=1;
dispaly();
}
else if (strcmp(params, "?cmd1=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin1, LOW);
flag1=0;
dispaly();
}
if (strcmp(params, "?cmd2=on") == 0)
{
digitalWrite(outputPin2, HIGH);
flag2=1;
dispaly();
}
else if (strcmp(params, "?cmd2=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin2, LOW);
flag2=0;
dispaly();
}
if (strcmp(params, "?cmd3=on") == 0)
{
digitalWrite(outputPin3, HIGH);
flag3=1;
dispaly();
}
else if (strcmp(params, "?cmd3=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin3, LOW);
flag3=0;
dispaly();
}
if (strcmp(params, "?cmd4=on") == 0)
{
digitalWrite(outputPin4, HIGH);
flag4=1;
dispaly();
}
else if (strcmp(params, "?cmd4=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin4, LOW);
flag4=0;
dispaly();
}
e.respond();
}
}
void dispaly()
{
if(flag1==0)
e.print("<A HREF='?cmd1=on'>RELAY1 ON</A></BR>");
else
e.print("<A HREF='?cmd1=off'>RELAY1 OFF</A></BR>");
if(flag2==0)
e.print("<A HREF='?cmd2=on'>'>RELAY2 ON</A></BR>");
else
e.print("<A HREF='?cmd2=off'>RELAY2 OFF</A></BR>");
if(flag3==0)
e.print("<A HREF='?cmd3=on'>'>RELAY3 ON</A></BR>");
else
e.print("<A HREF='?cmd3=off'>RELAY3 OFF</A></BR>");
if(flag4==0)
e.print("<A HREF='?cmd4=on'>'>RELAY4 ON</A></BR>");
else
e.print("<A HREF='?cmd4=off'>RELAY4 OFF</A></BR>");
}
#include "etherShield.h"
#include "ETHER_28J60.h"
int outputPin1 = 2;
int outputPin2 = 3;
int outputPin3 = 4;
int outputPin4 = 5;
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24}; // this just needs to be unique for your network,
// so unless you have more than one of these boards
// connected, you should be fine with this value.
static uint8_t ip[4] = {192, 168, 1, 15}; // the IP address for your board. Check your home hub
// to find an IP address not in use and pick that
// this or 10.0.0.15 are likely formats for an address
// that will work.
static uint16_t port = 80; // Use port 80 - the standard for HTTP
ETHER_28J60 e;
char flag1=0,flag2=0,flag3=0,flag4=0;
void setup()
{
e.setup(mac, ip, port);
pinMode(outputPin1, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(outputPin3, OUTPUT);
pinMode(outputPin4, OUTPUT);
}
void loop()
{
char* params;
if (params = e.serviceRequest())
{
e.print("<H1>Web Remote</H1>");
e.print("<A HREF='?cmd1=off'>RDL</A></BR>");
// dispaly();
if (strcmp(params, "?cmd1=on") == 0)
{
digitalWrite(outputPin1, HIGH);
flag1=1;
dispaly();
}
else if (strcmp(params, "?cmd1=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin1, LOW);
flag1=0;
dispaly();
}
if (strcmp(params, "?cmd2=on") == 0)
{
digitalWrite(outputPin2, HIGH);
flag2=1;
dispaly();
}
else if (strcmp(params, "?cmd2=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin2, LOW);
flag2=0;
dispaly();
}
if (strcmp(params, "?cmd3=on") == 0)
{
digitalWrite(outputPin3, HIGH);
flag3=1;
dispaly();
}
else if (strcmp(params, "?cmd3=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin3, LOW);
flag3=0;
dispaly();
}
if (strcmp(params, "?cmd4=on") == 0)
{
digitalWrite(outputPin4, HIGH);
flag4=1;
dispaly();
}
else if (strcmp(params, "?cmd4=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
{
digitalWrite(outputPin4, LOW);
flag4=0;
dispaly();
}
e.respond();
}
}
void dispaly()
{
if(flag1==0)
e.print("<A HREF='?cmd1=on'>RELAY1 ON</A></BR>");
else
e.print("<A HREF='?cmd1=off'>RELAY1 OFF</A></BR>");
if(flag2==0)
e.print("<A HREF='?cmd2=on'>'>RELAY2 ON</A></BR>");
else
e.print("<A HREF='?cmd2=off'>RELAY2 OFF</A></BR>");
if(flag3==0)
e.print("<A HREF='?cmd3=on'>'>RELAY3 ON</A></BR>");
else
e.print("<A HREF='?cmd3=off'>RELAY3 OFF</A></BR>");
if(flag4==0)
e.print("<A HREF='?cmd4=on'>'>RELAY4 ON</A></BR>");
else
e.print("<A HREF='?cmd4=off'>RELAY4 OFF</A></BR>");
}
4. web
integration
PIN CONNECTION
WITH ETHERNET MODULE
WITH RELAY
CODE
#include <EtherCard.h>
#define REQUEST_RATE 5000 // milliseconds
// ethernet interface mac address
static byte mymac[] = {
0x74,0x69,0x69,0x2D,0x30,0x31 };
// remote website name
const char website[] PROGMEM =
"passport.eu5.org";
byte Ethernet::buffer[700];
static long timer;
int i,val;
char RL1=0,RL2=0;
// called when the client request is complete
static void my_result_cb (byte status, word
off, word len) {
Serial.print("<<< reply ");
Serial.print(millis() - timer);
Serial.println(" ms");
//
Serial.println((const char*) Ethernet::buffer + off);
i=150;
val=0;
while(val!='R')
{
val=Ethernet::buffer[i];
i++;
}
while(val!='=')
{
val=Ethernet::buffer[i];
i++;
}
RL1=Ethernet::buffer[i];
while(val!='R')
timer = - REQUEST_RATE; // start timing out right away
{
val=Ethernet::buffer[i];
i++;
}
while(val!='=')
{
val=Ethernet::buffer[i];
i++;
}
RL2=Ethernet::buffer[i];
if(RL1=='1')
digitalWrite(7, HIGH);
else if(RL1=='0')
digitalWrite(7, LOW);
if(RL2=='1')
digitalWrite(6, HIGH);
else if(RL2=='0')
digitalWrite(6, LOW);
}
void setup () {
Serial.begin(9600);
Serial.println("\n[getDHCPandDNS]");
if
(ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if
(!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("My IP: ", ether.myip);
//
ether.printIp("Netmask: ", ether.mymask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
if
(!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if
(millis() > timer + REQUEST_RATE)
{
timer = millis();
Serial.println("\n>>> REQ");
ether.browseUrl(PSTR("/new/check.php"), " ",
website, my_result_cb);
}
}
PHP: (LOCAL HOST)
PHP CODE:
For buttons:
<html>
<body>
<?php
if(isset($_POST['first'])){
include "relay.php";
$sql="SELECT * FROM
reg WHERE ONNN='0' ";
$result=mysql_query($sql);
//$query = mysql_query("SELECT * FROM reg
)"
$sql1="UPDATE reg SET
ONNN='1' ";
$result2 = mysql_query($sql1);
//$query1=mysql_query("UPDATE reg SET
OFFF='0')"
//$sql2="UPDATE reg
SET OFFF='0' ";
//$result3 =
mysql_query($sql2);
}
if(isset($_POST['last'])){
include
"relay.php";
$sql="SELECT * FROM
reg WHERE ONNN='1' ";
$result=mysql_query($sql);
//$sql1="UPDATE reg
SET ONNN='0' ";
// $result2 = mysql_query($sql1);
$sql2="UPDATE reg SET
ONNN='0' ";
$result3 =
mysql_query($sql2);
}
if(isset($_POST['second'])){
include "relay.php";
$sql="SELECT * FROM
reg WHERE ONNN='0' ";
$result=mysql_query($sql);
//$query = mysql_query("SELECT * FROM reg
)"$sql1="UPDATE reg SET OFFF='1' "
$result2 = mysql_query($sql1);
//$query1=mysql_query("UPDATE
reg SET OFFF='0')"
//$sql2="UPDATE reg
SET OFFF='0' ";
//$result3 =
mysql_query($sql2);
}
if(isset($_POST['last2'])){
include
"relay.php";
$sql="SELECT * FROM
reg WHERE ONNN='1' ";
$result=mysql_query($sql);
//$sql1="UPDATE reg
SET ONNN='0' ";
// $result2 = mysql_query($sql1);
$sql2="UPDATE reg SET
OFFF='0' ";
$result3 =
mysql_query($sql2);
}
?>
<form
method="post" action="<?php echo $PHP_SELF?>">
<b>RELAY1</b>
: <input type="submit" name="first"
value="on"><input type="submit" name="last"
value="off"><br>
<b>RELAY2</b>
: <input type="submit" name="second"
value="on"><input type="submit"
name="last2" value="off"><br>
</form>
<?php
?>
</body>
</html>