This is the client side of our motion detection security scanner system.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of Ethernet_UDP_client by
Need to use this program too.
https://developer.mbed.org/users/dereklstinson/code/Motions_Secure_Server_IUPUI/
Revision 1:2f91eff1bb80, committed 2016-12-16
- Comitter:
- dereklstinson
- Date:
- Fri Dec 16 01:02:08 2016 +0000
- Parent:
- 0:29858159c001
- Commit message:
- version .01 alpha
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 29858159c001 -r 2f91eff1bb80 main.cpp --- a/main.cpp Wed Dec 23 21:00:27 2015 +0000 +++ b/main.cpp Fri Dec 16 01:02:08 2016 +0000 @@ -45,23 +45,36 @@ DigitalOut red(LED_RED); //debug led DigitalOut green(LED_GREEN); //debug led - - +DigitalIn button(SW3); +DigitalIn button2(SW2); +DigitalOut led(PTD3); //ARDUINO D12 compareable /*--VARIABLES---------------------------------------------------------------------------*/ int n; //size of received message char in_buffer[1]; //create receive buffer char counter[1] = {0}; //sample send buffer - +Ticker flashes; /*--FUNCTION DECLARATIONS---------------------------------------------------------------*/ void init_usb(void); //initializes pc.printf if required void init_eth(void); //initializes Ethernet void end_eth(void); //closes Ethernet socket int main(void); //main - +void alarmLight(); /*--FUNCTION DEFINITIONS----------------------------------------------------------------*/ +/***********ALARM************************************************************************/ + +void alarmLight(){ + if (in_buffer[0] =='z' || led ==1){ + + red=!red; + led=!led; + + + +} +} /*****************************************************************************INIT_USB***/ void init_usb(void) { @@ -95,25 +108,32 @@ { red = 0; //client green = 1; - + // led = 1; init_usb(); //initialize the PC interface init_eth(); //initialize the Ethernet connection - + flashes.attach(&alarmLight,.1); while(true) //repeat forever - { - pc.printf("\nCLIENT - Sending '%i' to server %s\r\n", counter[0], SERVER_IP); //print message to send - sock.sendTo(server, counter, sizeof(counter)); //send message + { + if(button2==0) counter[0]='x'; + if(button==0) counter[0]='b'; + pc.printf("\nCLIENT - Sending '%i' to server %s\r\n", counter[0], SERVER_IP); //print message to send + sock.sendTo(server, counter, sizeof(counter)); + pc.printf("CLIENT - Waiting for UDP packet...\r\n"); //wait for message n = sock.receiveFrom(server, in_buffer, sizeof(in_buffer)); //receive message from server in_buffer[n] = '\0'; //add \0 to end of message pc.printf("CLIENT - Received '%i' from server %s\r\n", in_buffer[0], SERVER_IP); //print message received - + + alarmLight(); + + counter[0] = (counter[0] + 1)%11; //only count up to 10, then reset to 0 - wait(1); //wait 1 second + // wait(1); + //wait 1 second } } //end main()