• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2014 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Ian Craggs - initial API and implementation and/or initial documentation
15  *******************************************************************************/
16 
17 #ifndef ARDUINOWIFIIPSTACK_H
18 #define ARDUINOWIFIIPSTACK_H
19 
20 #include <WiFi.h>
21 
22 class WifiIPStack
23 {
24 public:
WifiIPStack()25     WifiIPStack()
26     {
27         //WiFi.begin();              // Use DHCP
28         iface.setTimeout(1000);    // 1 second Timeout
29     }
30 
connect(char * hostname,int port)31     int connect(char* hostname, int port)
32     {
33         return iface.connect(hostname, port);
34     }
35 
connect(uint32_t hostname,int port)36     int connect(uint32_t hostname, int port)
37     {
38         return iface.connect(hostname, port);
39     }
40 
read(char * buffer,int len,int timeout)41     int read(char* buffer, int len, int timeout)
42     {
43         iface.setTimeout(timeout);
44         while(!iface.available());
45         return iface.readBytes(buffer, len);
46     }
47 
write(char * buffer,int len,int timeout)48     int write(char* buffer, int len, int timeout)
49     {
50         iface.setTimeout(timeout);
51         return iface.write((uint8_t*)buffer, len);
52     }
53 
disconnect()54     int disconnect()
55     {
56         iface.stop();
57         return 0;
58     }
59 
60 private:
61 
62     WiFiClient iface;
63 
64 };
65 
66 #endif
67 
68 
69 
70