Domoti SAS

Dependencies:   ControlAcceso MFRC522 mbed

Revision:
5:e0893c873954
Parent:
4:ef96fe085434
Child:
6:8ed278d1f2eb
--- a/main.cpp	Wed Apr 27 23:04:29 2016 +0000
+++ b/main.cpp	Thu Apr 28 23:26:38 2016 +0000
@@ -1,14 +1,18 @@
 #include "mbed.h"
 #include "MFRC522.h"
 #include "ESP8266.h"
+
+
 #define APIKEY 7X2TD78DKY4459M0
-#define IP "10.69.100.75" // thingspeak.com IP Address
-char snd[255],rcv[1000];
+#define IP "10.69.100.75" // Domoti Server IP Address
+char snd[255],rcv[100];
+char UIDstr[10];
 //#include "UIPEthernet.h"
 //#include "UIPClient.h"
 //#include "string"
 //using namespace std;
 
+
 //------------------------------------
 // Serial configuration
 // 9600 bauds, 8-bit data, no parity
@@ -32,6 +36,7 @@
 uint8_t UID_P[4] = {0x44,0xBE,0x5D,0x56};
 bool UID_OK;
 
+
 int main()
 {
     //uint8_t hello[9] = "HELLO!!!";
@@ -53,38 +58,44 @@
     //pc.printf("Enviando dato.... \n\r");
     //Client.write(hello,size);
     //pc.printf("dato enviado \n\r");
+    
     ESP_Enable = 0;
     ESP_Reset = 0;
     ESP_Reset = 1;
     ESP_Enable = 1;
     wifi.Reset();
-    wait(10);
+    wait(5);
     pc.printf("SET mode to AP\r\n");
     wifi.SetMode(1);    // set ESP mode to 1
     wifi.RcvReply(rcv, 1000);    //receive a response from ESP
     pc.printf("%s",rcv);    //Print the response onscreen
-    pc.printf("AP List\r\n");
-    wifi.SendCMD("AT+CWLAP\r\n");
-    wifi.RcvReply(rcv, 5000);
-    pc.printf("%s",rcv);
+    //pc.printf("AP List\r\n");
+    //wifi.SendCMD("AT+CWLAP\r\n");
+    //wifi.RcvReply(rcv, 5000);
+    //pc.printf("%s",rcv);
     pc.printf("Conneting to AP\r\n");
     wifi.Join("DOMOTI", "domotizamos");     // Your wifi username & Password
-    wifi.RcvReply(rcv, 1000);    //receive a response from ESP
+    wifi.RcvReply(rcv, 3000);    //receive a response from ESP
     pc.printf("%s", rcv);    //Print the response onscreen
     wait(10);     //waits for response from ESP
     pc.printf("Getting IP\r\n");    //get IP addresss from the connected AP
     wifi.GetIP(rcv);    //receive an IP address from the AP
     pc.printf("%s", rcv);
-    wait(5);
-    wifi.SendCMD("AT+CIPSTART=\"TCP\",\"10.69.100.75\",10022\r\n");
-    wifi.RcvReply(rcv, 1000);
+    pc.printf("Building Socket:\r\n");
+    strcpy(snd, "AT+CIPSTART=\"TCP\",\"10.69.100.25\",10022");
+    wifi.SendCMD(snd);
+    wifi.RcvReply(rcv, 3000);
     pc.printf("%s", rcv);
-    wifi.SendCMD("AT+CIPSEND=10\r\n");
-    wifi.RcvReply(rcv, 1000);
+    pc.printf("SET Single\r\n");
+    wifi.SetSingle();
+    wifi.RcvReply(rcv, 3000);
     pc.printf("%s", rcv);
-    wifi.SendCMD("POST HOLA!\r\n");
-    wifi.RcvReply(rcv, 1000);
-    pc.printf("%s", rcv);
+    //wifi.SendCMD("AT+CIPSEND=10\r\n");
+    //wifi.RcvReply(rcv, 1000);
+    //pc.printf("%s", rcv);
+    //wifi.SendCMD("HOLA!\r\n");
+    //wifi.RcvReply(rcv, 1000);
+    //pc.printf("%s", rcv);
     rf.PCD_Init();
     while(1) {
         green = 0;
@@ -92,7 +103,8 @@
             wait_ms(500);
             continue;
         }
-        if ( ! rf.PICC_ReadCardSerial()) {
+        pc.printf("NEW CARD:\r\n");
+        if ( !rf.PICC_ReadCardSerial()) {
             wait_ms(500);
             continue;
         }
@@ -104,7 +116,22 @@
                 UID_OK = false;
             }
         }
+        pc.printf("\r\n");
         if (UID_OK) green = 1;
+        
+        sprintf(UIDstr, "%X%X%X%X",
+                        rf.uid.uidByte[0],
+                        rf.uid.uidByte[1],
+                        rf.uid.uidByte[2],
+                        rf.uid.uidByte[3]);
+        strcpy(snd, "AT+CIPSEND=10");
+        wifi.SendCMD(snd);
+        wifi.RcvReply(rcv, 1000);
+        pc.printf("%s%s\r\n", rcv, UIDstr);
+        wifi.SendCMD(UIDstr);
+        wifi.RcvReply(rcv, 3000);
+        pc.printf("%s", rcv);
+        
         pc.printf("\n\r");
         uint8_t piccType = rf.PICC_GetType(rf.uid.sak);
         pc.printf("PICC Type: %s \n\r", rf.PICC_GetTypeName(piccType));