User Tools

Site Tools


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;
}
raspberrypi/temp.1488014582.txt.gz · Last modified: by aistis