Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
SocketInterface.h@21:17bb3eddcbae, 2014-08-26 (annotated)
- Committer:
- dan_ackme
- Date:
- Tue Aug 26 16:38:19 2014 -0700
- Revision:
- 21:17bb3eddcbae
- Parent:
- 17:7268f365676b
Add TCP server API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan_ackme | 21:17bb3eddcbae | 1 | /** |
dan_ackme | 21:17bb3eddcbae | 2 | * ACKme WiConnect Host Library is licensed under the BSD licence: |
dan_ackme | 21:17bb3eddcbae | 3 | * |
dan_ackme | 21:17bb3eddcbae | 4 | * Copyright (c)2014 ACKme Networks. |
dan_ackme | 21:17bb3eddcbae | 5 | * All rights reserved. |
dan_ackme | 21:17bb3eddcbae | 6 | * |
dan_ackme | 21:17bb3eddcbae | 7 | * Redistribution and use in source and binary forms, with or without modification, |
dan_ackme | 21:17bb3eddcbae | 8 | * are permitted provided that the following conditions are met: |
dan_ackme | 21:17bb3eddcbae | 9 | * |
dan_ackme | 21:17bb3eddcbae | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
dan_ackme | 21:17bb3eddcbae | 11 | * this list of conditions and the following disclaimer. |
dan_ackme | 21:17bb3eddcbae | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
dan_ackme | 21:17bb3eddcbae | 13 | * this list of conditions and the following disclaimer in the documentation |
dan_ackme | 21:17bb3eddcbae | 14 | * and/or other materials provided with the distribution. |
dan_ackme | 21:17bb3eddcbae | 15 | * 3. The name of the author may not be used to endorse or promote products |
dan_ackme | 21:17bb3eddcbae | 16 | * derived from this software without specific prior written permission. |
dan_ackme | 21:17bb3eddcbae | 17 | * |
dan_ackme | 21:17bb3eddcbae | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED |
dan_ackme | 21:17bb3eddcbae | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
dan_ackme | 21:17bb3eddcbae | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
dan_ackme | 21:17bb3eddcbae | 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
dan_ackme | 21:17bb3eddcbae | 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
dan_ackme | 21:17bb3eddcbae | 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
dan_ackme | 21:17bb3eddcbae | 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
dan_ackme | 21:17bb3eddcbae | 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
dan_ackme | 21:17bb3eddcbae | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
dan_ackme | 21:17bb3eddcbae | 27 | * OF SUCH DAMAGE. |
dan_ackme | 0:ea85c4bb5e1f | 28 | */ |
dan_ackme | 0:ea85c4bb5e1f | 29 | #pragma once |
dan_ackme | 0:ea85c4bb5e1f | 30 | |
dan_ackme | 0:ea85c4bb5e1f | 31 | #include "Wiconnect.h" |
dan_ackme | 17:7268f365676b | 32 | #include "types/WiconnectSocket.h" |
dan_ackme | 0:ea85c4bb5e1f | 33 | #include "types/SocketIrqHandlerMap.h" |
dan_ackme | 0:ea85c4bb5e1f | 34 | |
dan_ackme | 0:ea85c4bb5e1f | 35 | |
dan_ackme | 11:ea484e1b7fc4 | 36 | /** |
dan_ackme | 11:ea484e1b7fc4 | 37 | * @namespace wiconnect |
dan_ackme | 11:ea484e1b7fc4 | 38 | */ |
dan_ackme | 0:ea85c4bb5e1f | 39 | namespace wiconnect { |
dan_ackme | 0:ea85c4bb5e1f | 40 | |
dan_ackme | 0:ea85c4bb5e1f | 41 | |
dan_ackme | 11:ea484e1b7fc4 | 42 | /** |
dan_ackme | 13:2b51f5267c92 | 43 | * @ingroup api_socket_types |
dan_ackme | 11:ea484e1b7fc4 | 44 | * |
dan_ackme | 11:ea484e1b7fc4 | 45 | * @brief The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. |
dan_ackme | 11:ea484e1b7fc4 | 46 | * A client socket connects to a remote server. |
dan_ackme | 11:ea484e1b7fc4 | 47 | * |
dan_ackme | 13:2b51f5267c92 | 48 | * @note This class is an interface to the Wiconnect class. It should never be |
dan_ackme | 13:2b51f5267c92 | 49 | * independently instantiated or the parent of another class. |
dan_ackme | 11:ea484e1b7fc4 | 50 | */ |
dan_ackme | 0:ea85c4bb5e1f | 51 | class SocketInterface |
dan_ackme | 0:ea85c4bb5e1f | 52 | { |
dan_ackme | 0:ea85c4bb5e1f | 53 | public: |
dan_ackme | 11:ea484e1b7fc4 | 54 | /** |
dan_ackme | 11:ea484e1b7fc4 | 55 | * @ingroup api_socket_misc |
dan_ackme | 11:ea484e1b7fc4 | 56 | * |
dan_ackme | 11:ea484e1b7fc4 | 57 | * @brief Close all opened sockets. |
dan_ackme | 13:2b51f5267c92 | 58 | * |
dan_ackme | 13:2b51f5267c92 | 59 | * @note This closes all open sockets on the MODULE side. |
dan_ackme | 13:2b51f5267c92 | 60 | * Socket objects on the HOST side will be still open until |
dan_ackme | 13:2b51f5267c92 | 61 | * issuing a read/write command to the module using the socket handle. |
dan_ackme | 13:2b51f5267c92 | 62 | * |
dan_ackme | 13:2b51f5267c92 | 63 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 64 | */ |
dan_ackme | 0:ea85c4bb5e1f | 65 | WiconnectResult closeAllSockets(); |
dan_ackme | 11:ea484e1b7fc4 | 66 | |
dan_ackme | 11:ea484e1b7fc4 | 67 | /** |
dan_ackme | 11:ea484e1b7fc4 | 68 | * @ingroup api_socket_misc |
dan_ackme | 11:ea484e1b7fc4 | 69 | * |
dan_ackme | 11:ea484e1b7fc4 | 70 | * @brief Register a host pin as an external interrupt. When the external interrupt is |
dan_ackme | 11:ea484e1b7fc4 | 71 | * triggered, the supplied callback is executed. |
dan_ackme | 13:2b51f5267c92 | 72 | * |
dan_ackme | 13:2b51f5267c92 | 73 | * This should be called before calling one of the connect methods below |
dan_ackme | 13:2b51f5267c92 | 74 | * with an irqPin parameter. |
dan_ackme | 13:2b51f5267c92 | 75 | * |
dan_ackme | 13:2b51f5267c92 | 76 | * Basically how this works is: |
dan_ackme | 13:2b51f5267c92 | 77 | * 1. The supplied irqPin is configured as an external interrupt pin. |
dan_ackme | 13:2b51f5267c92 | 78 | * 2. A connection is opened and configured with the same irqPin. This |
dan_ackme | 13:2b51f5267c92 | 79 | * irqPin physically connected to a GPIO on the WiFi module. |
dan_ackme | 13:2b51f5267c92 | 80 | * 3. When the WiFi module has data to send to the HOST it asserts the irqPin. |
dan_ackme | 13:2b51f5267c92 | 81 | * 4. The irqPin interrupt executes and calls the supplied handler. |
dan_ackme | 13:2b51f5267c92 | 82 | * 5. The handler should notify the HOST that the given irqPin has triggered |
dan_ackme | 13:2b51f5267c92 | 83 | * and have the associated socket read data from the module. |
dan_ackme | 13:2b51f5267c92 | 84 | * |
dan_ackme | 13:2b51f5267c92 | 85 | * @note arg1 of the handler contains the irqPin |
dan_ackme | 13:2b51f5267c92 | 86 | * |
dan_ackme | 13:2b51f5267c92 | 87 | * |
dan_ackme | 13:2b51f5267c92 | 88 | * @param[in] irqPin The HOST pin to configure as an external interrupt. |
dan_ackme | 13:2b51f5267c92 | 89 | * This pin should be physically connected to a module GPIO. |
dan_ackme | 13:2b51f5267c92 | 90 | * @param[in] handler Callback to be executed with the external irqPin interrupt triggers |
dan_ackme | 13:2b51f5267c92 | 91 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 92 | */ |
dan_ackme | 0:ea85c4bb5e1f | 93 | WiconnectResult registerSocketIrqHandler(Pin irqPin, const Callback &handler); |
dan_ackme | 11:ea484e1b7fc4 | 94 | |
dan_ackme | 11:ea484e1b7fc4 | 95 | /** |
dan_ackme | 11:ea484e1b7fc4 | 96 | * @ingroup api_socket_misc |
dan_ackme | 11:ea484e1b7fc4 | 97 | * |
dan_ackme | 11:ea484e1b7fc4 | 98 | * @brief Unregister a previously registered IRQ pin. |
dan_ackme | 13:2b51f5267c92 | 99 | * |
dan_ackme | 13:2b51f5267c92 | 100 | * This disables the given irqPin as an external interrupt. |
dan_ackme | 13:2b51f5267c92 | 101 | * Refer to registerSocketIrqHandler() for more information. |
dan_ackme | 13:2b51f5267c92 | 102 | * |
dan_ackme | 13:2b51f5267c92 | 103 | * @param[in] irqPin The HOST pin to unregister |
dan_ackme | 13:2b51f5267c92 | 104 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 105 | */ |
dan_ackme | 0:ea85c4bb5e1f | 106 | WiconnectResult unregisterSocketIrqHandler(Pin irqPin); |
dan_ackme | 0:ea85c4bb5e1f | 107 | |
dan_ackme | 11:ea484e1b7fc4 | 108 | |
dan_ackme | 11:ea484e1b7fc4 | 109 | /** |
dan_ackme | 11:ea484e1b7fc4 | 110 | * @ingroup api_socket_misc |
dan_ackme | 11:ea484e1b7fc4 | 111 | * |
dan_ackme | 11:ea484e1b7fc4 | 112 | * @brief Connect to remote server. |
dan_ackme | 13:2b51f5267c92 | 113 | * |
dan_ackme | 13:2b51f5267c92 | 114 | * This is the base method used by all the other connect methods. |
dan_ackme | 13:2b51f5267c92 | 115 | * |
dan_ackme | 17:7268f365676b | 116 | * @param[out] socket @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 117 | * @param[in] type The @ref SocketType of connection to open |
dan_ackme | 13:2b51f5267c92 | 118 | * @param[in] host The host/IP address of the remote server |
dan_ackme | 13:2b51f5267c92 | 119 | * @param[in] remortPort The port of the remote server |
dan_ackme | 13:2b51f5267c92 | 120 | * @param[in] localPort The port of the module's side of the connection |
dan_ackme | 13:2b51f5267c92 | 121 | * @param[in] args Depedent on the connection type |
dan_ackme | 13:2b51f5267c92 | 122 | * @param[in] irqPin Data available external interrupt pin. See registerSocketIrqHandler() for more info |
dan_ackme | 13:2b51f5267c92 | 123 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 124 | */ |
dan_ackme | 17:7268f365676b | 125 | WiconnectResult connect(WiconnectSocket &socket, SocketType type, const char *host, uint16_t remortPort, uint16_t localPort, const void *args, Pin irqPin); |
dan_ackme | 11:ea484e1b7fc4 | 126 | |
dan_ackme | 11:ea484e1b7fc4 | 127 | |
dan_ackme | 11:ea484e1b7fc4 | 128 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 129 | |
dan_ackme | 11:ea484e1b7fc4 | 130 | /** |
dan_ackme | 11:ea484e1b7fc4 | 131 | * @ingroup api_socket_tcp |
dan_ackme | 11:ea484e1b7fc4 | 132 | * |
dan_ackme | 11:ea484e1b7fc4 | 133 | * @brief Connect to remote TCP server. |
dan_ackme | 13:2b51f5267c92 | 134 | * |
dan_ackme | 17:7268f365676b | 135 | * @param[out] socket TCP @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 136 | * @param[in] host The host/IP address of the remote TCP server |
dan_ackme | 13:2b51f5267c92 | 137 | * @param[in] remortPort The port of the remote server |
dan_ackme | 13:2b51f5267c92 | 138 | * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info |
dan_ackme | 13:2b51f5267c92 | 139 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 140 | */ |
dan_ackme | 21:17bb3eddcbae | 141 | WiconnectResult tcpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, Pin irqPin = PIN_NC); |
dan_ackme | 21:17bb3eddcbae | 142 | |
dan_ackme | 21:17bb3eddcbae | 143 | |
dan_ackme | 21:17bb3eddcbae | 144 | // ------------------------------------------------------------------------ |
dan_ackme | 21:17bb3eddcbae | 145 | |
dan_ackme | 21:17bb3eddcbae | 146 | /** |
dan_ackme | 21:17bb3eddcbae | 147 | * @ingroup api_socket_tcp |
dan_ackme | 21:17bb3eddcbae | 148 | * |
dan_ackme | 21:17bb3eddcbae | 149 | * @brief Start internal TCP server and listen on specified port. |
dan_ackme | 21:17bb3eddcbae | 150 | * |
dan_ackme | 21:17bb3eddcbae | 151 | * @param[in] listeningPort The local port the server should listen on |
dan_ackme | 21:17bb3eddcbae | 152 | * @param[in] maxClients Optional, the maximum simultaneous connected clients, 0 is default, 1-8 valid range |
dan_ackme | 21:17bb3eddcbae | 153 | * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info |
dan_ackme | 21:17bb3eddcbae | 154 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 21:17bb3eddcbae | 155 | */ |
dan_ackme | 21:17bb3eddcbae | 156 | WiconnectResult tcpListen(uint16_t listeningPort, int maxClients = 0, Pin irqPin = PIN_NC); |
dan_ackme | 21:17bb3eddcbae | 157 | |
dan_ackme | 21:17bb3eddcbae | 158 | |
dan_ackme | 21:17bb3eddcbae | 159 | // ------------------------------------------------------------------------ |
dan_ackme | 21:17bb3eddcbae | 160 | |
dan_ackme | 21:17bb3eddcbae | 161 | /** |
dan_ackme | 21:17bb3eddcbae | 162 | * @ingroup api_socket_tcp |
dan_ackme | 21:17bb3eddcbae | 163 | * |
dan_ackme | 21:17bb3eddcbae | 164 | * @brief Wait for next client to connect to TCP server. |
dan_ackme | 21:17bb3eddcbae | 165 | * |
dan_ackme | 21:17bb3eddcbae | 166 | * @param[in] socket Socket to connected client |
dan_ackme | 21:17bb3eddcbae | 167 | * @param[in] timeoutMs Optional, specifiy maximum amount of time in ms to wait for a client |
dan_ackme | 21:17bb3eddcbae | 168 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 21:17bb3eddcbae | 169 | */ |
dan_ackme | 21:17bb3eddcbae | 170 | WiconnectResult tcpAccept(WiconnectSocket &socket, int timeoutMs = WICONNECT_WAIT_FOREVER); |
dan_ackme | 21:17bb3eddcbae | 171 | |
dan_ackme | 21:17bb3eddcbae | 172 | |
dan_ackme | 21:17bb3eddcbae | 173 | // ------------------------------------------------------------------------ |
dan_ackme | 21:17bb3eddcbae | 174 | |
dan_ackme | 21:17bb3eddcbae | 175 | /** |
dan_ackme | 21:17bb3eddcbae | 176 | * @ingroup api_socket_tcp |
dan_ackme | 21:17bb3eddcbae | 177 | * |
dan_ackme | 21:17bb3eddcbae | 178 | * @brief Stop TCP server from listening on port. Close all connected clients. |
dan_ackme | 21:17bb3eddcbae | 179 | * |
dan_ackme | 21:17bb3eddcbae | 180 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 21:17bb3eddcbae | 181 | */ |
dan_ackme | 21:17bb3eddcbae | 182 | WiconnectResult tcpServerStop(void); |
dan_ackme | 11:ea484e1b7fc4 | 183 | |
dan_ackme | 11:ea484e1b7fc4 | 184 | |
dan_ackme | 11:ea484e1b7fc4 | 185 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 186 | |
dan_ackme | 11:ea484e1b7fc4 | 187 | /** |
dan_ackme | 11:ea484e1b7fc4 | 188 | * @ingroup api_socket_tls |
dan_ackme | 11:ea484e1b7fc4 | 189 | * |
dan_ackme | 11:ea484e1b7fc4 | 190 | * @brief Connect to remote TLS server. |
dan_ackme | 13:2b51f5267c92 | 191 | * |
dan_ackme | 17:7268f365676b | 192 | * @param[out] socket TLS @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 193 | * @param[in] host The host/IP address of the remote TLS server |
dan_ackme | 13:2b51f5267c92 | 194 | * @param[in] remortPort The port of the remote server |
dan_ackme | 13:2b51f5267c92 | 195 | * @param[in] certFilename Optional, filename of certificate on module's file system |
dan_ackme | 13:2b51f5267c92 | 196 | * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info |
dan_ackme | 13:2b51f5267c92 | 197 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 198 | */ |
dan_ackme | 21:17bb3eddcbae | 199 | WiconnectResult tlsConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, const char *certFilename = NULL, Pin irqPin = PIN_NC); |
dan_ackme | 11:ea484e1b7fc4 | 200 | |
dan_ackme | 11:ea484e1b7fc4 | 201 | |
dan_ackme | 11:ea484e1b7fc4 | 202 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 203 | |
dan_ackme | 11:ea484e1b7fc4 | 204 | /** |
dan_ackme | 11:ea484e1b7fc4 | 205 | * @ingroup api_socket_udp |
dan_ackme | 11:ea484e1b7fc4 | 206 | * |
dan_ackme | 11:ea484e1b7fc4 | 207 | * @brief Connect to remote UDP server. |
dan_ackme | 13:2b51f5267c92 | 208 | * |
dan_ackme | 17:7268f365676b | 209 | * @param[out] socket UDP @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 210 | * @param[in] host The host/IP address of the remote UDP server |
dan_ackme | 13:2b51f5267c92 | 211 | * @param[in] remortPort The port of the remote server |
dan_ackme | 13:2b51f5267c92 | 212 | * @param[in] localPort Optional, port of module's side of the connection |
dan_ackme | 13:2b51f5267c92 | 213 | * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info |
dan_ackme | 13:2b51f5267c92 | 214 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 215 | */ |
dan_ackme | 21:17bb3eddcbae | 216 | WiconnectResult udpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, uint16_t localPort = SOCKET_ANY_PORT, Pin irqPin = PIN_NC); |
dan_ackme | 11:ea484e1b7fc4 | 217 | |
dan_ackme | 11:ea484e1b7fc4 | 218 | |
dan_ackme | 11:ea484e1b7fc4 | 219 | // ------------------------------------------------------------------------ |
dan_ackme | 11:ea484e1b7fc4 | 220 | |
dan_ackme | 11:ea484e1b7fc4 | 221 | /** |
dan_ackme | 11:ea484e1b7fc4 | 222 | * @ingroup api_socket_http |
dan_ackme | 11:ea484e1b7fc4 | 223 | * |
dan_ackme | 11:ea484e1b7fc4 | 224 | * @brief Connect to remote HTTP server. |
dan_ackme | 13:2b51f5267c92 | 225 | * |
dan_ackme | 13:2b51f5267c92 | 226 | * This is the base method for the other HTTP methods. |
dan_ackme | 13:2b51f5267c92 | 227 | * |
dan_ackme | 13:2b51f5267c92 | 228 | * @section secure_http_connection Secure HTTP |
dan_ackme | 13:2b51f5267c92 | 229 | * Each HTTP method is able to connect to a secure HTTP server. To do this, |
dan_ackme | 13:2b51f5267c92 | 230 | * the URL string parameter must start with 'https://' |
dan_ackme | 13:2b51f5267c92 | 231 | * To connect to a secure HTTP server a TLS certificate is needed. The certificate |
dan_ackme | 13:2b51f5267c92 | 232 | * is specified in the certFilename parameter of the method (or @ref HttpSocketArgs parameter). |
dan_ackme | 13:2b51f5267c92 | 233 | * This is the filename of an existing certificate on the module file system. |
dan_ackme | 13:2b51f5267c92 | 234 | * |
dan_ackme | 13:2b51f5267c92 | 235 | * @note If the URL starts with 'https://' and no certificate filename is specified, |
dan_ackme | 13:2b51f5267c92 | 236 | * the module's default certificate is used. |
dan_ackme | 13:2b51f5267c92 | 237 | * |
dan_ackme | 17:7268f365676b | 238 | * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 239 | * @param[in] url URL of HTTP request |
dan_ackme | 13:2b51f5267c92 | 240 | * @param[in] args Configuration @ref HttpSocketArgs for HTTP connection |
dan_ackme | 13:2b51f5267c92 | 241 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 242 | */ |
dan_ackme | 17:7268f365676b | 243 | WiconnectResult httpConnect(WiconnectSocket &socket, const char *url, const HttpSocketArgs *args); |
dan_ackme | 11:ea484e1b7fc4 | 244 | |
dan_ackme | 11:ea484e1b7fc4 | 245 | /** |
dan_ackme | 11:ea484e1b7fc4 | 246 | * @ingroup api_socket_http |
dan_ackme | 11:ea484e1b7fc4 | 247 | * |
dan_ackme | 11:ea484e1b7fc4 | 248 | * @brief Issue HTTP GET Request |
dan_ackme | 13:2b51f5267c92 | 249 | * |
dan_ackme | 13:2b51f5267c92 | 250 | * This method has the open to only 'open' the connection (disabled by default). This means a connection |
dan_ackme | 13:2b51f5267c92 | 251 | * to the remote HTTP server is opened, but the HTTP request isn't issued. This |
dan_ackme | 13:2b51f5267c92 | 252 | * allow for addition data to be added to the request. For instance, use httpAddHeader() to add |
dan_ackme | 13:2b51f5267c92 | 253 | * additional headers to the request. |
dan_ackme | 13:2b51f5267c92 | 254 | * Use httpGetStatus() to issue the HTTP request and receive the HTTP response. |
dan_ackme | 13:2b51f5267c92 | 255 | * |
dan_ackme | 17:7268f365676b | 256 | * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 257 | * @param[in] url URL of HTTP GET request |
dan_ackme | 13:2b51f5267c92 | 258 | * @param[in] openOnly Optional, if TRUE this will only open a connection to the server (it won't issue the request) |
dan_ackme | 13:2b51f5267c92 | 259 | * @param[in] certFilename Optional, filename of existing TLS certificate on module's file system. See @ref secure_http_connection |
dan_ackme | 13:2b51f5267c92 | 260 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 261 | */ |
dan_ackme | 17:7268f365676b | 262 | WiconnectResult httpGet(WiconnectSocket &socket, const char *url, bool openOnly = false, const char *certFilename = NULL); |
dan_ackme | 11:ea484e1b7fc4 | 263 | |
dan_ackme | 11:ea484e1b7fc4 | 264 | /** |
dan_ackme | 11:ea484e1b7fc4 | 265 | * @ingroup api_socket_http |
dan_ackme | 11:ea484e1b7fc4 | 266 | * |
dan_ackme | 11:ea484e1b7fc4 | 267 | * @brief Issue HTTP POST Request |
dan_ackme | 13:2b51f5267c92 | 268 | * |
dan_ackme | 13:2b51f5267c92 | 269 | * This method has the open to only 'open' the connection which enabled by default. This means a connection |
dan_ackme | 13:2b51f5267c92 | 270 | * to the remote HTTP server is opened, but the HTTP request isn't issued. This |
dan_ackme | 17:7268f365676b | 271 | * allow for addition data to be added to the request. Use the returned @ref WiconnectSocket object's 'write' methods |
dan_ackme | 13:2b51f5267c92 | 272 | * to add POST data to the request. |
dan_ackme | 13:2b51f5267c92 | 273 | * When all POST data has been written, use httpGetStatus() to issue the HTTP request and receive the HTTP response. |
dan_ackme | 13:2b51f5267c92 | 274 | * |
dan_ackme | 17:7268f365676b | 275 | * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 276 | * @param[in] url URL of HTTP POST request |
dan_ackme | 13:2b51f5267c92 | 277 | * @param[in] contextType The value to go into the 'content-type' HTTP header (e.g. 'application/json') |
dan_ackme | 13:2b51f5267c92 | 278 | * @param[in] openOnly Optional, if FALSE this will immediately issue the POST request. |
dan_ackme | 13:2b51f5267c92 | 279 | * @param[in] certFilename Optional, filename of existing TLS certificate on module's file system. See @ref secure_http_connection |
dan_ackme | 13:2b51f5267c92 | 280 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 281 | */ |
dan_ackme | 17:7268f365676b | 282 | WiconnectResult httpPost(WiconnectSocket &socket, const char *url, const char *contextType, bool openOnly = true, const char *certFilename = NULL); |
dan_ackme | 11:ea484e1b7fc4 | 283 | |
dan_ackme | 11:ea484e1b7fc4 | 284 | /** |
dan_ackme | 11:ea484e1b7fc4 | 285 | * @ingroup api_socket_http |
dan_ackme | 11:ea484e1b7fc4 | 286 | * |
dan_ackme | 11:ea484e1b7fc4 | 287 | * @brief Issue HTTP HEAD Request |
dan_ackme | 13:2b51f5267c92 | 288 | * |
dan_ackme | 17:7268f365676b | 289 | * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. |
dan_ackme | 13:2b51f5267c92 | 290 | * @param[in] url URL of HTTP HEAD request |
dan_ackme | 13:2b51f5267c92 | 291 | * @param[in] certFilename Optional, filename of existing TLS certificate on module's file system. See @ref secure_http_connection |
dan_ackme | 13:2b51f5267c92 | 292 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 293 | */ |
dan_ackme | 17:7268f365676b | 294 | WiconnectResult httpHead(WiconnectSocket &socket, const char *url, const char *certFilename = NULL); |
dan_ackme | 11:ea484e1b7fc4 | 295 | |
dan_ackme | 11:ea484e1b7fc4 | 296 | /** |
dan_ackme | 11:ea484e1b7fc4 | 297 | * @ingroup api_socket_http |
dan_ackme | 11:ea484e1b7fc4 | 298 | * |
dan_ackme | 11:ea484e1b7fc4 | 299 | * @brief Add HTTP header key/value pair to opened HTTP request. |
dan_ackme | 13:2b51f5267c92 | 300 | * |
dan_ackme | 17:7268f365676b | 301 | * To use this function, the supplied @ref WiconnectSocket parameter must have been created |
dan_ackme | 13:2b51f5267c92 | 302 | * using either httpGet() or httpPost() and the 'openOnly' parameter TRUE. |
dan_ackme | 13:2b51f5267c92 | 303 | * |
dan_ackme | 13:2b51f5267c92 | 304 | * This will add additional header to the HTTP request. |
dan_ackme | 13:2b51f5267c92 | 305 | * |
dan_ackme | 13:2b51f5267c92 | 306 | * Use httpGetStatus() to issue the request. |
dan_ackme | 13:2b51f5267c92 | 307 | * |
dan_ackme | 13:2b51f5267c92 | 308 | * @param[in] socket Opened socket to add additonal HTTP header |
dan_ackme | 13:2b51f5267c92 | 309 | * @param[in] key Header key (e.g. 'content-type') |
dan_ackme | 13:2b51f5267c92 | 310 | * @param[in] value Header value (e.g. 'application/json') |
dan_ackme | 13:2b51f5267c92 | 311 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 312 | */ |
dan_ackme | 17:7268f365676b | 313 | WiconnectResult httpAddHeader(WiconnectSocket &socket, const char *key, const char *value); |
dan_ackme | 11:ea484e1b7fc4 | 314 | |
dan_ackme | 11:ea484e1b7fc4 | 315 | /** |
dan_ackme | 11:ea484e1b7fc4 | 316 | * @ingroup api_socket_http |
dan_ackme | 11:ea484e1b7fc4 | 317 | * |
dan_ackme | 11:ea484e1b7fc4 | 318 | * @brief Get the HTTP status code from HTTP request. |
dan_ackme | 13:2b51f5267c92 | 319 | * |
dan_ackme | 13:2b51f5267c92 | 320 | * This may be used to either issue an HTTP request of an opened HTTP connection |
dan_ackme | 13:2b51f5267c92 | 321 | * or return the status code of a request already issued. |
dan_ackme | 13:2b51f5267c92 | 322 | * |
dan_ackme | 13:2b51f5267c92 | 323 | * @param[in] socket Opened socket to get http response status code |
dan_ackme | 13:2b51f5267c92 | 324 | * @param[out] statusCodePtr Pointer to uint32 to hold http status code |
dan_ackme | 13:2b51f5267c92 | 325 | * @return Result of method. See @ref WiconnectResult |
dan_ackme | 11:ea484e1b7fc4 | 326 | */ |
dan_ackme | 17:7268f365676b | 327 | WiconnectResult httpGetStatus(WiconnectSocket &socket, uint32_t *statusCodePtr); |
dan_ackme | 0:ea85c4bb5e1f | 328 | |
dan_ackme | 0:ea85c4bb5e1f | 329 | protected: |
dan_ackme | 1:6ec9998427ad | 330 | SocketInterface(Wiconnect *wiconnect); |
dan_ackme | 21:17bb3eddcbae | 331 | ~SocketInterface(); |
dan_ackme | 1:6ec9998427ad | 332 | |
dan_ackme | 0:ea85c4bb5e1f | 333 | SocketIrqHandlerMap irqHandlers; |
dan_ackme | 0:ea85c4bb5e1f | 334 | |
dan_ackme | 21:17bb3eddcbae | 335 | bool serverConnectedClientList[WICONNECT_MAX_SOCKETS]; |
dan_ackme | 21:17bb3eddcbae | 336 | |
dan_ackme | 21:17bb3eddcbae | 337 | WiconnectResult pollForServerClient(uint8_t *handle = NULL, uint16_t *localPort = NULL, uint16_t *remotePort = NULL, uint32_t *ipAddress = NULL); |
dan_ackme | 21:17bb3eddcbae | 338 | |
dan_ackme | 21:17bb3eddcbae | 339 | void socketClosedCallback(const WiconnectSocket *socket); |
dan_ackme | 21:17bb3eddcbae | 340 | |
dan_ackme | 0:ea85c4bb5e1f | 341 | private: |
dan_ackme | 0:ea85c4bb5e1f | 342 | Wiconnect *wiconnect; |
dan_ackme | 0:ea85c4bb5e1f | 343 | }; |
dan_ackme | 0:ea85c4bb5e1f | 344 | |
dan_ackme | 0:ea85c4bb5e1f | 345 | } |