Paho MQTT Client example with W7500
Dependencies: DHT MQTTforLecture WIZnetInterface mbed-src
Fork of w7500-paho-mqtt by
Code
WIZwiki W7500 with paho mqtt client.
Import programw7500-paho-mqtt
Paho MQTT Client example with W7500
You have to change
You have to use your ethernet(network) information.
MQTTEthernet.h
uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x00, 0x00}; // your mac address const char * ip_addr = "???.???.???.???"; // your ip const char * gw_addr = "???.???.???.???"; // your gateway const char * snmask = "???.???.???.???"; // your subnetmask
And you have to use your mqtt broker server information. Broker server ip address and port number listed bleow are available now. But I will close the mqtt broker server on July 15,2015.
main.cpp
char* hostname = "104.199.146.45"; int port = 1883;
Platform
WIZwiki W7500 [ https://developer.mbed.org/platforms/WIZwiki-W7500/ ]
Component
YWRobot Easy module shield [ where to buy ] (This is not mbed component)
Test software
PC
MQTT-FX - A JavaFX based MQTT Client [ Home page ]
Mobile(iPhone)
ZMQTT-UTILITY - MQTT Test utility|You can download from App store(iPhone).
main.cpp@1:5cebe0e38cd2, 2012-07-25 (annotated)
- Committer:
- emilmont
- Date:
- Wed Jul 25 15:43:24 2012 +0000
- Revision:
- 1:5cebe0e38cd2
- Parent:
- 0:38cbb854d85f
- Child:
- 2:ec5ae99791da
First implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:38cbb854d85f | 1 | #include "mbed.h" |
emilmont | 1:5cebe0e38cd2 | 2 | #include "EthernetInterface.h" |
emilmont | 1:5cebe0e38cd2 | 3 | |
emilmont | 1:5cebe0e38cd2 | 4 | int main (void) { |
emilmont | 1:5cebe0e38cd2 | 5 | EthernetInterface eth; |
emilmont | 1:5cebe0e38cd2 | 6 | eth.init(); //Use DHCP |
emilmont | 1:5cebe0e38cd2 | 7 | eth.connect(); |
emilmont | 1:5cebe0e38cd2 | 8 | printf("IP Address is %s\n", eth.getIPAddress()); |
emilmont | 1:5cebe0e38cd2 | 9 | |
emilmont | 1:5cebe0e38cd2 | 10 | TCPSocketServer server; |
emilmont | 1:5cebe0e38cd2 | 11 | server.bind(7); |
emilmont | 1:5cebe0e38cd2 | 12 | server.listen(1); |
emilmont | 1:5cebe0e38cd2 | 13 | |
emilmont | 1:5cebe0e38cd2 | 14 | while (true) { |
emilmont | 1:5cebe0e38cd2 | 15 | printf("\nWait for new connection...\n"); |
emilmont | 1:5cebe0e38cd2 | 16 | TCPSocketConnection client; |
emilmont | 1:5cebe0e38cd2 | 17 | server.accept(client); |
emilmont | 1:5cebe0e38cd2 | 18 | |
emilmont | 1:5cebe0e38cd2 | 19 | printf("Connection from: %s\n", client.get_address()); |
emilmont | 1:5cebe0e38cd2 | 20 | char buffer[256]; |
emilmont | 1:5cebe0e38cd2 | 21 | while (true) { |
emilmont | 1:5cebe0e38cd2 | 22 | int n = client.receive(buffer, 256, 3000); |
emilmont | 1:5cebe0e38cd2 | 23 | if (n <= 0) break; |
emilmont | 1:5cebe0e38cd2 | 24 | |
emilmont | 1:5cebe0e38cd2 | 25 | client.send_all(buffer, n, 3000); |
emilmont | 1:5cebe0e38cd2 | 26 | if (n <= 0) break; |
emilmont | 1:5cebe0e38cd2 | 27 | } |
emilmont | 1:5cebe0e38cd2 | 28 | client.close(); |
emilmont | 1:5cebe0e38cd2 | 29 | } |
emilmont | 1:5cebe0e38cd2 | 30 | } |