MQTT For Wiz750sr

Dependencies:   FP MQTTPacket

Fork of MQTT by Albin Sebastian

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTEthernet.h Source File

MQTTEthernet.h

00001 
00002 #if !defined(MQTTETHERNET_H)
00003 #define MQTTETHERNET_H
00004 
00005 #include "MQTTmbed.h"
00006 #include "EthernetInterface.h"
00007 #include "MQTTSocket.h"
00008 
00009 
00010 
00011 class MQTTEthernet : public MQTTSocket
00012 {
00013 public:    
00014     MQTTEthernet()
00015     {
00016         wait(1);
00017         this->createSocket();
00018         //eth.init(mac_addr,ip_addr,snmask,gw_addr);                          // Do not use DHCP! If you use DHCP use "eth.init(mac_addr);".
00019         uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x54, 0x88, 0x76}; 
00020 
00021   eth.init(mac_addr);
00022   
00023   printf("Check Ethernet Link\r\n");
00024     while(1) { //Wait link up
00025         if(eth.link() == true)
00026             break;
00027     }
00028     printf("Link up\r\n");
00029 
00030     int ethErr = eth.connect();
00031     
00032   
00033   if(ethErr < 0)
00034   {
00035     printf("Error %d in setup.\n", ethErr);
00036   }
00037   printf("Server IP Address is %s\r\n", eth.getIPAddress());
00038   
00039     }
00040     
00041     EthernetInterface& getEth()
00042     {
00043         return eth;
00044     }
00045     
00046     void reconnect()
00047     {
00048         eth.connect();  // nothing I've tried actually works to reconnect 
00049     }
00050     
00051 private:
00052 
00053     EthernetInterface eth;
00054     
00055 };
00056 
00057 
00058 #endif