Water level sensing with simulation using potentiometer. The value uploads on the local phant server using HTTP GET method.

Dependencies:   WIZnet_Library mbed

Files at this revision

API Documentation at this revision

Comitter:
eduvanceIoT
Date:
Tue Aug 02 07:57:32 2016 +0000
Commit message:
Simple water level sensing with simulation using Potentiometer. The level is uploaded onto local phant server.

Changed in this revision

WIZnet_Library.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.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnet_Library.lib	Tue Aug 02 07:57:32 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/WIZnet/code/WIZnet_Library/#cb8808b47e69
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 02 07:57:32 2016 +0000
@@ -0,0 +1,103 @@
+#include "mbed.h"
+#include "WIZnetInterface.h"
+
+//MAC address of sheild
+unsigned char MAC_Addr[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+
+//server ip were server is set
+char* ServerIP = "192.168.0.101"; 
+
+//public and private key of stream
+char* public_key = "9Ojdd3Vk2aCqvx1Jg0yLsx2ParXq"; 
+char* private_key = "KzprrvRqKeC5neDN7GRbuQbExAG4"; 
+
+int Count = 15;
+int x;
+
+Serial pc(USBTX, USBRX);
+SPI spi(PTD2,PTD3,PTD1);
+
+//wiznet object
+WIZnetInterface ethernet(&spi,PTD0,PTA20);
+
+//analog input
+AnalogIn waterLevel(PTC1);
+int writtenLen,eth;
+
+int main()
+{
+    //Set serial port baudrate speed: 9600
+    pc.baud(9600);
+    pc.printf("Start\r\n");
+    
+    while(1) 
+    {
+        x=10*waterLevel.read();
+        int ret = ethernet.init(MAC_Addr);
+        
+        if (!ret) 
+        {
+            //print MAC address of device
+            pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
+            ret = ethernet.connect();
+            if (!ret)
+            {
+                //print IP alloted and details obtianed from network
+                pc.printf("IP: %s, MASK: %s, GW: %s\r\n",
+                          ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
+            }
+            else
+            {
+                pc.printf("Error ethernet.connect() - ret = %d\r\n", ret);
+                exit(0);
+            }
+        }
+        else
+        {
+            pc.printf("Error ethernet.init() - ret = %d\r\n", ret);
+            exit(0);
+        }  
+        
+        //create TCP socket
+        TCPSocketConnection sock;
+        
+        while(1){
+            
+        //connect the server to port 8080
+            sock.connect(ServerIP, 8080);
+            if(sock.is_connected())
+                pc.printf("Socket Connected\n\r");
+            else
+                pc.printf("Socket NoT Connected\n\r");
+        
+            //create character buffer for URL
+            char buffer[300];
+            int ret_t;
+        
+            char http_cmd[100];
+        
+            //make URL
+            sprintf(http_cmd,"GET /input/%s?private_key=%s&pot=%d HTTP/1.0\n\n",public_key,private_key,x);
+            printf("sending %d characters",strlen(http_cmd));
+            printf("Running - %s\r\n",http_cmd);
+            writtenLen = sock.send_all(http_cmd, strlen(http_cmd));
+            
+            //print the result of URL GET method
+            if(writtenLen == -1)
+                printf("sending failed\r\n");
+            else    
+                printf("sending success\r\n");
+                
+            eth=ret_t = sock.receive(buffer, strlen(buffer));
+            buffer[ret_t] = '\0';
+            printf("Received %d chars from server:\r\n%s\r\n", ret_t, buffer);
+        
+            sock.close();
+        
+            ethernet.disconnect();
+            pc.printf("Socket Closed\r\n");
+            wait(1);
+            
+            }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 02 07:57:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f9eeca106725
\ No newline at end of file