Monitor for central heating system (e.g. 2zones+hw) Supports up to 15 temp probes (DS18B20/DS18S20) 3 valve monitors Gas pulse meter recording Use stand-alone or with nodeEnergyServer See http://robdobson.com/2015/09/central-heating-monitor

Dependencies:   EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src

Files at this revision

API Documentation at this revision

Comitter:
Bobty
Date:
Fri Nov 07 14:15:21 2014 +0000
Child:
1:518f39df3485
Commit message:
First working version - doesn't handle ethernet unplugging

Changed in this revision

EthernetInterface.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri Nov 07 14:15:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#9b2d10dc0392
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 07 14:15:21 2014 +0000
@@ -0,0 +1,82 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+DigitalIn gpPin(p21);
+DigitalOut led(LED1);
+
+const int BROADCAST_PORT = 42853; // Arbitrarily chosen port number
+const int NUM_GASPULSE_VALS_IN_PACKET = 10;
+Serial pc(USBTX, USBRX);
+
+int main()
+{
+    pc.baud(115200);
+    printf("Gas Monitor - Rob Dobson 2014\n");
+
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    UDPSocket sendSocket;
+    Endpoint broadcast;
+    
+    // Connection establishment/re-establishment
+    Timer connectRetryTimer;
+    connectRetryTimer.start();
+    bool isConnected = false;
+
+    // Gas Meter Pulse sample timer
+    Timer gasPulseTimer;
+    gasPulseTimer.start();
+    int gasPulseCount = 0;
+    bool gasPulseVals[NUM_GASPULSE_VALS_IN_PACKET];
+    
+    // Forever    
+    while (true)
+    {
+        // Check if already connected to ethernet
+        if (!isConnected)
+        {
+            if (connectRetryTimer.read_ms() > 1000)
+            {
+                isConnected = eth.connect() == 0;
+                connectRetryTimer.reset();
+                if (isConnected)
+                {
+                    printf("Eth Connected - IP Address is %s - MAC is %s\n", eth.getIPAddress(), eth.getMACAddress());
+                    sendSocket.init();
+                    sendSocket.set_broadcasting();
+                    broadcast.set_address("255.255.255.255", BROADCAST_PORT);
+                    }
+                else
+                {
+                    printf("Eth Connect Attempt Failed\n");
+                }
+            }
+        }
+        else
+        {
+            if (gasPulseTimer.read_ms() > 1000)
+            {
+                gasPulseTimer.reset();
+                
+                // Read from Gas Pulse pin
+                gasPulseVals[gasPulseCount++] = gpPin;
+                led = gpPin;
+                if (gasPulseCount >= NUM_GASPULSE_VALS_IN_PACKET)
+                {
+                    gasPulseCount = 0;
+                    
+                    // Send the packet
+                    char outBuf[] = "{\"gaspulseval\":[0,0,0,0,0,0,0,0,0,0]}\n";
+                    char* pOutBuf = strchr(outBuf, '[') + 1;
+                    for (int i = 0; i < NUM_GASPULSE_VALS_IN_PACKET; i++)
+                    {
+                        *pOutBuf = gasPulseVals[i] ? '1' : '0';
+                        pOutBuf+=2;
+                    }
+                    sendSocket.sendTo(broadcast, outBuf, sizeof(outBuf)-2);
+                    printf("Sending %s", outBuf);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Nov 07 14:15:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#db1fc233faa9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 07 14:15:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7e6c9f46b3bd
\ No newline at end of file