AWS IoT demonstration using the Avnet Shield (AT&T LTE) and the FRDM-K64F target board.
Dependencies: K64F_FATFileSystem
Fork of mbed-os-example-tls-tls-client by
WNCInterface/WNCSocket/WNCEndpoint.cpp@25:91d771247ac8, 2016-12-19 (annotated)
- Committer:
- ampembeng
- Date:
- Mon Dec 19 20:52:28 2016 +0000
- Revision:
- 25:91d771247ac8
- Parent:
- 15:6f2798e45099
Updated the look/feel of the Python GUI to match the AT&T locker demo S3 page. Added "assets" folder to support this. Updated the README.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ampembeng | 15:6f2798e45099 | 1 | /* ===================================================================== |
ampembeng | 15:6f2798e45099 | 2 | Copyright © 2016, Avnet (R) |
ampembeng | 15:6f2798e45099 | 3 | |
ampembeng | 15:6f2798e45099 | 4 | Contributors: |
ampembeng | 15:6f2798e45099 | 5 | * James M Flynn, www.em.avnet.com |
ampembeng | 15:6f2798e45099 | 6 | |
ampembeng | 15:6f2798e45099 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
ampembeng | 15:6f2798e45099 | 8 | you may not use this file except in compliance with the License. |
ampembeng | 15:6f2798e45099 | 9 | You may obtain a copy of the License at |
ampembeng | 15:6f2798e45099 | 10 | |
ampembeng | 15:6f2798e45099 | 11 | http://www.apache.org/licenses/LICENSE-2.0 |
ampembeng | 15:6f2798e45099 | 12 | |
ampembeng | 15:6f2798e45099 | 13 | Unless required by applicable law or agreed to in writing, |
ampembeng | 15:6f2798e45099 | 14 | software distributed under the License is distributed on an |
ampembeng | 15:6f2798e45099 | 15 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
ampembeng | 15:6f2798e45099 | 16 | either express or implied. See the License for the specific |
ampembeng | 15:6f2798e45099 | 17 | language governing permissions and limitations under the License. |
ampembeng | 15:6f2798e45099 | 18 | |
ampembeng | 15:6f2798e45099 | 19 | @file WNCInterface.cpp |
ampembeng | 15:6f2798e45099 | 20 | @version 1.0 |
ampembeng | 15:6f2798e45099 | 21 | @date Sept 2016 |
ampembeng | 15:6f2798e45099 | 22 | |
ampembeng | 15:6f2798e45099 | 23 | ======================================================================== */ |
ampembeng | 15:6f2798e45099 | 24 | |
ampembeng | 15:6f2798e45099 | 25 | #include "../WNCInterface.h" |
ampembeng | 15:6f2798e45099 | 26 | #include "WNCSocket.h" |
ampembeng | 15:6f2798e45099 | 27 | #include "WNCEndpoint.h" |
ampembeng | 15:6f2798e45099 | 28 | |
ampembeng | 15:6f2798e45099 | 29 | WNCEndpoint::WNCEndpoint() { |
ampembeng | 15:6f2798e45099 | 30 | reset_address(); |
ampembeng | 15:6f2798e45099 | 31 | } |
ampembeng | 15:6f2798e45099 | 32 | |
ampembeng | 15:6f2798e45099 | 33 | WNCEndpoint::~WNCEndpoint() {} |
ampembeng | 15:6f2798e45099 | 34 | |
ampembeng | 15:6f2798e45099 | 35 | void WNCEndpoint::reset_address(void) { |
ampembeng | 15:6f2798e45099 | 36 | std::memset(&_epAddr, 0, sizeof(struct EndPointAddr)); |
ampembeng | 15:6f2798e45099 | 37 | } |
ampembeng | 15:6f2798e45099 | 38 | |
ampembeng | 15:6f2798e45099 | 39 | // |
ampembeng | 15:6f2798e45099 | 40 | // It is possible to call set_address with either a URL or |
ampembeng | 15:6f2798e45099 | 41 | // an IP address. So try each in-turn and set the end point |
ampembeng | 15:6f2798e45099 | 42 | // address. |
ampembeng | 15:6f2798e45099 | 43 | // |
ampembeng | 15:6f2798e45099 | 44 | |
ampembeng | 15:6f2798e45099 | 45 | int WNCEndpoint::set_address(const char* host, const int port) { |
ampembeng | 15:6f2798e45099 | 46 | // IP Address |
ampembeng | 15:6f2798e45099 | 47 | char address[5]; |
ampembeng | 15:6f2798e45099 | 48 | int rslt; |
ampembeng | 15:6f2798e45099 | 49 | |
ampembeng | 15:6f2798e45099 | 50 | CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail); |
ampembeng | 15:6f2798e45099 | 51 | |
ampembeng | 15:6f2798e45099 | 52 | reset_address(); |
ampembeng | 15:6f2798e45099 | 53 | _epAddr.port = port; //go ahead and save the port |
ampembeng | 15:6f2798e45099 | 54 | |
ampembeng | 15:6f2798e45099 | 55 | // Dot-decimal notation? |
ampembeng | 15:6f2798e45099 | 56 | rslt = std::sscanf(host, "%3u.%3u.%3u.%3u", |
ampembeng | 15:6f2798e45099 | 57 | (unsigned int*)&address[0], (unsigned int*)&address[1], |
ampembeng | 15:6f2798e45099 | 58 | (unsigned int*)&address[2], (unsigned int*)&address[3]); |
ampembeng | 15:6f2798e45099 | 59 | |
ampembeng | 15:6f2798e45099 | 60 | M_LOCK; |
ampembeng | 15:6f2798e45099 | 61 | if (rslt != 4) // No, need to resolve address with DNS |
ampembeng | 15:6f2798e45099 | 62 | WNCInterface::_pwnc->resolveUrl(0,host); |
ampembeng | 15:6f2798e45099 | 63 | else |
ampembeng | 15:6f2798e45099 | 64 | WNCInterface::_pwnc->setIpAddr(0,host); |
ampembeng | 15:6f2798e45099 | 65 | |
ampembeng | 15:6f2798e45099 | 66 | rslt = WNCInterface::_pwnc->getIpAddr(0,_epAddr.IP); |
ampembeng | 15:6f2798e45099 | 67 | M_ULOCK; |
ampembeng | 15:6f2798e45099 | 68 | return rslt; |
ampembeng | 15:6f2798e45099 | 69 | } |
ampembeng | 15:6f2798e45099 | 70 | |
ampembeng | 15:6f2798e45099 | 71 | char* WNCEndpoint::get_address() { |
ampembeng | 15:6f2798e45099 | 72 | return _epAddr.IP; |
ampembeng | 15:6f2798e45099 | 73 | } |
ampembeng | 15:6f2798e45099 | 74 | |
ampembeng | 15:6f2798e45099 | 75 | int WNCEndpoint::get_port() { |
ampembeng | 15:6f2798e45099 | 76 | return _epAddr.port; |
ampembeng | 15:6f2798e45099 | 77 | } |
ampembeng | 15:6f2798e45099 | 78 | |
ampembeng | 15:6f2798e45099 | 79 |