Skip to content

Commit

Permalink
Merge branch 'hotfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawzygmunt committed Feb 3, 2020
2 parents 3a193f5 + 9e4c332 commit 71fecb3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
52 changes: 50 additions & 2 deletions supla-dev/README.md
Expand Up @@ -5,7 +5,7 @@ Make a SUPLA-managed device from your RaspberryPI (or any other linux).
## Installation

```
sudo apt-get install libssl-dev
sudo apt-get install git libssl-dev build-essential
git clone https://github.com/SUPLA/supla-core
cd supla-core/supla-dev/Release
make all
Expand All @@ -23,7 +23,55 @@ cd supla-core/supla-dev/Release

## Configure autostart

TODO
In order to reliably run `supla-dev` you should run it
by some process control system. Here are a few options.

### init.d

If you are familiar with `init.d`, you can prepare a configuration for running
`supla-dev` without installing any new stuff. Check out sample
config in the official
[raspberry image sources](https://github.com/SUPLA/raspberry/blob/master/ext01/etc/init.d/supla-dev).

### supervisor

1. Install supervisor with `sudo apt-get install supervisor`.
1. Edit configuration file so you can manage the processes without root access:
`sudo nano /etc/supervisor/supervisord.conf`. Set the following options in
the `[unix_http_server]` section (replace `pi` with your username)
and exit from the editor (<kbd>Ctrl</kbd>+<kbd>X</kbd>, <kbd>Y</kbd>, <kbd>Enter</kbd>):

```
chmod=0770
chown=root:pi
```

1. Create `supla-dev` process setup: `sudo nano /etc/supervisor/conf.d/supla-dev.conf`
with the following contents (adjust path and user if needed, then save the changes and
exit edit as before):

```
[program:supla-dev]
command=/home/pi/supla-core/supla-dev/Release/supla-dev -c supla.cfg
directory=/home/pi/supla-core/supla-dev/Release
autostart=true
autorestart=true
user=pi
```

1. Restart supervisor: `sudo service supervisor restart`

### Managing the process with supervisor

The `supla-dev` should start automatically after initial configuration
and after the system boots. From now on, you will use the `supervisorctl`
command (without sudo) to manage the process.

* `supervisorctl status` shows if everything is ok
* `supervisorctl stop supla-dev` stops it
* `supervisorctl start supla-dev` starts it
* `supervisorctl restart supla-dev` restarts it
* `supervisorctl tail supla-dev` shows error output (in case of problems)

## Upgrade

Expand Down
12 changes: 5 additions & 7 deletions supla-dev/Release/supla.cfg.sample
Expand Up @@ -13,13 +13,7 @@ ssl_enabled=Y
ID=
PASSWORD=

# DHT 22 sensor connected to GPIO22 pin
# [CHANNEL_0]
# type=DHT22
# w1=22
#

# Available types: SENSORNO,RELAYHFD4,RELAYG5LA1A,2XRELAYG5LA1A,THERMOMETERDS18B20,DHT11,DHT22,AM2302
# Available types: https://github.com/SUPLA/supla-core/blob/master/supla-dev/src/devcfg.c#L34
# Help: https://forum.supla.org

[CHANNEL_0]
Expand All @@ -45,3 +39,7 @@ gpio1=23
[CHANNEL_5]
type=SENSORNO
gpio1=18

[CHANNEL_6]
type=DHT22
w1=22
17 changes: 16 additions & 1 deletion supla-dev/src/channel-io.c
Expand Up @@ -229,6 +229,7 @@ char channelio_allowed_type(int type) {
case SUPLA_CHANNELTYPE_DIMMER:
case SUPLA_CHANNELTYPE_RGBLEDCONTROLLER:
case SUPLA_CHANNELTYPE_DIMMERANDRGBLED:
case SUPLA_CHANNELTYPE_HUMIDITYSENSOR:
return 1;
}

Expand Down Expand Up @@ -281,9 +282,11 @@ char channelio_read_temp_and_humidity(int type, char *w1,

if (type != SUPLA_CHANNELTYPE_THERMOMETERDS18B20 &&
type != SUPLA_CHANNELTYPE_DHT11 && type != SUPLA_CHANNELTYPE_DHT22 &&
type != SUPLA_CHANNELTYPE_AM2302)
type != SUPLA_CHANNELTYPE_AM2302 &&
type != SUPLA_CHANNELTYPE_HUMIDITYSENSOR)
return 0;


if (w1 != NULL || type != SUPLA_CHANNELTYPE_THERMOMETERDS18B20) {
gettimeofday(&now, NULL);

Expand All @@ -301,6 +304,7 @@ char channelio_read_temp_and_humidity(int type, char *w1,
break;
case SUPLA_CHANNELTYPE_DHT22:
case SUPLA_CHANNELTYPE_AM2302:
case SUPLA_CHANNELTYPE_HUMIDITYSENSOR:
read_result = w1_dht_read(w1, &temp, &humidity, 22);
break;
}
Expand Down Expand Up @@ -663,6 +667,17 @@ char channelio_get_cvalue(TDeviceChannel *channel,
return 1;
}

if (channel->type == SUPLA_CHANNELTYPE_HUMIDITYSENSOR) {
assert(sizeof(double) <= SUPLA_CHANNELVALUE_SIZE);

lck_lock(channel->w1_value.lck);
int h = channel->w1_value.humidity * 1000.00;
memcpy(&value[4], &h, 4);
lck_unlock(channel->w1_value.lck);

return 1;
}

if (channel->type == SUPLA_CHANNELTYPE_DHT11 ||
channel->type == SUPLA_CHANNELTYPE_DHT22 ||
channel->type == SUPLA_CHANNELTYPE_AM2302) {
Expand Down
3 changes: 3 additions & 0 deletions supla-dev/src/devcfg.c
Expand Up @@ -16,6 +16,7 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -58,6 +59,8 @@ static int decode_channel_type(const char *type) {
return SUPLA_CHANNELTYPE_RGBLEDCONTROLLER;
} else if (strcasecmp(type, "DIMMERANDRGBLED") == 0) {
return SUPLA_CHANNELTYPE_DIMMERANDRGBLED;
} else if (strcasecmp(type, "HUMIDITYSENSOR") == 0) {
return SUPLA_CHANNELTYPE_HUMIDITYSENSOR;
}

return atoi(type);
Expand Down
3 changes: 3 additions & 0 deletions supla-dev/src/gpio.c
Expand Up @@ -51,7 +51,10 @@ char gpio_write_file(const char *file, const char *str) {
fd = open(file, O_WRONLY);

if (fd != -1) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
write(fd, str, strlen(str));
#pragma GCC diagnostic pop
close(fd);
return 1;
}
Expand Down

0 comments on commit 71fecb3

Please sign in to comment.