Simple Thing for DJ

Dependencies:   WIZnet_Library mbed

Fork of SimpleThing_DJ by Ganesh Gore

Committer:
ganeshgore
Date:
Tue Jun 30 06:35:18 2015 +0000
Revision:
3:bf6b5491779a
Parent:
2:1e8031dab116
Child:
4:06bee14d4029
Initial Commit;

Who changed what in which revision?

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