modified by ohneta
Dependents: HelloESP8266Interface_mine
Fork of ESP8266Interface by
ESP8266Interface.h@30:fd77d067f5ab, 2015-11-10 (annotated)
- Committer:
- ohneta
- Date:
- Tue Nov 10 14:46:06 2015 +0000
- Revision:
- 30:fd77d067f5ab
- Parent:
- 26:6e36dd3cec3f
for AT_V0.50/SDK_V1.4.0 ; modified to work normally
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:91c4e9d34b77 | 22 | #include "DnsQuery.h" |
sarahmarshy | 18:9fc7976c7b27 | 23 | |
sarahmarshy | 18:9fc7976c7b27 | 24 | /** ESP8266Socket class. |
sarahmarshy | 18:9fc7976c7b27 | 25 | This is a ESP8266 implementation of a socket that implements the SocketInterface class. |
sarahmarshy | 18:9fc7976c7b27 | 26 | This mock ESP8266 hardware uses AT commands, so an ATParser is used to communicate with the hardware over serial. |
sarahmarshy | 18:9fc7976c7b27 | 27 | In a non-AT command set, ATParser could be replaced by RawSerial or another hardware communication interface. |
sarahmarshy | 18:9fc7976c7b27 | 28 | */ |
sarahmarshy | 18:9fc7976c7b27 | 29 | |
sarahmarshy | 18:9fc7976c7b27 | 30 | class ESP8266Socket : public SocketInterface |
sarahmarshy | 18:9fc7976c7b27 | 31 | { |
sarahmarshy | 18:9fc7976c7b27 | 32 | public: |
sam_grove | 24:37504440f296 | 33 | ESP8266Socket(uint32_t handle, ESP8266 &driver, socket_protocol_t type, uint8_t id); |
sarahmarshy | 18:9fc7976c7b27 | 34 | virtual const char *getHostByName(const char *name) const; |
sarahmarshy | 18:9fc7976c7b27 | 35 | virtual void setAddress(const char* addr) ; |
sarahmarshy | 18:9fc7976c7b27 | 36 | virtual void setPort(uint16_t port) ; |
sarahmarshy | 18:9fc7976c7b27 | 37 | virtual void setAddressPort(const char* addr, uint16_t port); |
sarahmarshy | 18:9fc7976c7b27 | 38 | virtual const char *getAddress(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 39 | virtual uint16_t getPort(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 40 | virtual int32_t bind(uint16_t port) const; |
sarahmarshy | 18:9fc7976c7b27 | 41 | virtual int32_t listen(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 42 | virtual int32_t accept() const; |
sarahmarshy | 18:9fc7976c7b27 | 43 | virtual int32_t open() ; |
sarahmarshy | 18:9fc7976c7b27 | 44 | virtual int32_t send(const void *data, uint32_t amount, uint32_t timeout_ms = 15000) ; |
sarahmarshy | 18:9fc7976c7b27 | 45 | virtual uint32_t recv(void *data, uint32_t amount, uint32_t timeout_ms = 15000) ; |
sarahmarshy | 18:9fc7976c7b27 | 46 | virtual int32_t close() const; |
sam_grove | 24:37504440f296 | 47 | virtual uint32_t getHandle() const; |
sam_grove | 24:37504440f296 | 48 | |
sarahmarshy | 18:9fc7976c7b27 | 49 | uint8_t getID(); |
sarahmarshy | 18:9fc7976c7b27 | 50 | void handleRecieve(); |
sam_grove | 24:37504440f296 | 51 | |
sarahmarshy | 18:9fc7976c7b27 | 52 | protected: |
sarahmarshy | 18:9fc7976c7b27 | 53 | uint8_t _id; |
sam_grove | 24:37504440f296 | 54 | ESP8266* _driver; |
sarahmarshy | 18:9fc7976c7b27 | 55 | }; |
sarahmarshy | 18:9fc7976c7b27 | 56 | |
sarahmarshy | 18:9fc7976c7b27 | 57 | /** ESP8266Interface class. |
sarahmarshy | 18:9fc7976c7b27 | 58 | This is an interface to a ESP8266 radio. |
sarahmarshy | 18:9fc7976c7b27 | 59 | */ |
sarahmarshy | 18:9fc7976c7b27 | 60 | class ESP8266Interface : public WiFiInterface |
sarahmarshy | 18:9fc7976c7b27 | 61 | { |
sarahmarshy | 18:9fc7976c7b27 | 62 | public: |
sarahmarshy | 18:9fc7976c7b27 | 63 | ESP8266Interface(PinName tx, PinName rx); |
sarahmarshy | 18:9fc7976c7b27 | 64 | virtual int32_t init(void); |
sarahmarshy | 18:9fc7976c7b27 | 65 | virtual int32_t init(const char *ip, const char *mask, const char *gateway); |
sarahmarshy | 18:9fc7976c7b27 | 66 | virtual int32_t connect(uint32_t timeout_ms) ; |
sarahmarshy | 18:9fc7976c7b27 | 67 | 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 | 68 | virtual int32_t disconnect(void) ; |
sarahmarshy | 18:9fc7976c7b27 | 69 | virtual char *getIPAddress(void) ; |
sarahmarshy | 18:9fc7976c7b27 | 70 | virtual char *getGateway(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 71 | virtual char *getNetworkMask(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 72 | virtual char *getMACAddress(void) const; |
sarahmarshy | 18:9fc7976c7b27 | 73 | virtual int32_t isConnected(void) ; |
sarahmarshy | 18:9fc7976c7b27 | 74 | virtual SocketInterface *allocateSocket(socket_protocol_t socketProtocol) ; |
sarahmarshy | 18:9fc7976c7b27 | 75 | virtual int deallocateSocket(SocketInterface *socket) ; |
sarahmarshy | 25:91c4e9d34b77 | 76 | void getHostByName(const char *name, char* hostIP); |
ohneta | 30:fd77d067f5ab | 77 | |
ohneta | 30:fd77d067f5ab | 78 | void setPreferredDns(const char *preferredDnsIP); |
sarahmarshy | 18:9fc7976c7b27 | 79 | |
sarahmarshy | 18:9fc7976c7b27 | 80 | private: |
sarahmarshy | 23:fd0f3197c30b | 81 | ESP8266 esp8266; |
sam_grove | 24:37504440f296 | 82 | static const int numSockets = 5; |
sarahmarshy | 22:312453862371 | 83 | int availableID[numSockets]; |
sarahmarshy | 20:5d0762aa4680 | 84 | char ip[100]; |
ohneta | 30:fd77d067f5ab | 85 | |
ohneta | 30:fd77d067f5ab | 86 | const char* preferred_dnsip; |
sarahmarshy | 18:9fc7976c7b27 | 87 | }; |
sarahmarshy | 18:9fc7976c7b27 | 88 | |
sarahmarshy | 18:9fc7976c7b27 | 89 | #endif |