Ethernet

Dependencies:   ASDL_using_Ethernet MMA8451Q mbed

Files at this revision

API Documentation at this revision

Comitter:
RITVIK_DAVE
Date:
Sat Feb 25 11:59:22 2017 +0000
Commit message:
Ethernet

Changed in this revision

ASDL_using_Ethernet.lib Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 13b0a84d31ec ASDL_using_Ethernet.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ASDL_using_Ethernet.lib	Sat Feb 25 11:59:22 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/eduvanceIoT/code/ASDL_using_Ethernet/#c2e8c0ee6341
diff -r 000000000000 -r 13b0a84d31ec MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Sat Feb 25 11:59:22 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r 13b0a84d31ec main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 25 11:59:22 2017 +0000
@@ -0,0 +1,84 @@
+#include "mbed.h"
+#include "WIZnetInterface.h"
+//MAC address of sheild
+unsigned char MAC_Addr[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+char* ServerIP = "192.168.0.2"; //server ip were server is set
+//public and private key of stream
+char* public_key = "YmYBg4do89c4MvQoLxXBhb6DpD9";
+char* private_key = "YK6DmdejWAF0Bwdj5pzGH7vP8Pn";
+int Count = 15;
+int x,y;
+Serial pc(USBTX, USBRX);
+SPI spi(PTD2,PTD3,PTD1);
+//wiznet object
+WIZnetInterface ethernet(&spi,PTD0,PTA20);
+//analog input
+AnalogIn pot(PTB1);
+AnalogIn ldr(PTB0);
+int writtenLen,eth;
+int main()
+{
+//Set serial port baudrate speed: 9600
+pc.baud(9600);
+pc.printf("Start\r\n");
+while(1)
+{
+//pc.printf("%d\r\n",x);
+int ret = ethernet.init(MAC_Addr);
+if (!ret)
+{
+//print MAC address of device
+pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
+ret = ethernet.connect();
+if (!ret)
+{
+//print IP alloted and details obtianed from network
+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);
+}
+//create TCP socket
+TCPSocketConnection sock;
+while(1){
+x=255*pot.read();
+y=255*ldr.read();
+//connect the server to port 8080
+sock.connect(ServerIP, 8080);
+if(sock.is_connected())
+pc.printf("Socket Connected\n\r");
+else
+pc.printf("Socket NoT Connected\n\r");
+//create character buffer for URL
+char buffer[300];
+int ret_t;
+char http_cmd[100];
+//make URL
+sprintf(http_cmd,"GET /input/%s?private_key=%s&pot=%d&ldr=%d HTTP/1.0\n\n",public_key,private_key,x,y);
+printf("sending %d characters",strlen(http_cmd));
+printf("Running - %s\r\n",http_cmd);
+writtenLen = sock.send_all(http_cmd, strlen(http_cmd));
+//print the result of URL GET method
+if(writtenLen == -1)
+printf("sending failed\r\n");
+else
+printf("sending success\r\n");
+eth=ret_t = sock.receive(buffer, strlen(buffer));
+buffer[ret_t] = '\0';
+printf("Received %d chars from server:\r\n%s\r\n", ret_t, buffer);
+sock.close();
+//ethernet.disconnect();
+pc.printf("Socket Closed\r\n");
+wait(3);
+}
+}
+}
\ No newline at end of file
diff -r 000000000000 -r 13b0a84d31ec mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Feb 25 11:59:22 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f
\ No newline at end of file