thermferm/devices.c

Sun, 05 May 2024 17:24:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 05 May 2024 17:24:54 +0200
changeset 730
6eba006ed8f5
parent 729
f5d94730db18
permissions
-rw-r--r--

Much faster shutdown of the websocket service.

158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
643
586d376ab629 Updates for DHT11 reading
Michiel Broek <mbroek@mbse.eu>
parents: 596
diff changeset
2 * Copyright (C) 2014..2024
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with thermferm; see the file COPYING. If not, write to the Free
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
23 #include "thermferm.h"
652
16d3d4b58b5b Moved all delay functions into a new general file.
Michiel Broek <mbroek@mbse.eu>
parents: 650
diff changeset
24 #include "delay.h"
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 #include "devices.h"
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
26 #include "rc-switch.h"
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
27 #include "panel.h"
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 #include "xutil.h"
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
29 #include "websocket.h"
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
32 int my_devices_shutdown = 0;
646
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
33 int my_devices_state = 0;
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
34
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 extern sys_config Config;
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 644
diff changeset
36 extern pthread_mutex_t mutexes[5];
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
37 extern w1_list *w1_devices;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
38
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
39 extern const char DEVTYPE[8][6];
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
40 extern const char DEVPRESENT[4][6];
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
41 extern const char DEVDIR[7][11];
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
42
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
43 #ifdef USE_SIMULATOR
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
44 extern int my_simulator_state;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
45 #endif
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
47
643
586d376ab629 Updates for DHT11 reading
Michiel Broek <mbroek@mbse.eu>
parents: 596
diff changeset
48 /*
586d376ab629 Updates for DHT11 reading
Michiel Broek <mbroek@mbse.eu>
parents: 596
diff changeset
49 * Since kernel version 4 there is a module, and a dtoverlay so that the
586d376ab629 Updates for DHT11 reading
Michiel Broek <mbroek@mbse.eu>
parents: 596
diff changeset
50 * temperature and humidity can simply read from the /sys filesystem.
586d376ab629 Updates for DHT11 reading
Michiel Broek <mbroek@mbse.eu>
parents: 596
diff changeset
51 */
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
52 int dht11_temperature = -1;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
53 int dht11_humidity = -1;
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
54 int dht11_state = DEVPRESENT_UNDEF;
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
55 time_t dht11_next;
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
56
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
57
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
58
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
59 /*
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 212
diff changeset
60 * DHT11 sensor read.
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
61 * Called at 30 seconds interval if all is well.
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
62 * If last read was an error, the interval is 2 seconds.
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
63 */
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
64 void dht11Read(char *address)
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
65 {
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
66 int temp, hum;
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
67 int fd, rc, err, oldstate;
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
68 char buffer[25], *dhtpath = NULL;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
69
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
70 dht11_temperature = -1;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
71 dht11_humidity = -1;
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
72 oldstate = dht11_state;
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
73 dhtpath = xstrcpy((char *)"/sys/bus/iio/devices/");
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
74 dhtpath = xstrcat(dhtpath, address);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
75 dhtpath = xstrcat(dhtpath, (char *)"/in_temp_input");
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
76
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
77 fd = open(dhtpath, O_RDONLY);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
78 if (fd < 0) {
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
79 /*
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
80 * The sensor is gone.
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
81 */
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
82 err = errno;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
83 syslog(LOG_NOTICE, "DHT11 open temperature: %d %s", err, strerror(err));
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
84 free(dhtpath);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
85 dht11_state = DEVPRESENT_NO;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
86 return;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
87 }
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
88
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
89 rc = read(fd, buffer, 25);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
90 if (rc == -1) {
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
91 err = errno;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
92 if (err == 110) {
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
93 dht11_state = DEVPRESENT_NO; /* Device is gone */
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
94 } else {
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
95 dht11_state = DEVPRESENT_ERROR;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
96 }
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
97 syslog(LOG_NOTICE, "DHT11 read temperature: %s", strerror(err));
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
98 } else {
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
99 sscanf(buffer, "%d", &temp);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
100 dht11_temperature = temp;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
101 dht11_state = DEVPRESENT_YES;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
102 }
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
103 close(fd);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
104 free(dhtpath);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
105 dhtpath = NULL;
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
106
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
107 /*
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
108 * Only read humidity if state is DEVPRESENT_YES
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
109 */
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
110 if (dht11_state == DEVPRESENT_YES) {
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
111 dhtpath = xstrcpy((char *)"/sys/bus/iio/devices/");
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
112 dhtpath = xstrcat(dhtpath, address);
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
113 dhtpath = xstrcat(dhtpath, (char *)"/in_humidityrelative_input");
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
114
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
115 fd = open(dhtpath, O_RDONLY);
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
116 rc = read(fd, buffer, 25);
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
117 if (rc == -1) {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
118 err = errno;
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
119 if (err == 110) {
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
120 dht11_state = DEVPRESENT_NO;
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
121 } else {
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
122 dht11_state = DEVPRESENT_ERROR;
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
123 }
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
124 syslog(LOG_NOTICE, "DHT11 read humidity: %s", strerror(err));
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
125 dht11_temperature = -1; /* Make invalid */
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
126 } else {
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
127 sscanf(buffer, "%d", &hum);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
128 dht11_humidity = hum;
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
129 dht11_state = DEVPRESENT_YES;
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
130 }
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
131 close(fd);
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
132 free(dhtpath);
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
133 dhtpath = NULL;
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
134 }
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
135
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
136 if (oldstate != dht11_state)
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
137 syslog(LOG_NOTICE, "dht11 t:%d h:%d state:%d", dht11_temperature, dht11_humidity, dht11_state);
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
138 }
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
139
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
140
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
142 /*
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
143 * Read one byte from a 1-wire device like a DS2413
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
144 */
347
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
145 int read_w1(char *address, char *file)
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
146 {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
147 char *addr = NULL;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
148 int fn = -1, rc = -1, retries = 5;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
149 uint8_t val;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
150
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
151 addr = xstrcpy((char *)"/sys/bus/w1/devices/");
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
152 addr = xstrcat(addr, address);
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
153 addr = xstrcat(addr, (char *)"/");
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
154 addr = xstrcat(addr, file);
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
155
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
156 if ((fn = open(addr, O_RDONLY)) >= 0) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
157
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
158 if ((lseek(fn, 0L, SEEK_SET)) == 0) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
159
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
160 while (retries--) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
161 if ((read(fn, &val, 1)) == 1) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
162 rc = (int)val;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
163 goto leave;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
164 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
165 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
166 syslog(LOG_NOTICE, "read_w1() read %s fatal: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
167
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
168 } else {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
169 syslog(LOG_NOTICE, "read_w1() lseek %s: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
170 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
171
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
172 } else {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
173 syslog(LOG_NOTICE, "read_w1() open %s: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
174 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
175
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
176 leave:
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
177 if (fn != -1) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
178 if ((close(fn)) == -1) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
179 syslog(LOG_NOTICE, "read_w1() close %s: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
180 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
181 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
182
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
183 free(addr);
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
184 return rc;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
185 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
186
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
187
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
188
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
189 /*
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
190 * Write a byte to a 1-wire device like a DS2413
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
191 */
347
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
192 int write_w1(char *address, char *file, uint8_t val)
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
193 {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
194 char *addr = NULL;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
195 int fn = -1, rc = -1, retries = 5;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
196
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
197 addr = xstrcpy((char *)"/sys/bus/w1/devices/");
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
198 addr = xstrcat(addr, address);
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
199 addr = xstrcat(addr, (char *)"/");
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
200 addr = xstrcat(addr, file);
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
201
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
202 if ((fn = open(addr, O_WRONLY)) >= 0) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
203
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
204 if ((lseek(fn, 0L, SEEK_SET)) == 0) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
205
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
206 while (retries--) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
207 if ((write(fn, &val, 1)) == 1) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
208 rc = 0;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
209 goto leave;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
210 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
211 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
212 syslog(LOG_NOTICE, "write_w1() write %s fatal: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
213
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
214 } else {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
215 syslog(LOG_NOTICE, "write_w1() lseek %s: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
216 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
217
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
218 } else {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
219 syslog(LOG_NOTICE, "write_w1() open %s: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
220 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
221
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
222 leave:
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
223 if (fn != -1) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
224 if ((close(fn)) == -1) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
225 syslog(LOG_NOTICE, "write_w1() close %s: %s", addr, strerror(errno));
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
226 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
227 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
228
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
229 free(addr);
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
230 return rc;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
231 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
232
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
233
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
234
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
235 int device_out(char *uuid, int value)
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
236 {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
237 devices_list *device;
323
608592f74b10 Added extra lock
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
238 time_t now, my_timestamp;
671
b2e2cbb13cb3 Finished one-wire ds2413 output
Michiel Broek <mbroek@mbse.eu>
parents: 661
diff changeset
239 int my_value, test_value;
187
3c8bf18fdf42 Updated conditional defines and dependencies
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
240 #ifdef HAVE_WIRINGPI_H
672
0c2c66920d79 Only log temperature error once. Only log temperature Ok again once. Do not log changed temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 671
diff changeset
241 int rc, i;
187
3c8bf18fdf42 Updated conditional defines and dependencies
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
242 char buf[40];
3c8bf18fdf42 Updated conditional defines and dependencies
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
243 #endif
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
244 #ifdef USE_SIMULATOR
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
245 simulator_list *simulator;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
246 #endif
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
247
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
248 if (uuid == NULL)
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
249 return 0;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
250
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 181
diff changeset
251 now = time(NULL);
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
252 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
337
5d3670aafd1b More global device locking
Michiel Broek <mbroek@mbse.eu>
parents: 325
diff changeset
253
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
254 for (device = Config.devices; device; device = device->next) {
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 239
diff changeset
255 if (! strcmp(uuid, device->uuid)) {
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 181
diff changeset
256 /*
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 181
diff changeset
257 * Execute command if different then the old value. But also
212
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
258 * every 2 minutes because commands can have temporary
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
259 * disconnects, or have radio problems.
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 181
diff changeset
260 */
323
608592f74b10 Added extra lock
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
261 my_timestamp = device->timestamp;
608592f74b10 Added extra lock
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
262 my_value = device->value;
347
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
263
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
264 if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN)) {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
265 test_value = (value == 0) ? 0 : 1;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
266 } else {
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
267 test_value = value;
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
268 }
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
269
351
d8c410c320db Fixed auto device update timer
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
270 if ((test_value != my_value) || (((int)now - (int)my_timestamp) >= 120)) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
271
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
272 #ifdef HAVE_WIRINGPI_H
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
273 rc = 0;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
274 if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
275 snprintf(buf, 39, "%s,%d", device->address, value ? 1:0);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
276 for (i = 0; i < strlen(buf); i++)
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
277 if (buf[i] == '-')
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 239
diff changeset
278 buf[i] = ',';
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
279 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 239
diff changeset
280 enableTransmit(device->gpiopin);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
281 rc = toggleSwitch(buf);
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 239
diff changeset
282 disableTransmit();
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
283 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
284 syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc);
212
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
285 device->value = value;
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
286 device->timestamp = time(NULL);
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
287 devices_ws();
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
288 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
212
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
289 return rc;
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
290 }
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
291
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
292 if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
293
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
294 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
295 #endif
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
296 if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) {
347
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
297 if (strncmp(device->address, (char *)"3a", 2) == 0) {
711
844588d0df65 Version 0.9.19b1. Less noisy logging.
Michiel Broek <mbroek@mbse.eu>
parents: 693
diff changeset
298 // syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment);
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
299 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
300 if (device->value != (value == 0) ? 0 : 1) {
711
844588d0df65 Version 0.9.19b1. Less noisy logging.
Michiel Broek <mbroek@mbse.eu>
parents: 693
diff changeset
301 syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment);
685
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
302 device->value = (value == 0) ? 0 : 1;
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
303 device->timestamp = time(NULL);
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
304 devices_ws();
819553a2b97e Devices list grid added.
Michiel Broek <mbroek@mbse.eu>
parents: 684
diff changeset
305 }
674
6cabc02f4c8d Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 672
diff changeset
306 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
347
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
307 }
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
308 }
347
0ab5c3fd7c77 Completed DS2413 device code and driver.
Michiel Broek <mbroek@mbse.eu>
parents: 344
diff changeset
309
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
310 #ifdef USE_SIMULATOR
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
311 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN)) {
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
312 while (my_simulator_state == THREAD_PAUSE) { mDelay(20); };
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
313 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
314 if ((strcmp(device->address, simulator->cooler_address) == 0) ||
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
315 (strcmp(device->address, simulator->heater_address) == 0) ||
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
316 (strcmp(device->address, simulator->fan_address) == 0) ||
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
317 (strcmp(device->address, simulator->light_address) == 0)) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
318 if (value != device->value) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
319 int rc = DEVPRESENT_UNDEF;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
320 device->value = value;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
321 device->timestamp = time(NULL);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
322 if (strcmp(device->address, simulator->cooler_address) == 0) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
323 simulator->cooler_power = value;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
324 rc = simulator->cooler_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
325 } else if (strcmp(device->address, simulator->heater_address) == 0) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
326 simulator->heater_power = value;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
327 rc = simulator->heater_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
328 } else if (strcmp(device->address, simulator->fan_address) == 0) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
329 simulator->fan_power = value;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
330 rc = simulator->fan_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
331 } else if (strcmp(device->address, simulator->light_address) == 0) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
332 simulator->light_power = value;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
333 rc = simulator->light_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
334 }
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
335 syslog(LOG_NOTICE, "SIM %s value=%d, present=%s", device->address, value, DEVPRESENT[rc]);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
336 device->present = rc;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
337 devices_ws();
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
338 }
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 354
diff changeset
339 }
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 354
diff changeset
340 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
341 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
342 #endif
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
343 } else {
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
344 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
345 return 0;
583
9795a16de807 Attempt to better check the temperature sensors and lower the cpu load.
Michiel Broek <mbroek@mbse.eu>
parents: 573
diff changeset
346 } // if ((test_value != my_value) || (((int)now - (int)my_timestamp) >= 120))
9795a16de807 Attempt to better check the temperature sensors and lower the cpu load.
Michiel Broek <mbroek@mbse.eu>
parents: 573
diff changeset
347 } // if (! strcmp(uuid, device->uuid))
9795a16de807 Attempt to better check the temperature sensors and lower the cpu load.
Michiel Broek <mbroek@mbse.eu>
parents: 573
diff changeset
348 } // for (device = Config.devices; device; device = device->next)
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 181
diff changeset
349
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
350 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
351 return 0;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
352 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
353
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
354
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
355 /*
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
356 * Returns DEVPRESENT_NO if failed.
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
357 * Returns DEVPRESENT_YES if success, value contains new value.
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
358 */
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
359 int device_in(char *uuid, int *value)
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
360 {
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
361 devices_list *device;
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
362 int tmp, present;
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
363
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
364 if (uuid == NULL)
693
3518c07737d8 Version 0.9.19a2. Dropped TEMPSTATE[] and only use DEVPRESENT[] to mark devices state. Adjusted webpages for this switch in responses. Adjusted MySQL mon_fermenters enum values too. Rename some global Config records to better reflect their real use.Added one-wire json records and websocket. Announce when some onewire device changes. Add UNITS JSON command without parameter. Dropped global tempFormat setting that was never used.
Michiel Broek <mbroek@mbse.eu>
parents: 687
diff changeset
365 return DEVPRESENT_UNDEF;
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
366
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
367 for (device = Config.devices; device; device = device->next) {
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
368 if (! strcmp(uuid, device->uuid)) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
369 present = device->present;
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
370 if (present == DEVPRESENT_YES) {
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
371 tmp = device->value + device->offset;
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
372 } else {
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
373 tmp = 0;
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
374 }
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
375 *value = tmp;
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
376 return present;
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
377 }
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
378 }
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
379
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 394
diff changeset
380 return DEVPRESENT_NO;
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
381 }
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
382
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
383
715
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
384 int device_present(char *address, int present)
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
385 {
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
386 devices_list *device;
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
387
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
388 if (address == NULL || present < DEVPRESENT_UNDEF || present > DEVPRESENT_ERROR) {
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
389 return -1;
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
390 }
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
391
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
392 for (device = Config.devices; device; device = device->next) {
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
393 if (! strcmp(address, device->address)) {
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
394 if (device->present != present) {
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
395 device->present = present;
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
396 device->timestamp = time(NULL);
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
397 return 1;
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
398 }
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
399 return 0;
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
400 }
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
401 }
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
402 return -1;
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
403 }
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
404
f5d85af156ab Added device_present() function to easy update device present from one-wire and simulator devices. When a simulator temperature sensor present is changed, the device table is changed too. Controlling simulator relays is now for each simulator. The simulator runs under the state machine. If something changed in the running simulator, all data is broadcasted over websocket. Completed the web editor.
Michiel Broek <mbroek@mbse.eu>
parents: 714
diff changeset
405
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
406 /*
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
407 * Return json data for one device.
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
408 */
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
409 char *device_json(devices_list *device)
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
410 {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
411 char *payload;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
412 char vbuf[64];
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
413
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
414 payload = xstrcpy((char *)"{\"uuid\":\"");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
415 payload = xstrcat(payload, device->uuid);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
416 payload = xstrcat(payload, (char *)"\",\"type\":\"");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
417 payload = xstrcat(payload, (char *)DEVTYPE[device->type]);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
418 payload = xstrcat(payload, (char *)"\",\"direction\":\"");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
419 payload = xstrcat(payload, (char *)DEVDIR[device->direction]);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
420 payload = xstrcat(payload, (char *)"\",\"address\":\"");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
421 payload = xstrcat(payload, device->address);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
422 payload = xstrcat(payload, (char *)"\",\"subdevice\":");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
423 snprintf(vbuf, 63, "%d", device->subdevice);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
424 payload = xstrcat(payload, vbuf);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
425 payload = xstrcat(payload, (char *)",\"value\":");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
426 snprintf(vbuf, 63, "%d", device->value);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
427 payload = xstrcat(payload, vbuf);
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
428 payload = xstrcat(payload, (char *)",\"offset\":");
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
429 snprintf(vbuf, 63, "%d", device->offset);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
430 payload = xstrcat(payload, vbuf);
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
431 payload = xstrcat(payload, (char *)",\"present\":\"");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
432 payload = xstrcat(payload, (char *)DEVPRESENT[device->present]);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
433 payload = xstrcat(payload, (char *)"\"");
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
434 payload = xstrcat(payload, (char *)",\"gpiopin\":");
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
435 snprintf(vbuf, 63, "%d", device->gpiopin);
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
436 payload = xstrcat(payload, vbuf);
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
437 payload = xstrcat(payload, (char *)",\"inuse\":");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
438 snprintf(vbuf, 63, "%d", device->inuse);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
439 payload = xstrcat(payload, vbuf);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
440 payload = xstrcat(payload, (char *)",\"description\":\"");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
441 payload = xstrcat(payload, device->description);
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
442 payload = xstrcat(payload, (char *)"\",\"comment\":\"");
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
443 payload = xstrcat(payload, device->comment);
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
444 payload = xstrcat(payload, (char *)"\",\"timestamp\":");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
445 snprintf(vbuf, 63, "%ld", (long)device->timestamp);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
446 payload = xstrcat(payload, vbuf);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
447 payload = xstrcat(payload, (char *)"}");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
448
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
449 return payload;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
450 }
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
451
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
452
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
453
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
454 void devices_ws(void)
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
455 {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
456 bool comma = false;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
457 char *payload = NULL, *payloadu = NULL;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
458 devices_list *device;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
459
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
460 payload = xstrcpy((char *)"{\"type\":\"device\",\"metric\":[");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
461 for (device = Config.devices; device; device = device->next) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
462 if (comma)
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
463 payload = xstrcat(payload, (char *)",");
687
f5d05b420732 Devices edit popup layout ready.
Michiel Broek <mbroek@mbse.eu>
parents: 685
diff changeset
464 payloadu = device_json(device);
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
465 payload = xstrcat(payload, payloadu);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
466 comma = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
467 free(payloadu);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
468 payloadu = NULL;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
469 }
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
470 payload = xstrcat(payload, (char *)"]}");
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
471 ws_broadcast(payload);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
472 free(payload);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
473 payload = NULL;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
474 }
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
475
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
476
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 166
diff changeset
477
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 /*
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 * Auto detect hotplugged or known to be present devices
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 */
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 int devices_detect(void)
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 {
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 struct dirent *de;
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 DIR *fd;
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
485 w1_list *dev_w1;
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 devices_list *device, *ndev;
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
487 int found, subdevices, i, rc = 0;
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 uuid_t uu;
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
489 #ifdef HAVE_WIRINGPI_H
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
490 int pin;
658
b10d0f6337a3 Fix for compile with wiringPi
Michiel Broek <mbroek@mbse.eu>
parents: 657
diff changeset
491 char buf[40];
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
492 #endif
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
493 #ifdef USE_SIMULATOR
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
494 simulator_list *simulator;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
495 #endif
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 /*
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
498 * Scan for 1-wire devices. These are already detected by the
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
499 * one-wire thread that is already running. So we just check
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
500 * these detected devices.
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 */
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
502 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
503 found = FALSE;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
504 for (device = Config.devices; device; device = device->next) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
505 if (strcmp(device->address, dev_w1->address) == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
506 found = TRUE;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
507 break;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
508 }
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
509 }
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
510
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
511 if (found == FALSE) {
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
512 subdevices = (strcmp(dev_w1->family, (char *)"3a") == 0) ? 2:1;
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
513 for (i = 0; i < subdevices; i++) {
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
514 ndev = (devices_list *)malloc(sizeof(devices_list));
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
515 ndev->next = NULL;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
516 ndev->uuid = malloc(37);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
517 uuid_generate(uu);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
518 uuid_unparse(uu, ndev->uuid);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
519 ndev->type = DEVTYPE_W1;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
520 ndev->direction = DEVDIR_IN_ANALOG;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
521 if (strcmp(dev_w1->family, (char *)"10") == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
522 ndev->description = xstrcpy((char *)"DS18S20 Digital thermometer");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
523 } else if (strcmp(dev_w1->family, (char *)"22") == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
524 ndev->description = xstrcpy((char *)"DS1822 Digital thermometer");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
525 } else if (strcmp(dev_w1->family, (char *)"28") == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
526 ndev->description = xstrcpy((char *)"DS18B20 Digital thermometer");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
527 } else if (strcmp(dev_w1->family, (char *)"3a") == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
528 ndev->description = xstrcpy((char *)"DS2413 Dual channel addressable switch");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
529 ndev->direction = DEVDIR_IN_BIN;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
530 } else if (strcmp(dev_w1->family, (char *)"3b") == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
531 ndev->description = xstrcpy((char *)"DS1825 Digital thermometer");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
532 } else if (strcmp(dev_w1->family, (char *)"42") == 0) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
533 ndev->description = xstrcpy((char *)"DS28EA00 Digital thermometer");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
534 } else {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
535 ndev->description = xstrcpy((char *)"Unknown device family ");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
536 ndev->direction = DEVDIR_UNDEF;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
537 }
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
538 ndev->value = ndev->offset = ndev->inuse = 0;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
539 ndev->present = DEVPRESENT_YES;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
540 ndev->address = xstrcpy(dev_w1->address);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
541 ndev->subdevice = i;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
542 ndev->gpiopin = -1;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
543 ndev->comment = xstrcpy((char *)"Auto detected device");
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
544 ndev->timestamp = time(NULL);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
545
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
546 syslog(LOG_NOTICE, "New W1 device %s, subdevice %d, %s", ndev->address, ndev->subdevice, ndev->description);
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
547
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
548 if (Config.devices == NULL) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
549 Config.devices = ndev;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
550 } else {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
551 for (device = Config.devices; device; device = device->next) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
552 if (device->next == NULL) {
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
553 device->next = ndev;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
554 break;
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
555 }
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 }
656
ca47c742a25d One-wire thread is now the first to start. The devices_detect() function now uses the detected one-wire linked list instead of scan the sysfs. Base code for ds2413 added in the state table, needs rework.
Michiel Broek <mbroek@mbse.eu>
parents: 654
diff changeset
558 rc++;
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 644
diff changeset
563 /*
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
564 * DHT11 as kernel module. The number after the @ is the hexadecimal
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
565 * number of the BCM gpio pin. Since we use pin 22 at connector pin 15
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
566 * the number is 16.
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 644
diff changeset
567 */
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
568 char *dhtaddr = NULL;
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
569 if ((fd = opendir((char *)"/sys/devices/platform/dht11@16"))) {
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
570 while ((de = readdir(fd))) {
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
571 if (de->d_name[0] != '.') {
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
572 if (strncmp(de->d_name, (char *)"iio", 3) == 0) {
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
573 dhtaddr = xstrcpy(de->d_name);
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
574 }
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
575 }
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
576 }
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
577 closedir(fd);
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
578 }
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
579
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
580 if (dhtaddr) {
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
581
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
582 found = FALSE;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
583 for (device = Config.devices; device; device = device->next) {
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
584 if (strcmp(device->address, dhtaddr) == 0) {
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
585 found = TRUE;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
586 break;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
587 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
588 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
589
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
590 if (found == FALSE) {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
591 for (i = 0; i < 2; i++) {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
592 ndev = (devices_list *)malloc(sizeof(devices_list));
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
593 ndev->next = NULL;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
594 ndev->uuid = malloc(37);
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
595 uuid_generate(uu);
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
596 uuid_unparse(uu, ndev->uuid);
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
597 ndev->type = DEVTYPE_DHT;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
598 ndev->direction = DEVDIR_IN_ANALOG;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
599 if (i == 0)
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
600 ndev->description = xstrcpy((char *)"DHT11 temperature sensor");
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
601 else
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
602 ndev->description = xstrcpy((char *)"DHT11 humidity sensor");
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
603 ndev->value = ndev->offset = ndev->inuse = 0;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
604 ndev->present = DEVPRESENT_YES;
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
605 ndev->address = xstrcpy(dhtaddr);
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
606 ndev->subdevice = i;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
607 ndev->gpiopin = -1;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
608 ndev->comment = xstrcpy((char *)"Auto detected device");
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
609 ndev->timestamp = time(NULL);
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
610
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
611 syslog(LOG_NOTICE, "New DHT11 device %s, subdevice %d, %s", ndev->address, ndev->subdevice, ndev->description);
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
612
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
613 if (Config.devices == NULL) {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
614 Config.devices = ndev;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
615 } else {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
616 for (device = Config.devices; device; device = device->next) {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
617 if (device->next == NULL) {
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
618 device->next = ndev;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
619 break;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
620 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
621 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
622 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
623 rc++;
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
624 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
625 }
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
626 }
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 644
diff changeset
627
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
628 #ifdef HAVE_WIRINGPI_H
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
629 if (piBoardRev() == 2) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
630 /*
324
940a668e568f Update for newer boards
Michiel Broek <mbroek@mbse.eu>
parents: 323
diff changeset
631 * Support rev B and newer boards only
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
632 */
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
633 found = FALSE;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
634 for (device = Config.devices; device; device = device->next) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
635 if (device->type == DEVTYPE_GPIO) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
636 found = TRUE;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
637 break;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
638 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
639 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
640
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
641 if (found == FALSE) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
642 /*
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
643 * There were no GPIO devices found.
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
644 */
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
645 subdevices = 12;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
646 pin = 0;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
647 for (i = 0; i < subdevices; i++) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
648 if (i == 8)
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
649 pin = 17;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
650
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
651 ndev = (devices_list *)malloc(sizeof(devices_list));
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
652 ndev->next = NULL;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
653 ndev->uuid = malloc(37);
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
654 uuid_generate(uu);
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
655 uuid_unparse(uu, ndev->uuid);
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
656 ndev->type = DEVTYPE_GPIO;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
657 ndev->value = digitalRead(pin);
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
658 ndev->offset = 0;
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
659 ndev->present = DEVPRESENT_YES;
163
3d813570a5e3 LIST BUS now displays the new devices table. Adjusted the web screen
Michiel Broek <mbroek@mbse.eu>
parents: 162
diff changeset
660 ndev->address = xstrcpy((char *)"GPIO");
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
661 snprintf(buf, 39, "Raspberry GPIO %d", i);
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
662 ndev->description = xstrcpy(buf);
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
663 ndev->subdevice = i;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
664 ndev->gpiopin = pin;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
665 ndev->timestamp = time(NULL);
393
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
666 if (i == 0) {
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
667 ndev->direction = DEVDIR_INTERN;
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
668 ndev->inuse = 1;
394
14231379bec2 Spelling correction.
Michiel Broek <mbroek@mbse.eu>
parents: 393
diff changeset
669 ndev->comment = xstrcpy((char *)"433 Mhz transmitter");
393
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
670 } else if (i == 3) {
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
671 ndev->direction = DEVDIR_INTERN;
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
672 ndev->inuse = 1;
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 644
diff changeset
673 ndev->comment = xstrcpy((char *)"DHT11 sensor");
393
220f2f30bf68 Fixed initialisation of new GPIO RS433 and DHT11 devices.
Michiel Broek <mbroek@mbse.eu>
parents: 392
diff changeset
674 } else if (i == PANEL_LED) {
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
675 ndev->direction = DEVDIR_OUT_BIN;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
676 ndev->inuse = 1;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
677 ndev->comment = xstrcpy((char *)"Frontpanel LED");
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
678 } else if (i == PANEL_ENTER) {
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
679 ndev->direction = DEVDIR_IN_BIN;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
680 ndev->inuse = 1;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
681 ndev->comment = xstrcpy((char *)"Frontpanel Enter key");
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
682 } else if (i == PANEL_DOWN) {
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
683 ndev->direction = DEVDIR_IN_BIN;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
684 ndev->inuse = 1;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
685 ndev->comment = xstrcpy((char *)"Frontpanel Down key");
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
686 } else if (i == PANEL_UP) {
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
687 ndev->direction = DEVDIR_IN_BIN;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
688 ndev->inuse = 1;
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
689 ndev->comment = xstrcpy((char *)"Frontpanel Up key");
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
690 } else if (i == 7) {
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
691 ndev->direction = DEVDIR_INTERN;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
692 ndev->inuse = 1;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
693 ndev->comment = xstrcpy((char *)"1-Wire bus");
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
694 } else {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
695 ndev->direction = DEVDIR_IN_BIN;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
696 ndev->inuse = 0;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
697 ndev->comment = xstrcpy((char *)"Raspberry GPIO");
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
698 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
699 pin++;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
700
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
701 syslog(LOG_NOTICE, "New GPIO device %s, subdevice %d, %s", ndev->address, ndev->subdevice, ndev->description);
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
702
162
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
703 if (Config.devices == NULL) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
704 Config.devices = ndev;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
705 } else {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
706 for (device = Config.devices; device; device = device->next) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
707 if (device->next == NULL) {
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
708 device->next = ndev;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
709 break;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
710 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
711 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
712 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
713 rc++;
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
714 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
715 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
716 }
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
717 #endif
6fc9e3f7962f Added Raspberry GPIO devices
Michiel Broek <mbroek@mbse.eu>
parents: 161
diff changeset
718
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
719 #ifdef USE_SIMULATOR
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
720
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
721 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
722 for (i = 0; i < 12; i++) {
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
723
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
724 found = FALSE;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
725 for (device = Config.devices; device; device = device->next) {
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
726 if ((i == 0 && strcmp(device->address, simulator->room_tempaddress) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
727 (i == 1 && strcmp(device->address, simulator->air_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
728 (i == 2 && strcmp(device->address, simulator->beer_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
729 (i == 3 && strcmp(device->address, simulator->heater_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
730 (i == 4 && strcmp(device->address, simulator->cooler_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
731 (i == 5 && strcmp(device->address, simulator->room_humaddress) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
732 (i == 6 && strcmp(device->address, simulator->chiller_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
733 (i == 7 && strcmp(device->address, simulator->fan_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
734 (i == 8 && strcmp(device->address, simulator->light_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
735 (i == 9 && strcmp(device->address, simulator->beer_address2) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
736 (i == 10 && strcmp(device->address, simulator->door_address) == 0) ||
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
737 (i == 11 && strcmp(device->address, simulator->psu_address) == 0)) {
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
738 found = TRUE;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
739 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
740 }
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
741 }
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
742
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
743 if (found == FALSE) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
744 ndev = (devices_list *)malloc(sizeof(devices_list));
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
745 ndev->next = NULL;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
746 ndev->uuid = malloc(37);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
747 uuid_generate(uu);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
748 uuid_unparse(uu, ndev->uuid);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
749 ndev->type = DEVTYPE_SIM;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
750 ndev->value = ndev->offset = 0;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
751 ndev->present = DEVPRESENT_NO;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
752 ndev->gpiopin = -1;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
753 ndev->subdevice = i;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
754 ndev->comment = xstrcpy((char *)"Auto detected device");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
755 ndev->timestamp = time(NULL);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
756 ndev->inuse = 0;
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
757
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
758 switch (i) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
759 case 0: ndev->direction = DEVDIR_IN_ANALOG;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
760 ndev->address = xstrcpy(simulator->room_tempaddress);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
761 ndev->description = xstrcpy((char *)"Simulated room temperature");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
762 ndev->present = DEVPRESENT_YES;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
763 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
764 case 1: ndev->direction = DEVDIR_IN_ANALOG;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
765 ndev->address = xstrcpy(simulator->air_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
766 ndev->description = xstrcpy((char *)"Simulated air temperature");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
767 ndev->present = simulator->air_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
768 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
769 case 2: ndev->direction = DEVDIR_IN_ANALOG;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
770 ndev->address = xstrcpy(simulator->beer_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
771 ndev->description = xstrcpy((char *)"Simulated beer temperature");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
772 ndev->present = simulator->beer_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
773 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
774 case 3: ndev->direction = DEVDIR_OUT_BIN;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
775 ndev->address = xstrcpy(simulator->heater_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
776 ndev->description = xstrcpy((char *)"Simulated heater");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
777 ndev->present = simulator->heater_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
778 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
779 case 4: ndev->direction = DEVDIR_OUT_BIN;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
780 ndev->address = xstrcpy(simulator->cooler_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
781 ndev->description = xstrcpy((char *)"Simulated cooler");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
782 ndev->present = simulator->cooler_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
783 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
784 case 5: ndev->direction = DEVDIR_IN_ANALOG;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
785 ndev->address = xstrcpy(simulator->room_humaddress);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
786 ndev->description = xstrcpy((char *)"Simulated room humidity");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
787 ndev->present = DEVPRESENT_YES;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
788 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
789 case 6: ndev->direction = DEVDIR_IN_ANALOG;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
790 ndev->address = xstrcpy(simulator->chiller_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
791 ndev->description = xstrcpy((char *)"Simulated Chiller temperature");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
792 ndev->present = simulator->chiller_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
793 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
794 case 7: ndev->direction = DEVDIR_OUT_BIN;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
795 ndev->address = xstrcpy(simulator->fan_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
796 ndev->description = xstrcpy((char *)"Simulated fan");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
797 ndev->present = simulator->fan_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
798 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
799 case 8: ndev->direction = DEVDIR_OUT_BIN;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
800 ndev->address = xstrcpy(simulator->light_address);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
801 ndev->description = xstrcpy((char *)"Simulated light");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
802 ndev->present = simulator->light_present;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
803 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
804 case 9: ndev->direction = DEVDIR_IN_ANALOG;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
805 ndev->address = xstrcpy(simulator->beer_address2);
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
806 ndev->description = xstrcpy((char *)"Simulated beer temperature (alt)");
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
807 ndev->present = simulator->beer_present2;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
808 break;
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
809 case 10: ndev->direction = DEVDIR_IN_BIN;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
810 ndev->address = xstrcpy(simulator->door_address);
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
811 ndev->description = xstrcpy((char *)"Simulated fridge door");
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
812 ndev->present = simulator->door_present;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
813 break;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
814 case 11: ndev->direction = DEVDIR_IN_BIN;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
815 ndev->address = xstrcpy(simulator->psu_address);
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
816 ndev->description = xstrcpy((char *)"Simulated PSU status");
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
817 ndev->present = simulator->psu_present;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
818 break;
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
819 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
820
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
821 syslog(LOG_NOTICE, "New Simulator device %s, subdevice %d", ndev->address, ndev->subdevice);
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
822
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
823 if (Config.devices == NULL) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
824 Config.devices = ndev;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
825 } else {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
826 for (device = Config.devices; device; device = device->next) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
827 if (device->next == NULL) {
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
828 device->next = ndev;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
829 break;
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
830 }
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
831 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
832 }
714
24749c296a50 Version 0.9.19b2. Simulator redesign and it is now possible to run more then one simulator. All simulated devices have address names that include the simulator number. Added the setup screen for the most part. Not compatible with previous versions if a simulator was used, delete all simulators and simulated devices during stop and start.
Michiel Broek <mbroek@mbse.eu>
parents: 713
diff changeset
833 rc++;
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
834 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
835 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
836 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
837 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
838
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 return rc;
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
843
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
844 void *my_devices_loop(void *threadid)
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 {
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846 devices_list *device;
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
847 w1_list *dev_w1;
262
d0014ccec615 Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
848 #ifdef USE_SIMULATOR
d0014ccec615 Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
849 simulator_list *simulator;
d0014ccec615 Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
850 #endif
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
851 int found;
220
382938c5fce2 Make sure we don't read the DHT11 within 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
852 time_t now;
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
853 bool changed;
724
01e3936f62d4 Log pid of each started thread so we can see which uses the most cpu time.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
854 pid_t pid = gettid();
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855
646
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
856 my_devices_state = 1;
724
01e3936f62d4 Log pid of each started thread so we can see which uses the most cpu time.
Michiel Broek <mbroek@mbse.eu>
parents: 716
diff changeset
857 syslog(LOG_NOTICE, "Thread my_devices_loop started, pid=%d", pid);
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
858 dht11_next = time(NULL);
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
859
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
860 /*
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861 * Loop forever until the external shutdown variable is set.
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
862 */
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
863 for (;;) {
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
865 changed = false;
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
866 /*
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
867 * Process all devices.
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 */
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 for (device = Config.devices; device; device = device->next) {
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
870
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
871 if (my_devices_shutdown)
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872 break;
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
874 switch (device->type) {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
875 case DEVTYPE_W1:
338
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
876 /*
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
877 * Only tested with DS18B20 but from the kernel source this
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
878 * should work with all 1-wire thermometer sensors.
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
879 */
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
880 if ((strncmp(device->address, (char *)"10", 2) == 0) ||
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
881 (strncmp(device->address, (char *)"22", 2) == 0) ||
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
882 (strncmp(device->address, (char *)"28", 2) == 0) ||
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
883 (strncmp(device->address, (char *)"3b", 2) == 0) ||
8e29d142d67d Added support for all 1-wire temperature sensors that are in the Linux kernel source.
Michiel Broek <mbroek@mbse.eu>
parents: 337
diff changeset
884 (strncmp(device->address, (char *)"42", 2) == 0)) {
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
885 found = FALSE;
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
886 for (dev_w1 = w1_devices; dev_w1; dev_w1 = dev_w1->next) {
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
887 if (strcmp(device->address, dev_w1->address) == 0) {
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
888 found = TRUE;
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
889 if ((dev_w1->value == -1) || (dev_w1->value < -55000)) {
672
0c2c66920d79 Only log temperature error once. Only log temperature Ok again once. Do not log changed temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 671
diff changeset
890 if (device->present != DEVPRESENT_ERROR)
0c2c66920d79 Only log temperature error once. Only log temperature Ok again once. Do not log changed temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 671
diff changeset
891 syslog(LOG_NOTICE, "sensor %s value error %d, keep %d", device->address, dev_w1->value, device->value);
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
892 device->present = DEVPRESENT_ERROR;
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
893 changed = true;
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
894 } else {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
895 if (device->present != DEVPRESENT_YES) {
672
0c2c66920d79 Only log temperature error once. Only log temperature Ok again once. Do not log changed temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 671
diff changeset
896 syslog(LOG_NOTICE, "sensor %s value ok %d", device->address, dev_w1->value);
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
897 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
898 device->present = DEVPRESENT_YES;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
899 }
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
900 if (device->value != dev_w1->value) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
901 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
902 device->value = dev_w1->value;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
903 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
904 }
528
908ef02d5d22 Changed 1-wire logic a little bit
Michiel Broek <mbroek@mbse.eu>
parents: 527
diff changeset
905 }
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
906 }
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
907 }
528
908ef02d5d22 Changed 1-wire logic a little bit
Michiel Broek <mbroek@mbse.eu>
parents: 527
diff changeset
908
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
909 if (found == FALSE) {
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
910 if (device->present != DEVPRESENT_NO) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 262
diff changeset
911 syslog(LOG_NOTICE, "sensor %s is missing", device->address);
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
912 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
913 device->present = DEVPRESENT_NO;
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
914 changed = true;
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
915 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
916 }
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
917 }
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
918
341
cfc952a68d4a Possible part of DS2408 code added.
Michiel Broek <mbroek@mbse.eu>
parents: 340
diff changeset
919 } /* if temperature sensor */
342
3bbc8f42adc0 Added device read for the DS2413 dual channel PIO
Michiel Broek <mbroek@mbse.eu>
parents: 341
diff changeset
920
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
921 break;
203
47e5109c7f53 Added DHT11 sensor code
Michiel Broek <mbroek@mbse.eu>
parents: 202
diff changeset
922
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
923 case DEVTYPE_DHT:
220
382938c5fce2 Make sure we don't read the DHT11 within 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
924 /*
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
925 * Don't read these to often, 2 seconds minimum delay.
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
926 * Delay 30 seconds if last update was successfull,
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
927 * else delay 2 seconds.
220
382938c5fce2 Make sure we don't read the DHT11 within 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
928 */
382938c5fce2 Make sure we don't read the DHT11 within 2 seconds.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
929 now = time(NULL);
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
930 if ((int)(now >= dht11_next)) {
586
504463dad07d Changed 1-wire DS18B20 sensor error check.
Michiel Broek <mbroek@mbse.eu>
parents: 585
diff changeset
931 if (device->subdevice == 0) {
643
586d376ab629 Updates for DHT11 reading
Michiel Broek <mbroek@mbse.eu>
parents: 596
diff changeset
932 /* Read once during subdevice 0 */
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
933 dht11Read(device->address);
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
934 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
935 device->present = dht11_state;
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
936 if (dht11_state == DEVPRESENT_YES) {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
937 if (device->value != dht11_temperature) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
938 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
939 device->value = dht11_temperature;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
940 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
941 }
586
504463dad07d Changed 1-wire DS18B20 sensor error check.
Michiel Broek <mbroek@mbse.eu>
parents: 585
diff changeset
942 }
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
943 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
586
504463dad07d Changed 1-wire DS18B20 sensor error check.
Michiel Broek <mbroek@mbse.eu>
parents: 585
diff changeset
944 } else if (device->subdevice == 1) {
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
945 /* Data already present, valid or not. */
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
946 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
648
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
947 device->present = dht11_state;
62c5ed1b9cfd Better detection of the DHT11 sensors. Read DHT11 with errors detection and reapeated tries.
Michiel Broek <mbroek@mbse.eu>
parents: 647
diff changeset
948 if (dht11_state == DEVPRESENT_YES) {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
949 if (device->value != dht11_humidity) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
950 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
951 device->value = dht11_humidity;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
952 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
953 }
650
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
954 dht11_next = now + 29;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
955 } else {
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
956 dht11_next = now + 1;
0b215e4b814e Brought the retry attempts to read the DHT11 sensors to the main devices loop. The actual read function is now very simple. Called every 30 seconds when all is well, or 2 seconds if something is wrong.
Michiel Broek <mbroek@mbse.eu>
parents: 649
diff changeset
957 }
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
958 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
203
47e5109c7f53 Added DHT11 sensor code
Michiel Broek <mbroek@mbse.eu>
parents: 202
diff changeset
959 }
585
326cf2982eee More relaxed DHT11 readings
Michiel Broek <mbroek@mbse.eu>
parents: 584
diff changeset
960 }
202
5d09ca728809 Code added on the wrong machine
Michiel Broek <mbroek@mbse.eu>
parents: 187
diff changeset
961 break;
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
962
647
fcd85176ea2e Work to move dht userspace code to kernel module.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
963 #ifdef HAVE_WIRINGPI_H
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
964 case DEVTYPE_GPIO:
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
965 if (device->direction == DEVDIR_IN_BIN) {
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
966 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
967 if (device->value != digitalRead(device->gpiopin)) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
968 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
969 device->value = digitalRead(device->gpiopin);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
970 device->offset = 0;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
971 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
972 }
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
973 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
392
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
974 }
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
975 break;
034746506c3d Fixed initialisation of new GPIO devices.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
976
203
47e5109c7f53 Added DHT11 sensor code
Michiel Broek <mbroek@mbse.eu>
parents: 202
diff changeset
977 #endif
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
978 #ifdef USE_SIMULATOR
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
979 case DEVTYPE_SIM:
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
980 while (my_simulator_state == THREAD_PAUSE) { mDelay(20); };
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
981 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
982 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
983 int val;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
984
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
985 if (strcmp(simulator->room_tempaddress, device->address) == 0) {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
986 val = (int)((int)(simulator->room_temperature * 1000) / 500) * 500;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
987 if (device->value != val) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
988 device->value = val;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
989 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
990 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
991 }
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
992 } else if (strcmp(simulator->air_address, device->address) == 0) {
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
993 val = (int)((int)((simulator->air_temperature * 1000) + 31.25) / 62.5) * 62.5;
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
994 if (device->value != val) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
995 device->value = val;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
996 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
997 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
998 }
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
999 } else if (strcmp(simulator->beer_address, device->address) == 0) {
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1000 val = (int)((int)((simulator->beer_temperature * 1000) + 31.25) / 62.5) * 62.5;
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1001 if (device->value != val) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1002 device->value = val;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1003 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1004 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1005 }
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1006 } else if (strcmp(simulator->room_humaddress, device->address) == 0) {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1007 val = (int)((int)(simulator->room_humidity * 1000) / 500) * 500;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1008 if (device->value != val) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1009 device->value = val;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1010 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1011 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1012 }
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1013 } else if (strcmp(simulator->chiller_address, device->address) == 0) {
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1014 val = (int)((int)(simulator->chiller_temperature * 1000) / 62.5) * 62.5;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1015 if (device->value != val) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1016 device->value = val;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1017 device->timestamp = time(NULL);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1018 changed = true;
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1019 }
716
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1020 } else if (strcmp(simulator->door_address, device->address) == 0) {
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1021 val = simulator->door_value;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1022 if (device->value != val) {
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1023 device->value = val;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1024 device->timestamp = time(NULL);
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1025 changed = true;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1026 }
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1027 } else if (strcmp(simulator->psu_address, device->address) == 0) {
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1028 val = simulator->psu_value;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1029 if (device->value != val) {
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1030 device->value = val;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1031 device->timestamp = time(NULL);
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1032 changed = true;
5c30c8ef83a8 Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.
Michiel Broek <mbroek@mbse.eu>
parents: 715
diff changeset
1033 }
262
d0014ccec615 Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1034 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
1035 }
661
8c1e7a52e24f Version 0.9.17a2. Disabled a lot of mutex locks, some are blocking and need to be fixed. This version seems to be working, more or less.
Michiel Broek <mbroek@mbse.eu>
parents: 660
diff changeset
1036 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
1037 break;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 242
diff changeset
1038 #endif
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
1039 default:
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
1040 break;
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 163
diff changeset
1041 }
212
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1042
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
1043 if (my_devices_shutdown)
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
1044 break;
212
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1045 /*
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1046 * Delay a bit after procesing a device.
a76cbe676bf1 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1047 */
729
f5d94730db18 Made devices loop a bit slower.
Michiel Broek <mbroek@mbse.eu>
parents: 724
diff changeset
1048 mDelay(15);
f5d94730db18 Made devices loop a bit slower.
Michiel Broek <mbroek@mbse.eu>
parents: 724
diff changeset
1049 } /* for device = ... */
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 658
diff changeset
1050 if (my_devices_shutdown)
437
5664743eaf2f Stop devices thread if the program ends.
Michiel Broek <mbroek@mbse.eu>
parents: 408
diff changeset
1051 break;
215
5ad534c79a22 Do not use 100% cpu on a system without devices
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1052 /*
5ad534c79a22 Do not use 100% cpu on a system without devices
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1053 * Delay a bit after all devices
5ad534c79a22 Do not use 100% cpu on a system without devices
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1054 */
684
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1055 mDelay(50);
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1056 if (changed) {
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1057 devices_ws();
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1058 }
b2265c7e5707 Updated dependencies. Devices json data is created in de devices source for all places where it is needed. Added devices_ws function to broadcast all devices, to be used when any device is changed. The devices loop detects changes in input values and calls devices_ws if so. The server uses the general devices json data.
Michiel Broek <mbroek@mbse.eu>
parents: 674
diff changeset
1059 mDelay(50);
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1060 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1061
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1062 syslog(LOG_NOTICE, "Thread my_devices_loop stopped");
646
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
1063 my_devices_state = 0;
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1064 return 0;
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1065 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1066
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1067
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1068

mercurial