Example of using the ATT M2X back end. Connect over Ethernet with the WIZnet 5500 chip. This code sends random data to M2X.
Dependencies: M2XStreamClient WIZnet_Library jsonlite mbed
Fork of M2X_Nucleo411_ESP8266-wifi by
Revision 7:748a599726d8, committed 2015-12-26
- Comitter:
- sjallouli
- Date:
- Sat Dec 26 21:27:15 2015 +0000
- Parent:
- 6:694279899cf2
- Commit message:
- Example of using the ATT M2X back end. Connect over Ethernet with the WIZnet5500 chip. This code sends random data to M2X. This code can be used for Any board.
Changed in this revision
diff -r 694279899cf2 -r 748a599726d8 ESP8266Interface.lib --- a/ESP8266Interface.lib Fri Dec 11 00:58:10 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/ESP8266/code/ESP8266Interface/#03fd9333670d
diff -r 694279899cf2 -r 748a599726d8 WIZnet_Library.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WIZnet_Library.lib Sat Dec 26 21:27:15 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/WIZnet/code/WIZnet_Library/#cb8808b47e69
diff -r 694279899cf2 -r 748a599726d8 main.cpp --- a/main.cpp Fri Dec 11 00:58:10 2015 +0000 +++ b/main.cpp Sat Dec 26 21:27:15 2015 +0000 @@ -1,14 +1,21 @@ #include "mbed.h" #include "M2XStreamClient.h" -#include "ESP8266Interface.h" +#include "WIZnetInterface.h" #include "TCPSocketConnection.h" /* -* ESP8266 Wifi Config for nucleo 411 +* WIZnet 5500 Config for nucleo 411 */ -ESP8266Interface wifi(D8,D2,D3,"wifiName","wifiPassword",115200); // TX,RX,Reset,SSID,Password,Baud +Serial pc(SERIAL_TX, SERIAL_RX); +SPI spi(D11, D12, D13); // mosi, miso, sclk + +#define USE_DHCP 1 +const char * IP_Addr = "192.168.2.72"; +const char * IP_Subnet = "255.255.255.0"; +const char * IP_Gateway = "192.168.2.2"; +unsigned char MAC_Addr[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // // Fill these field in from you ATT M2X Account // @@ -18,18 +25,48 @@ int main() { - printf("Starting...\r\n"); + pc.baud(115200); // console terminal to 115200 baud + + pc.printf("STM32 WIZnet M2X Example\r\n"); + + pc.printf("Initializing SPI\r\n"); + spi.frequency(1000000); + pc.printf("Initializing Ethernet\r\n"); + WIZnetInterface ethernet(&spi,D10, D3); + +#if USE_DHCP + pc.printf("Ethernet Init\r\n"); + int ret = ethernet.init(MAC_Addr); +#else + int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); +#endif - // connect to wifi - wifi.init(); //Reset - wifi.connect(); //Use DHCP - printf("IP Address is %s \n\r", wifi.getIPAddress()); + 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()); + } + else + { + pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); + exit(0); + } + } + else + { + pc.printf("Error ethernet.init() - ret = %d\r\n", ret); + exit(0); + } // Initialize the M2X client Client client; M2XStreamClient m2xClient(&client, m2xKey,1,"52.22.150.98"); // api-m2x.att.com - int ret; volatile int randomNumber = 0; while (true) {