Skip to content

Commit 9648433

Browse files
shaun feakesshaun feakes
shaun feakes
authored and
shaun feakes
committed
Minor updates
1 parent b6b96e1 commit 9648433

17 files changed

+415
-191
lines changed

Makefile

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ CFLAGS = $(GCCFLAGS) -I. -I./minIni $(DBG) $(LIBS) -D MG_DISABLE_MD5 -D MG_DISAB
2727

2828
# define the C source files
2929
SRCS = sprinkler.c utils.c config.c net_services.c json_messages.c zone_ctrl.c sd_cron.c mongoose.c minIni/minIni.c $(sd_GPIO_C)
30-
TSRC = test.c config.c utils.c minIni/minIni.c
3130

3231
# define the C object files
3332
#
@@ -38,11 +37,11 @@ TSRC = test.c config.c utils.c minIni/minIni.c
3837
# with the .o suffix
3938
#
4039
OBJS = $(SRCS:.c=.o)
41-
TOBJ = $(TSRC:.c=.o)
4240

4341
# define the executable file
4442
MAIN = ./release/sprinklerd
45-
TEST = ./release/testing
43+
GMON = ./release/gpio_monitor
44+
GPIO = ./release/gpio
4645

4746
#
4847
# The following part of the makefile is generic; it can be used to
@@ -58,11 +57,9 @@ all: $(MAIN)
5857
$(MAIN): $(OBJS)
5958
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
6059

61-
test: $(TEST)
62-
@echo: $(TEST) have been compiled
63-
64-
$(TEST): $(TOBJ)
65-
$(CC) $(CFLAGS) $(INCLUDES) -o $(TEST) $(TOBJ) $(LFLAGS) $(LIBS)
60+
gpio_tools:
61+
$(CC) -o $(GMON) sd_GPIO.c -lm -lpthread -D GPIO_MONITOR
62+
$(CC) -o $(GPIO) sd_GPIO.c -lm -lpthread -D GPIO_RW
6663

6764
# this is a suffix replacement rule for building .o's from .c's
6865
# it uses automatic variables $<: the name of the prerequisite of

config.c

+61-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#include <wiringPi.h>
1010
#define PIN_CFG_NAME "WPI_PIN"
1111
#else
12-
#include "sd_GPIO.h"
12+
//#include "sd_GPIO.h"
1313
#define PIN_CFG_NAME "GPIO_PIN"
1414
#endif
1515

16+
#include "sd_GPIO.h"
1617
#include "minIni.h"
1718
#include "utils.h"
1819
#include "config.h"
@@ -308,13 +309,13 @@ void readCfg(char *inifile)
308309
_sdconfig_.zonecfg[i].default_runtime = ini_getl(str, "DEFAULT_RUNTIME", 10, inifile);
309310
//ini_gets(str, "NAME", NULL, _sdconfig_.zonecfg[idx].name, sizearray(_sdconfig_.zonecfg[idx].name), inifile);
310311
ini_gets(str, "NAME", NULL, _sdconfig_.zonecfg[i].name, sizearray(_sdconfig_.zonecfg[i].name), inifile);
311-
#ifndef USE_WIRINGPI
312+
//#ifndef USE_WIRINGPI
312313
if ( ! validGPIO(pin) ) {
313-
logMessage (LOG_ERR, "GPIO %d is not valid, found in ZONE:%d of configuration file %s \n",pin, i, inifile);
314-
pin = GPIO_MAX; // Set pin to MAX so we can continue to run if error is not fixed.
315-
sprintf(_sdconfig_.zonecfg[i].name, "ERROR in cfg");
314+
logMessage (LOG_ERR, "GPIO pin %d is not valid, found in ZONE:%d of configuration file %s \n",pin, i, inifile);
315+
pin = -1;
316+
sprintf(_sdconfig_.zonecfg[i].name, "ERROR");
316317
}
317-
#endif
318+
//#endif
318319
/*
319320
logMessage (LOG_DEBUG,"Zone Config : %s\n%25s : %d\n%25s : %d\n%25s : %d\n%25s : %d\n%25s : %d\n",
320321
_sdconfig_.zonecfg[i].name,
@@ -354,6 +355,60 @@ void readCfg(char *inifile)
354355
logMessage (LOG_ERR," no config zones set\n");
355356
exit (EXIT_FAILURE);
356357
}
358+
359+
// Caculate how many inputs we have
360+
for (i=1; i <= 24; i++) // 24 = Just some arbutary number (max GPIO without expansion board)
361+
{
362+
sprintf(str, "INPUT:%d", i);
363+
pin = ini_getl(str, PIN_CFG_NAME, -1, inifile);
364+
if (pin == -1)
365+
break;
366+
else
367+
_sdconfig_.inputs = i;
368+
}
369+
370+
logMessage (LOG_DEBUG, "Found %d INPUTS\n", _sdconfig_.inputs);
371+
372+
if ( _sdconfig_.inputs != 0) {
373+
// n= _sdconfig_.zones+1;
374+
_sdconfig_.inputcfg = malloc((_sdconfig_.inputs + 1) * sizeof(struct GPIOcfg));
375+
for (i=0; i < _sdconfig_.inputs; i++)
376+
{
377+
sprintf(str, "INPUT:%d", i+1);
378+
pin = ini_getl(str, PIN_CFG_NAME, -1, inifile);
379+
if (! validGPIO(pin) ) {
380+
logMessage (LOG_ERR, "GPIO pin %d is not valid, found in INPUT:%d of configuration file %s \n",pin, i+1, inifile);
381+
continue;
382+
}
383+
logMessage (LOG_DEBUG, "INPUT = %d\n", i+1);
384+
385+
_sdconfig_.inputcfg[i].input_output = INPUT; // Zone is always input
386+
_sdconfig_.inputcfg[i].receive_mode = BOTH; // Zone always needs trigger on both (high or low)
387+
_sdconfig_.inputcfg[i].zone = i+1;
388+
_sdconfig_.inputcfg[i].pin = pin;
389+
_sdconfig_.inputcfg[i].on_state = ini_getl(str, "GPIO_ON_STATE", NO, inifile);
390+
//_sdconfig_.inputcfg[i].startup_state = !_sdconfig_.inputcfg[i].on_state;
391+
//_sdconfig_.inputcfg[i].shutdown_state = !_sdconfig_.inputcfg[i].on_state;
392+
393+
_sdconfig_.inputcfg[i].set_pull_updown = ini_getl(str, "GPIO_PULL_UPDN", -1, inifile);
394+
_sdconfig_.inputcfg[i].dz_idx = ini_getl(str, "DOMOTICZ_IDX", -1, inifile); // Not used at the moment.
395+
ini_gets(str, "NAME", NULL, _sdconfig_.inputcfg[i].name, sizearray(_sdconfig_.inputcfg[i].name), inifile);
396+
397+
_sdconfig_.inputcfg[i].command_on = malloc(COMMAND_SIZE * sizeof(char));
398+
_sdconfig_.inputcfg[i].command_off = malloc(COMMAND_SIZE * sizeof(char));
399+
ini_gets(str, "COMMAND_ON", NULL, _sdconfig_.inputcfg[i].command_on, COMMAND_SIZE, inifile);
400+
ini_gets(str, "COMMAND_OFF", NULL, _sdconfig_.inputcfg[i].command_off, COMMAND_SIZE, inifile);
401+
402+
logMessage (LOG_DEBUG,"Input Config : %s\n%25s : %d\n%25s : %d\n%25s : %d\n%25s : %d\n",
403+
_sdconfig_.inputcfg[i].name,
404+
"PIN",_sdconfig_.inputcfg[i].pin,
405+
"Set pull up/down", _sdconfig_.inputcfg[i].set_pull_updown,
406+
"ON state", _sdconfig_.inputcfg[i].on_state,
407+
"Domoticz IDX", _sdconfig_.inputcfg[i].dz_idx);
408+
}
409+
}
410+
411+
357412
/*
358413
idx=0;
359414
pin=-1;

config.h

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct GPIOcfg {
4646
//int ignore_requests;
4747
int zone;
4848
int default_runtime;
49+
char *command_on;
50+
char *command_off;
4951
//bool master_valve;
5052
//struct GPIOextra *extra;
5153
};
@@ -74,6 +76,7 @@ struct sprinklerdcfg {
7476
bool enableMQTTdz;
7577
bool enableMQTTaq;
7678
int zones;
79+
int inputs;
7780
//int pincfgs;
7881
bool calendar;
7982
bool delay24h;
@@ -84,6 +87,7 @@ struct sprinklerdcfg {
8487
float precipInchDelay2day;
8588
struct DZcache *dz_cache;
8689
struct GPIOcfg *zonecfg;
90+
struct GPIOcfg *inputcfg;
8791
//struct GPIOcfg *gpiocfg;
8892
struct CALENDARday cron[7];
8993
//time_t cron_update;

json_messages.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int build_sprinkler_cal_JSON(char* buffer, int size)
3939
for (day=0; day <= 6; day++) {
4040
if (_sdconfig_.cron[day].hour >= 0 && _sdconfig_.cron[day].minute >= 0) {
4141
length += sprintf(buffer+length, ", \"d%d-starttime\" : \"%.2d:%.2d\" ",day,_sdconfig_.cron[day].hour,_sdconfig_.cron[day].minute);
42-
for (zone=0; zone < _sdconfig_.zones; zone ++) {
42+
for (zone=1; zone < _sdconfig_.zones; zone ++) {
4343
if (_sdconfig_.cron[day].zruntimes[zone] >= 0) {
4444
length += sprintf(buffer+length, ", \"d%dz%d-runtime\" : %d",day,zone+1,_sdconfig_.cron[day].zruntimes[zone]);
4545
//logMessage(LOG_DEBUG, "Zone %d, length %d limit %d\n",zone,length,size);
@@ -105,6 +105,7 @@ int build_advanced_sprinkler_JSON(char* buffer, int size)
105105
int i, day;
106106
memset(&buffer[0], 0, size);
107107
int length = 0;
108+
bool cal = false;
108109
/*
109110
length += sprintf(buffer+length, "{ \"title\" : \"%s\",\"calendar\" : \"%s\", \"24hdelay\" : \"%s\", \"allz\" : \"%s\", \"#zones\" : %d, \"24hdelay-offtime\" : %li",
110111
_sdconfig_.name,
@@ -146,8 +147,9 @@ int build_advanced_sprinkler_JSON(char* buffer, int size)
146147

147148
for (day=0; day <= 6; day++) {
148149
if (_sdconfig_.cron[day].hour >= 0 && _sdconfig_.cron[day].minute >= 0) {
150+
cal = true;
149151
length += sprintf(buffer+length, "\"day %d\" : { \"start time\" : \"%.2d:%.2d\", ",day,_sdconfig_.cron[day].hour,_sdconfig_.cron[day].minute);
150-
for (i=0; i < _sdconfig_.zones; i ++) {
152+
for (i=1; i < _sdconfig_.zones; i ++) {
151153
if (_sdconfig_.cron[day].zruntimes[i] >= 0) {
152154
length += sprintf(buffer+length, "\"Zone %d\" : %d,",i+1,_sdconfig_.cron[day].zruntimes[i]);
153155
//logMessage(LOG_DEBUG, "Zone %d, length %d limit %d\n",i+1,length,size);
@@ -157,8 +159,11 @@ int build_advanced_sprinkler_JSON(char* buffer, int size)
157159
length += sprintf(buffer+length, "},");
158160
}
159161
}
160-
length -= 1;
162+
if (cal) {
163+
length -= 1;
164+
}
161165
length += sprintf(buffer+length, "}}");
166+
162167

163168
buffer[length] = '\0';
164169
return strlen(buffer);

net_services.c

-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ void publish_zone_mqtt(struct mg_connection *nc, struct GPIOcfg *gpiopin) {
197197
static char mqtt_topic[250];
198198
static char mqtt_msg[50];
199199

200-
printf("PUBLISH pin %d\n",gpiopin->pin);
201-
202200
if (_sdconfig_.enableMQTTaq == true) {
203201
// sprintf(mqtt_topic, "%s/%s", _sdconfig_.mqtt_topic, gpiopin->name);
204202
sprintf(mqtt_topic, "%s/zone%d", _sdconfig_.mqtt_topic, gpiopin->zone);

release/gpio

19 KB
Binary file not shown.

release/gpio_monitor

19.1 KB
Binary file not shown.

release/sprinklerd

64 Bytes
Binary file not shown.

release/sprinklerd.test.conf

+33-22
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ NAME=My Sprinklers
44
DOCUMENTROOT = /nas/data/Development/Raspberry/SprinklerD/web/
55
CACHE = /var/cache/sprinklerd.cache
66
# The log level. [DEBUG, INFO, NOTICE, WARNING, ERROR]
7-
LOG_LEVEL = DEBUG
8-
#LOG_LEVEL = NOTICE
7+
#LOG_LEVEL = DEBUG
8+
#LOG_LEVEL = NOTICE
9+
LOG_LEVEL = INFO
910

1011
# mqtt stuff
1112
MQTT_ADDRESS = trident:1883
1213
#MQTT_USER = someusername
1314
#MQTT_PASSWD = somepassword
1415
MQT_TOPIC = sd_test
15-
#MQTT_DZ_PUB_TOPIC = domoticz/in
16-
#MQTT_DZ_SUB_TOPIC = domoticz/out
16+
MQTT_DZ_PUB_TOPIC = domoticz/in
17+
MQTT_DZ_SUB_TOPIC = domoticz/out
1718

1819
DZIDX_CALENDAR = 197
1920
DZIDX_24HDELAY = 198
@@ -39,51 +40,61 @@ DZIDX_RAINSENSOR = 48
3940

4041
# Don't use ZONE:0 for anything other than master valve, if you don't have a master valve simply delete it and start from ZONE:1
4142
[ZONE]
42-
#[ZONE:0]
43-
#NAME=Master Valve
44-
#MASTER_VALVE=1
45-
#GPIO_PIN=17
46-
#WPI_PIN=0
47-
#GPIO_PULL_UPDN=1
48-
#GPIO_ON_STATE=0
43+
[ZONE:0]
44+
NAME=Master Valve
45+
MASTER_VALVE=1
46+
GPIO_PIN=2
47+
WPI_PIN=0
48+
GPIO_PULL_UPDN=1
49+
GPIO_ON_STATE=0
4950

5051
[ZONE:1]
5152
NAME=Island
5253
DEFAULT_RUNTIME=10
5354
#GPIO_PIN=18
54-
GPIO_PIN=2
55+
GPIO_PIN=3
5556
WPI_PIN=1
5657
GPIO_PULL_UPDN=1
5758
GPIO_ON_STATE=0
58-
DOMOTICZ_IDX=200
59+
DOMOTICZ_IDX=2000
5960

6061
[ZONE:2]
6162
NAME=Driveway
6263
DEFAULT_RUNTIME=10
6364
#GPIO_PIN=27
64-
GPIO_PIN=3
65+
GPIO_PIN=40
6566
WPI_PIN=2
6667
GPIO_PULL_UPDN=1
6768
GPIO_ON_STATE=0
68-
DOMOTICZ_IDX=201
69+
DOMOTICZ_IDX=2010
6970

7071
[ZONE:3]
7172
NAME=Diningroom Flowerbeds
7273
DEFAULT_RUNTIME=10
73-
GPIO_PIN=22
74+
GPIO_PIN=5
7475
WPI_PIN=3
7576
GPIO_PULL_UPDN=1
7677
GPIO_ON_STATE=0
77-
DOMOTICZ_IDX=202
78+
DOMOTICZ_IDX=2020
7879

79-
[ZONE:4]
80-
NAME=Diningroom error
81-
DEFAULT_RUNTIME=10
82-
GPIO_PIN=28
80+
[INPUT]
81+
[INPUT:1]
82+
NAME=Test Switch
83+
GPIO_PIN=6
8384
WPI_PIN=3
8485
GPIO_PULL_UPDN=1
8586
GPIO_ON_STATE=0
86-
DOMOTICZ_IDX=202
87+
COMMAND_ON=/usr/bin/curl -s -o /dev/null 'http://localhost?type=option&option=24hdelay&state=on'
88+
COMMAND_OFF=/usr/bin/curl -s -o /dev/null 'http://localhost?type=option&option=24hdelay&state=off'
89+
90+
#[ZONE:4]
91+
#NAME=Diningroom error
92+
#DEFAULT_RUNTIME=10
93+
#GPIO_PIN=28
94+
#WPI_PIN=3
95+
#GPIO_PULL_UPDN=1
96+
#GPIO_ON_STATE=0
97+
#DOMOTICZ_IDX=2020
8798

8899
#[ZONE:4]
89100
#NAME=Front Flowerbeds

0 commit comments

Comments
 (0)