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.
Dependencies: DHT WIZnetInterface mbed-src
ThingerMBedEthernet.h
00001 // The MIT License (MIT) 00002 // 00003 // Copyright (c) 2015 THINGER LTD 00004 // Author: alvarolb@gmail.com (Alvaro Luis Bustamante) 00005 // 00006 // Permission is hereby granted, free of charge, to any person obtaining a copy 00007 // of this software and associated documentation files (the "Software"), to deal 00008 // in the Software without restriction, including without limitation the rights 00009 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 // copies of the Software, and to permit persons to whom the Software is 00011 // furnished to do so, subject to the following conditions: 00012 // 00013 // The above copyright notice and this permission notice shall be included in 00014 // all copies or substantial portions of the Software. 00015 // 00016 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 // THE SOFTWARE. 00023 00024 #ifndef THINGER_MBED_ETHERNET_H 00025 #define THINGER_MBED_ETHERNET_H 00026 00027 #include "ThingerMBedClient.h" 00028 00029 //#define _DEBUG_ 00030 00031 #ifndef _DHCP_ // Should be defined your network information. 00032 #define DEV_IP_ADDRESS "192.168.0.100" 00033 #define DEV_GW_ADDRESS "192.168.0.1" 00034 #define DEV_SN_ADDRESS "255.255.255.0" 00035 #endif 00036 00037 00038 class ThingerEthernet : public ThingerClient { 00039 00040 public: 00041 ThingerEthernet(const char* user, const char* device, const char* device_credential) : 00042 ThingerClient(client_, user, device, device_credential), connected_(false) 00043 {} 00044 00045 ~ThingerEthernet(){ 00046 00047 } 00048 00049 protected: 00050 00051 virtual bool network_connected(){ 00052 return connected_; 00053 } 00054 00055 virtual bool connect_network(){ 00056 if(connected_) return true; 00057 uint8_t mac[6] = { 0x1D, 0xdc, 0x08, 0x00, 0x62, 0x11 }; 00058 unsigned long ethernet_timeout = millis(); 00059 00060 #ifdef _DHCP_ 00061 #ifdef _DEBUG_ 00062 printf("[NETWORK] Getting DHCP IP Address...\r\n"); 00063 #endif 00064 ((EthernetInterface*)WIZnet_Chip::getInstance()).init(mac); 00065 #else 00066 ((EthernetInterface*)WIZnet_Chip::getInstance())->init(mac,DEV_IP_ADDRESS,DEV_SN_ADDRESS,DEV_GW_ADDRESS); 00067 #endif 00068 00069 ((EthernetInterface*)WIZnet_Chip::getInstance())->ethernet_link(); 00070 delay(3000); 00071 #ifdef _DEBUG_ 00072 #ifdef _DHCP_ 00073 printf("[NETWORK] Waiting for IP...\r\n"); 00074 #endif 00075 #endif 00076 00077 connected_ = true; 00078 if(((EthernetInterface*)WIZnet_Chip::getInstance())->connect() > 0) connected_ = false; 00079 00080 #ifdef _DEBUG_ 00081 printf("[NETWORK] Got Ip Address: %s\r\n",((EthernetInterface*)WIZnet_Chip::getInstance())->getIPAddress()); 00082 #endif 00083 delay(1000); 00084 return connected_; 00085 } 00086 00087 private: 00088 bool connected_; 00089 TCPSocketConnectionArdu client_; 00090 }; 00091 00092 #endif
Generated on Wed Jul 13 2022 02:25:39 by
