raspberrypi:temp
This is an old revision of the document!
Rasperry Pi turi 1-wire protokolo palaikymą. Pats populiariausias W1 įrenginys yra skaitmeninis termometras DS18B20
panaudojus sita gida pavyko gauti temperaturas ir jas irasyti i faila: http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/
#include <stdio.h> #include <stdlib.h> #include <time.h> /* gcc -Wall -pthread -o w1_temp_rec w1_temp_rec.c && sudo ./w1_temp_rec sudo ./w1_temp_rec watch -n10 ./w1_temp_rec */ int main() { FILE * temp_log = fopen("temp_log.txt", "a"); time_t now; time(&now); char buf[sizeof "2011-10-08T07:07:09Z"]; strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now)); //printf("%s\n", buf); printf("record temperature readings to file\n"); FILE * fp; char * line = NULL; size_t len = 0; fp = fopen("/sys/bus/w1/devices/28-031688217aff/w1_slave", "r"); getline(&line, &len, fp); //printf("%s", line); getline(&line, &len, fp); strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now)); printf("%s OUT %s", buf, line); fprintf(temp_log, "%s OUT %s", buf, line); fclose(fp); fp = fopen("/sys/bus/w1/devices/28-03168812d2ff/w1_slave", "r"); getline(&line, &len, fp); //printf("%s", line); getline(&line, &len, fp); strftime(buf, sizeof buf, "%FT%TZ", gmtime(&now)); printf("%s IN %s", buf, line); fprintf(temp_log, "%s IN %s", buf, line); fclose(fp); fclose(temp_log); if (line) free(line); return 0; }
Paleidau 2 termometrus, viesnas matuoja temperatūrą namuose kitas lauke. Tada nubraižiau grafikus su matlab ir gavau toki vaizdą:
%% read temerature log and plot chart fileID = fopen('\\aistis\pihome\home\pi\temp_log.txt','r'); C = textscan(fileID,'%s %s %s %s %s %s %s %s %s %s %s %s'); fclose(fileID); disp(C); clear d for i=1:length(C{1}) d(i).date = datenum(C{1}{i},'yyyy-mm-ddTHH:MM:SSZ'); d(i).type = C{2}{i}; z = strsplit(C{end}{i},'='); d(i).temp = str2num(z{2})/1000; end figure(1);clf; l = strcmp({d.type},'IN'); plot([d(l).date],[d(l).temp]); dynamicDateTicks;grid on;title('temperature in the house'); xlabel('time');ylabel('temperature in celcius'); figure(2);clf; l = strcmp({d.type},'OUT'); plot([d(l).date],[d(l).temp],'r'); dynamicDateTicks;grid on;title('temperature outside'); xlabel('time');ylabel('temperature in celcius');
raspberrypi/temp.1488014805.txt.gz · Last modified: by aistis



