Ethernet State Machine

Dependencies:   C12832 Client

Revision:
11:d7b17df4c98a
Parent:
8:e0f3f151c3cc
Child:
13:368c6181b81e
--- a/main.cpp	Tue Sep 19 19:34:46 2017 +0000
+++ b/main.cpp	Thu Oct 29 17:56:30 2020 +0000
@@ -1,17 +1,46 @@
 #include "mbed.h"
 #include "LM75B.h"
 #include "C12832.h"
+#include "EthernetInterface.h"
 
 // Using Arduino pin notation
 C12832 lcd(D11, D13, D12, D7, D10);
 LM75B sensor(D14,D15);
+AnalogIn pot1 (A0);
 
-int main ()
+int main()
 {
-    while (1) {
-        lcd.cls();
-        lcd.locate(0,3);
-        lcd.printf("Temp = %.1f\n", sensor.temp());
-        wait(1.0);
-    }
+    printf("Client example\n\r");
+ 
+    EthernetInterface eth;
+    eth.set_network("192.168.0.20","255.255.255.0","192.168.0.1");
+    eth.connect();
+ 
+    printf("The client IP address is '%s'\n\r", eth.get_ip_address());
+ 
+    TCPSocket socket;
+    socket.open(&eth);
+    socket.connect("192.168.0.28",4000);
+ 
+    uint16_t temperature =(sensor.read());
+    char upperbyte = (temperature >> 8) & 0x00FF;
+    char lowerbyte = temperature & 0x00FF;
+    char pwm = (char)(pot1);
+    char id = 0x14;
+    
+    char data[4];
+    data[0] = upperbyte;
+    data[1] = lowerbyte;
+    data[2] = pwm;
+    data[3] = id;
+    
+    printf("%d\n", upperbyte);
+    printf("%d\n", lowerbyte);
+
+    // print hex value of temperature on lcd
+    lcd.printf("Temp %.1x\n", sensor.read() );
+    printf(data);
+    
+    socket.send(data, 4);
+    socket.close();
 }