MiCO MXCHIP
/
MXCHIP_WIFI_Demo
It's MXCHIP WIFI demo.
MXCHIP_WIFI_Driver/MXCHIP/MXCHIP.h@0:cd7c54f07d25, 2017-03-21 (annotated)
- Committer:
- lizhibo32
- Date:
- Tue Mar 21 03:56:12 2017 +0000
- Revision:
- 0:cd7c54f07d25
build system
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lizhibo32 | 0:cd7c54f07d25 | 1 | |
lizhibo32 | 0:cd7c54f07d25 | 2 | #ifndef __MBED_MXCHIP_H |
lizhibo32 | 0:cd7c54f07d25 | 3 | #define __MBED_MXCHIP_H |
lizhibo32 | 0:cd7c54f07d25 | 4 | |
lizhibo32 | 0:cd7c54f07d25 | 5 | #include "ATParser.h" |
lizhibo32 | 0:cd7c54f07d25 | 6 | |
lizhibo32 | 0:cd7c54f07d25 | 7 | class MXCHIP |
lizhibo32 | 0:cd7c54f07d25 | 8 | { |
lizhibo32 | 0:cd7c54f07d25 | 9 | public: |
lizhibo32 | 0:cd7c54f07d25 | 10 | MXCHIP(PinName tx, PinName rx, bool debug=false); |
lizhibo32 | 0:cd7c54f07d25 | 11 | /** |
lizhibo32 | 0:cd7c54f07d25 | 12 | * Startup the ESP8266 |
lizhibo32 | 0:cd7c54f07d25 | 13 | * |
lizhibo32 | 0:cd7c54f07d25 | 14 | * @param mode mode of WIFI 1-client, 2-host, 3-both |
lizhibo32 | 0:cd7c54f07d25 | 15 | * @return true only if ESP8266 was setup correctly |
lizhibo32 | 0:cd7c54f07d25 | 16 | */ |
lizhibo32 | 0:cd7c54f07d25 | 17 | bool startup(int mode); |
lizhibo32 | 0:cd7c54f07d25 | 18 | /** |
lizhibo32 | 0:cd7c54f07d25 | 19 | * Reset ESP8266 |
lizhibo32 | 0:cd7c54f07d25 | 20 | * |
lizhibo32 | 0:cd7c54f07d25 | 21 | * @return true only if ESP8266 resets successfully |
lizhibo32 | 0:cd7c54f07d25 | 22 | */ |
lizhibo32 | 0:cd7c54f07d25 | 23 | bool reset(void); |
lizhibo32 | 0:cd7c54f07d25 | 24 | |
lizhibo32 | 0:cd7c54f07d25 | 25 | /** |
lizhibo32 | 0:cd7c54f07d25 | 26 | * Enable/Disable DHCP |
lizhibo32 | 0:cd7c54f07d25 | 27 | * |
lizhibo32 | 0:cd7c54f07d25 | 28 | * @param enabled DHCP enabled when true |
lizhibo32 | 0:cd7c54f07d25 | 29 | * @param mode mode of DHCP 0-softAP, 1-station, 2-both |
lizhibo32 | 0:cd7c54f07d25 | 30 | * @return true only if ESP8266 enables/disables DHCP successfully |
lizhibo32 | 0:cd7c54f07d25 | 31 | */ |
lizhibo32 | 0:cd7c54f07d25 | 32 | bool dhcp(bool enabled, int mode); |
lizhibo32 | 0:cd7c54f07d25 | 33 | |
lizhibo32 | 0:cd7c54f07d25 | 34 | /** |
lizhibo32 | 0:cd7c54f07d25 | 35 | * Connect ESP8266 to AP |
lizhibo32 | 0:cd7c54f07d25 | 36 | * |
lizhibo32 | 0:cd7c54f07d25 | 37 | * @param ap the name of the AP |
lizhibo32 | 0:cd7c54f07d25 | 38 | * @param passPhrase the password of AP |
lizhibo32 | 0:cd7c54f07d25 | 39 | * @return true only if ESP8266 is connected successfully |
lizhibo32 | 0:cd7c54f07d25 | 40 | */ |
lizhibo32 | 0:cd7c54f07d25 | 41 | bool connect(const char *ap, const char *passPhrase); |
lizhibo32 | 0:cd7c54f07d25 | 42 | |
lizhibo32 | 0:cd7c54f07d25 | 43 | /** |
lizhibo32 | 0:cd7c54f07d25 | 44 | * Disconnect ESP8266 from AP |
lizhibo32 | 0:cd7c54f07d25 | 45 | * |
lizhibo32 | 0:cd7c54f07d25 | 46 | * @return true only if ESP8266 is disconnected successfully |
lizhibo32 | 0:cd7c54f07d25 | 47 | */ |
lizhibo32 | 0:cd7c54f07d25 | 48 | bool disconnect(void); |
lizhibo32 | 0:cd7c54f07d25 | 49 | |
lizhibo32 | 0:cd7c54f07d25 | 50 | /** |
lizhibo32 | 0:cd7c54f07d25 | 51 | * Get the IP address of ESP8266 |
lizhibo32 | 0:cd7c54f07d25 | 52 | * |
lizhibo32 | 0:cd7c54f07d25 | 53 | * @return null-teriminated IP address or null if no IP address is assigned |
lizhibo32 | 0:cd7c54f07d25 | 54 | */ |
lizhibo32 | 0:cd7c54f07d25 | 55 | const char *getIPAddress(void); |
lizhibo32 | 0:cd7c54f07d25 | 56 | |
lizhibo32 | 0:cd7c54f07d25 | 57 | /** |
lizhibo32 | 0:cd7c54f07d25 | 58 | * Get the MAC address of ESP8266 |
lizhibo32 | 0:cd7c54f07d25 | 59 | * |
lizhibo32 | 0:cd7c54f07d25 | 60 | * @return null-terminated MAC address or null if no MAC address is assigned |
lizhibo32 | 0:cd7c54f07d25 | 61 | */ |
lizhibo32 | 0:cd7c54f07d25 | 62 | const char *getMACAddress(void); |
lizhibo32 | 0:cd7c54f07d25 | 63 | |
lizhibo32 | 0:cd7c54f07d25 | 64 | /** Get the local gateway |
lizhibo32 | 0:cd7c54f07d25 | 65 | * |
lizhibo32 | 0:cd7c54f07d25 | 66 | * @return Null-terminated representation of the local gateway |
lizhibo32 | 0:cd7c54f07d25 | 67 | * or null if no network mask has been recieved |
lizhibo32 | 0:cd7c54f07d25 | 68 | */ |
lizhibo32 | 0:cd7c54f07d25 | 69 | const char *getGateway(); |
lizhibo32 | 0:cd7c54f07d25 | 70 | |
lizhibo32 | 0:cd7c54f07d25 | 71 | /** Get the local network mask |
lizhibo32 | 0:cd7c54f07d25 | 72 | * |
lizhibo32 | 0:cd7c54f07d25 | 73 | * @return Null-terminated representation of the local network mask |
lizhibo32 | 0:cd7c54f07d25 | 74 | * or null if no network mask has been recieved |
lizhibo32 | 0:cd7c54f07d25 | 75 | */ |
lizhibo32 | 0:cd7c54f07d25 | 76 | const char *getNetmask(); |
lizhibo32 | 0:cd7c54f07d25 | 77 | |
lizhibo32 | 0:cd7c54f07d25 | 78 | |
lizhibo32 | 0:cd7c54f07d25 | 79 | private: |
lizhibo32 | 0:cd7c54f07d25 | 80 | BufferedSerial _serial; |
lizhibo32 | 0:cd7c54f07d25 | 81 | ATParser _parser; |
lizhibo32 | 0:cd7c54f07d25 | 82 | |
lizhibo32 | 0:cd7c54f07d25 | 83 | struct packet |
lizhibo32 | 0:cd7c54f07d25 | 84 | { |
lizhibo32 | 0:cd7c54f07d25 | 85 | struct packet *next; |
lizhibo32 | 0:cd7c54f07d25 | 86 | int id; |
lizhibo32 | 0:cd7c54f07d25 | 87 | uint32_t len; |
lizhibo32 | 0:cd7c54f07d25 | 88 | // data follows |
lizhibo32 | 0:cd7c54f07d25 | 89 | } *_packets, **_packets_end; |
lizhibo32 | 0:cd7c54f07d25 | 90 | |
lizhibo32 | 0:cd7c54f07d25 | 91 | //buffer |
lizhibo32 | 0:cd7c54f07d25 | 92 | char _ip_buffer[16]; |
lizhibo32 | 0:cd7c54f07d25 | 93 | char _gateway_buffer[16]; |
lizhibo32 | 0:cd7c54f07d25 | 94 | char _netmask_buffer[16]; |
lizhibo32 | 0:cd7c54f07d25 | 95 | char _mac_buffer[18]; |
lizhibo32 | 0:cd7c54f07d25 | 96 | |
lizhibo32 | 0:cd7c54f07d25 | 97 | } |
lizhibo32 | 0:cd7c54f07d25 | 98 | |
lizhibo32 | 0:cd7c54f07d25 | 99 | #endif |