see http://mbed.org/users/okini3939/notebook/wattmeter-shield-on-mbed/

Dependencies:   mbed

Fork of GSwifi_xively by gs fan

Committer:
okini3939
Date:
Wed Nov 27 08:18:45 2013 +0000
Revision:
4:9a2415f2ab07
update GSwifiInterface library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 4:9a2415f2ab07 1 /* Copyright (C) 2012 mbed.org, MIT License
okini3939 4:9a2415f2ab07 2 *
okini3939 4:9a2415f2ab07 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
okini3939 4:9a2415f2ab07 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
okini3939 4:9a2415f2ab07 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
okini3939 4:9a2415f2ab07 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
okini3939 4:9a2415f2ab07 7 * furnished to do so, subject to the following conditions:
okini3939 4:9a2415f2ab07 8 *
okini3939 4:9a2415f2ab07 9 * The above copyright notice and this permission notice shall be included in all copies or
okini3939 4:9a2415f2ab07 10 * substantial portions of the Software.
okini3939 4:9a2415f2ab07 11 *
okini3939 4:9a2415f2ab07 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
okini3939 4:9a2415f2ab07 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
okini3939 4:9a2415f2ab07 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
okini3939 4:9a2415f2ab07 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
okini3939 4:9a2415f2ab07 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
okini3939 4:9a2415f2ab07 17 */
okini3939 4:9a2415f2ab07 18 /* Copyright (C) 2013 gsfan, MIT License
okini3939 4:9a2415f2ab07 19 * port to the GainSpan Wi-FI module GS1011
okini3939 4:9a2415f2ab07 20 */
okini3939 4:9a2415f2ab07 21 #include "Socket/Socket.h"
okini3939 4:9a2415f2ab07 22 #include "Socket/Endpoint.h"
okini3939 4:9a2415f2ab07 23 #include <cstring>
okini3939 4:9a2415f2ab07 24
okini3939 4:9a2415f2ab07 25 using std::memset;
okini3939 4:9a2415f2ab07 26
okini3939 4:9a2415f2ab07 27 Endpoint::Endpoint() {
okini3939 4:9a2415f2ab07 28 _ewifi = GSwifi::getInstance();
okini3939 4:9a2415f2ab07 29 if (_ewifi == NULL)
okini3939 4:9a2415f2ab07 30 error("Endpoint constructor error: no wifly instance available!\r\n");
okini3939 4:9a2415f2ab07 31 reset_address();
okini3939 4:9a2415f2ab07 32 }
okini3939 4:9a2415f2ab07 33 Endpoint::~Endpoint() {}
okini3939 4:9a2415f2ab07 34
okini3939 4:9a2415f2ab07 35 void Endpoint::reset_address(void) {
okini3939 4:9a2415f2ab07 36 _ipAddress[0] = '\0';
okini3939 4:9a2415f2ab07 37 _port = 0;
okini3939 4:9a2415f2ab07 38 }
okini3939 4:9a2415f2ab07 39
okini3939 4:9a2415f2ab07 40 int Endpoint::set_address(const char* host, const int port) {
okini3939 4:9a2415f2ab07 41 //Resolve DNS address or populate hard-coded IP address
okini3939 4:9a2415f2ab07 42 _port = port;
okini3939 4:9a2415f2ab07 43 return _ewifi->getHostByName(host, _ipAddress);
okini3939 4:9a2415f2ab07 44 }
okini3939 4:9a2415f2ab07 45
okini3939 4:9a2415f2ab07 46 char* Endpoint::get_address() {
okini3939 4:9a2415f2ab07 47 return _ipAddress;
okini3939 4:9a2415f2ab07 48 }
okini3939 4:9a2415f2ab07 49
okini3939 4:9a2415f2ab07 50 int Endpoint::get_port() {
okini3939 4:9a2415f2ab07 51 return _port;
okini3939 4:9a2415f2ab07 52 }