MQTT client test with W5200 ethernet shield
Dependents: IBMIoTClientEthernetExample_W5200
Fork of W5500Interface by
EthernetInterface.h@5:8aefaef88f79, 2014-09-26 (annotated)
- Committer:
- kaizen
- Date:
- Fri Sep 26 08:05:41 2014 +0000
- Revision:
- 5:8aefaef88f79
- Parent:
- 0:e11e8793c3ce
- Child:
- 6:677dfa3984d1
Modified for using MQTT protocol ( IBMIoTClient )
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); |
kaizen | 5:8aefaef88f79 | 23 | // EthernetInterface(); |
Bongjun | 0:e11e8793c3ce | 24 | |
Bongjun | 0:e11e8793c3ce | 25 | /** Initialize the interface with DHCP w/o MAC address |
Bongjun | 0:e11e8793c3ce | 26 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 27 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 28 | */ |
Bongjun | 0:e11e8793c3ce | 29 | int init(); //With DHCP |
Bongjun | 0:e11e8793c3ce | 30 | /** Initialize the interface with DHCP. |
Bongjun | 0:e11e8793c3ce | 31 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 32 | * \param mac the MAC address to use |
Bongjun | 0:e11e8793c3ce | 33 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 34 | */ |
Bongjun | 0:e11e8793c3ce | 35 | int init(uint8_t * mac); //With DHCP |
Bongjun | 0:e11e8793c3ce | 36 | |
Bongjun | 0:e11e8793c3ce | 37 | /** Initialize the interface with a static IP address without MAC. |
Bongjun | 0:e11e8793c3ce | 38 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 39 | * \param ip the IP address to use |
Bongjun | 0:e11e8793c3ce | 40 | * \param mask the IP address mask |
Bongjun | 0:e11e8793c3ce | 41 | * \param gateway the gateway to use |
Bongjun | 0:e11e8793c3ce | 42 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 43 | */ |
Bongjun | 0:e11e8793c3ce | 44 | |
Bongjun | 0:e11e8793c3ce | 45 | int init(const char* ip, const char* mask, const char* gateway); |
Bongjun | 0:e11e8793c3ce | 46 | /** Initialize the interface with a static IP address. |
Bongjun | 0:e11e8793c3ce | 47 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
Bongjun | 0:e11e8793c3ce | 48 | * \param mac the MAC address to use |
Bongjun | 0:e11e8793c3ce | 49 | * \param ip the IP address to use |
Bongjun | 0:e11e8793c3ce | 50 | * \param mask the IP address mask |
Bongjun | 0:e11e8793c3ce | 51 | * \param gateway the gateway to use |
Bongjun | 0:e11e8793c3ce | 52 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 53 | */ |
Bongjun | 0:e11e8793c3ce | 54 | int init(uint8_t * mac, const char* ip, const char* mask, const char* gateway); |
Bongjun | 0:e11e8793c3ce | 55 | |
Bongjun | 0:e11e8793c3ce | 56 | /** Connect |
Bongjun | 0:e11e8793c3ce | 57 | * Bring the interface up, start DHCP if needed. |
Bongjun | 0:e11e8793c3ce | 58 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 59 | */ |
Bongjun | 0:e11e8793c3ce | 60 | int connect(); |
Bongjun | 0:e11e8793c3ce | 61 | |
Bongjun | 0:e11e8793c3ce | 62 | /** Disconnect |
Bongjun | 0:e11e8793c3ce | 63 | * Bring the interface down |
Bongjun | 0:e11e8793c3ce | 64 | * \return 0 on success, a negative number on failure |
Bongjun | 0:e11e8793c3ce | 65 | */ |
Bongjun | 0:e11e8793c3ce | 66 | int disconnect(); |
Bongjun | 0:e11e8793c3ce | 67 | |
Bongjun | 0:e11e8793c3ce | 68 | /** Get IP address |
Bongjun | 0:e11e8793c3ce | 69 | * |
Bongjun | 0:e11e8793c3ce | 70 | * @ returns ip address |
Bongjun | 0:e11e8793c3ce | 71 | */ |
Bongjun | 0:e11e8793c3ce | 72 | char* getIPAddress(); |
Bongjun | 0:e11e8793c3ce | 73 | char* getNetworkMask(); |
Bongjun | 0:e11e8793c3ce | 74 | char* getGateway(); |
Bongjun | 0:e11e8793c3ce | 75 | char* getMACAddress(); |
Bongjun | 0:e11e8793c3ce | 76 | |
Bongjun | 0:e11e8793c3ce | 77 | int IPrenew(int timeout_ms = 15*1000); |
Bongjun | 0:e11e8793c3ce | 78 | |
Bongjun | 0:e11e8793c3ce | 79 | private: |
Bongjun | 0:e11e8793c3ce | 80 | char ip_string[20]; |
Bongjun | 0:e11e8793c3ce | 81 | char mask_string[20]; |
Bongjun | 0:e11e8793c3ce | 82 | char gw_string[20]; |
Bongjun | 0:e11e8793c3ce | 83 | char mac_string[20]; |
Bongjun | 0:e11e8793c3ce | 84 | bool ip_set; |
Bongjun | 0:e11e8793c3ce | 85 | }; |
Bongjun | 0:e11e8793c3ce | 86 | |
Bongjun | 0:e11e8793c3ce | 87 | #include "TCPSocketConnection.h" |
Bongjun | 0:e11e8793c3ce | 88 | #include "TCPSocketServer.h" |
Bongjun | 0:e11e8793c3ce | 89 | #include "UDPSocket.h" |