Simple Thing For VIT

Dependencies:   WIZnet_Library mbed

Committer:
ganeshgore
Date:
Tue Jun 30 11:18:54 2015 +0000
Revision:
0:9abf70ba4b3f
Initial;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganeshgore 0:9abf70ba4b3f 1 #include "mbed.h"
ganeshgore 0:9abf70ba4b3f 2 #include "WIZnetInterface.h"
ganeshgore 0:9abf70ba4b3f 3
ganeshgore 0:9abf70ba4b3f 4 unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x07,0x07};
ganeshgore 0:9abf70ba4b3f 5
ganeshgore 0:9abf70ba4b3f 6 char* Update_Key = "YTDILMQL53ASDCJ4";
ganeshgore 0:9abf70ba4b3f 7 char* ServerIP = "184.106.153.149";
ganeshgore 0:9abf70ba4b3f 8 int Count = 15;
ganeshgore 0:9abf70ba4b3f 9
ganeshgore 0:9abf70ba4b3f 10 Serial pc(USBTX, USBRX);
ganeshgore 0:9abf70ba4b3f 11 SPI spi(PTD2,PTD3,PTD1);
ganeshgore 0:9abf70ba4b3f 12 WIZnetInterface ethernet(&spi,PTD0,PTA20);
ganeshgore 0:9abf70ba4b3f 13 AnalogIn temp(PTC1);
ganeshgore 0:9abf70ba4b3f 14
ganeshgore 0:9abf70ba4b3f 15
ganeshgore 0:9abf70ba4b3f 16 int main()
ganeshgore 0:9abf70ba4b3f 17 {
ganeshgore 0:9abf70ba4b3f 18 //Set serial port baudrate speed: 19200
ganeshgore 0:9abf70ba4b3f 19 pc.baud(19200);
ganeshgore 0:9abf70ba4b3f 20 pc.printf("Start\r\n");
ganeshgore 0:9abf70ba4b3f 21
ganeshgore 0:9abf70ba4b3f 22 while(1) {
ganeshgore 0:9abf70ba4b3f 23 int ret = ethernet.init(MAC_Addr);
ganeshgore 0:9abf70ba4b3f 24
ganeshgore 0:9abf70ba4b3f 25 if (!ret) {
ganeshgore 0:9abf70ba4b3f 26 pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
ganeshgore 0:9abf70ba4b3f 27 ret = ethernet.connect();
ganeshgore 0:9abf70ba4b3f 28 if (!ret) {
ganeshgore 0:9abf70ba4b3f 29 pc.printf("IP: %s, MASK: %s, GW: %s\r\n",
ganeshgore 0:9abf70ba4b3f 30 ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
ganeshgore 0:9abf70ba4b3f 31 } else {
ganeshgore 0:9abf70ba4b3f 32 pc.printf("Error ethernet.connect() - ret = %d\r\n", ret);
ganeshgore 0:9abf70ba4b3f 33 exit(0);
ganeshgore 0:9abf70ba4b3f 34 }
ganeshgore 0:9abf70ba4b3f 35 } else {
ganeshgore 0:9abf70ba4b3f 36 pc.printf("Error ethernet.init() - ret = %d\r\n", ret);
ganeshgore 0:9abf70ba4b3f 37 exit(0);
ganeshgore 0:9abf70ba4b3f 38 }
ganeshgore 0:9abf70ba4b3f 39
ganeshgore 0:9abf70ba4b3f 40 TCPSocketConnection sock;
ganeshgore 0:9abf70ba4b3f 41 sock.connect("184.106.153.149", 80);
ganeshgore 0:9abf70ba4b3f 42 if(sock.is_connected())
ganeshgore 0:9abf70ba4b3f 43 pc.printf("Socket Connected\n\r");
ganeshgore 0:9abf70ba4b3f 44 else
ganeshgore 0:9abf70ba4b3f 45 pc.printf("Socket NoT Connected\n\r");
ganeshgore 0:9abf70ba4b3f 46
ganeshgore 0:9abf70ba4b3f 47
ganeshgore 0:9abf70ba4b3f 48 char buffer[300];
ganeshgore 0:9abf70ba4b3f 49 int ret_t;
ganeshgore 0:9abf70ba4b3f 50
ganeshgore 0:9abf70ba4b3f 51 char http_cmd[256];
ganeshgore 0:9abf70ba4b3f 52 sprintf(http_cmd,"GET /update?key=YTDILMQL53ASDCJ4&field1=500 HTTP/1.0\n\n");
ganeshgore 0:9abf70ba4b3f 53 printf("Running - %s\r\n",http_cmd);
ganeshgore 0:9abf70ba4b3f 54 sock.send_all(http_cmd, sizeof(http_cmd)-1);
ganeshgore 0:9abf70ba4b3f 55
ganeshgore 0:9abf70ba4b3f 56 ret_t = sock.receive(buffer, sizeof(buffer)-1);
ganeshgore 0:9abf70ba4b3f 57 buffer[ret_t] = '\0';
ganeshgore 0:9abf70ba4b3f 58 printf("Received %d chars from server:\n%s\r\n", ret_t, buffer);
ganeshgore 0:9abf70ba4b3f 59
ganeshgore 0:9abf70ba4b3f 60 sock.close();
ganeshgore 0:9abf70ba4b3f 61
ganeshgore 0:9abf70ba4b3f 62 ethernet.disconnect();
ganeshgore 0:9abf70ba4b3f 63 printf("Socket Closed");
ganeshgore 0:9abf70ba4b3f 64
ganeshgore 0:9abf70ba4b3f 65 while(1);
ganeshgore 0:9abf70ba4b3f 66 }
ganeshgore 0:9abf70ba4b3f 67 }