Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ESP8266Interface by
ESP8266Interface.h@40:83c6b4129468, 2016-02-24 (annotated)
- Committer:
- Christopher Haster
- Date:
- Wed Feb 24 22:17:45 2016 -0600
- Branch:
- api-changes
- Revision:
- 40:83c6b4129468
- Parent:
- 38:eb1e46561a19
- Child:
- 42:4bf09cadf328
Moved ESP8266SocketInterface into ESP8266Interface
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 | |
Christopher Haster |
34:9c26a3dcdc1f | 17 | #ifndef ESP8266_INTERFACE_H |
Christopher Haster |
34:9c26a3dcdc1f | 18 | #define ESP8266_INTERFACE_H |
sarahmarshy | 18:9fc7976c7b27 | 19 | |
sarahmarshy | 18:9fc7976c7b27 | 20 | #include "WiFiInterface.h" |
sarahmarshy | 23:fd0f3197c30b | 21 | #include "ESP8266.h" |
Christopher Haster |
34:9c26a3dcdc1f | 22 | |
Christopher Haster |
34:9c26a3dcdc1f | 23 | #define ESP8266_SOCKET_COUNT 5 |
sarahmarshy | 18:9fc7976c7b27 | 24 | |
Christopher Haster |
40:83c6b4129468 | 25 | |
Christopher Haster |
34:9c26a3dcdc1f | 26 | /** ESP8266Interface class |
Christopher Haster |
34:9c26a3dcdc1f | 27 | * Implementation of the NetworkInterface for the ESP8266 |
sarahmarshy | 18:9fc7976c7b27 | 28 | */ |
sarahmarshy | 18:9fc7976c7b27 | 29 | class ESP8266Interface : public WiFiInterface |
sarahmarshy | 18:9fc7976c7b27 | 30 | { |
sarahmarshy | 18:9fc7976c7b27 | 31 | public: |
Christopher Haster |
34:9c26a3dcdc1f | 32 | ESP8266Interface(PinName tx, PinName rx, bool debug = false); |
Christopher Haster |
40:83c6b4129468 | 33 | virtual ~ESP8266Interface(); |
Christopher Haster |
34:9c26a3dcdc1f | 34 | |
Christopher Haster |
34:9c26a3dcdc1f | 35 | // Implementation of WiFiInterface |
Christopher Haster |
34:9c26a3dcdc1f | 36 | virtual int32_t connect( |
Christopher Haster |
34:9c26a3dcdc1f | 37 | const char *ssid, |
Christopher Haster |
34:9c26a3dcdc1f | 38 | const char *pass, |
Christopher Haster |
38:eb1e46561a19 | 39 | wifi_security_t security = WI_NONE); |
Christopher Haster |
34:9c26a3dcdc1f | 40 | |
Christopher Haster |
34:9c26a3dcdc1f | 41 | virtual int32_t disconnect(); |
Christopher Haster |
34:9c26a3dcdc1f | 42 | |
Christopher Haster |
34:9c26a3dcdc1f | 43 | // Implementation of NetworkInterface |
Christopher Haster |
34:9c26a3dcdc1f | 44 | virtual const char *getIPAddress(); |
Christopher Haster |
34:9c26a3dcdc1f | 45 | virtual const char *getMACAddress(); |
Christopher Haster |
34:9c26a3dcdc1f | 46 | |
Christopher Haster |
34:9c26a3dcdc1f | 47 | virtual SocketInterface *createSocket(socket_protocol_t proto); |
Christopher Haster |
34:9c26a3dcdc1f | 48 | virtual void destroySocket(SocketInterface *socket); |
Christopher Haster |
34:9c26a3dcdc1f | 49 | |
Christopher Haster |
34:9c26a3dcdc1f | 50 | private: |
Christopher Haster |
34:9c26a3dcdc1f | 51 | ESP8266 _esp; |
sarahmarshy | 18:9fc7976c7b27 | 52 | |
Christopher Haster |
34:9c26a3dcdc1f | 53 | bool _ids[ESP8266_SOCKET_COUNT]; |
Christopher Haster |
34:9c26a3dcdc1f | 54 | const char *_ip_address; |
Christopher Haster |
34:9c26a3dcdc1f | 55 | const char *_mac_address; |
Christopher Haster |
40:83c6b4129468 | 56 | |
Christopher Haster |
40:83c6b4129468 | 57 | class ESP8266Socket; |
Christopher Haster |
40:83c6b4129468 | 58 | }; |
Christopher Haster |
40:83c6b4129468 | 59 | |
Christopher Haster |
40:83c6b4129468 | 60 | |
Christopher Haster |
40:83c6b4129468 | 61 | /** ESP8266Socket class |
Christopher Haster |
40:83c6b4129468 | 62 | * Implementation of the SocketInterface for the ESP8266 |
Christopher Haster |
40:83c6b4129468 | 63 | */ |
Christopher Haster |
40:83c6b4129468 | 64 | class ESP8266Interface::ESP8266Socket : public SocketInterface |
Christopher Haster |
40:83c6b4129468 | 65 | { |
Christopher Haster |
40:83c6b4129468 | 66 | public: |
Christopher Haster |
40:83c6b4129468 | 67 | // ESP8266 specific methods |
Christopher Haster |
40:83c6b4129468 | 68 | ESP8266Socket( |
Christopher Haster |
40:83c6b4129468 | 69 | ESP8266 *esp, |
Christopher Haster |
40:83c6b4129468 | 70 | socket_protocol_t proto, |
Christopher Haster |
40:83c6b4129468 | 71 | int id); |
Christopher Haster |
40:83c6b4129468 | 72 | |
Christopher Haster |
40:83c6b4129468 | 73 | virtual ~ESP8266Socket(); |
Christopher Haster |
40:83c6b4129468 | 74 | |
Christopher Haster |
40:83c6b4129468 | 75 | int getID() const; |
Christopher Haster |
40:83c6b4129468 | 76 | |
Christopher Haster |
40:83c6b4129468 | 77 | // Implementation of SocketInterface |
Christopher Haster |
40:83c6b4129468 | 78 | virtual int32_t open(const char *ip, uint16_t port); |
Christopher Haster |
40:83c6b4129468 | 79 | virtual int32_t close(); |
Christopher Haster |
40:83c6b4129468 | 80 | |
Christopher Haster |
40:83c6b4129468 | 81 | virtual int32_t send(const void *data, uint32_t len); |
Christopher Haster |
40:83c6b4129468 | 82 | virtual int32_t recv(void *data, uint32_t len); |
Christopher Haster |
40:83c6b4129468 | 83 | |
Christopher Haster |
40:83c6b4129468 | 84 | private: |
Christopher Haster |
40:83c6b4129468 | 85 | ESP8266 *_esp; |
Christopher Haster |
40:83c6b4129468 | 86 | socket_protocol_t _proto; |
Christopher Haster |
40:83c6b4129468 | 87 | int _id; |
sarahmarshy | 18:9fc7976c7b27 | 88 | }; |
sarahmarshy | 18:9fc7976c7b27 | 89 | |
Christopher Haster |
34:9c26a3dcdc1f | 90 | |
sarahmarshy | 18:9fc7976c7b27 | 91 | #endif |