..
Dependencies: ESP8266Interface WIZnetInterface_namespace mbed-src
main.cpp
00001 #include "mbed.h" 00002 00003 #include "ESP8266Interface.h" 00004 #include "EthernetInterface.hpp" 00005 00006 DigitalOut led1(LED1); 00007 DigitalOut led2(LED2); 00008 00009 ESP8266Interface wifi(D1, D0, D2, "WizFiDemoAP","12345678",115200); // tx, rx for 00010 wiznet_space::EthernetInterface eth; 00011 00012 RawSerial pc(USBTX, USBRX); // tx, rx 00013 00014 extern void ProcessDataViaEthernet(); 00015 extern void ProcessDataViaWiFi(); 00016 00017 // For monitoring data from ESP8266 00018 Timeout timer_buffer_debug; 00019 CircBuffer<char> buffer_ESP8266_recv(1024); 00020 00021 void print_buffer_ESP8266() 00022 { 00023 char c=0; 00024 while ( buffer_ESP8266_recv.available() ) { 00025 buffer_ESP8266_recv.dequeue(&c); 00026 pc.putc(c); 00027 } 00028 timer_buffer_debug.attach(&print_buffer_ESP8266, 0.1); 00029 } 00030 00031 00032 bool InitializeWiznetEthernet() 00033 { 00034 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xFF, 0x11, 0x22}; 00035 00036 //eth.init(mac_addr); //Use DHCP 00037 eth.init(mac_addr, "192.168.3.102", "255.255.255.0", "192.168.3.1"); //Use DHCP 00038 00039 // Check Ethenret Link 00040 if( eth.link()!=true ) 00041 { 00042 printf("- Ethernet PHY Link- Fail\r\n"); 00043 return false; 00044 } 00045 00046 // Start Ethernet connecting: Trying to get an IP address using DHCP 00047 if ( eth.connect() < 0 ){ 00048 printf("Fail - Ethernet Connecing"); 00049 return false; 00050 } 00051 00052 //pc.printf("IP Address(Ethernet Interface) is %s\r\n", eth.getIPAddress()); 00053 00054 return true; 00055 } 00056 00057 bool InitializeESP8266() 00058 { 00059 // if you don't want to monitor ESP-module-data, remove below line. 00060 //timer_buffer_debug.attach(&print_buffer_ESP8266, 0.5); 00061 00062 wifi.init(); 00063 00064 bool result = wifi.connect(); 00065 if ( !result ) { 00066 pc.printf("wifi.connect error\r\n"); 00067 return false; 00068 } 00069 00070 //pc.printf("IP Address(WiFi Interface) is %s\r\n", wifi.getIPAddress()); 00071 return true; 00072 } 00073 00074 00075 int main() 00076 { 00077 // Initialize LED 00078 for (int i=0; i<20; i++) 00079 { 00080 led1 = !led1; 00081 led2 = !led2; 00082 wait(0.05); 00083 } 00084 00085 // Initialize UART 00086 pc.baud(115200); 00087 pc.printf("\r\nDual Network Interface Test.\r\n"); 00088 00089 // Ethernet : WIZnet hardwired TCP/IP in W7500 00090 if ( InitializeWiznetEthernet() ) 00091 { 00092 ProcessDataViaEthernet(); 00093 pc.printf("WIZnet hardwired TCP/IP in W7500 Test Done.\r\n"); 00094 } 00095 00096 // WiFi : ESP8266 00097 if ( InitializeESP8266() ) 00098 { 00099 ProcessDataViaWiFi(); 00100 pc.printf("ESP8266 Test Done.\r\n"); 00101 } 00102 00103 00104 while(1) { 00105 wait(1); 00106 } 00107 } 00108
Generated on Sat Jul 16 2022 19:04:04 by 1.7.2