Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WifiIPStack.h Source File

WifiIPStack.h

00001 /*******************************************************************************
00002  * Copyright (c) 2014 IBM Corp.
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Ian Craggs - initial API and implementation and/or initial documentation
00015  *******************************************************************************/
00016 
00017 #ifndef ARDUINOWIFIIPSTACK_H
00018 #define ARDUINOWIFIIPSTACK_H
00019 
00020 #include <WiFi.h>
00021 
00022 class WifiIPStack 
00023 {
00024 public:    
00025     WifiIPStack()
00026     {
00027         //WiFi.begin();              // Use DHCP
00028         iface.setTimeout(1000);    // 1 second Timeout 
00029     }
00030     
00031     int connect(char* hostname, int port)
00032     {
00033         return iface.connect(hostname, port);
00034     }
00035 
00036     int connect(uint32_t hostname, int port)
00037     {
00038         return iface.connect(hostname, port);
00039     }
00040 
00041     int read(char* buffer, int len, int timeout)
00042     {
00043         iface.setTimeout(timeout);
00044         while(!iface.available());
00045         return iface.readBytes(buffer, len);
00046     }
00047     
00048     int write(char* buffer, int len, int timeout)
00049     {
00050         iface.setTimeout(timeout);  
00051         return iface.write((uint8_t*)buffer, len);
00052     }
00053     
00054     int disconnect()
00055     {
00056         iface.stop();
00057         return 0;
00058     }
00059     
00060 private:
00061 
00062     WiFiClient iface;
00063     
00064 };
00065 
00066 #endif
00067 
00068 
00069