modified by ohneta

Dependencies:   ESP8266

Dependents:   HelloESP8266Interface_mine

Fork of ESP8266Interface by NetworkSocketAPI

Committer:
sarahmarshy
Date:
Thu Jul 23 21:25:30 2015 +0000
Revision:
23:fd0f3197c30b
Parent:
22:312453862371
Child:
24:37504440f296
Child:
25:91c4e9d34b77
Moved AT commands to driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sarahmarshy 18:9fc7976c7b27 1 /* ESP8266Interface Example
sarahmarshy 18:9fc7976c7b27 2 * Copyright (c) 2015 ARM Limited
sarahmarshy 18:9fc7976c7b27 3 *
sarahmarshy 18:9fc7976c7b27 4 * Licensed under the Apache License, Version 2.0 (the "License");
sarahmarshy 18:9fc7976c7b27 5 * you may not use this file except in compliance with the License.
sarahmarshy 18:9fc7976c7b27 6 * You may obtain a copy of the License at
sarahmarshy 18:9fc7976c7b27 7 *
sarahmarshy 18:9fc7976c7b27 8 * http://www.apache.org/licenses/LICENSE-2.0
sarahmarshy 18:9fc7976c7b27 9 *
sarahmarshy 18:9fc7976c7b27 10 * Unless required by applicable law or agreed to in writing, software
sarahmarshy 18:9fc7976c7b27 11 * distributed under the License is distributed on an "AS IS" BASIS,
sarahmarshy 18:9fc7976c7b27 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sarahmarshy 18:9fc7976c7b27 13 * See the License for the specific language governing permissions and
sarahmarshy 18:9fc7976c7b27 14 * limitations under the License.
sarahmarshy 18:9fc7976c7b27 15 */
sarahmarshy 18:9fc7976c7b27 16
sarahmarshy 18:9fc7976c7b27 17 #ifndef ESP8266INTERFACE_H
sarahmarshy 18:9fc7976c7b27 18 #define ESP8266INTERFACE_H
sarahmarshy 18:9fc7976c7b27 19
sarahmarshy 18:9fc7976c7b27 20 #include "WiFiInterface.h"
sarahmarshy 23:fd0f3197c30b 21 #include "ESP8266.h"
sarahmarshy 18:9fc7976c7b27 22
sarahmarshy 18:9fc7976c7b27 23 /** ESP8266Socket class.
sarahmarshy 18:9fc7976c7b27 24 This is a ESP8266 implementation of a socket that implements the SocketInterface class.
sarahmarshy 18:9fc7976c7b27 25 This mock ESP8266 hardware uses AT commands, so an ATParser is used to communicate with the hardware over serial.
sarahmarshy 18:9fc7976c7b27 26 In a non-AT command set, ATParser could be replaced by RawSerial or another hardware communication interface.
sarahmarshy 18:9fc7976c7b27 27 */
sarahmarshy 18:9fc7976c7b27 28
sarahmarshy 18:9fc7976c7b27 29 class ESP8266Socket : public SocketInterface
sarahmarshy 18:9fc7976c7b27 30 {
sarahmarshy 18:9fc7976c7b27 31 public:
sarahmarshy 23:fd0f3197c30b 32 ESP8266Socket(uint32_t handle, ESP8266* driver, socket_protocol_t type, uint8_t id);
sarahmarshy 18:9fc7976c7b27 33 virtual const char *getHostByName(const char *name) const;
sarahmarshy 18:9fc7976c7b27 34 virtual void setAddress(const char* addr) ;
sarahmarshy 18:9fc7976c7b27 35 virtual void setPort(uint16_t port) ;
sarahmarshy 18:9fc7976c7b27 36 virtual void setAddressPort(const char* addr, uint16_t port);
sarahmarshy 18:9fc7976c7b27 37 virtual const char *getAddress(void) const;
sarahmarshy 18:9fc7976c7b27 38 virtual uint16_t getPort(void) const;
sarahmarshy 18:9fc7976c7b27 39 virtual int32_t bind(uint16_t port) const;
sarahmarshy 18:9fc7976c7b27 40 virtual int32_t listen(void) const;
sarahmarshy 18:9fc7976c7b27 41 virtual int32_t accept() const;
sarahmarshy 18:9fc7976c7b27 42 virtual int32_t open() ;
sarahmarshy 18:9fc7976c7b27 43 virtual int32_t send(const void *data, uint32_t amount, uint32_t timeout_ms = 15000) ;
sarahmarshy 18:9fc7976c7b27 44 virtual uint32_t recv(void *data, uint32_t amount, uint32_t timeout_ms = 15000) ;
sarahmarshy 18:9fc7976c7b27 45 virtual int32_t close() const;
sarahmarshy 22:312453862371 46 uint32_t getHandle() const;
sarahmarshy 18:9fc7976c7b27 47 uint8_t getID();
sarahmarshy 18:9fc7976c7b27 48 void handleRecieve();
sarahmarshy 18:9fc7976c7b27 49 protected:
sarahmarshy 18:9fc7976c7b27 50 uint8_t _id;
sarahmarshy 23:fd0f3197c30b 51 ESP8266* driver;
sarahmarshy 18:9fc7976c7b27 52 };
sarahmarshy 18:9fc7976c7b27 53
sarahmarshy 18:9fc7976c7b27 54 /** ESP8266Interface class.
sarahmarshy 18:9fc7976c7b27 55 This is an interface to a ESP8266 radio.
sarahmarshy 18:9fc7976c7b27 56 */
sarahmarshy 18:9fc7976c7b27 57 class ESP8266Interface : public WiFiInterface
sarahmarshy 18:9fc7976c7b27 58 {
sarahmarshy 18:9fc7976c7b27 59 public:
sarahmarshy 18:9fc7976c7b27 60 ESP8266Interface(PinName tx, PinName rx);
sarahmarshy 18:9fc7976c7b27 61 virtual int32_t init(void);
sarahmarshy 18:9fc7976c7b27 62 virtual int32_t init(const char *ip, const char *mask, const char *gateway);
sarahmarshy 18:9fc7976c7b27 63 virtual int32_t connect(uint32_t timeout_ms) ;
sarahmarshy 18:9fc7976c7b27 64 virtual int32_t connect(const char *ap, const char *pass_phrase = 0, wifi_security_t security = WI_NONE, uint32_t timeout_ms = 15000);
sarahmarshy 22:312453862371 65 virtual int32_t disconnect(void) ;
sarahmarshy 18:9fc7976c7b27 66 virtual char *getIPAddress(void) ;
sarahmarshy 18:9fc7976c7b27 67 virtual char *getGateway(void) const;
sarahmarshy 18:9fc7976c7b27 68 virtual char *getNetworkMask(void) const;
sarahmarshy 18:9fc7976c7b27 69 virtual char *getMACAddress(void) const;
sarahmarshy 18:9fc7976c7b27 70 virtual int32_t isConnected(void) ;
sarahmarshy 18:9fc7976c7b27 71 virtual SocketInterface *allocateSocket(socket_protocol_t socketProtocol) ;
sarahmarshy 18:9fc7976c7b27 72 virtual int deallocateSocket(SocketInterface *socket) ;
sarahmarshy 18:9fc7976c7b27 73
sarahmarshy 18:9fc7976c7b27 74 private:
sarahmarshy 23:fd0f3197c30b 75 ESP8266 esp8266;
sarahmarshy 22:312453862371 76 const int numSockets = 5;
sarahmarshy 22:312453862371 77 int availableID[numSockets];
sarahmarshy 20:5d0762aa4680 78 char ip[100];
sarahmarshy 18:9fc7976c7b27 79 };
sarahmarshy 18:9fc7976c7b27 80
sarahmarshy 18:9fc7976c7b27 81 #endif