PIR sensor
Fork of WizFi310Interface_Legacy_newv2 by
WizFi310Interface.cpp@2:3194ebe06182, 2017-09-18 (annotated)
- Committer:
- ajeet3004
- Date:
- Mon Sep 18 08:11:28 2017 +0000
- Revision:
- 2:3194ebe06182
- Parent:
- 1:e08ea0ee2788
- Child:
- 3:8d47f7e3f9d6
bgh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaizen | 0:774ff1e8b26b | 1 | /* |
kaizen | 0:774ff1e8b26b | 2 | * Copyright (C) 2013 gsfan, MIT License |
kaizen | 0:774ff1e8b26b | 3 | * |
kaizen | 0:774ff1e8b26b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
kaizen | 0:774ff1e8b26b | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
kaizen | 0:774ff1e8b26b | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
kaizen | 0:774ff1e8b26b | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
kaizen | 0:774ff1e8b26b | 8 | * furnished to do so, subject to the following conditions: |
kaizen | 0:774ff1e8b26b | 9 | * |
kaizen | 0:774ff1e8b26b | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
kaizen | 0:774ff1e8b26b | 11 | * substantial portions of the Software. |
kaizen | 0:774ff1e8b26b | 12 | * |
kaizen | 0:774ff1e8b26b | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
kaizen | 0:774ff1e8b26b | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
kaizen | 0:774ff1e8b26b | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kaizen | 0:774ff1e8b26b | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kaizen | 0:774ff1e8b26b | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kaizen | 0:774ff1e8b26b | 18 | */ |
kaizen | 0:774ff1e8b26b | 19 | /* Copyright (C) 2014 Wiznet, MIT License |
kaizen | 0:774ff1e8b26b | 20 | * port to the Wiznet Module WizFi250 |
kaizen | 0:774ff1e8b26b | 21 | */ |
kaizen | 0:774ff1e8b26b | 22 | /* Copyright (C) 2017 Wiznet, MIT License |
kaizen | 0:774ff1e8b26b | 23 | * port to the Wiznet Module WizFi310 |
kaizen | 0:774ff1e8b26b | 24 | */ |
kaizen | 0:774ff1e8b26b | 25 | |
kaizen | 0:774ff1e8b26b | 26 | |
kaizen | 0:774ff1e8b26b | 27 | #include "WizFi310Interface.h" |
kaizen | 0:774ff1e8b26b | 28 | |
kaizen | 0:774ff1e8b26b | 29 | WizFi310Interface::WizFi310Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud): |
kaizen | 0:774ff1e8b26b | 30 | WizFi310(tx, rx, cts, rts, reset, alarm, baud) |
kaizen | 0:774ff1e8b26b | 31 | { |
kaizen | 0:774ff1e8b26b | 32 | |
kaizen | 0:774ff1e8b26b | 33 | } |
kaizen | 0:774ff1e8b26b | 34 | |
kaizen | 0:774ff1e8b26b | 35 | int WizFi310Interface::init(const char *name) |
kaizen | 0:774ff1e8b26b | 36 | { |
kaizen | 1:e08ea0ee2788 | 37 | startup(); |
kaizen | 0:774ff1e8b26b | 38 | return setAddress(name); |
kaizen | 0:774ff1e8b26b | 39 | } |
kaizen | 0:774ff1e8b26b | 40 | |
kaizen | 0:774ff1e8b26b | 41 | int WizFi310Interface::init(const char* ip, const char* netmask, const char* gateway, const char* name) |
kaizen | 0:774ff1e8b26b | 42 | { |
kaizen | 0:774ff1e8b26b | 43 | return setAddress(ip, netmask, gateway, name); |
kaizen | 0:774ff1e8b26b | 44 | } |
kaizen | 0:774ff1e8b26b | 45 | |
kaizen | 0:774ff1e8b26b | 46 | int WizFi310Interface::connect(Security sec, const char* ssid, const char* phrase, WiFiMode mode) |
kaizen | 0:774ff1e8b26b | 47 | { |
kaizen | 0:774ff1e8b26b | 48 | setSsid(ssid); |
kaizen | 0:774ff1e8b26b | 49 | setSec(sec, phrase); |
kaizen | 0:774ff1e8b26b | 50 | |
kaizen | 0:774ff1e8b26b | 51 | switch (mode) |
kaizen | 0:774ff1e8b26b | 52 | { |
kaizen | 0:774ff1e8b26b | 53 | case WM_STATION: |
kaizen | 0:774ff1e8b26b | 54 | return join(WizFi310::WM_STATION); |
kaizen | 0:774ff1e8b26b | 55 | case WM_AP: |
kaizen | 0:774ff1e8b26b | 56 | return join(WizFi310::WM_AP); |
kaizen | 0:774ff1e8b26b | 57 | } |
kaizen | 0:774ff1e8b26b | 58 | |
kaizen | 0:774ff1e8b26b | 59 | return 0; |
kaizen | 0:774ff1e8b26b | 60 | } |
kaizen | 0:774ff1e8b26b | 61 | |
kaizen | 0:774ff1e8b26b | 62 | int WizFi310Interface::disconnect() |
kaizen | 0:774ff1e8b26b | 63 | { |
kaizen | 0:774ff1e8b26b | 64 | return cmdWLEAVE(); |
kaizen | 0:774ff1e8b26b | 65 | } |
kaizen | 0:774ff1e8b26b | 66 | |
ajeet3004 | 2:3194ebe06182 | 67 | |
ajeet3004 | 2:3194ebe06182 | 68 | |
kaizen | 0:774ff1e8b26b | 69 | char* WizFi310Interface::getMACAddress() |
kaizen | 0:774ff1e8b26b | 70 | { |
kaizen | 0:774ff1e8b26b | 71 | return _state.mac; |
kaizen | 0:774ff1e8b26b | 72 | } |
kaizen | 0:774ff1e8b26b | 73 | |
kaizen | 0:774ff1e8b26b | 74 | char* WizFi310Interface::getIPAddress() |
kaizen | 0:774ff1e8b26b | 75 | { |
kaizen | 0:774ff1e8b26b | 76 | return _state.ip; |
kaizen | 0:774ff1e8b26b | 77 | } |
kaizen | 0:774ff1e8b26b | 78 | |
kaizen | 0:774ff1e8b26b | 79 | char* WizFi310Interface::getGateway() |
kaizen | 0:774ff1e8b26b | 80 | { |
kaizen | 0:774ff1e8b26b | 81 | return _state.gateway; |
kaizen | 0:774ff1e8b26b | 82 | } |
kaizen | 0:774ff1e8b26b | 83 | |
kaizen | 0:774ff1e8b26b | 84 | int WizFi310Interface::setAntMode(AntennaMode mode) |
kaizen | 0:774ff1e8b26b | 85 | { |
kaizen | 0:774ff1e8b26b | 86 | return cmdWANT(mode); |
kaizen | 0:774ff1e8b26b | 87 | } |
ajeet3004 | 2:3194ebe06182 | 88 | //int WizFi310Interface::test() |
ajeet3004 | 2:3194ebe06182 | 89 | //{ |
ajeet3004 | 2:3194ebe06182 | 90 | // return cmdWSTATUS(); |
ajeet3004 | 2:3194ebe06182 | 91 | //} |
kaizen | 0:774ff1e8b26b | 92 | |
ajeet3004 | 2:3194ebe06182 | 93 | |
ajeet3004 | 2:3194ebe06182 | 94 | int WizFi310Interface::test_twitter() |
ajeet3004 | 2:3194ebe06182 | 95 | { |
ajeet3004 | 2:3194ebe06182 | 96 | // TCPSocketConnection(); |
ajeet3004 | 2:3194ebe06182 | 97 | int errConnect; |
ajeet3004 | 2:3194ebe06182 | 98 | char http_cmd[1000] = ""; |
ajeet3004 | 2:3194ebe06182 | 99 | char buffer[2048] = ""; |
ajeet3004 | 2:3194ebe06182 | 100 | TCPSocketConnection TCPconnection; |
ajeet3004 | 2:3194ebe06182 | 101 | |
ajeet3004 | 2:3194ebe06182 | 102 | char *p="arduino-tweet.appspot.com"; |
ajeet3004 | 2:3194ebe06182 | 103 | int a=TCPconnection.connect(p,80); |
ajeet3004 | 2:3194ebe06182 | 104 | while (true) { |
ajeet3004 | 2:3194ebe06182 | 105 | if(a!=0) { |
ajeet3004 | 2:3194ebe06182 | 106 | printf("\r\ncould not connect to socket : error = %d\r\n", p); |
ajeet3004 | 2:3194ebe06182 | 107 | a = TCPconnection.connect(p, 80); |
ajeet3004 | 2:3194ebe06182 | 108 | } else { |
ajeet3004 | 2:3194ebe06182 | 109 | printf("socket connected\r\n"); |
ajeet3004 | 2:3194ebe06182 | 110 | break; |
ajeet3004 | 2:3194ebe06182 | 111 | } |
ajeet3004 | 2:3194ebe06182 | 112 | } |
ajeet3004 | 2:3194ebe06182 | 113 | |
ajeet3004 | 2:3194ebe06182 | 114 | sprintf((char *)http_cmd,"GET http://arduino-tweet.appspot.com/update?token=904626807491530753-sOaChz44g9YFS7EuvRkR75l1W9T303K&status=hell\r\n"); |
ajeet3004 | 2:3194ebe06182 | 115 | |
ajeet3004 | 2:3194ebe06182 | 116 | TCPconnection.send_all(http_cmd, sizeof(http_cmd)); |
ajeet3004 | 2:3194ebe06182 | 117 | |
ajeet3004 | 2:3194ebe06182 | 118 | TCPconnection.receive_all(buffer, sizeof(buffer)); |
ajeet3004 | 2:3194ebe06182 | 119 | printf("%s",buffer); |
ajeet3004 | 2:3194ebe06182 | 120 | |
ajeet3004 | 2:3194ebe06182 | 121 | |
ajeet3004 | 2:3194ebe06182 | 122 | return 0; |
ajeet3004 | 2:3194ebe06182 | 123 | } |
kaizen | 0:774ff1e8b26b | 124 | //char* getNetworkMask(); |
ajeet3004 | 2:3194ebe06182 | 125 | |
ajeet3004 | 2:3194ebe06182 | 126 |