Switched to server mode instead of client mode
This commit is contained in:
parent
97d1534066
commit
84e9dd1a03
|
@ -45,8 +45,8 @@ byte DS1307::bcdToDec(byte val)
|
||||||
void DS1307::stopDs1307()
|
void DS1307::stopDs1307()
|
||||||
{
|
{
|
||||||
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||||
Wire.send(0);
|
Wire.write(0);
|
||||||
Wire.send(0x80);
|
Wire.write(0x80);
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -65,15 +65,15 @@ void DS1307::setDateDs1307(byte second, // 0-59
|
||||||
byte year) // 0-99
|
byte year) // 0-99
|
||||||
{
|
{
|
||||||
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||||
Wire.send(0);
|
Wire.write(0);
|
||||||
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
|
Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock
|
||||||
Wire.send(decToBcd(minute));
|
Wire.write(decToBcd(minute));
|
||||||
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
|
Wire.write(decToBcd(hour)); // If you want 12 hour am/pm you need to set
|
||||||
// bit 6 (also need to change readDateDs1307)
|
// bit 6 (also need to change readDateDs1307)
|
||||||
Wire.send(decToBcd(dayOfWeek));
|
Wire.write(decToBcd(dayOfWeek));
|
||||||
Wire.send(decToBcd(dayOfMonth));
|
Wire.write(decToBcd(dayOfMonth));
|
||||||
Wire.send(decToBcd(month));
|
Wire.write(decToBcd(month));
|
||||||
Wire.send(decToBcd(year));
|
Wire.write(decToBcd(year));
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,19 +88,19 @@ void DS1307::getDateDs1307(byte *second,
|
||||||
{
|
{
|
||||||
// Reset the register pointer
|
// Reset the register pointer
|
||||||
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||||
Wire.send(0);
|
Wire.write(0);
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
||||||
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
|
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
|
||||||
|
|
||||||
// A few of these need masks because certain bits are control bits
|
// A few of these need masks because certain bits are control bits
|
||||||
*second = bcdToDec(Wire.receive() & 0x7f);
|
*second = bcdToDec(Wire.read() & 0x7f);
|
||||||
*minute = bcdToDec(Wire.receive());
|
*minute = bcdToDec(Wire.read());
|
||||||
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
|
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
|
||||||
*dayOfWeek = bcdToDec(Wire.receive());
|
*dayOfWeek = bcdToDec(Wire.read());
|
||||||
*dayOfMonth = bcdToDec(Wire.receive());
|
*dayOfMonth = bcdToDec(Wire.read());
|
||||||
*month = bcdToDec(Wire.receive());
|
*month = bcdToDec(Wire.read());
|
||||||
*year = bcdToDec(Wire.receive());
|
*year = bcdToDec(Wire.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
134
Open_Access_Control_Ethernet.pde → Open_Access_Control_Ethernet.ino
Executable file → Normal file
134
Open_Access_Control_Ethernet.pde → Open_Access_Control_Ethernet.ino
Executable file → Normal file
|
@ -60,8 +60,6 @@
|
||||||
|
|
||||||
#include <Ethernet.h> // Ethernet stuff
|
#include <Ethernet.h> // Ethernet stuff
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Server.h>
|
|
||||||
#include <Client.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include <DS1307.h> // DS1307 RTC Clock/Date/Time chip library
|
#include <DS1307.h> // DS1307 RTC Clock/Date/Time chip library
|
||||||
|
@ -160,17 +158,13 @@ boolean privmodeEnabled = false; // Switch for ena
|
||||||
|
|
||||||
// Enter a MAC address and IP address for your controller below.
|
// Enter a MAC address and IP address for your controller below.
|
||||||
// The IP address will be dependent on your local network:
|
// The IP address will be dependent on your local network:
|
||||||
byte mac[] = { 0xAB, 0xBA, 0xDA, 0xDE, 0xFE, 0xED };
|
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||||
byte ip[] = { 192,168,1,199 };
|
IPAddress ip(192,168,1,177);
|
||||||
byte server[] = { 192,168,1,200 }; // webserver for logging, access control, etc
|
|
||||||
|
|
||||||
// Initialize the Ethernet client library
|
// Initialize the Ethernet server library
|
||||||
// with the IP address and port of the server
|
// with the IP address and port you want to use
|
||||||
// that you want to connect to (port 80 is default for HTTP):
|
// (port 80 is default for HTTP):
|
||||||
Client client(server, 80);
|
EthernetServer server(80);
|
||||||
|
|
||||||
// strings for storing results from web server
|
|
||||||
String httpresponse = "";
|
|
||||||
|
|
||||||
/* Create an instance of the various C++ libraries we are using.
|
/* Create an instance of the various C++ libraries we are using.
|
||||||
*/
|
*/
|
||||||
|
@ -213,6 +207,9 @@ const prog_uchar statusMessage6[] PROGMEM = {"Door2UnlockedState_1_Lock
|
||||||
|
|
||||||
void setup(){ // Runs once at Arduino boot-up
|
void setup(){ // Runs once at Arduino boot-up
|
||||||
|
|
||||||
|
// start the Ethernet connection and the server:
|
||||||
|
Ethernet.begin(mac, ip);
|
||||||
|
server.begin();
|
||||||
|
|
||||||
Wire.begin(); // start Wire library as I2C-Bus Master
|
Wire.begin(); // start Wire library as I2C-Bus Master
|
||||||
|
|
||||||
|
@ -252,10 +249,6 @@ void setup(){ // Runs once at Arduino boot-up
|
||||||
|
|
||||||
Serial.begin(57600); // Set up Serial output at 8,N,1,57600bps
|
Serial.begin(57600); // Set up Serial output at 8,N,1,57600bps
|
||||||
|
|
||||||
// start the Ethernet connection:
|
|
||||||
Ethernet.begin(mac, ip);
|
|
||||||
// wait a bit
|
|
||||||
delay(10000);
|
|
||||||
|
|
||||||
logReboot();
|
logReboot();
|
||||||
chirpAlarm(1); // Chirp the alarm to show system ready.
|
chirpAlarm(1); // Chirp the alarm to show system ready.
|
||||||
|
@ -266,12 +259,75 @@ void setup(){ // Runs once at Arduino boot-up
|
||||||
|
|
||||||
}
|
}
|
||||||
void loop() // Main branch, runs over and over again
|
void loop() // Main branch, runs over and over again
|
||||||
{
|
{
|
||||||
// if the server's disconnected, stop the client:
|
|
||||||
if (!client.connected()) {
|
|
||||||
client.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// listen for incoming clients
|
||||||
|
EthernetClient client = server.available();
|
||||||
|
|
||||||
|
String readString = String(100); //string for fetching data from address
|
||||||
|
|
||||||
|
if (client) {
|
||||||
|
// an http request ends with a blank line
|
||||||
|
boolean currentLineIsBlank = true;
|
||||||
|
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 you've gotten to the end of the line (received a newline
|
||||||
|
// character) and the line is blank, the http request has ended,
|
||||||
|
// so you can send a reply
|
||||||
|
if (c == '\n' && currentLineIsBlank) {
|
||||||
|
// send a standard http response header
|
||||||
|
client.println("HTTP/1.1 200 OK");
|
||||||
|
client.println("Content-Type: text/html");
|
||||||
|
client.println();
|
||||||
|
|
||||||
|
if(readString.indexOf('?') > 0) {
|
||||||
|
client.println("hello!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// output status
|
||||||
|
client.println("<pre>");
|
||||||
|
client.print("Alarm armed:");
|
||||||
|
client.println(alarmArmed,DEC);
|
||||||
|
client.print("Alarm activated:");
|
||||||
|
client.println(alarmActivated,DEC);
|
||||||
|
client.print("Alarm 3:");
|
||||||
|
client.println(pollAlarm(3),DEC);
|
||||||
|
client.print("Alarm 2:");
|
||||||
|
client.println(pollAlarm(2),DEC);
|
||||||
|
client.print("Door 1 locked:");
|
||||||
|
client.println(door1Locked);
|
||||||
|
client.print("Door 2 locked:");
|
||||||
|
client.println(door2Locked);
|
||||||
|
client.println("</pre>");
|
||||||
|
client.println("<a href=");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (c == '\n') {
|
||||||
|
// you're starting a new line
|
||||||
|
currentLineIsBlank = true;
|
||||||
|
}
|
||||||
|
else if (c != '\r') {
|
||||||
|
// you've gotten a character on the current line
|
||||||
|
currentLineIsBlank = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// give the web browser time to receive the data
|
||||||
|
delay(1);
|
||||||
|
// close the connection:
|
||||||
|
client.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
readCommand(); // Check for commands entered at serial console
|
readCommand(); // Check for commands entered at serial console
|
||||||
|
|
||||||
|
|
||||||
|
@ -945,18 +1001,18 @@ void PROGMEMprintln(const prog_uchar str[]) // Function to retrieve logging s
|
||||||
char c;
|
char c;
|
||||||
if(!str) return;
|
if(!str) return;
|
||||||
|
|
||||||
if(client.connect()) {
|
//if(client.connect(server, 80) > 0) {
|
||||||
client.print("GET /~access/log/?device=door&data=");
|
// client.print("GET /~access/log/?device=door&data=");
|
||||||
while((c = pgm_read_byte(str++))){
|
while((c = pgm_read_byte(str++))){
|
||||||
Serial.print(c,BYTE);
|
Serial.write(c);
|
||||||
client.print(c,BYTE);
|
// client.write(c);
|
||||||
}
|
}
|
||||||
client.println(" HTTP/1.0");
|
//client.println(" HTTP/1.0");
|
||||||
client.println();
|
//client.println();
|
||||||
client.stop();
|
//client.stop();
|
||||||
// reset values coming from http
|
// reset values coming from http
|
||||||
httpresponse = "";
|
// httpresponse = "";
|
||||||
}
|
//}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -965,18 +1021,18 @@ void PROGMEMprint(const prog_uchar str[]) // Function to retrieve logging str
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
if(!str) return;
|
if(!str) return;
|
||||||
if(client.connect()) {
|
//if(client.connect(server, 80) > 0) {
|
||||||
client.print("GET /~access/log/?device=door&data=");
|
// client.print("GET /~access/log/?device=door&data=");
|
||||||
while((c = pgm_read_byte(str++))){
|
while((c = pgm_read_byte(str++))){
|
||||||
Serial.print(c,BYTE);
|
Serial.write(c);
|
||||||
client.print(c,BYTE);
|
// client.write(c);
|
||||||
}
|
}
|
||||||
client.println(" HTTP/1.0");
|
// client.println(" HTTP/1.0");
|
||||||
client.println();
|
// client.println();
|
||||||
client.stop();
|
// client.stop();
|
||||||
// reset values coming from http
|
// reset values coming from http
|
||||||
httpresponse = "";
|
// httpresponse = "";
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user