Monitoring Suhu dan Kelembaban Udara

Dependencies:   DHT EthernetInterface NetworkAPI mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
naufalboys
Date:
Tue Jul 10 10:16:32 2018 +0000
Commit message:
Temperature and Humidity Monitoring

Changed in this revision

DHT.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
NetworkAPI.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/DHT.lib	Tue Jul 10 10:16:32 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/components/code/DHT/#6937e130feca
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Tue Jul 10 10:16:32 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkAPI.lib	Tue Jul 10 10:16:32 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/NegativeBlack/code/NetworkAPI/#7ac7c29fea3d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 10 10:16:32 2018 +0000
@@ -0,0 +1,102 @@
+#include "mbed.h"
+#include "DHT.h"
+#include "EthernetInterface.h"
+#include "NetworkAPI/buffer.hpp"
+#include "NetworkAPI/ip/address.hpp"
+#include "NetworkAPI/tcp/socket.hpp"
+#include <string>
+
+using namespace std;
+
+static const int PORT        = 80;
+const char* host      = "192.168.137.1";
+static const char* SERVER_IP = "192.168.137.1"; //IP of server board
+static const char* CLIENT_IP = "192.168.137.2"; //IP of client board
+static const char* MASK      = "255.255.255.0";      //mask
+static const char* GATEWAY   = "192.168.137.1";     //gateway
+
+DHT sensor(D2, DHT22);
+DHT sensor2(D3, DHT22);
+DHT sensor3(D4, DHT11);
+
+EthernetInterface eth;
+network::tcp::Socket socket;
+
+int main()
+{  
+    char buffer[1000];
+    int error = 0, error2 = 0, error3 = 0;
+    eth.init(CLIENT_IP, MASK, GATEWAY);    
+    eth.connect();                                                              
+    printf("\nCLIENT - Client IP Address is %s\r\n", eth.getIPAddress()); 
+    
+    while(1) 
+    {
+        socket.open(); 
+        printf("Socket open\n");
+        if (socket.connect(SERVER_IP, PORT) < 0) 
+        {
+            printf("Failed to connect with %s\n\r", SERVER_IP);
+            main();
+            //return -1;
+        }
+        else
+        {
+            printf("bisa masuk fungsi ini \n");
+            wait(2.0f);
+
+            error = sensor.readData();
+            error2 = sensor2.readData();
+            error3 = sensor3.readData();
+            
+            if ((0 == error) && (0 == error2) && (0 == error3)) 
+            {
+                float c   = sensor.ReadTemperature(CELCIUS);
+                float h   = sensor.ReadHumidity();
+                
+                float c2   = sensor2.ReadTemperature(CELCIUS);
+                float h2   = sensor2.ReadHumidity();           
+                 
+                float c3   = sensor3.ReadTemperature(CELCIUS);
+                float h3   = sensor3.ReadHumidity();            
+                
+                printf("Temperature 1 : %.2f *C\t", c);
+                printf("Humidity    1 : %.2f %%\n", h);
+                printf("\n");
+                printf("Temperature 2 : %.2f *C\t", c2);
+                printf("Humidity    2 : %.2f %%\n", h2);       
+                printf("\n");     
+                printf("Temperature 3 : %.2f *C\t", c3);
+                printf("Humidity    3 : %.2f %%\n", h3);
+                printf("\n");
+                printf("\n");
+                
+                snprintf(buffer,1000,"/radhumidity2/input.php?temperature=%.2f&humidity=%.2f&temperature2=%.2f&humidity2=%.2f&temperature3=%.2f&humidity3=%.2f",c,h,c2,h2,c3,h3);
+                
+                std::string request(string("GET ") + buffer + " HTTP/1.1\r\n" +
+                             "Host: " + host + "\r\n" +
+                             "Connection: close\r\n\r\n");
+                
+                if (socket.write((void *)request.data(), request.size()) < 0) 
+                {
+                    printf("Failed to write HTTP request\n\r");
+                    return -1;
+                }
+                
+                socket.close();
+                printf("\nSudah berhasil socket close\n"); 
+                wait(1);
+            }    
+
+            else 
+            {
+                printf("Error Sensor 1 : %d\n", error);
+                printf("Error Sensor 2 : %d\n", error2);
+                printf("Error Sensor 3 : %d\n", error3);
+            }  
+        }
+        //socket.close();
+        //eth.disconnect();
+        //wait(3.0f);    
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Jul 10 10:16:32 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#c825593ece39
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 10 10:16:32 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file