Updated Sensors Module. Added person counter.

Dependencies:   EthernetInterface HC_SR04_Ultrasonic_Library Middleware mbed-rtos mbed

Fork of SmartLabProyect by Jorge Martin Beltran Avila

Files at this revision

API Documentation at this revision

Comitter:
RoHe
Date:
Sat Dec 05 17:46:07 2015 +0000
Child:
1:106e93f9c7c8
Commit message:
MiddleWare GUS

Changed in this revision

Coments.cpp Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
Middleware.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Coments.cpp	Sat Dec 05 17:46:07 2015 +0000
@@ -0,0 +1,122 @@
+/*
+
+TODO:
+
+1.- Conectar a ambos servidores
+    1.1 - si no solo conectar a uno y tener present la conección activa
+2.-hacer funciones para dvidir las cadenas de los mensajes
+3.-hace funcion para formar cadenas para enviar mensajes
+4. Formato de mensajes para que los pueda leer el server
+
+*/
+
+
+/*
+
+    
+    
+    /*
+
+            // Receive message from server
+        char buf1[256];
+        int n1 = socketTCP1.receive(buf1, 256);
+        buf1[n1] = '\0';
+
+        if(n1>0) {
+            pc.printf("Received message from server1 IF: '%s'\n\r", buf1);
+            socketTCP1.close();
+            //isConnectedServer1=false;
+        } else {
+            //_isConnectedServer1==false; //quiere decir que se desconecto del servidor
+            pc.printf("Not received ELSE value of lenght: '%u'\n\r",strlen(buf1));
+            socketTCP1.close();
+            //isConnectedServer1=false;
+        }
+
+            if(bo_somethingWrong==true) {
+                return 0;
+            }
+
+    //if(socketTCP.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) == -1 && _isConnectedServer1==false ) {
+        if(socketTCP.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) == -1) {
+        _isConnectedServer1=socketTCP.is_connected();
+       //_isConnectedServer1=false;
+        pc.printf("Unable to connect to (%s) on port (%d)\n\r", ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1);
+        wait(1);
+    } else {
+        _isConnectedServer1=socketTCP.is_connected();
+       //_isConnectedServer1=true;
+        //pc.printf("Connected to Server at %s\n\r",ECHO_SERVER_ADDRESS1);
+        pc.printf("Connected to Server at %s\n\r",socketTCP.get_address());
+        pc.printf("Connected to PORT at %u\n\r",socketTCP.get_port());
+
+
+
+        //TODO: split strings
+
+        char hello[] = "reply:get:status:192.168.1.77:door:1\n\r";
+
+        pc.printf("Sending  message to Server : %s \n\r",hello);
+        socketTCP.send_all(hello, sizeof(hello)- 1);
+
+
+
+    // Receive message from server
+        char buf[256];
+        int n = socketTCP.receive(buf, 256);
+        buf[n] = '\0';
+        pc.printf("Received message from server: '%s'\n\r", buf);
+
+                if(bo_somethingWrong==true) {
+                    return 0;
+                }
+
+
+    }
+
+
+
+    }
+
+    // Clean up
+    socketTCP1.close();
+    socketTCP2.close();
+    */
+
+
+
+// Send message to server
+/*
+strcat(s_myIP,"\n\r");
+pc.printf("Sending  message to Server : %s \n\r",s_myIP);
+socketTCP.send_all(s_myIP, sizeof(s_myIP) - 1);
+*/
+/*
+c_myIP = "192.168.1.77\n\r";
+//strcat(c_myIP,"\n\r");
+pc.printf("Sending  message to Server : %s \n\r",c_myIP);
+socketTCP.send_all(c_myIP, sizeof(c_myIP) - 1);
+*/
+
+//char hello[] = "reply:get:";
+//char hello2[] = "status:192.168.1.77:door:1\n\r" ;
+//strcat(hello,hello2);
+
+
+//THREADS CSDECLARATION
+//Thread thread2(conect_Server);
+//Thread *thread2;
+//thread2 = new Thread(conect_Server);
+
+
+
+
+//IMPORT FROM LIBRARY
+/*
+cad = driver.echo();
+pc.printf("libraryECHO: %s\n\r",cad);
+int var = driver.is_good();
+pc.printf("libraryVAR: %u\n\r",var);
+*/
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Sat Dec 05 17:46:07 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/RoHe/code/EthernetInterface/#184320d42a15
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Middleware.lib	Sat Dec 05 17:46:07 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/RoHe/code/Middleware/#d1ff330c5128
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 05 17:46:07 2015 +0000
@@ -0,0 +1,193 @@
+/*
+
+Main.cpp
+
+Last update by RoHe 16/11/2015
+
+*/
+#include <string.h>
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "rtos.h"
+#include "SensorPIR.h"
+#include "Ether.h"
+#include "Initial.h"
+#include "Threads.cpp"
+#include "StringManager.h"
+
+
+int main()
+{
+    /*////////////////////////////////////
+    Initialization of the outports
+
+    Comments:
+    -Inicialize all the output in zero
+    -It has Pull - up
+    */
+    ledRED=1; // it has pull-up
+    ledGREEN=1;
+    ledBLUE=1;
+
+
+    /*////////////////////////////////////
+    SET Initial configuration and welcome message
+    */
+    pc.baud(115200);
+    pc.printf("Hello World from TCP Client-Server RoHE Main TASK GUS integrate YORCH1.\n\r");
+
+
+    /*//////////////////////////////////
+    Declares all necessary CLASSES
+    */
+    
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+
+
+    /*///////////////////////////////////
+    Declares all necessary THREADS
+    */
+    Thread thread1(led_thread);
+    //Thread thread2(receivedFromServer1);
+
+    /*////////////////////////////////////
+    Declares all necessary INTERRUPTIONS
+    */
+    sw2.fall(&sw2_press);
+
+//////////////////////////////////////////////////////APPLICATION /////////////////////////////////////////////////////////
+    
+    
+    s_myIP = eth.getIPAddress();
+    pc.printf("\nClient IP Address is %s\r", s_myIP);
+    pc.printf("\nClient IP MAC address is %s\r", eth.getMACAddress);
+    pc.printf("\nClient IP Gateway is %s\r", eth.getGateway());
+    pc.printf("\nClient IP network mask is %s\n\r", eth.getNetworkMask());
+    /*
+    CONSTRAINS:
+    -No se puede poner un serial print el los threads ....
+    -se tiene que abrir y cerrar las conecciones par que pueda leer nuevos mensajes
+    -se puede leer mensajes si no se cierra el socket pero la conexion se queda abierta
+     y no puede recibir mas mensajes .. se saco el forpara hacerlo una sola vez y no se cierra la conexion
+
+    */
+
+
+    /*
+    // Connect to Server2
+         (socketTCP.connect(ECHO_SERVER_ADDRESS2, ECHO_SERVER_PORT2) < 0) {
+            pc.printf("Unable to connect to (%s) on port (%d)\n\r", ECHO_SERVER_ADDRESS2, ECHO_SERVER_PORT2);
+        }
+        _isConnectedServer2=true;
+        pc.printf("Connected to Server at %s\n\r",ECHO_SERVER_ADDRESS2);
+    */
+
+
+    while(true) {
+      
+        // Connect to Server1
+        //TODO: try to connect to both servers
+        //TODO: only try 5 times after ti server1 goes down
+        //TODO: cual es la diferencia entre recieved_all y recieved
+        //TOTRY: que valor regresa cuando hace el connect???
+        
+        //QUESTION: que son los numero que aparecen despues de los dos puntos, 
+        //parece ser uqe es el numero que noceciones que lleva acabo 192.168.1.81:49160
+        //NOSIRVE: si se conecta los dos micros  con el programa de TCP Server4 y se les pide un reply
+        //los micros no contestan y para terminarla si pides dos veces un reply se queda colgado ..        
+        //ACCOMPLISH: los colores de los leds ya responen de acuerdo a la conexion
+        
+        //GetPersonStatus(1);
+
+        for(int i=0,isConServer1=0; i<2 && isConServer1==0; i++) {
+            if(socketTCP1.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) == -1) {
+                _isConnectedServer1=false;
+                pc.printf("Unable to connect1 to (%s) on port (%d)\n\r", ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1);
+                pc.printf("TRY SERVER 1 number (%d)\n\r",(i+1));
+                isConServer1=0;
+            } else {
+                _isConnectedServer1=socketTCP1.is_connected();
+                pc.printf("Ya se conecto con el servidor 1\n\r");
+                isConServer1=1;
+                wait(1);
+            
+                char hello[] = "Hello World\n\r";
+                printf("Sending  message to Server : '%s' \n",hello);
+                socketTCP1.send_all(hello, sizeof(hello) - 1);
+                
+                
+                
+        
+            }
+        }//END FOR1
+        
+                for(int i=0,isConServer2=0; i<2 && isConServer2==0; i++) {
+                    if(socketTCP2.connect(ECHO_SERVER_ADDRESS2, ECHO_SERVER_PORT2) == -1) {
+                        _isConnectedServer2=false;
+                        pc.printf("Unable to connect2 to (%s) on port (%d)\n\r", ECHO_SERVER_ADDRESS2, ECHO_SERVER_PORT2);
+                        pc.printf("TRY SERVER 2 number (%d)\n\r",(i+1));
+                        isConServer2=0;
+                        //wait(1);
+                    } else {
+                        _isConnectedServer2=socketTCP2.is_connected();
+                        pc.printf("Ya se conecto con el servidor 2\n\r");
+                        isConServer2=1;
+                    }
+                }//END FOR2
+        
+
+        //RECEIVED from TCP SERVER1
+        n1 = socketTCP1.receive_all(buf1, 256);
+        buf1[n1] = '\0';
+        if(n1>0) {
+            pc.printf("Received message from server1 IF: '%s'\n\r", buf1);
+             socketTCP1.close();
+
+        } else {
+            //_isConnectedServer1==false; //quiere decir que se desconecto del servidor
+            pc.printf("Not received1 ELSE value of lenght: '%u'\n\r",strlen(buf1));
+            socketTCP1.close();
+            //isConnectedServer1=false;
+        }
+        //socketTCP1.close();
+        //socketTCP2.close();
+
+        if(strcmp(buf1,"reply")==0) {
+            // SEND to server1
+            //Entra pero no puede mandar los datos 
+            // pc.printf("Entro a la funcion strcmp: \n\r");
+            if(socketTCP1.connect(ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1) == -1) {
+                pc.printf("Unable to connect1 to (%s) on port (%d)\n\r", ECHO_SERVER_ADDRESS1, ECHO_SERVER_PORT1);               
+                }
+                
+            char c_myIP[] = "192.168.1.77\n\r";
+            pc.printf("Sending  message to Server : %s \n\r",c_myIP);
+            socketTCP1.send_all(c_myIP, sizeof(c_myIP) - 1); 
+            socketTCP1.close();
+        }
+        //socketTCP1.close();
+
+
+        
+                //RECEIVED from TCP SERVER2
+                n2 = socketTCP2.receive(buf2, 256);
+                buf2[n2] = '\0';
+                if(n2>0) {
+                    pc.printf("Received message from server2 IF: '%s'\n\r", buf2);
+                    socketTCP2.close();
+                    //isConnectedServer1=false;
+                } else {
+                    //_isConnectedServer1==false; //quiere decir que se desconecto del servidor
+                    pc.printf("Not received2 ELSE value of lenght: '%u'\n\r",strlen(buf2));
+                    socketTCP2.close();
+                    //isConnectedServer1=false;
+                }
+        //
+    }// END while
+    eth.disconnect();
+    
+    
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sat Dec 05 17:46:07 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#6d90423c236e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 05 17:46:07 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file