
WIZwiki-W7500 mbed platform & IFTTT maker channel. The aim of this project is to catch a thief when I wasn't home. If the PIR sensor catches a thief. It will send notification to your mobile device.
Dependencies: IFTTT WIZnetInterface mbed
main.cpp@0:801a968f1625, 2015-07-30 (annotated)
- Committer:
- jehoon
- Date:
- Thu Jul 30 05:36:01 2015 +0000
- Revision:
- 0:801a968f1625
Stop Thief - WIZwiki-W7500 mbed platform & IFTTT maker channel.; The aim of this project is to catch a thief when I wasn't home.; If the PIR sensor catches a thief. It will send notification to your mobile device.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jehoon | 0:801a968f1625 | 1 | #include "mbed.h" |
jehoon | 0:801a968f1625 | 2 | #include "EthernetInterface.h" |
jehoon | 0:801a968f1625 | 3 | #include "TCPSocketConnection.h" |
jehoon | 0:801a968f1625 | 4 | #include "ifttt.h" |
jehoon | 0:801a968f1625 | 5 | |
jehoon | 0:801a968f1625 | 6 | #define YourEventName "YOUREVENT" |
jehoon | 0:801a968f1625 | 7 | #define YourSecretKey "YOURKEY" |
jehoon | 0:801a968f1625 | 8 | |
jehoon | 0:801a968f1625 | 9 | #define DuringSafety 5 //hours |
jehoon | 0:801a968f1625 | 10 | |
jehoon | 0:801a968f1625 | 11 | EthernetInterface eth; |
jehoon | 0:801a968f1625 | 12 | Serial pc(USBTX, USBRX); // tx, rx |
jehoon | 0:801a968f1625 | 13 | DigitalOut led(LED1); |
jehoon | 0:801a968f1625 | 14 | AnalogIn sw(A0); |
jehoon | 0:801a968f1625 | 15 | DigitalIn pir(D8,PullUp); |
jehoon | 0:801a968f1625 | 16 | Timer timer; |
jehoon | 0:801a968f1625 | 17 | |
jehoon | 0:801a968f1625 | 18 | int main() |
jehoon | 0:801a968f1625 | 19 | { |
jehoon | 0:801a968f1625 | 20 | int phy_link; |
jehoon | 0:801a968f1625 | 21 | int flag = 0; |
jehoon | 0:801a968f1625 | 22 | int onetimeflag = 0; |
jehoon | 0:801a968f1625 | 23 | float sec = 0.0; |
jehoon | 0:801a968f1625 | 24 | |
jehoon | 0:801a968f1625 | 25 | pc.baud(115200); |
jehoon | 0:801a968f1625 | 26 | printf("Wait a second...\r\n"); |
jehoon | 0:801a968f1625 | 27 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}; |
jehoon | 0:801a968f1625 | 28 | eth.init(mac_addr); //Use DHCP |
jehoon | 0:801a968f1625 | 29 | eth.connect(); |
jehoon | 0:801a968f1625 | 30 | |
jehoon | 0:801a968f1625 | 31 | do{ |
jehoon | 0:801a968f1625 | 32 | phy_link = eth.ethernet_link(); |
jehoon | 0:801a968f1625 | 33 | printf("..."); |
jehoon | 0:801a968f1625 | 34 | wait(2); |
jehoon | 0:801a968f1625 | 35 | }while(!phy_link); |
jehoon | 0:801a968f1625 | 36 | printf("\r\nIP Address is %s \r\n", eth.getIPAddress()); |
jehoon | 0:801a968f1625 | 37 | TCPSocketConnection sock; |
jehoon | 0:801a968f1625 | 38 | |
jehoon | 0:801a968f1625 | 39 | // Initialize ifttt object, add up to 3 optional values, trigger event. |
jehoon | 0:801a968f1625 | 40 | IFTTT ifttt(YourEventName,YourSecretKey, &sock); // EventName, Secret Key, socket to use |
jehoon | 0:801a968f1625 | 41 | |
jehoon | 0:801a968f1625 | 42 | |
jehoon | 0:801a968f1625 | 43 | while(1) { |
jehoon | 0:801a968f1625 | 44 | |
jehoon | 0:801a968f1625 | 45 | if(!pir){ |
jehoon | 0:801a968f1625 | 46 | led = 0; |
jehoon | 0:801a968f1625 | 47 | onetimeflag = 0; |
jehoon | 0:801a968f1625 | 48 | printf("Safety\r\n"); |
jehoon | 0:801a968f1625 | 49 | if(!flag){ |
jehoon | 0:801a968f1625 | 50 | timer.start(); |
jehoon | 0:801a968f1625 | 51 | flag = 1; |
jehoon | 0:801a968f1625 | 52 | } |
jehoon | 0:801a968f1625 | 53 | wait(1); |
jehoon | 0:801a968f1625 | 54 | } |
jehoon | 0:801a968f1625 | 55 | else if(pir && (float)sw.read()>=0.9 && !onetimeflag){ |
jehoon | 0:801a968f1625 | 56 | led=1; |
jehoon | 0:801a968f1625 | 57 | onetimeflag=1; |
jehoon | 0:801a968f1625 | 58 | printf("Thief Detected\r\n"); |
jehoon | 0:801a968f1625 | 59 | ifttt.addIngredients("===WARNING===","The Thief was found","Report him to the police"); |
jehoon | 0:801a968f1625 | 60 | ifttt.trigger(); |
jehoon | 0:801a968f1625 | 61 | timer.reset(); |
jehoon | 0:801a968f1625 | 62 | wait(1); |
jehoon | 0:801a968f1625 | 63 | } |
jehoon | 0:801a968f1625 | 64 | sec = timer.read(); |
jehoon | 0:801a968f1625 | 65 | if(sec > DuringSafety*3600 && (float)sw.read()>=0.9){ |
jehoon | 0:801a968f1625 | 66 | timer.reset(); |
jehoon | 0:801a968f1625 | 67 | ifttt.addIngredients("Your home in safety during",(char*)DuringSafety,"hours!"); |
jehoon | 0:801a968f1625 | 68 | ifttt.trigger(); |
jehoon | 0:801a968f1625 | 69 | } |
jehoon | 0:801a968f1625 | 70 | } |
jehoon | 0:801a968f1625 | 71 | |
jehoon | 0:801a968f1625 | 72 | } |