bayern

Dependencies:   mbed DHT22

main.cpp

Committer:
svupper
Date:
2019-01-16
Revision:
1:cfd64ae75009
Parent:
0:76148ffba877

File content as of revision 1:cfd64ae75009:

#include "mbed.h"
#include <iostream>
#include "DHT22.h"
#include "string.h"

using namespace std;

Serial pc(USBTX, USBRX, 9600);
DHT22 dht22(D3);

//Serial device(PA_6, PA_7);
//Serial device(A7, A2);
//Serial device(PB_6, PB_7);
//Serial device(PB_7, PB_6);
Serial device(PA_9, PA_10);
//Serial device(PA_2, PA_15);
//SoftSerial device(PA_4, PA_5);
//SoftSerial_IR device(PB_6, PB_7);
//Serial sc2(D5, D4);

void test(){
    pc.printf("---New Call ---\r\n");
    
    if(device.writeable()) { 
        pc.printf("Device writeable\r\n");
    }

    /* Debut Test Communication*/
    
    device.printf("AT\r");

    }
    
    void read(){
        char temp;
        do{
            temp = device.getc();
            pc.printf("%c", temp);
        }while(temp != ';');    
    }
    
    void send(char c[]){
        
    char donnee[] = "AT$SF=";
    strcat(donnee,c);
    strcat(donnee,"\r");
    device.printf(donnee);
    pc.printf(donnee);
    }

int main() {
    int humidite;  
    int temperature;  
    char c[] = "fff";
    device.baud(9600);
    
    test();
    read();
    
    while(1) {
                
        dht22.sample() ;
        humidite=dht22.getHumidity()/10.0;
        temperature=dht22.getTemperature()/10.0;
        pc.printf("temperature: %d humidity: %d\n\r",temperature,humidite);
        
        wait(1); 
        
        //char c = humidite+'0';
        
        send(c);
        wait(100.0);

    }
}