Sump Pump Monitor v1.00 12-16-16 ABEtronics.com http://www.abetronics.com/?page_id=380
Dependencies: STATIC_COLORS WIZnetInterface mbed
Fork of HTTP_SDCard_File_Server_WIZwiki-W7500 by
Revision 15:e6985c3724a8, committed 2016-11-14
- Comitter:
- abraham3433
- Date:
- Mon Nov 14 20:29:48 2016 +0000
- Parent:
- 14:c53cbdcb6b3b
- Child:
- 16:b948cc536df5
- Commit message:
- 11-14-16
Changed in this revision
--- a/SDFileSystem.lib Mon Nov 07 01:35:32 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/azsymaivan/code/SDFileSystem/#f242d7bdef28
--- a/main_ABE.cpp Mon Nov 07 01:35:32 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +0,0 @@
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "SDFileSystem.h"
-#include <stdio.h>
-#include <string.h>
-
-#define USE_DHCP 1
-
-#define MAC "\x00\x08\xDC\x11\x34\x78"
-#define IP "192.168.0.12"
-#define MASK "255.255.255.0"
-#define GATEWAY "192.168.0.254"
-
-#define HTTPD_SERVER_PORT 80
-#define HTTPD_MAX_REQ_LENGTH 1023
-#define HTTPD_MAX_HDR_LENGTH 255
-#define HTTPD_MAX_FNAME_LENGTH 127
-#define HTTPD_MAX_DNAME_LENGTH 127
-
-#if defined(TARGET_WIZwiki_W7500)
-Serial uart(USBTX, USBRX);
-SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500
-#include "static_colors.h"
-// LED R : server listning status
-// LED GREEN : socket connecting status Ok
-// LED BLUE : socket connecting status Busy
-#endif
-
-EthernetInterface eth;
-TCPSocketServer server;
-TCPSocketConnection client;
-
-char buffer[HTTPD_MAX_REQ_LENGTH+1];
-char httpHeader[HTTPD_MAX_HDR_LENGTH+1];
-char fileName[HTTPD_MAX_FNAME_LENGTH+1];
-char dirName[HTTPD_MAX_DNAME_LENGTH+1];
-char *uristr;
-char *eou;
-char *qrystr;
-
-FILE *fp;
-int rdCnt;
-
-// Initialize a pins to perform analog input and digital output fucntions
-AnalogIn ain0(A0);
-
-Ticker ledTick;
-
-//char str[] = "This is a sample string";
-char *pch;
-char ext[5];
-char ext_gif[] = "gif";
-char ext_jpg[] = "jpg";
-char ext_png[] = "png";
-char ext_tiff[] = "tiff";
-int pos_ext;
-int extLen;
-
-void ledTickfunc()
-{
- led_r = !led_r;
-}
-
-int main(void)
-{
- ledTick.attach(&ledTickfunc,0.5);
- // Serial Interface eth;
- // Serial port configuration (valeurs par defaut) : 9600 baud, 8-bit data, no parity, stop bit
- uart.baud(9600);
- uart.format(8, SerialBase::None, 1);
- uart.printf("Initializing\n");
- wait(1.0);
-// EthernetInterface eth;
- uart.printf("Initializing Ethernet\n");
- #if USE_DHCP
- //eth.init Use DHCP
- int ret = eth.init((uint8_t*)MAC); // Use DHCP for WIZnetInterface
- uart.printf("Connecting DHCP\n");
- #else
- int ret = eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
- uart.printf("Connecting (IP,mask,Gateway)\n");
- #endif
- wait(1.0);
- // Check Ethernet Link-Done
- uart.printf("Check Ethernet Link\r\n");
-
- if(eth.link() == true)
- {
- uart.printf("- Ethernet PHY Link - Done\r\n");
- //led_r = LED_ON;
- COLOR(_RED_);
- }
- else
- {
- uart.printf("- Ethernet PHY Link - Fail\r\n");
- //led_r = LED_OFF;
- COLOR(_BLACK_);
- }
- wait(1.0);
- if(!ret)
- {
- uart.printf("Initialized, MAC: %s\r\n", eth.getMACAddress());
- ret = eth.connect();
-
- if(!ret)
- {
- uart.printf("IP: %s, MASK: %s, GW: %s\r\n",
- eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
- // led_b = LED_ON, led_g = LED_ON;
- COLOR(_CYAN_);
- }
- else
- {
- uart.printf("Error ethernet.connect() - ret = %d\r\n", ret);
- //led_b = LED_OFF;
- COLOR(_BLUE_);
- exit(0);
- }
- }
- else
- {
- uart.printf("Error ethernet.init() - ret = %d\r\n", ret);
- //led_b = LED_OFF;
- COLOR(_BLACK_);
- exit(0);
- }
- wait(1.0);
-// TCPSocketServer server;
- server.bind(HTTPD_SERVER_PORT);
- server.listen();
- uart.printf("Server Listening\n");
-
- while(true)
- {
- uart.printf("\nWait for new connection...\r\n");
- server.accept(client);
- client.set_blocking(false, 1500); // Timeout after (1.5)s
-
- uart.printf("Connection from: %s\r\n", client.get_address());
- while(true)
- {
- //led_g = LED_ON;
- COLOR(_GREEN_);
- int n = client.receive(buffer, sizeof(buffer));
- if(n <= 0) break;
- uart.printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer);
- // mesures ADC
- float a0_f;
- float meas; // = 0.0;
- //meas = ain0; // Converts and read the analog input value
- a0_f = ain0*3.3;
- sprintf(httpHeader,"A0 = %3.3f;\r\n", a0_f);
- client.send(httpHeader,strlen(httpHeader));
- }
- //led_g = LED_OFF;
- COLOR(_BLACK_);
- client.close();
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_SPM.cpp Mon Nov 14 20:29:48 2016 +0000
@@ -0,0 +1,226 @@
+/*
+==========================================================================
+Project: Sump Pump Monitor
+Description: Measure pump current to indicate run status. (10amp pump)
+Date: 11-6-16
+Author: Jim Abraham
+Board: WIZwiki-W7500
+Rev:
+==========================================================================
+*/
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include <stdio.h>
+#include <string.h>
+
+#define USE_DHCP 0 // 0= no dhcp
+#define MAC "\x00\x08\xDC\x11\x34\x78"
+#define IP "192.168.0.12"
+#define MASK "255.255.255.0"
+#define GATEWAY "192.168.0.254"
+#define HTTPD_SERVER_PORT 80
+#define HTTPD_MAX_REQ_LENGTH 1023
+#define HTTPD_MAX_HDR_LENGTH 255
+#define HTTPD_MAX_FNAME_LENGTH 127
+#define HTTPD_MAX_DNAME_LENGTH 127
+
+#if defined(TARGET_WIZwiki_W7500)
+Serial uart(USBTX, USBRX);
+#include "static_colors.h"
+// LED R : server listning status
+// LED GREEN : socket connecting status Ok
+// LED BLUE : socket connecting status Busy
+#endif
+
+EthernetInterface eth;
+TCPSocketServer server;
+TCPSocketConnection client;
+
+//========================================================
+// Data Variables.
+//========================================================
+int LP1,LP2,LP3;
+float AMP_Reading_on_AO, AMPreadingHI, AMPreading;
+char buffer[HTTPD_MAX_REQ_LENGTH+1];
+char httpHeader[HTTPD_MAX_HDR_LENGTH+1];
+
+//-----------------------------------------------------------
+// Initialize a pins to perform analog input
+//-----------------------------------------------------------
+AnalogIn ain0(A0);
+
+//-----------------------------------------------------------
+void Serial_Interface_init(void)
+//-----------------------------------------------------------
+{
+ // Serial Interface eth;
+ // Serial port configuration:
+ // 9600 baud, 8-bit data, no parity, stop bit
+ uart.baud(9600);
+ uart.format(8, SerialBase::None, 1);
+ uart.printf("Initializing\n");
+ wait(1.0);
+}
+
+//-----------------------------------------------------------
+void ethernet_init(void)
+//-----------------------------------------------------------
+{
+ // EthernetInterface eth;
+ uart.printf("Initializing Ethernet\n");
+ #if USE_DHCP
+ //eth.init Use DHCP
+ // Use DHCP for WIZnetInterface
+ int ret = eth.init((uint8_t*)MAC);
+ uart.printf("Connecting DHCP\n");
+ #else
+ // IP,mask,Gateway
+ int ret = eth.init((uint8_t*)MAC,IP,MASK,GATEWAY);
+ uart.printf("Connecting (IP,mask,Gateway)\n");
+ #endif
+ wait(1.0);
+ // Check Ethernet Link-Done
+ uart.printf("Check Ethernet Link\r\n");
+
+ if(eth.link() == true)
+ {
+ uart.printf("- Ethernet PHY Link - Done\r\n");
+ COLOR(_RED_);
+ }
+ else
+ {
+ uart.printf("- Ethernet PHY Link - Fail\r\n");
+ COLOR(_BLACK_);
+ }
+ wait(1.0);
+ if(!ret)
+ {
+ uart.printf("Initialized, MAC: %s\r\n", eth.getMACAddress());
+ ret = eth.connect();
+
+ if(!ret)
+ {
+ uart.printf("IP: %s, MASK: %s, GW: %s\r\n",
+ eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
+ COLOR(_CYAN_);
+ }
+ else
+ {
+ uart.printf("Error ethernet.connect() - ret = %d\r\n", ret);
+ COLOR(_YELLOW_);
+ exit(0);
+ }
+ }
+ else
+ {
+ uart.printf("Error ethernet.init() - ret = %d\r\n", ret);
+ COLOR(_BLACK_);
+ exit(0);
+ }
+
+ wait(1.0);
+ // TCPSocketServer server;
+ server.bind(HTTPD_SERVER_PORT);
+ server.listen();
+ uart.printf("Server Listening\n");
+}
+
+//-----------------------------------------------------------
+void VAC_Zero_Cross(void)
+//-----------------------------------------------------------
+{
+ LP1=0; // Indicator to exit while loop
+ if (LP2==1)
+ {
+//Waits for the waveform to be close to 'zero' (500 adc)
+ while(LP1==0)
+ {
+ wait_us(100);
+ AMPreading=ain0.read();
+
+//check its within range. (+/- 5)
+ if ((AMPreading < 0.5) && (AMPreading > 0.4))
+ {
+ LP1=1;
+ }
+ }
+ }
+ LP2=1;
+}
+
+//-----------------------------------------------------------
+ void Measure_AMPS(void)
+//-----------------------------------------------------------
+// Measure AC Current.
+// 12bit ADC, 10MHz = 0.1usec conversion time.
+// 12bit ADC (0-3.3v = 0-4095 values) 3.3/4096 = 0.81mv
+// 1.65v = 2047 = 0 amps.
+//-----------------------------------------------------------
+{
+ AMPreadingHI=0.0;
+ for (LP3=0; LP3<100; LP3++)
+ {
+ wait_us(200);
+ AMPreading=ain0.read();
+ if (AMPreadingHI < AMPreading) AMPreadingHI = AMPreading;
+ }
+
+ if (AMPreadingHI <0.6)
+ {
+ COLOR(_BLUE_);
+ }
+ else
+ {
+ COLOR(_GREEN_);
+ }
+
+ AMP_Reading_on_AO = AMPreadingHI;
+ uart.printf("$%2.2f!", AMPreading);
+ sprintf(httpHeader,"$%2.2f!", AMP_Reading_on_AO);
+ client.send(httpHeader,strlen(httpHeader)); //send amps to PC.
+}
+
+
+//===================================================================
+int main(void)
+//===================================================================
+{
+//RGB LED:
+//WHITE = program running.
+//RED = not connected to PC.
+//GRN = pump running.
+//BLUE = pump not running.
+
+ Serial_Interface_init();
+ ethernet_init();
+ LP1=0; // Indicator to exit while loop
+ LP2=0;
+//-----------------------------------------------------------
+ while(true)
+//-----------------------------------------------------------
+ {
+ uart.printf("\nWait for new connection...\r\n");
+ server.accept(client);
+ client.set_blocking(false, 1500); // Timeout after (1.5)s
+ uart.printf("Connection from: %s\r\n", client.get_address());
+
+//-----------------------------------------------------------
+ while(true)
+//-----------------------------------------------------------
+ {
+ if(!client.is_connected())
+ {
+ COLOR(_RED_);
+ break; //exit while
+ }
+ // Mesure ADC 0 - Check Sump Pump Run Status
+ VAC_Zero_Cross();
+ Measure_AMPS();
+ wait(1.0);
+ COLOR(_WHITE_);
+ }
+//-----------------------------------------------------------
+ client.close(); //close connection to pc app.
+ }
+}
\ No newline at end of file
