Solar-Online

Karl-von-Frisch Gymnasium

     
Aktuell: 0.00 °C  - 0 Watt Leistung     Letzte Aktualisierung: 08.02.2012 14:20:02 CET


 

Source-Code


Zum Upload der Daten werden auf einem Linux-Rechner
ein selbstgesschriebenes (in C++) Programm und Shell-
Scripte, sowie das Programm digitemp eingesetzt.
  • C++ Programm zum Auslesen der Leistungsdaten der Solaranlage

    leistung.c:
     1 #include <sys/types.h>
     2 #include <sys/stat.h>
     3 #include <fcntl.h>
     4 #include <termios.h>
     5 #include <stdlib.h>
     6 #include <stdio.h>
     7 #define BAUDRATE B300
     8 #define MODEMDEVICE "/dev/ttyS0"
     9 #define _POSIX_SOURCE 1 /* POSIX compliant source */
    10 #define FALSE 0
    11 #define TRUE 1
    12
    13 volatile int STOP=FALSE;
    14 main()
    15 {
    16    int fd,c, res,i;
    17    struct termios oldtio,newtio;
    18    char buf[255];
    19    char url[255];
    20    fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
    21    if (fd <0) {perror(MODEMDEVICE); exit(-1); }
    22    bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings */
    23    newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
    24    newtio.c_iflag = IGNPAR | ICRNL;
    25    newtio.c_oflag = 0;
    26    newtio.c_lflag = ICANON;
    27    newtio.c_cc[VINTR]    = 0;     /* Ctrl-c */
    28    newtio.c_cc[VQUIT]    = 0;     /* Ctrl-\ */
    29    newtio.c_cc[VERASE]   = 0;     /* del */
    30    newtio.c_cc[VKILL]    = 0;     /* @ */
    31    newtio.c_cc[VEOF]     = 4;     /* Ctrl-d */
    32    newtio.c_cc[VTIME]    = 0;     /* inter-character timer unused */
    33    newtio.c_cc[VMIN]     = 1;     /* blocking read until 1 character arrives */
    34    newtio.c_cc[VSWTC]    = 0;     /* '\0' */
    35    newtio.c_cc[VSTART]   = 0;     /* Ctrl-q */
    36    newtio.c_cc[VSTOP]    = 0;     /* Ctrl-s */
    37    newtio.c_cc[VSUSP]    = 0;     /* Ctrl-z */
    38    newtio.c_cc[VEOL]     = 0;     /* '\0' */
    39    newtio.c_cc[VREPRINT] = 0;     /* Ctrl-r */
    40    newtio.c_cc[VDISCARD] = 0;     /* Ctrl-u */
    41    newtio.c_cc[VWERASE]  = 0;     /* Ctrl-w */
    42    newtio.c_cc[VLNEXT]   = 0;     /* Ctrl-v */
    43    newtio.c_cc[VEOL2]    = 0;     /* '\0' */
    44    tcflush(fd, TCIFLUSH);
    45    tcsetattr(fd,TCSANOW,&newtio);
    46
    47    while (STOP==FALSE) {
    48        res = read(fd, buf, 255);
    49        buf[res]=0;
    50        if (buf[0]=='B') STOP=TRUE;
    51    }
    52    STOP=FALSE;
    53
    54    i=0;
    55
    56    while (STOP==FALSE) {     /* loop urminating condition */
    57      i++;
    58      res = read(fd,buf,255);
    59      buf[res]=0;             /* set end of string, so we can pntf */
    60      if (i!=1) strcat(url,"x");
    61      strncat(url,buf,(strlen(buf)-1));
    62      if (buf[0]=='B') STOP=TRUE;
    63    }
    64    printf("%s\n",url);
    65 }
    

  • C++ Programm zum Auslesen der Helligkeit (A/D-Wanlder)
    Der TLC1549 muss folgendermaßen angeschlossen werden:
    Pin1 (REF+)       <-  Pin 5 (DATA3)      = Versorgungs- & Referenzspannung
    Pin2 (ANALOG IN)   -                     = Plus Messleitung
    Pin3 (REF-)        -  Pin18-19 (GND)     = Masse & Minus Referenzspannug
    Pin4 (GND)         -  Pin18-19 (GND)     = Masse & Minus Referenzspannug
    Pin5 (CS)         <-  Pin14 (AUTO FEED)  = Chip-Select
    Pin6 (DATA OUT)   ->  Pin15 (ERROR)      = Wandlerdaten
    Pin7 (I/O CLOCK)  <-  Pin16 (INIT/RESET) = Taktleitung
    Pin8 (VCC)        <-  Pin 5 (DATA3)      = Versorgungs- & Referenzspannung
    
    Zwischen "Versorgungsspannung", "Plus Messleitung" und "Minus Messleitung"
    wird der Spannungsteiler mit dem Fototransistor aufgebaut. Die Werte einfach
    ausprobieren. Bei mir tats ein 10k Poti.

    tlc1549.c:
     1 #include <sys/io.h>
     2 #include <unistd.h>
     3 #include <stdio.h>
     4 #include <stdlib.h>
     5 #include <math.h>
     6 /**
     7 Programmierung: Hanno Rein 2002
     8 http://solar.kvfg.de
     9
    10 Aufruf:    ./tlc1549 (Basisadresse des Druckerports) (Anzahl der Abfragen, für Mittelwert)
    11 Beispiel:  ./tlc1549 888 10
    12 **/
    13
    14
    15 main(int argc, char* argv[]){
    16  int base=atoi(argv[1]);
    17  int i,u;
    18  int erg,all=0,overall=0,times=atoi(argv[2]);
    19  /**Port Zugriff freischalten**/
    20  ioperm(base,3,1);
    21  /**Stromversorgung für AD-Wandler anschalten**/
    22  outb(8,base);
    23  for (u=0;u<times+1;u++){
    24   /**Initialisierung des Wandlers**/
    25   outb(0,base+2);
    26   usleep(1000);
    27   outb(2,base+2);
    28   /**die 10 Bit einlesen*/
    29   for (i=9;i>=0;i--)
    30   {
    31    /**Diese Zahl (119) kann von System zu System variieren.
    32       Einfach inb(base+1) ausgeben und nachgucken          **/
    33     if(inb(base+1)!=119){
    34    /**Bits Aufsummieren**/
    35       all=all+(int)(pow(2,i));
    36     }
    37    /**Clock Hoch**/
    38    outb(6,base+2);
    39    /**Clock runter**/
    40    outb(2,base+2);
    41   }
    42   usleep(1000);
    43   /**die verschiedenen Abfragen aufsummieren (--> Mittelwert)**/
    44   if(u!=0){overall=overall+all;}
    45   all=0;
    46  }
    47  /**Mittelwert berechnen**/
    48  erg=(int)(overall)/times;
    49  /**Stromversorgung aus und Rechte abtreten**/
    50  outb(0,base);
    51  ioperm(base,3,0);
    52  /**Mittelwert ausgeben**/
    53  printf("%i\n",erg);
    54 };
    

  • Shell-Skript (wird durch Cron alle 5 Minuten gestartet)
     1 rm /root/temptemp.txt
     2 rm /root/templeistung.txt
     3 rm /root/tempbright.txt
     4
     5 /root/digitemp -o"%.2C" -s/dev/ttyS1 -l/root/temptemp.txt -n1 -a -r1000 > /dev/null
     6 /root/leistung > /root/templeistung.txt
     7 /root/tlc1549 888 10 > /root/tempbright.txt
     8
     9 export TEST1=$(cat /root/templeistung.txt)
    10 export TEST2=$(cat /root/temptemp.txt)
    11 export TEST3=$(cat /root/tempbright.txt)
    12
    13 wget "http://username:passwort@solar.kvfg.de/solarupload/solar.php?
       leistung=$TEST1%26temperatur=$TEST2%26brightness=$TEST3" --delete-after --quiet
    

  • Digitemp
    Dieses Programm wird benötigt um die die 1-Wire
    Temperatursensoren auszulesen. Näheres auf der
    Homepage von Brian Lane



Rechenzeit: 0.0007 Sekunden - © 2002-2012 Solar-Online