![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
TCP client mbed RTOS
Dependencies: mbed LM75B mbed-rtos EthernetInterface
Revision 16:3d431098b650, committed 2020-07-16
- Comitter:
- metroboominwantsoen
- Date:
- Thu Jul 16 12:45:14 2020 +0000
- Parent:
- 15:954b6cd3d853
- Commit message:
- Incorporating the temperature
Changed in this revision
LM75B.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Thu Jul 16 12:45:14 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/MSS/code/LM75B/#f7dc7b327a4a
--- a/main.cpp Tue Jun 30 12:48:22 2020 +0000 +++ b/main.cpp Thu Jul 16 12:45:14 2020 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "EthernetInterface.h" +#include "LM75B.h" static const char* mbedIP = "192.168.5.10"; //IP static const char* mbedMask = "255.255.255.0"; // Mask @@ -8,6 +9,8 @@ const int ECHO_SERVER_PORT = 2224; const char* ECHO_SERVER_ADDRESS = "192.168.5.15"; // laptop address +LM75B sensor(p28,p27); + int main() { EthernetInterface eth; eth.init(mbedIP,mbedMask,mbedGateway); //Use DHCP @@ -15,24 +18,38 @@ printf("IP Address is %s\n", eth.getIPAddress()); while(1) { - TCPSocketConnection sock; - sock.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); - - char http_cmd[] = "Testing"; - sock.send_all(http_cmd, sizeof(http_cmd)-1); + if (sensor.open()) { + printf("Device detected!\n"); + + while (1) { + cls(); + locate(0,3); + printf("Temp = %.3f\n", (float)sensor); + wait(1.0); + TCPSocketConnection sock; + sock.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); + char http_cmd[] = "Testing"; + sock.send_all(http_cmd, sizeof(http_cmd)-1); - char buffer[300]; - int ret; - while (false) { - 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); + char buffer[300]; + int ret; + while (false) { + ret = sock.receive(buffer, sizeof(buffer)-1); + if (ret <= 0) + break; + buffer[ret] = '\0'; + printf("Temp = %.3f\n", (float)sensor); + printf("Received %d chars from server:\n%s\n", ret, buffer); + } + + sock.close(); + Thread::wait(1000); + } - - sock.close(); - Thread::wait(1000); + + } else { + error("Device not detected!\n"); + } } eth.disconnect();