Uploading a value to the Sparkfun IOT cloud using Ethernet present on NXP K64F board.
Dependencies: EthernetInterface mbed-rtos mbed
Revision 0:9eca947a9efa, committed 2016-05-19
- Comitter:
- janhavi
- Date:
- Thu May 19 06:52:59 2016 +0000
- Commit message:
- Basic Ethernet communication with sparkfun in K64F
Changed in this revision
diff -r 000000000000 -r 9eca947a9efa EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Thu May 19 06:52:59 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
diff -r 000000000000 -r 9eca947a9efa main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 19 06:52:59 2016 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" +#include "EthernetInterface.h" + +char* Public_Key = "ro9WnDLy63t4xp5n18vm"; +char* Private_Key = "jkKr0obAEnS0MgJRNa92"; +char* ServerIP = "data.sparkfun.com"; + +Serial pc(USBTX, USBRX); + +EthernetInterface ethernet; + +int main() +{ + pc.baud(115200); + pc.printf("Start\r\n"); + int a=100; + while(1) + { + int ret = ethernet.init(); + 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); + } + TCPSocketConnection sock; + char buffer[300]; + int ret_t; + char http_cmd[256]; + while(1) + { + + sock.connect(ServerIP, 80); + if(sock.is_connected()) + printf("Socket Connected\n\r"); + else + printf("Socket NoT Connected\n\r"); + //sprintf(http_cmd,"GET /input/%s?private_key=%s&a=%2d HTTP/1.0\n\n",Public_Key,Private_Key,a); + sprintf(http_cmd,"GET /input/%s?private_key=%s&a=%2d HTTP/1.0\n\n",Public_Key,Private_Key,a); + pc.printf("Running - %s\r\n",http_cmd); + sock.send_all(http_cmd, sizeof(http_cmd)-1); + + ret_t = sock.receive(buffer, sizeof(buffer)-1); + buffer[ret_t] = '\0'; + pc.printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); + sock.close(); + a=a+1; + wait(5); + } + + } + + + }
diff -r 000000000000 -r 9eca947a9efa mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu May 19 06:52:59 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#11950e007d8a
diff -r 000000000000 -r 9eca947a9efa mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 19 06:52:59 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e \ No newline at end of file