Domoti SAS
Dependencies: ControlAcceso MFRC522 mbed
Revision 9:6cf1d9384054, committed 2016-07-14
- Comitter:
- capantojar
- Date:
- Thu Jul 14 15:17:53 2016 +0000
- Parent:
- 8:b6fc53b95377
- Commit message:
- 14/07/2016
Changed in this revision
| ESP8266.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266.lib Wed May 04 22:22:23 2016 +0000 +++ b/ESP8266.lib Thu Jul 14 15:17:53 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/quevedo/code/ESP8266/#77388e8f0697 +https://developer.mbed.org/users/capantojar/code/ControlAcceso/#6124a6e99b86
--- a/main.cpp Wed May 04 22:22:23 2016 +0000
+++ b/main.cpp Thu Jul 14 15:17:53 2016 +0000
@@ -2,9 +2,8 @@
#include "MFRC522.h"
#include "ESP8266.h"
-
-#define APIKEY 7X2TD78DKY4459M0
-#define IP "10.69.100.75" // Domoti Server IP Address
+#define IP "104.196.113.161" // Domoti Server IP Address
+#define PORT "6666" // Domoti Server IP Address
char snd[255],rcv[100];
char *spr;
char UIDstr[10];
@@ -22,33 +21,41 @@
DigitalOut green(PA_5);
void connect() {
+ green = 1;
while (1) {
- wifi.Join("DOMOTI", "domotizamos"); // Your wifi username & Password
- wifi.RcvReply(rcv, 3000); //receive a response from ESP
+ wifi.Join("DOMOTI_EXT", "domotizamos"); // Your wifi username & Password
+ //wifi.Join("AulasAMIGAS", "900292680"); // Your wifi username & Password
+ wifi.RcvReply(rcv, 3000); // receive a response from ESP
if (!strstr(rcv,"A\"")) continue;
- wait(10); //waits for response from ESP
+ wait(10); // waits for response from ESP
while (1) {
- wifi.GetIP(rcv); //receive an IP address from the AP
+ wifi.GetIP(rcv); // receive an IP address from the AP
if (!strstr(rcv,"busy")) break;
}
if (!strstr(rcv,"AR")) break;
}
+ pc.printf("Conectado\r\n");
}
void buildSocket() {
+ green = 1;
wifi.SetSingle();
wifi.RcvReply(rcv, 3000);
while (1) {
- strcpy(snd, "AT+CIPSTART=\"TCP\",\"10.69.100.4\",10022");
+ //strcpy(snd, "AT+CIPSTART=\"TCP\",\"104.196.113.161\",6666");
+ strcpy(snd, "AT+CIPSTART=\"TCP\",\"10.69.17.20\",6666");
wifi.SendCMD(snd);
wifi.RcvReply(rcv, 3000);
+ pc.printf("Conectando al servidor.... \r\n");
if (strstr(rcv,"Linked")||strstr(rcv,"ALREAY CONNECT")) break;
}
+ pc.printf("Link creado\r\n");
}
void readCard(MFRC522 *rf, bool in) {
+ green = 1;
if (!rf->PICC_ReadCardSerial()) return;
- sprintf(UIDstr, "%X%X%X%X",
+ sprintf(UIDstr, "%02X%02X%02X%02X",
rf->uid.uidByte[0],
rf->uid.uidByte[1],
rf->uid.uidByte[2],
@@ -67,12 +74,11 @@
ESP_Enable = 1;
wifi.Reset();
wait(5);
- wifi.SetMode(1); //set ESP mode to 1
- wifi.RcvReply(rcv, 1000); //receive a response from ESP
- // Connect to wifi
- connect();
- // Build socket
- buildSocket();
+ wifi.SetMode(1); // set ESP mode to 1
+ wifi.RcvReply(rcv, 1000); // receive a response from ESP
+ connect(); // Connect to wifi
+ buildSocket(); // Build socket
+
// Init RF sensors
rf_in = new MFRC522(PB_15, PB_14, PB_13, PC_4, PA_13);
rf_in->PCD_Init();
@@ -81,13 +87,13 @@
while(1) {
green = 0;
dir = 0;
- if (rf_in->PICC_IsNewCardPresent()) readCard(rf_in,1);
+ if (rf_in->PICC_IsNewCardPresent()) {readCard(rf_in,1);}
else if (rf_out->PICC_IsNewCardPresent()) readCard(rf_out,0);
if (!dir) {wait_ms(500);continue;}
strcpy(snd, "AT+CIPSEND=12");
wifi.SendCMD(snd);
- wifi.RcvReply(rcv, 1000);
+ wifi.RcvReply(rcv, 500);
// Socket verification
if (strstr(rcv,"ERROR")||strstr(rcv,"link is not")) {
buildSocket();
@@ -95,15 +101,16 @@
}
if (dir==1) sprintf(snd,"%s,I",UIDstr);
else sprintf(snd,"%s,O",UIDstr);
+ pc.printf("REQ: %s\r\n", snd);
wifi.SendCMD(snd);
- wifi.RcvReply(rcv, 5000);
- pc.printf("%s", rcv);
+ wifi.RcvReply(rcv, 10000);
+ pc.printf("%s\r\n", rcv);
spr = strchr(rcv,'+');
if (spr!=NULL) {
if (spr[1]=='I'&&spr[3]=='D') {
spr = strchr(rcv,':');
- if (spr[1]=='E') {
+ if (spr[1]=='1') {
green = 1;
pc.printf("Acceso Concedido\r\n");
} else {