DHT11

Dependencies:   mbed mbed-rtos SDFileSystem EthernetInterface DHT11

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 #include "EthernetInterface.h"
00004 #include <iostream>
00005 #include <fstream>
00006 #include "DHT11.h"
00007 
00008 #define NUMBER_OF_LINES     23
00009 #define COLOR_LINE          12
00010 #define TEMPERATURE_LINE    17
00011 #define PRESSURE_LINE       18
00012 #define HUMADITY_LINE       19
00013 #define RAINFALL_LINE       20
00014 #define TIME_LINE           21
00015 
00016 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); 
00017 Serial pc(USBTX, USBRX);
00018 string file_content[NUMBER_OF_LINES];
00019 
00020 
00021 DHT11 d(PTD1);
00022 
00023 void DHT11_read()
00024   {
00025       int s;
00026       s = d.readData();
00027       if (s != DHT11::OK) {
00028           pc.printf("Error!\r\n");
00029       }
00030       else {
00031           pc.printf("T:%d, H:%d\r\n", d.readTemperature(), d.readHumidity());
00032       }
00033   }
00034 
00035 
00036 void initializeEthernet(void)
00037 {
00038     EthernetInterface eth;
00039     const char *ip = "192.168.1.3";
00040     const char *mask = "255.255.255.0";
00041     const char *gateway = "192.168.1.1";
00042     if(!eth.init(ip,mask,gateway))
00043     {   
00044         pc.printf("Ethernet card initialized successfully.\r");
00045         eth.connect();        
00046         pc.printf("IP address: %s\n",eth.getIPAddress());
00047         pc.printf("Network mask: %s\n",eth.getNetworkMask());
00048         pc.printf("Gateway: %s\n",eth.getGateway());
00049         pc.printf("MAC address: %s\n",eth.getMACAddress());
00050     }
00051     else
00052         pc.printf("Ethernet card could not be initialized.\r");    
00053     return; 
00054 }
00055 
00056 void readHTMLCode(void)
00057 {
00058     fstream file;    
00059     int cnt = 0;
00060     for (int i = 0; i < NUMBER_OF_LINES; i++)
00061         file_content[i] = " ";
00062     file.open("/sd/index.html", ios::in);
00063     if (file.good())
00064     {
00065         pc.printf("The index.html file has been opened. \r");
00066         while(!file.eof())
00067         {
00068             getline(file,file_content[cnt]);
00069             pc.printf("cnt: %i \n \r", cnt);
00070             cnt++;           
00071         }
00072         file.close();
00073         pc.printf("The file has been closed. \r");
00074     }
00075     else
00076     {
00077         pc.printf("The file could not be opened. \r");
00078         return;
00079     }
00080 }
00081 
00082 void initializeSerialPC(void)
00083 {
00084     pc.baud(115200);
00085     pc.printf("Serial port initialized. \r");
00086 }
00087 
00088 int main() 
00089 {
00090 
00091     initializeSerialPC();
00092     //DHT11_read(); 
00093     readHTMLCode();  
00094     initializeEthernet(); 
00095 
00096     while(1);
00097 }