Simple Thing for DJ
Dependencies: WIZnet_Library mbed
Fork of SimpleThing_DJ by
main.cpp@5:7b21f6b1bdaa, 2015-06-30 (annotated)
- Committer:
- ganeshgore
- Date:
- Tue Jun 30 07:22:50 2015 +0000
- Revision:
- 5:7b21f6b1bdaa
- Parent:
- 4:06bee14d4029
new;
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:7b21f6b1bdaa | 6 | char* Public_Key = "g1WVqxqKqNtr2AVG6424TVvoyopy"; |
ganeshgore | 5:7b21f6b1bdaa | 7 | char* Private_Key = "dRbwA0AeAWf7DqyMOdDdHzlA9Av9"; |
ganeshgore | 3:bf6b5491779a | 8 | char* ServerIP = "192.168.44.70"; |
ganeshgore | 5:7b21f6b1bdaa | 9 | int Count = 15; |
ganeshgore | 3:bf6b5491779a | 10 | |
bangbh | 0:412f9c1172b7 | 11 | Serial pc(USBTX, USBRX); |
ganeshgore | 1:421fd0a7b5d7 | 12 | SPI spi(PTD2,PTD3,PTD1); |
ganeshgore | 1:421fd0a7b5d7 | 13 | WIZnetInterface ethernet(&spi,PTD0,PTA20); |
ganeshgore | 3:bf6b5491779a | 14 | AnalogIn temp(PTC1); |
ganeshgore | 3:bf6b5491779a | 15 | |
bangbh | 0:412f9c1172b7 | 16 | |
ganeshgore | 1:421fd0a7b5d7 | 17 | int main() |
ganeshgore | 1:421fd0a7b5d7 | 18 | { |
bangbh | 0:412f9c1172b7 | 19 | //Set serial port baudrate speed: 115200 |
bangbh | 0:412f9c1172b7 | 20 | pc.baud(115200); |
ganeshgore | 3:bf6b5491779a | 21 | pc.printf("Start\r\n"); |
ganeshgore | 3:bf6b5491779a | 22 | |
ganeshgore | 1:421fd0a7b5d7 | 23 | while(1) { |
ganeshgore | 3:bf6b5491779a | 24 | int ret = ethernet.init(MAC_Addr); |
ganeshgore | 3:bf6b5491779a | 25 | |
bangbh | 0:412f9c1172b7 | 26 | if (!ret) { |
bangbh | 0:412f9c1172b7 | 27 | pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress()); |
bangbh | 0:412f9c1172b7 | 28 | ret = ethernet.connect(); |
bangbh | 0:412f9c1172b7 | 29 | if (!ret) { |
bangbh | 0:412f9c1172b7 | 30 | pc.printf("IP: %s, MASK: %s, GW: %s\r\n", |
bangbh | 0:412f9c1172b7 | 31 | ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); |
bangbh | 0:412f9c1172b7 | 32 | } else { |
bangbh | 0:412f9c1172b7 | 33 | pc.printf("Error ethernet.connect() - ret = %d\r\n", ret); |
bangbh | 0:412f9c1172b7 | 34 | exit(0); |
bangbh | 0:412f9c1172b7 | 35 | } |
bangbh | 0:412f9c1172b7 | 36 | } else { |
bangbh | 0:412f9c1172b7 | 37 | pc.printf("Error ethernet.init() - ret = %d\r\n", ret); |
bangbh | 0:412f9c1172b7 | 38 | exit(0); |
ganeshgore | 5:7b21f6b1bdaa | 39 | } |
ganeshgore | 3:bf6b5491779a | 40 | |
ganeshgore | 3:bf6b5491779a | 41 | TCPSocketConnection sock; |
ganeshgore | 3:bf6b5491779a | 42 | sock.connect(ServerIP, 8080); |
ganeshgore | 3:bf6b5491779a | 43 | if(sock.is_connected()) |
ganeshgore | 3:bf6b5491779a | 44 | printf("Socket Connected\n\r"); |
ganeshgore | 3:bf6b5491779a | 45 | else |
ganeshgore | 3:bf6b5491779a | 46 | printf("Socket NoT Connected\n\r"); |
ganeshgore | 3:bf6b5491779a | 47 | |
ganeshgore | 3:bf6b5491779a | 48 | char buffer[300]; |
ganeshgore | 3:bf6b5491779a | 49 | int ret_t; |
ganeshgore | 3:bf6b5491779a | 50 | |
ganeshgore | 5:7b21f6b1bdaa | 51 | char http_cmd[256]; |
ganeshgore | 5:7b21f6b1bdaa | 52 | |
ganeshgore | 5:7b21f6b1bdaa | 53 | sprintf(http_cmd,"GET /input/%s?private_key=%s&counter=%d HTTP/1.0\n\n",Public_Key,Private_Key,Count); |
ganeshgore | 5:7b21f6b1bdaa | 54 | printf("Running - %s\r\n",http_cmd); |
ganeshgore | 3:bf6b5491779a | 55 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
ganeshgore | 3:bf6b5491779a | 56 | |
ganeshgore | 5:7b21f6b1bdaa | 57 | ret_t = sock.receive(buffer, sizeof(buffer)-1); |
ganeshgore | 5:7b21f6b1bdaa | 58 | buffer[ret_t] = '\0'; |
ganeshgore | 5:7b21f6b1bdaa | 59 | printf("Received %d chars from server:\n%s\r\n", ret_t, buffer); |
ganeshgore | 4:06bee14d4029 | 60 | |
ganeshgore | 3:bf6b5491779a | 61 | sock.close(); |
ganeshgore | 3:bf6b5491779a | 62 | |
ganeshgore | 3:bf6b5491779a | 63 | ethernet.disconnect(); |
ganeshgore | 3:bf6b5491779a | 64 | printf("Socket Closed"); |
ganeshgore | 3:bf6b5491779a | 65 | |
ganeshgore | 3:bf6b5491779a | 66 | while(1) {} |
ganeshgore | 3:bf6b5491779a | 67 | }} |