MQTT client test with W5200 ethernet shield
Dependents: IBMIoTClientEthernetExample_W5200
Fork of W5500Interface by
EthernetInterface.h@0:e11e8793c3ce, 2014-08-20 (annotated)
- Committer:
- Bongjun
- Date:
- Wed Aug 20 00:28:37 2014 +0000
- Revision:
- 0:e11e8793c3ce
- Child:
- 5:8aefaef88f79
first release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bongjun | 0:e11e8793c3ce | 1 | // EthernetInterface for W5500 2014/8/20 |
Bongjun | 0:e11e8793c3ce | 2 | |
Bongjun | 0:e11e8793c3ce | 3 | #pragma once |
Bongjun | 0:e11e8793c3ce | 4 | #include "wiznet.h" |
Bongjun | 0:e11e8793c3ce | 5 | |
Bongjun | 0:e11e8793c3ce | 6 | /** Interface using Wiznet W5500 chip to connect to an IP-based network |
Bongjun | 0:e11e8793c3ce | 7 | * |
Bongjun | 0:e11e8793c3ce | 8 | */ |
Bongjun | 0:e11e8793c3ce | 9 | class EthernetInterface: public WIZnet_Chip { |
Bongjun | 0:e11e8793c3ce | 10 | public: |
Bongjun | 0:e11e8793c3ce | 11 | |
Bongjun | 0:e11e8793c3ce | 12 | /** |
Bongjun | 0:e11e8793c3ce | 13 | * Constructor |
Bongjun | 0:e11e8793c3ce | 14 | * |
Bongjun | 0:e11e8793c3ce | 15 | * \param mosi mbed pin to use for SPI |
Bongjun | 0:e11e8793c3ce | 16 | * \param miso mbed pin to use for SPI |
Bongjun | 0:e11e8793c3ce | 17 | * \param sclk mbed pin to use for SPI |
Bongjun | 0:e11e8793c3ce | 18 | * \param cs chip select of the WIZnet_Chip |
Bongjun | 0:e11e8793c3ce | 19 | * \param reset reset pin of the WIZnet_Chip |
Bongjun | 0:e11e8793c3ce | 20 | */ |
Bongjun | 0:e11e8793c3ce | 21 | EthernetInterface(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset); |
Bongjun | 0:e11e8793c3ce | 22 | EthernetInterface(SPI* spi, PinName cs, PinName reset); |
Bongjun | 0:e11e8793c3ce | 23 | |
Bongjun | 0:e11e8793c3ce | 24 | /** Initialize the interface with DHCP w/o MAC address |
Bongjun | 0:e11e8793c3ce | 25 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 26 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 27 | */ |
Bongjun | 0:e11e8793c3ce | 28 | int init(); //With DHCP |
Bongjun | 0:e11e8793c3ce | 29 | /** Initialize the interface with DHCP. |
Bongjun | 0:e11e8793c3ce | 30 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 31 | * \param mac the MAC address to use |
Bongjun | 0:e11e8793c3ce | 32 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 33 | */ |
Bongjun | 0:e11e8793c3ce | 34 | int init(uint8_t * mac); //With DHCP |
Bongjun | 0:e11e8793c3ce | 35 | |
Bongjun | 0:e11e8793c3ce | 36 | /** Initialize the interface with a static IP address without MAC. |
Bongjun | 0:e11e8793c3ce | 37 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 38 | * \param ip the IP address to use |
Bongjun | 0:e11e8793c3ce | 39 | * \param mask the IP address mask |
Bongjun | 0:e11e8793c3ce | 40 | * \param gateway the gateway to use |
Bongjun | 0:e11e8793c3ce | 41 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 42 | */ |
Bongjun | 0:e11e8793c3ce | 43 | |
Bongjun | 0:e11e8793c3ce | 44 | int init(const char* ip, const char* mask, const char* gateway); |
Bongjun | 0:e11e8793c3ce | 45 | /** Initialize the interface with a static IP address. |
Bongjun | 0:e11e8793c3ce | 46 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 47 | * \param mac the MAC address to use |
Bongjun | 0:e11e8793c3ce | 48 | * \param ip the IP address to use |
Bongjun | 0:e11e8793c3ce | 49 | * \param mask the IP address mask |
Bongjun | 0:e11e8793c3ce | 50 | * \param gateway the gateway to use |
Bongjun | 0:e11e8793c3ce | 51 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 52 | */ |
Bongjun | 0:e11e8793c3ce | 53 | int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway); |
Bongjun | 0:e11e8793c3ce | 54 | |
Bongjun | 0:e11e8793c3ce | 55 | /** Connect |
Bongjun | 0:e11e8793c3ce | 56 | * Bring the interface up, start DHCP if needed. |
Bongjun | 0:e11e8793c3ce | 57 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 58 | */ |
Bongjun | 0:e11e8793c3ce | 59 | int connect(); |
Bongjun | 0:e11e8793c3ce | 60 | |
Bongjun | 0:e11e8793c3ce | 61 | /** Disconnect |
Bongjun | 0:e11e8793c3ce | 62 | * Bring the interface down |
Bongjun | 0:e11e8793c3ce | 63 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 64 | */ |
Bongjun | 0:e11e8793c3ce | 65 | int disconnect(); |
Bongjun | 0:e11e8793c3ce | 66 | |
Bongjun | 0:e11e8793c3ce | 67 | /** Get IP address |
Bongjun | 0:e11e8793c3ce | 68 | * |
Bongjun | 0:e11e8793c3ce | 69 | * @ returns ip address |
Bongjun | 0:e11e8793c3ce | 70 | */ |
Bongjun | 0:e11e8793c3ce | 71 | char* getIPAddress(); |
Bongjun | 0:e11e8793c3ce | 72 | char* getNetworkMask(); |
Bongjun | 0:e11e8793c3ce | 73 | char* getGateway(); |
Bongjun | 0:e11e8793c3ce | 74 | char* getMACAddress(); |
Bongjun | 0:e11e8793c3ce | 75 | |
Bongjun | 0:e11e8793c3ce | 76 | int IPrenew(int timeout_ms = 15*1000); |
Bongjun | 0:e11e8793c3ce | 77 | |
Bongjun | 0:e11e8793c3ce | 78 | private: |
Bongjun | 0:e11e8793c3ce | 79 | char ip_string[20]; |
Bongjun | 0:e11e8793c3ce | 80 | char mask_string[20]; |
Bongjun | 0:e11e8793c3ce | 81 | char gw_string[20]; |
Bongjun | 0:e11e8793c3ce | 82 | char mac_string[20]; |
Bongjun | 0:e11e8793c3ce | 83 | bool ip_set; |
Bongjun | 0:e11e8793c3ce | 84 | }; |
Bongjun | 0:e11e8793c3ce | 85 | |
Bongjun | 0:e11e8793c3ce | 86 | #include "TCPSocketConnection.h" |
Bongjun | 0:e11e8793c3ce | 87 | #include "TCPSocketServer.h" |
Bongjun | 0:e11e8793c3ce | 88 | #include "UDPSocket.h" |