lpc824lite 采集温湿度压强数据显示至oled12864,通w5500与用户进行TCP交互
Dependencies: mbed WIZnet_Library AM2320 BME280
Diff: main.cpp
- Revision:
- 1:cc2094da451b
- Parent:
- 0:ef802f772981
- Child:
- 2:82785740745d
diff -r ef802f772981 -r cc2094da451b main.cpp --- a/main.cpp Thu May 11 16:51:19 2017 +0000 +++ b/main.cpp Mon May 29 00:35:16 2017 +0000 @@ -22,6 +22,8 @@ DigitalOut myled1(P0_27); DigitalOut myled2(P0_13); DigitalOut myled3(P0_17); //用户led +DigitalOut myled4(P0_18); +DigitalOut myled5(P0_19); Ticker ticker; float sampleTime = 1.0; long times; @@ -78,6 +80,7 @@ } Serial pc(P0_4,P0_0,921600); +// Line buffers for sprintf and sscanf //w5500初始化函数 #include "WIZnetInterface.h" #define USE_DHCP 1 @@ -100,6 +103,9 @@ int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); #endif myled2=1; + myled3=1; + myled4=1; + myled5=1; if (!ret) { pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); ret = ethernet.connect(); @@ -135,7 +141,9 @@ sendStrXY(client.get_address(),3,3); while (client.is_connected() == true) { myled2=0; + memset(buffer,'\0',sizeof(buffer)); int n = client.receive(buffer, sizeof(buffer)); + if(n > 0) { //client.send_all(buffer, n); //将接受的数据发送回去 @@ -149,11 +157,18 @@ client.send(buffer3, sizeof(buffer3)); if(strstr(buffer,"LED")) + { myled3=!myled3; + } + + if(strstr(buffer,"led")) + { + myled5=!myled5; + } if(strstr(buffer,"ALL")) { - snprintf(Buffer,sizeof(Buffer), " %s\r\n %s\r\n %s\r\n ledstatus:%d\r\n",buffer1,buffer2,buffer3,!myled3); + snprintf(Buffer,sizeof(Buffer), " %s\r\n %s\r\n %s\r\n led3:%d led5:%d\r\n",buffer1,buffer2,buffer3,!myled3,!myled5); client.send(Buffer, sizeof(Buffer)); } @@ -161,7 +176,12 @@ { snprintf(Buffer,sizeof(Buffer), " MAC_Addr: %s\r\n LocalIp: %s\r\n ClientIp: %s\r\n",ethernet.getMACAddress(),ethernet.getIPAddress(),client.get_address()); client.send(Buffer, sizeof(Buffer)); - } + } + if(strstr(buffer,"NET")) + { + snprintf(Buffer,sizeof(Buffer), " Network: %s\r\n Gateway: %s\r\n",ethernet.getNetworkMask(), ethernet.getGateway()); + client.send(Buffer, sizeof(Buffer)); + } } if(client.is_fin_received()) client.close(); @@ -173,12 +193,34 @@ } } - +void rxCallback() { + myled4 = 0; + while (pc.readable()) { + switch(pc.getc()) + { + case '0':pc.printf("%s\r\n",buffer1);break; + case '1':pc.printf("%s\r\n",buffer2);break; + case '2':pc.printf("%s\r\n",buffer3);break; + case '3':pc.printf("%s\r\n",Buffer);break; + case 'O':myled3=0;pc.printf("LED3 ON\r\n");break; + case 'F':myled3=1;pc.printf("LED3 OFF\r\n");break; + case 'o':myled5=0;pc.printf("LED5 ON\r\n");break; + case 'f':myled5=1;pc.printf("LED5 OFF\r\n");break; + case 'P':pc.printf(" Network: %s\r\n Gateway: %s\r\n" + " MAC_Addr: %s\r\n LocalIp: %s\r\n", + ethernet.getNetworkMask(), ethernet.getGateway(), + ethernet.getMACAddress(),ethernet.getIPAddress());break; + default:break; + } + } + myled4 = 1; +} int main() { - pc.printf("Start\r\n"); + pc.printf("LPC824_W5500_SD1306_AM2320_BMP280 Demo\r\n"); oled_init(); - wait(5); + pc.attach(&rxCallback, Serial::RxIrq); +// wait(5); while(1) { w5500_httpserver();