|
這段程式在dht 11 傳感器上 溫度與濕度顯是都是正常
我把傳感器換成dht22 溫度 濕度都會變成 %
如何轉換 謝謝
// verify cheksum and print the verified data
if((j>=40)&&(dht11_val[4]==((dht11_val[0]+dht11_val[1]+dht11_val[2]+dht11_val[3])& 0xFF)))
{
printf("Humidity = %d.%d %% Temperature = %d.%d°C\n",dht11_val[0],dht11_val[1],dht11_val[2],dht11_val[3]);
char text[100];
time_t now = time(NULL);
struct tm *t = localtime(&now);
strftime(text, sizeof(text)-1, "%d-%m-%Y", t);
char prefix[50] = "/var/www/log-";
strcat(prefix,text);
char suffix[50] = ".csv";
strcat(prefix,suffix);
FILE *fp;
fp=fopen(prefix,"a");
fprintf(fp,"%u000,%d%d,%d\n",(unsigned)time(NULL),dht11_val[2],dht11_val[3],dht11_val[0]);
fclose(fp);
FILE *fh;
fh=fopen("/var/www/current_hyg.csv", "w");
fprintf(fh,"%d\n",dht11_val[0]);
fclose(fh);
FILE *ft;
ft=fopen("/var/www/current_temp.csv", "w");
fprintf(ft,"%d.%d\n",dht11_val[2],dht11_val[3]);
fclose(ft);
exit(1);
}
else
printf("Invalid Data!!\n");
}
int main(void)
{
printf("Interfacing Temperature and Humidity Sensor (DHT11) With Banana Pi\n");
if(wiringPiSetup()==-1)
exit(1);
while(1)
{
dht11_read_val();
delay(3000);
}
return 0;
}
|
|