pro_EthServer

Dependencies:   C12832 EthernetInterface LM75B mbed-rtos mbed

Fork of exe5_3_Ethernet_UDP_server by Zhengguo Sheng

Revision:
1:e29e7d1b1929
Parent:
0:86b7ebac3e60
--- a/main.cpp	Thu Dec 01 14:12:26 2016 +0000
+++ b/main.cpp	Thu Jan 12 15:49:42 2017 +0000
@@ -22,8 +22,8 @@
 /*--INCLUDES----------------------------------------------------------------------------*/
 #include "mbed.h"
 #include "EthernetInterface.h"
- 
-
+#include "LM75B.h"
+#include "C12832.h"
 /*--DEFINES-----------------------------------------------------------------------------*/
 
 
@@ -34,20 +34,25 @@
 static const char* SERVER_IP = "192.168.1.101"; //IP of server board
 static const char* MASK = "255.255.255.0";      //mask
 static const char* GATEWAY = "192.168.1.1";     //gateway
+static const char* BOILER_IP = "192.168.1.102"; //Boiler device
+static const char* MASTER_IP = "192.168.1.110"; //Master device
 
 
 /*--INITS-------------------------------------------------------------------------------*/
 Serial pc(USBTX, USBRX);        //create PC interface
 EthernetInterface eth;          //create ethernet
-UDPSocket server;               //creat server
+UDPSocket server;               //create server
 Endpoint client;                //create endpoint
 
 DigitalOut red(LED_RED);        //debug led
 DigitalOut green(LED_GREEN);    //debug led
 
+LM75B sensor(D14,D15);          //temp sensor
+C12832 lcd(D11, D13, D12, D7, D10);//LCD screen arduino notation
 
 /*--VARIABLES---------------------------------------------------------------------------*/
 int n;                  //size of received message
+int idealtemp;     //ideal room temp
 char counter[1] = {0};  //sample receive/send buffer
 
 
@@ -84,6 +89,21 @@
     pc.printf("\nSERVER - Waiting for UDP packet...\r\n");                                      //wait for packet
     n = server.receiveFrom(client, counter, sizeof(counter));                                   //receive message from client
     counter[n] = '\0';                                                                          //add \0 to end of message
+
+    if(client.get_address()==BOILER_IP)                                                         //if address is boiler device
+    {
+        if(sensor.read() < idealtemp)
+        {
+            counter[0] = 0;                                                                   //reset counter if temp is below ideal
+            counter[1] = '/0';
+        }                                                                                      
+    }
+    if(client.get_address()==MASTER_IP)                                                         //if address is boiler device
+    {
+        idealtemp = counter[0];                                                                 //new ideal temp is from master device
+        counter[0] = (int)sensor.read();                                                        //send sensor temp to master                            
+    }
+
     
     pc.printf("SERVER - Received '%i' from client %s\r\n", counter[0], client.get_address());   //print message and client
     pc.printf("SERVER - Sending '%i' back to client %s\r\n", counter[0], client.get_address()); //print sending back
@@ -94,6 +114,11 @@
 /*********************************************************************************MAIN***/
 int main(void)
 {
+    int j=0;
+    lcd.cls();
+    lcd.locate(0,3);
+    lcd.printf("mbed application shield!");
+    
     red = 1;
     green = 0;      //server
     
@@ -102,6 +127,10 @@
 
     while (true)    //repeat forever
     {
+        lcd.locate(0,15);
+        lcd.printf("Counting : %d",j);
+        j++;
+        wait(1.0);
         receive();  //wait for message
     }