1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <VirtualWire.h>
#include <DHT.h>
#include <stdio.h>
#include <string.h>
#define PIN 8
#define TYPE DHT22
DHT dht(PIN, TYPE);
const char *msgT = "Temperature = ";
const char *msgH = "Humidite = ";
char Temp[VW_MAX_MESSAGE_LEN];
char Humi[VW_MAX_MESSAGE_LEN];
char Temp2[VW_MAX_MESSAGE_LEN];
char Humi2[VW_MAX_MESSAGE_LEN];
char message[VW_MAX_MESSAGE_LEN];
void setup()
{
Serial.begin(9600);
dht.begin();
//vw_set_tx_pin(12);
vw_setup(2000);
}
void loop()
{
// LECTURE DES DONNEES
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
Serial.println("Echec de lecture !");
return;
}
Serial.print("Humidite: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print("\n");
// Conversion en tableau de chars
int t1;
int t2;
int h1;
int h2;
t1 = (int)t;
t2 = (int)((t - t1) * 100);
h1 = (int)h;
h2 = (int)((h - h1) * 100);
itoa(t1,Temp,10); // 10 car décimal
itoa(h1,Humi,10); // 10 car décimal
itoa(t2,Temp2,10); // 10 car décimal
itoa(h2,Humi2,10); // 10 car décimal
strcpy (message, msgT);
strcat(message,Temp);
strcat(message,".");
strcat(message,Temp2);
//strcat(message,"-");
strcat(message,msgH);
strcat(message,Humi);
strcat(message,".");
strcat(message,Humi2);
//TRANSMISSION DES DONNEES
//vw_send((uint8_t *)&t, sizeof (t));
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx();
//delay(60000); // 1 minute
delay(2000);
} |
Partager