![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is a demo to show how to use Arch Link and dweet.io
Dependencies: BLE_API DHT HTTPClient SDFileSystem WIZnet_Library mbed nRF51822
Fork of archlink_Temperture_ethernet_http by
Diff: main.cpp
- Revision:
- 0:29bbc7eec5e1
- Child:
- 1:0f6a216263aa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 30 03:40:02 2015 +0000 @@ -0,0 +1,95 @@ +#include "mbed.h" +#include "SDFileSystem.h" +#include "BLE.h" +#include "WIZnetInterface.h" + + +#define USE_DHCP 0 +#define LOOPBACKPORT 5000 +int W5500_Test(void); +SPI spi(SPI_PSELMOSI0, SPI_PSELMISO0, SPI_PSELSCK0); +WIZnetInterface ethernet(&spi, p24, p17); // Spi ,cs, reset +int ret, dummy, lv = 1; +const char * IP_Addr = "192.168.21.247"; +const char * IP_Subnet = "255.255.255.0"; +const char * IP_Gateway = "192.168.21.2"; +unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x1C,0xAA,0xCA}; + + +DigitalOut myled(LED1); +//Arch Link +Serial pc(USBTX, USBRX); /* uart */ + + +int main() { + wait(1); + pc.baud(115200); + wait(1); + printf("helloworld\r\n"); + + if(W5500_Test() == 0) { + printf("W5500 tested OK \r\n"); + } + + while(1) { + myled = 1; + printf("light1\r\n"); + wait(3); + myled = 0; + printf("light0\r\n"); + wait(3); + } +} + +int W5500_Test(void) +{ + mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres + wait(1); + printf("Start to test ethernet!\r\n"); + + #if USE_DHCP + printf("use DHCP\r\n"); + ret = ethernet.init(MAC_Addr); + #else + printf("do NOT use DHCP\r\n"); + int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); + #endif + + if (!ret) { + pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); + ret = ethernet.connect(); + if (!ret) { + pc.printf("IP: %s, MASK: %s, GW: %s\r\n", + ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); + return 0; + } else { + pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); + //exit(0); + return -1; + } + } else { + pc.printf("Error ethernet.init() - ret = %d\r\n", ret); + //exit(0); + return -1; + } + /* + TCPSocketServer server; + server.bind(LOOPBACKPORT); + server.listen(); + + while (1) { + pc.printf("\nWait for new connection...\r\n"); + TCPSocketConnection client; + server.accept(client); + client.set_blocking(false, 0); // Timeout=0. + pc.printf("Connection from: %s\r\n", client.get_address()); + while (client.is_connected() == true) { + int n = client.receive(buffer, sizeof(buffer)); + if(n > 0) + client.send_all(buffer, n); + if(client.is_fin_received()) + client.close(); + } + pc.printf("Disconnected.\r\n"); + }*/ +} \ No newline at end of file