DHT22

Dependencies:   DHT_HW3 SDFileSystem mbed

Fork of DHT22 by jajn HA

Files at this revision

API Documentation at this revision

Comitter:
priscilla5328
Date:
Tue Jan 02 14:09:45 2018 +0000
Parent:
0:97c2d4128ff3
Commit message:
21400032/Koo_Heejeong/HW3

Changed in this revision

DHT.lib Show annotated file Show diff for this revision Revisions of this file
easy-connect.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-os.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
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/DHT.lib	Thu Jul 20 09:05:08 2017 +0000
+++ b/DHT.lib	Tue Jan 02 14:09:45 2018 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/david8251/code/DHT/#1e78a462b211
+https://os.mbed.com/users/priscilla5328/code/DHT_HW3/#d69bf5f18bf8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/easy-connect.lib	Tue Jan 02 14:09:45 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/easy-connect/#a913964341394430cd3997c6f2950f93ba1d75c8
--- a/main.cpp	Thu Jul 20 09:05:08 2017 +0000
+++ b/main.cpp	Tue Jan 02 14:09:45 2018 +0000
@@ -1,33 +1,70 @@
+#include <string.h>
 #include "mbed.h"
+#include "easy-connect.h"
+#include "TCPSocket.h"
 #include "DHT.h"
 
-DHT sensor(D7,DHT22);
+DHT sensor(A0,DHT22);
+
+#define SERVER_IP "192.168.0.5"
+#define SERVER_PORT 50000
+
+Serial pc(USBTX, USBRX);
+
+char rec_buf[20];
+
+int main(){
+    int error = 0;
+    pc.baud(115200);
 
-void task_DHT();
+    pc.printf("\r\nConnecting...\r\n");
+    NetworkInterface *network = easy_connect(true);
+    while(!network){
+        pc.printf("Error: Cannot connect to the network\r\n");
+        wait(1);
+        network = easy_connect(true);
+    }
+    
+    pc.printf("Success\r\n\r\n");
+    pc.printf("MAC: %s\r\n", network->get_mac_address());
+    pc.printf("IP: %s\r\n", network->get_ip_address());
+    pc.printf("Netmask: %s\r\n", network->get_netmask());
+    pc.printf("Gateway: %s\r\n", network->get_gateway());
+    pc.printf("RSSI: %d\r\n\r\n", wifi.get_rssi());
+
+    pc.printf("\r\nDone\r\n");
 
-int main()
-{   
-    
-    while(1) {
-         task_DHT();
+    TCPSocket socket;
+
+    socket.open(network);
+    socket.connect(SERVER_IP, SERVER_PORT);
+
+    int c = 0, h = 0;
+    int send_cnt, rec_cnt;
+    while(1){
+        pc.printf("Sending request to %s : %d ...\r\n", SERVER_IP, SERVER_PORT);
+        char rec_buf[64]={};
+        rec_cnt = socket.recv(rec_buf, sizeof rec_buf);
+        pc.printf("%s\r\n", rec_buf);
+        if(!strcmp(rec_buf, "GET /DHT22\r\n")){
+            char send_buf[64]={};
+            send_cnt = socket.send("OK\r\n", sizeof("OK\r\n"));
+            error = sensor.readData();
+            if (error == 0) {
+                c   = sensor.ReadTemperature(CELCIUS);
+                h   = sensor.ReadHumidity();
+            }
+            else {
+                printf("Error: %d\r\n", error);
+            }
+            sprintf(send_buf, "{ \"temp\": \"%d\", \"humid\": \"%d\"}\r\n", c, h);
+            send_cnt = socket.send(send_buf, sizeof(send_buf));
+            pc.printf(send_buf);
+        }
+        else{
+            pc.printf("Unknown request\r\n");
+            send_cnt = socket.send("Unknown request\r\n", sizeof("Unknown request\r\n"));
+        }
     }
 }
-void task_DHT(){
-    int error = 0;
-    int h, c,f;
-    float dp = 0.0f;
- 
-        wait(2.0f);
-        error = sensor.readData();
-        if (0 == error) {
-            c   = sensor.ReadTemperature(CELCIUS);
-            f   = sensor.ReadTemperature(FARENHEIT);
-            h   = sensor.ReadHumidity();
-            dp  = sensor.CalcdewPoint(c, h);
-    
-            printf("Temperature in Celcius: %d, Farenheit %d\r\n", c, f);
-            printf("Humidity is %d, Dewpoint: %4.2f\r\n\n", h, dp);
-        } else {
-            printf("Error: %d\r\n", error);
-        }
-}
+
--- a/mbed-os.lib	Thu Jul 20 09:05:08 2017 +0000
+++ b/mbed-os.lib	Tue Jan 02 14:09:45 2018 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#a1c0840b3d69060e5eb708edb18358e424a40f51
+https://github.com/ARMmbed/mbed-os/#269f58d75b752a4e67a6a2d8c5c698635ffd6752
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jan 02 14:09:45 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/7130f322cb7e
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Tue Jan 02 14:09:45 2018 +0000
@@ -0,0 +1,78 @@
+{
+    "config": {
+        "network-interface":{
+            "help": "options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, MESH_LOWPAN_ND, MESH_THREAD",
+            "value": "WIFI_ESP8266"
+        },
+        "mesh_radio_type": {
+        	"help": "options are ATMEL, MCR20",
+        	"value": "ATMEL"
+        },
+        "esp8266-tx": {
+            "help": "Pin used as TX (connects to ESP8266 RX)",
+            "value": "D8"
+        },
+        "esp8266-rx": {
+            "help": "Pin used as RX (connects to ESP8266 TX)",
+            "value": "D2"
+        },
+        "esp8266-debug": {
+            "value": true
+        },
+        "wifi-ssid": {
+            "value": "\"netlab2\""
+        },
+        "wifi-password": {
+            "value": "\"netlab2@414\""
+        },
+        "button": {
+            "help": "Pin which you'll use as button (can be overriden per target below)",
+            "value": "BUTTON1"
+        },
+        "builtin_led_on": {
+            "help": "Value to write to built-in LEDs to turn them on",
+            "value": 1,
+            "macro_name": "BUILTIN_LED_ON"
+        },
+        "builtin_led_off": {
+            "help": "Value to write to built-in LEDs to turn them off",
+            "value": 0,
+            "macro_name": "BUILTIN_LED_OFF"
+        }
+    },
+    "target_overrides": {
+        "*": {
+            "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
+            "platform.stdio-baud-rate": 115200,
+            "platform.stdio-convert-newlines": true,
+            "mbed-mesh-api.6lowpan-nd-channel-page": 0,
+            "mbed-mesh-api.6lowpan-nd-channel": 12,
+            "mbed-trace.enable": 0
+        },
+        "K64F": {
+            "button": "SW2",
+            "builtin_led_on": 0,
+            "builtin_led_off": 1
+        },
+        "HEXIWEAR": {
+            "button": "PTA12",
+            "esp8266-tx": "PTD3",
+            "esp8266-rx": "PTD2"
+        },
+        "NUCLEO_F401RE": {
+            "button": "USER_BUTTON",
+            "esp8266-tx": "D8",
+            "esp8266-rx": "D2"
+        },
+        "NUCLEO_F411RE": {
+            "button": "USER_BUTTON",
+            "esp8266-tx": "D8",
+            "esp8266-rx": "D2"
+        },
+        "NUMAKER_PFM_NUC472": {
+            "button": "SW1",
+            "builtin_led_on": 0,
+            "builtin_led_off": 1
+        }
+    }
+}