Difference between revisions of "Rolpoort bediening"
| Line 1: | Line 1: | ||
{{Project | {{Project | ||
| − | |Members=Da Syntax | + | |State=Completed |
| + | |Members=Da Syntax, Prodigity | ||
|Description=Controll the gate using your cellphone | |Description=Controll the gate using your cellphone | ||
}} | }} | ||
| Line 61: | Line 62: | ||
---- | ---- | ||
https://ackspace.nl/wiki/File:Phone_relais_V2.tar | https://ackspace.nl/wiki/File:Phone_relais_V2.tar | ||
| + | ---- | ||
| + | #include <SoftwareSerial.h> | ||
| + | #include <EEPROM.h> | ||
| + | |||
| + | SoftwareSerial mobiel(9, 10); // RX, TX | ||
| + | unsigned long CID_Current; | ||
| + | unsigned long CID_Sender; | ||
| + | unsigned long CID_Add; | ||
| + | unsigned long CID_Joshua = 642828732; | ||
| + | unsigned long CID_Michel = 655986620; | ||
| + | byte myChar; | ||
| + | int mobMSGi = 0; | ||
| + | char mobMSG[128]; | ||
| + | char incomingCall[] = "*ECAV: 1,6,1,,,"; | ||
| + | char readSMS[] = "+CMGL:"; | ||
| + | |||
| + | void checknumber(long CID_call); | ||
| + | void addnumber(long CID_Call, long CID_sms); | ||
| + | boolean compare(char stringone[], char stringtwo[]); | ||
| + | boolean timerflag = false; | ||
| + | |||
| + | boolean addNumber = false; | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | pinMode(7, OUTPUT); | ||
| + | |||
| + | Serial.begin(9600); | ||
| + | |||
| + | mobiel.begin(9600); | ||
| + | delay(500); | ||
| + | |||
| + | mobiel.println("AT*ECAM=1"); | ||
| + | delay(500); | ||
| + | mobiel.println("AT+CPMS=\"ME\""); | ||
| + | delay(500); | ||
| + | mobiel.println("AT+CMGF=1"); | ||
| + | Serial.println("Setup done"); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | if (mobiel.available()) { | ||
| + | mobMSG[mobMSGi] = mobiel.read(); | ||
| + | Serial.write(mobMSG[mobMSGi]); | ||
| + | if ( mobMSG[mobMSGi] == '\n' ) { | ||
| + | if(addNumber == true){ | ||
| + | |||
| + | CID_Add = 0; | ||
| + | for(int i = 1; i < 15; i++){ | ||
| + | if(mobMSG[i] == '\r'){ | ||
| + | i = i+15; | ||
| + | } | ||
| + | else{ | ||
| + | CID_Add *= 10; | ||
| + | CID_Add += mobMSG[i] - 48; | ||
| + | //Serial.print(mobMSG[i], DEC); | ||
| + | } | ||
| + | } | ||
| + | Serial.print("Sender:"); | ||
| + | Serial.print(CID_Sender); | ||
| + | Serial.print(" Add:"); | ||
| + | Serial.println(CID_Add); | ||
| + | addnumber(CID_Sender, CID_Add); | ||
| + | addNumber = false; | ||
| + | } | ||
| + | else if ( compare(mobMSG, incomingCall, 15) == true ) { | ||
| + | Serial.println("JACKPOT!!!!!!!!!!!"); | ||
| + | CID_Current = 0; | ||
| + | for (int i = sizeof(incomingCall)+2; mobMSG[i+1] != '"'; i++) { | ||
| + | CID_Current *= 10; | ||
| + | CID_Current += mobMSG[i+1] - 48; | ||
| + | } | ||
| + | Serial.print("Telefoonnummer: "); | ||
| + | Serial.print(CID_Current); | ||
| + | Serial.println(""); | ||
| + | checknumber(CID_Current); | ||
| + | |||
| + | } | ||
| + | else if(compare(mobMSG, readSMS, 6) == true){ | ||
| + | for(int i = 0; i < 60; i++) { | ||
| + | if(mobMSG[i] == '"'){ | ||
| + | if(mobMSG[i+1] == ','){ | ||
| + | if(mobMSG[i+2] == '"'){ | ||
| + | CID_Sender = 0; | ||
| + | for(int c = i+6; c < (i+3+15); c++){ | ||
| + | if(mobMSG[c] == '"'){ | ||
| + | c = c+15; | ||
| + | } | ||
| + | else{ | ||
| + | CID_Sender *= 10; | ||
| + | CID_Sender += mobMSG[c] - 48; | ||
| + | } | ||
| + | } | ||
| + | addNumber = true; | ||
| + | |||
| + | i=i+60; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | for(int i = 0; i < 60; i++) { | ||
| + | if(mobMSG[i] == 'L'){ | ||
| + | if(mobMSG[i+1] == ':'){ | ||
| + | if(mobMSG[i+2] == ' '){ | ||
| + | delay(500); | ||
| + | mobiel.print("AT+CMGD="); | ||
| + | delay(500); | ||
| + | mobiel.println(mobMSG[i+3]); | ||
| + | Serial.print("delete for: "); | ||
| + | Serial.println(mobMSG[i+3]); | ||
| + | i=i+60; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | mobMSGi = 0; | ||
| + | } | ||
| + | mobMSGi++; | ||
| + | } | ||
| + | |||
| + | if (Serial.available()) | ||
| + | mobiel.write(Serial.read()); | ||
| + | if (millis()%60000 < 5000 && timerflag == false) { | ||
| + | mobiel.println("AT+CMGL=\"ALL\""); | ||
| + | timerflag = true; | ||
| + | } | ||
| + | else if (millis()%60000 > 5000) { | ||
| + | timerflag = false; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | boolean compare(char stringone[], char stringtwo[], int length) { | ||
| + | boolean check = true; | ||
| + | for(int i = 0; i < length; i++) { | ||
| + | if (stringone[i+1] != stringtwo[i]) { | ||
| + | check = false; | ||
| + | } | ||
| + | } | ||
| + | return check; | ||
| + | } | ||
| + | |||
| + | void checknumber(long CID_call) { | ||
| + | // Check if current CID is in our EEPROM, if so open door. | ||
| + | |||
| + | byte value; | ||
| + | unsigned long CID_mem = 0; | ||
| + | |||
| + | for (int EEPROMloc = 0; EEPROMloc < 1024; EEPROMloc+=4) { | ||
| + | for (int i = 0; i < 4; i++) { | ||
| + | value = EEPROM.read(EEPROMloc+i); | ||
| + | CID_mem = CID_mem << 8; | ||
| + | CID_mem += value; | ||
| + | } | ||
| + | if (CID_mem == CID_call) { | ||
| + | opendoor(); | ||
| + | Serial.println("Opening door"); | ||
| + | EEPROMloc = 1024; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void addnumber(long CID_Call, long CID_sms) { | ||
| + | // Add number to EEPROM if sender is admin | ||
| + | |||
| + | byte value; | ||
| + | byte temp; | ||
| + | unsigned long CID_mem = 0; | ||
| + | |||
| + | long CID_Josh = 642828732; | ||
| + | long CID_Michel = 655986620; | ||
| + | |||
| + | if (CID_Call == CID_Josh || CID_Call == CID_Michel) { | ||
| + | Serial.println("Admin recognized"); | ||
| + | for (int EEPROMloc = 0; EEPROMloc < 1024; EEPROMloc+=4) { | ||
| + | for (int i = 0; i < 4; i++) { | ||
| + | value = EEPROM.read(EEPROMloc+i); | ||
| + | CID_mem = CID_mem << 8; | ||
| + | CID_mem += (unsigned long) value; | ||
| + | Serial.println(value); | ||
| + | } | ||
| + | Serial.println(CID_mem); | ||
| + | if (CID_mem == 0) { | ||
| + | temp = (CID_sms << 0) >> 24; | ||
| + | EEPROM.write(EEPROMloc, temp); | ||
| + | temp = (CID_sms << 8) >> 24; | ||
| + | EEPROM.write(EEPROMloc + 1, temp); | ||
| + | temp = (CID_sms << 16) >> 24; | ||
| + | EEPROM.write(EEPROMloc + 2, temp); | ||
| + | temp = (CID_sms << 24) >> 24; | ||
| + | EEPROM.write(EEPROMloc + 3, temp); | ||
| + | Serial.print("Address: "); | ||
| + | Serial.println(EEPROMloc); | ||
| + | Serial.print("Number: "); | ||
| + | Serial.println(CID_sms); | ||
| + | EEPROMloc = 1024; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void opendoor() { | ||
| + | digitalWrite(7, HIGH); | ||
| + | delay(1000); | ||
| + | digitalWrite(7, LOW); | ||
| + | } | ||
Revision as of 20:10, 14 October 2012
| Project: Rolpoort bediening | |
|---|---|
| Featured: | |
| State | Completed |
| Members | Da Syntax, Prodigity |
| GitHub | No GitHub project defined. Add your project here. |
| Description | Controll the gate using your cellphone |
| Picture | |
| No project picture! Fill in form Picture or Upload a jpeg here | |
Setup done AT*ECAM=1
OK
RING
- ECAV: 1,6,1,,,"31642828732",145
RING
- ECAV: 1,0,1,08,222
Code om PDU packed bitsequence om te zetten naar "Human readable" code
https://ackspace.nl/wiki/File:Sketchbook.tar
- include <SoftwareSerial.h>
SoftwareSerial mobiel(9, 10); // RX, TX
unsigned long CID_Current;
unsigned long CID_Joshua = 642828732;
unsigned long CID_Michel = 655986620;
byte myChar;
int mobMSGi = 0;
char mobMSG[128];
char bingo[] = "*ECAV: 1,6,1,,,";
boolean compare(char stringone[], char stringtwo[]);
void setup()
{
pinMode(7, OUTPUT);
Serial.begin(9600);
mobiel.begin(9600);
delay(500);
mobiel.println("AT*ECAM=1");
Serial.println("Setup done");
}
void loop()
{
if (mobiel.available()) {
mobMSG[mobMSGi] = mobiel.read();
Serial.write(mobMSG[mobMSGi]);
if ( mobMSG[mobMSGi] == '\n' ) {
if ( compare(mobMSG, bingo) == true ) {
Serial.println("JACKPOT!!!!!!!!!!!");
CID_Current = 0;
for (int i = sizeof(bingo)+2; mobMSG[i+1] != '"'; i++) {
CID_Current *= 10;
CID_Current += mobMSG[i+1] - 48;
}
Serial.print("Telefoonnummer: ");
Serial.print(CID_Current);
Serial.println("");
switch (CID_Current) {
case 642828732:
Serial.println("Joshua belt");
break;
case 655986620:
Serial.println("Michel belt");
break;
default:
Serial.println("Onbekend belt");
}
}
mobMSGi = 0;
}
mobMSGi++;
}
if (Serial.available())
mobiel.write(Serial.read());
}
boolean compare(char stringone[], char stringtwo[]) {
boolean check = true;
for(int i = 0; i < 15; i++) {
if (stringone[i+1] != stringtwo[i]) {
check = false;
}
}
return check;
}
AT
OK
AT+CMGF=1
OK
AT+CMGL="ALL"
+CMGL: 1,"REC READ","+85291234567",,"06/11/11,00:30:29+32"
Hello, welcome to our SMS tutorial.
+CMGL: 2,"REC READ","+85291234567",,"06/11/11,00:32:20+32"
A simple demo of SMS text messaging.
OK
https://ackspace.nl/wiki/File:Phone_relais_V2.tar
- include <SoftwareSerial.h>
- include <EEPROM.h>
SoftwareSerial mobiel(9, 10); // RX, TX unsigned long CID_Current; unsigned long CID_Sender; unsigned long CID_Add; unsigned long CID_Joshua = 642828732; unsigned long CID_Michel = 655986620; byte myChar; int mobMSGi = 0; char mobMSG[128]; char incomingCall[] = "*ECAV: 1,6,1,,,"; char readSMS[] = "+CMGL:";
void checknumber(long CID_call); void addnumber(long CID_Call, long CID_sms); boolean compare(char stringone[], char stringtwo[]); boolean timerflag = false;
boolean addNumber = false;
void setup() {
pinMode(7, OUTPUT);
Serial.begin(9600);
mobiel.begin(9600);
delay(500);
mobiel.println("AT*ECAM=1");
delay(500);
mobiel.println("AT+CPMS=\"ME\"");
delay(500);
mobiel.println("AT+CMGF=1");
Serial.println("Setup done");
}
void loop() {
if (mobiel.available()) {
mobMSG[mobMSGi] = mobiel.read();
Serial.write(mobMSG[mobMSGi]);
if ( mobMSG[mobMSGi] == '\n' ) {
if(addNumber == true){
CID_Add = 0;
for(int i = 1; i < 15; i++){
if(mobMSG[i] == '\r'){
i = i+15;
}
else{
CID_Add *= 10;
CID_Add += mobMSG[i] - 48;
//Serial.print(mobMSG[i], DEC);
}
}
Serial.print("Sender:");
Serial.print(CID_Sender);
Serial.print(" Add:");
Serial.println(CID_Add);
addnumber(CID_Sender, CID_Add);
addNumber = false;
}
else if ( compare(mobMSG, incomingCall, 15) == true ) {
Serial.println("JACKPOT!!!!!!!!!!!");
CID_Current = 0;
for (int i = sizeof(incomingCall)+2; mobMSG[i+1] != '"'; i++) {
CID_Current *= 10;
CID_Current += mobMSG[i+1] - 48;
}
Serial.print("Telefoonnummer: ");
Serial.print(CID_Current);
Serial.println("");
checknumber(CID_Current);
}
else if(compare(mobMSG, readSMS, 6) == true){
for(int i = 0; i < 60; i++) {
if(mobMSG[i] == '"'){
if(mobMSG[i+1] == ','){
if(mobMSG[i+2] == '"'){
CID_Sender = 0;
for(int c = i+6; c < (i+3+15); c++){
if(mobMSG[c] == '"'){
c = c+15;
}
else{
CID_Sender *= 10;
CID_Sender += mobMSG[c] - 48;
}
}
addNumber = true;
i=i+60;
}
}
}
}
for(int i = 0; i < 60; i++) {
if(mobMSG[i] == 'L'){
if(mobMSG[i+1] == ':'){
if(mobMSG[i+2] == ' '){
delay(500);
mobiel.print("AT+CMGD=");
delay(500);
mobiel.println(mobMSG[i+3]);
Serial.print("delete for: ");
Serial.println(mobMSG[i+3]);
i=i+60;
}
}
}
}
}
mobMSGi = 0;
}
mobMSGi++;
}
if (Serial.available())
mobiel.write(Serial.read());
if (millis()%60000 < 5000 && timerflag == false) {
mobiel.println("AT+CMGL=\"ALL\"");
timerflag = true;
}
else if (millis()%60000 > 5000) {
timerflag = false;
}
}
boolean compare(char stringone[], char stringtwo[], int length) {
boolean check = true;
for(int i = 0; i < length; i++) {
if (stringone[i+1] != stringtwo[i]) {
check = false;
}
}
return check;
}
void checknumber(long CID_call) {
// Check if current CID is in our EEPROM, if so open door.
byte value; unsigned long CID_mem = 0;
for (int EEPROMloc = 0; EEPROMloc < 1024; EEPROMloc+=4) {
for (int i = 0; i < 4; i++) {
value = EEPROM.read(EEPROMloc+i);
CID_mem = CID_mem << 8;
CID_mem += value;
}
if (CID_mem == CID_call) {
opendoor();
Serial.println("Opening door");
EEPROMloc = 1024;
}
}
}
void addnumber(long CID_Call, long CID_sms) {
// Add number to EEPROM if sender is admin
byte value; byte temp; unsigned long CID_mem = 0;
long CID_Josh = 642828732;
long CID_Michel = 655986620;
if (CID_Call == CID_Josh || CID_Call == CID_Michel) {
Serial.println("Admin recognized");
for (int EEPROMloc = 0; EEPROMloc < 1024; EEPROMloc+=4) {
for (int i = 0; i < 4; i++) {
value = EEPROM.read(EEPROMloc+i);
CID_mem = CID_mem << 8;
CID_mem += (unsigned long) value;
Serial.println(value);
}
Serial.println(CID_mem);
if (CID_mem == 0) {
temp = (CID_sms << 0) >> 24;
EEPROM.write(EEPROMloc, temp);
temp = (CID_sms << 8) >> 24;
EEPROM.write(EEPROMloc + 1, temp);
temp = (CID_sms << 16) >> 24;
EEPROM.write(EEPROMloc + 2, temp);
temp = (CID_sms << 24) >> 24;
EEPROM.write(EEPROMloc + 3, temp);
Serial.print("Address: ");
Serial.println(EEPROMloc);
Serial.print("Number: ");
Serial.println(CID_sms);
EEPROMloc = 1024;
}
}
}
}
void opendoor() {
digitalWrite(7, HIGH); delay(1000); digitalWrite(7, LOW);
}