Fri, 09 May 2014 22:29:42 +0200
Added user log with temperatures and cooler state
7 | 1 | #ifndef _MBSELIB_H |
2 | #define _MBSELIB_H | |
3 | ||
4 | #include "../config.h" | |
5 | ||
6 | #include <stdlib.h> | |
7 | #include <stdio.h> | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
8 | #include <stdint.h> |
7 | 9 | #include <string.h> |
10 | #include <ctype.h> | |
11 | #include <sys/types.h> | |
12 | 12 | #include <sys/stat.h> |
32
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
13 | #include <sys/time.h> |
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
14 | #include <time.h> |
12 | 15 | #include <fcntl.h> |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
16 | #include <syslog.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
17 | #include <unistd.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
18 | #include <errno.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
19 | #include <signal.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
20 | #include <getopt.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
21 | |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
22 | /* mosquitto */ |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
23 | #include <mosquitto.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
24 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
25 | #ifdef HAVE_WIRINGPI_H |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
26 | /* wiringPi */ |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
27 | #include <wiringPi.h> |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
28 | #include <pcf8574.h> |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
29 | #include <lcd.h> |
7 | 30 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
31 | #endif |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
32 | |
7 | 33 | #define TRUE 1 |
34 | #define FALSE 0 | |
35 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
36 | #define MBSE_SS(x) (x)?(x):"(null)" |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
37 | |
7 | 38 | /* rdconfig.c */ |
39 | typedef struct _key_list { | |
40 | char *key; | |
41 | int (*prc)(char **); | |
42 | char **dest; | |
43 | } key_list; | |
44 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
45 | typedef struct _w1_therm { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
46 | struct _w1_therm *next; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
47 | char *master; /* Master for this device */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
48 | int bus; /* Reserved for ds2482-800 */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
49 | char *name; /* Name of this device */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
50 | char *alias; /* Friendly name */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
51 | int present; /* 1=present, 0=absent */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
52 | int lastval; /* Last valid value */ |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
53 | int update; /* Value updated */ |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
54 | } w1_therm; |
7 | 55 | |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
56 | typedef struct _rc_switch { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
57 | struct _rc_switch *next; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
58 | char *address; /* Address code */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
59 | char *alias; /* Friendly name */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
60 | } rc_switch; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
61 | |
7 | 62 | typedef struct _sys_config { |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
63 | char *name; /* Configuration name */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
64 | char *mosq_host; /* mosquitto server hostname */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
65 | int mosq_port; /* mosquitto server port */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
66 | w1_therm *w1therms; /* 1-wire temp sensors */ |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
67 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
68 | int lcd_cols; /* LCD display columns */ |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
69 | int lcd_rows; /* LCD display rows */ |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
70 | int rx433; /* 433 MHz receiver pin */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
71 | int tx433; /* 433 MHz transmitter pin */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
72 | rc_switch *rcswitch; /* 433 MHz RC Power switches */ |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
73 | #endif |
7 | 74 | } sys_config; |
75 | ||
76 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
77 | |
7 | 78 | void killconfig(void); |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
79 | int rdconfig(char *); |
7 | 80 | |
81 | ||
82 | /* xutil.c */ | |
83 | char *xmalloc(size_t); | |
84 | char *xstrcpy(char *); | |
85 | char *xstrcat(char *, char *); | |
86 | ||
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
87 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
88 | #ifdef HAVE_WIRINGPI_H |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
89 | |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
90 | /* lcd-pcf8574.c */ |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
91 | // Defines for the pcf8574 Pi LCD interface board |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
92 | #define AF_BASE 100 |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
93 | |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
94 | #define AF_RS (AF_BASE + 0) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
95 | #define AF_RW (AF_BASE + 1) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
96 | #define AF_E (AF_BASE + 2) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
97 | #define AF_BACKLIGHT (AF_BASE + 3) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
98 | #define AF_DB4 (AF_BASE + 4) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
99 | #define AF_DB5 (AF_BASE + 5) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
100 | #define AF_DB6 (AF_BASE + 6) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
101 | #define AF_DB7 (AF_BASE + 7) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
102 | |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
103 | void setBacklight (int); |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
104 | int initLCD (int, int); |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
105 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
106 | |
32
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
107 | /* logger.c */ |
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
108 | void logger(char *, char *, char *); |
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
31
diff
changeset
|
109 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
110 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
111 | /* rc-switch.c */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
112 | |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
113 | int toggleSwitch(char *); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
114 | int toggleTypeA(char *, char *, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
115 | int toggleTypeB(int, int, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
116 | int toggleTypeC(char, int, int, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
117 | int toggleTypeE(char, int, bool); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
118 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
119 | void enableReceiveIRQ(int interrupt); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
120 | void enableReceive(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
121 | void disableReceive(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
122 | bool available(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
123 | void resetAvailable(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
124 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
125 | unsigned long getReceivedValue(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
126 | unsigned int getReceivedBitlength(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
127 | unsigned int getReceivedDelay(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
128 | unsigned int getReceivedProtocol(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
129 | unsigned int *getReceivedRawdata(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
130 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
131 | void enableTransmit(int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
132 | void disableTransmit(void); |
29
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
28
diff
changeset
|
133 | |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
28
diff
changeset
|
134 | char *dec2binWzerofill(unsigned long, unsigned int); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
135 | |
31
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
136 | |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
137 | /* dht11.c */ |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
138 | void dht11Read(void); |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
139 | void dht11Init(int, int, int); |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
140 | |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
141 | |
7 | 142 | #endif |
143 | ||
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
144 | |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
145 | #endif |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
146 |