Ethernet part for lab 4
Dependencies: EthernetInterface mbed-rtos mbed
Revision 15:3745a5a88226, committed 2015-10-21
- Comitter:
- jbenamy
- Date:
- Wed Oct 21 00:10:35 2015 +0000
- Parent:
- 14:72be2b8b7f24
- Commit message:
- share
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 72be2b8b7f24 -r 3745a5a88226 main.cpp --- a/main.cpp Wed May 14 15:07:26 2014 +0000 +++ b/main.cpp Wed Oct 21 00:10:35 2015 +0000 @@ -2,15 +2,17 @@ #include "EthernetInterface.h" int main() { + // ethernet setup EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); + // send alert TCPSocketConnection sock; - sock.connect("mbed.org", 80); - - char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; + sock.connect("dreamphysix.com", 80); + + char http_cmd[] = "GET http://dreamphysix.com/alert.php?authcode=0e9cae34a0 HTTP/1.0\n\n"; sock.send_all(http_cmd, sizeof(http_cmd)-1); char buffer[300]; @@ -22,10 +24,35 @@ buffer[ret] = '\0'; printf("Received %d chars from server:\n%s\n", ret, buffer); } - + + sock.close(); + + wait(5); + + // send random code + srand(time(NULL)); + int randomNumber = rand() % 89999 + 10000; + char randomCode[sizeof(int)*5]; + snprintf(randomCode, sizeof(randomCode), "%i", randomNumber); + + sock.connect("dreamphysix.com", 80); + + char http_cmd1[100] = "GET http://dreamphysix.com/sendcode.php?authcode=0e9cae34a0&randomcode="; + strcat(http_cmd1, randomCode); + strcat(http_cmd1, " HTTP/1.0\n\n"); + sock.send_all(http_cmd1, sizeof(http_cmd1)-1); + + while (true) { + ret = sock.receive(buffer, sizeof(buffer)-1); + if (ret <= 0) + break; + buffer[ret] = '\0'; + printf("Received %d chars from server:\n%s\n", ret, buffer); + } + sock.close(); eth.disconnect(); - while(1) {} -} + while(1) { } +} \ No newline at end of file