Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Blynk_Example_WIZwiki-W7500
Fork of Blynk by
BlynkEthernet.h
00001 /** 00002 * @file BlynkEthernet.h 00003 * @author Volodymyr Shymanskyy 00004 * @license This project is released under the MIT License (MIT) 00005 * @copyright Copyright (c) 2015 Volodymyr Shymanskyy 00006 * @date Jan 2015 00007 * @brief 00008 * 00009 */ 00010 00011 #ifndef BlynkEthernet_h 00012 #define BlynkEthernet_h 00013 00014 #ifndef BLYNK_INFO_CONNECTION 00015 #define BLYNK_INFO_CONNECTION "W5000" 00016 #endif 00017 00018 #include <EthernetInterface.h> 00019 #include <BlynkApiMbed.h > 00020 #include <Blynk/BlynkProtocol.h> 00021 #include <Adapters/BlynkMbedClient.h> 00022 00023 EthernetInterface eth; 00024 00025 class BlynkEthernet 00026 : public BlynkProtocol<BlynkMbedClient> 00027 { 00028 typedef BlynkProtocol<BlynkMbedClient> Base; 00029 public: 00030 BlynkEthernet(BlynkMbedClient& transp) 00031 : Base(transp) 00032 {} 00033 00034 void config(const char* auth, 00035 const char* domain = BLYNK_DEFAULT_DOMAIN, 00036 uint16_t port = BLYNK_DEFAULT_PORT) 00037 { 00038 Base::begin(auth); 00039 this->conn.begin(domain, port); 00040 } 00041 00042 void config(const char* auth, 00043 char* ip, 00044 uint16_t port = BLYNK_DEFAULT_PORT) 00045 { 00046 Base::begin(auth); 00047 this->conn.begin(ip, port); 00048 } 00049 00050 // DHCP with domain 00051 void begin( const char* auth, 00052 const char* domain = BLYNK_DEFAULT_DOMAIN, 00053 uint16_t port = BLYNK_DEFAULT_PORT, 00054 uint8_t mac[] = NULL) 00055 { 00056 int phy_link; 00057 eth.init(mac); 00058 // phy link 00059 do{ 00060 phy_link = eth.ethernet_link(); 00061 printf("..."); 00062 wait(2); 00063 }while(!phy_link); 00064 00065 BLYNK_LOG1(BLYNK_F("Getting IP...")); 00066 if (eth.connect()==-1) { 00067 BLYNK_FATAL(BLYNK_F("DHCP Failed!")); 00068 } 00069 00070 00071 // give the Ethernet shield a second to initialize: 00072 ::delay(1000); 00073 char* myip = eth.getIPAddress(); 00074 BLYNK_LOG_IP("IP:", myip); 00075 00076 config(auth, domain, port); 00077 printf("configure!\r\n"); 00078 while(this->connect() != true) {} 00079 } 00080 // 00081 // // Static IP with domain 00082 // void begin( const char* auth, 00083 // const char* domain, 00084 // uint16_t port, 00085 // char* local, 00086 // char* dns, 00087 // const uint8_t mac[] = NULL) 00088 // { 00089 // BLYNK_LOG1(BLYNK_F("Using static IP")); 00090 // Ethernet.begin(SelectMacAddress(auth, mac), local, dns); 00091 // // give the Ethernet shield a second to initialize: 00092 // ::delay(1000); 00093 // char* myip = Ethernet.localIP(); 00094 // BLYNK_LOG_IP("IP:", myip); 00095 // 00096 // config(auth, domain, port); 00097 // while(this->connect() != true) {} 00098 // } 00099 // 00100 // // Static IP with domain, gateway, etc 00101 // void begin( const char* auth, 00102 // const char* domain, 00103 // uint16_t port, 00104 // char* local, 00105 // char* dns, 00106 // char* gateway, 00107 // char* subnet, 00108 // const uint8_t mac[] = NULL) 00109 // { 00110 // BLYNK_LOG1(BLYNK_F("Using static IP")); 00111 // Ethernet.begin(SelectMacAddress(auth, mac), local, dns, gateway, subnet); 00112 // // give the Ethernet shield a second to initialize: 00113 // ::delay(1000); 00114 // char* myip = Ethernet.localIP(); 00115 // BLYNK_LOG_IP("IP:", myip); 00116 // 00117 // config(auth, domain, port); 00118 // while(this->connect() != true) {} 00119 // } 00120 // 00121 // // DHCP with server IP 00122 // void begin( const char* auth, 00123 // char* addr, 00124 // uint16_t port = BLYNK_DEFAULT_PORT, 00125 // const uint8_t mac[] = NULL) 00126 // { 00127 // BLYNK_LOG1(BLYNK_F("Getting IP...")); 00128 // if (!Ethernet.begin(SelectMacAddress(auth, mac))) { 00129 // BLYNK_FATAL(BLYNK_F("DHCP Failed!")); 00130 // } 00131 // // give the Ethernet shield a second to initialize: 00132 // ::delay(1000); 00133 // char* myip = Ethernet.localIP(); 00134 // BLYNK_LOG_IP("IP:", myip); 00135 // 00136 // config(auth, addr, port); 00137 // while(this->connect() != true) {} 00138 // } 00139 // 00140 // // Static IP with server IP 00141 // void begin( const char* auth, 00142 // char* addr, 00143 // uint16_t port, 00144 // char* local, 00145 // const uint8_t mac[] = NULL) 00146 // { 00147 // BLYNK_LOG1(BLYNK_F("Using static IP")); 00148 // Ethernet.begin(SelectMacAddress(auth, mac), local); 00149 // // give the Ethernet shield a second to initialize: 00150 // ::delay(1000); 00151 // char* myip = Ethernet.localIP(); 00152 // BLYNK_LOG_IP("IP:", myip); 00153 // 00154 // config(auth, addr, port); 00155 // while(this->connect() != true) {} 00156 // } 00157 // 00158 // // Static IP with server IP, DNS, gateway, etc 00159 // void begin( const char* auth, 00160 // char* addr, 00161 // uint16_t port, 00162 // char* local, 00163 // char* dns, 00164 // char* gateway, 00165 // char* subnet, 00166 // const uint8_t mac[] = NULL) 00167 // { 00168 // BLYNK_LOG1(BLYNK_F("Using static IP")); 00169 // Ethernet.begin(SelectMacAddress(auth, mac), local, dns, gateway, subnet); 00170 // // give the Ethernet shield a second to initialize: 00171 // ::delay(1000); 00172 // char* myip = Ethernet.localIP(); 00173 // BLYNK_LOG_IP("IP:", myip); 00174 // 00175 // config(auth, addr, port); 00176 // while(this->connect() != true) {} 00177 // } 00178 // 00179 //private: 00180 // 00181 // byte* SelectMacAddress(const char* token, const uint8_t mac[]) 00182 // { 00183 // if (mac != NULL) { 00184 // return (byte*)mac; 00185 // } 00186 // 00187 // macAddress[0] = 0xFE; 00188 // macAddress[1] = 0xED; 00189 // macAddress[2] = 0xBA; 00190 // macAddress[3] = 0xFE; 00191 // macAddress[4] = 0xFE; 00192 // macAddress[5] = 0xED; 00193 // 00194 // int len = strlen(token); 00195 // int mac_index = 1; 00196 // for (int i=0; i<len; i++) { 00197 // macAddress[mac_index++] ^= token[i]; 00198 // 00199 // if (mac_index > 5) { mac_index = 1; } 00200 // } 00201 // /* BLYNK_LOG("MAC: %02X-%02X-%02X-%02X-%02X-%02X", 00202 // macAddress[0], macAddress[1], 00203 // macAddress[2], macAddress[3], 00204 // macAddress[4], macAddress[5]); 00205 // */ 00206 // return macAddress; 00207 // } 00208 00209 private: 00210 uint8_t macAddress[6]; 00211 00212 }; 00213 00214 #endif
Generated on Tue Jul 12 2022 17:30:45 by
1.7.2
