Skip to content

Commit 1f46cf2

Browse files
shaun feakesshaun feakes
shaun feakes
authored and
shaun feakes
committed
Update
1 parent dad3541 commit 1f46cf2

13 files changed

+187
-92
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LIBS := $(WPI_LIB) -lm -lpthread
1919
$DBG =
2020

2121
# define any compile-time flags
22-
GCCFLAGS = -Wall
22+
GCCFLAGS = -Wall -O3
2323
#CFLAGS = -Wall -lpthread -lwiringPi -lwiringPiDev -lm -I. -I./minIni
2424
CFLAGS = $(GCCFLAGS) -I. -I./minIni $(DBG) $(LIBS) -D MG_DISABLE_MD5 -D MG_DISABLE_HTTP_DIGEST_AUTH -D MG_DISABLE_MD5 -D MG_DISABLE_JSON_RPC
2525
#CFLAGS = -Wextra -Wall -g -I./wiringPI

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ http://sprinklerd.ip.address:port?type=option&option=24hdelay&state=off
200200
* // Run options
201201
<host>?type=option&option=allz&state=on // Run all zones default times (ignore 24h delay & calendar settings)
202202
<host>?type=zone&zone=2&state=on&runtime=3 // Run zone 2 for 3 mins (ignore 24h delay & calendar settings)
203+
<host>?type=zone&zone=2&state=off // Turn off zone 2
204+
<host>?type=zone&zone=2&state=flip // Flip state of zone 2, Turn off if on, Turn on if off
203205
<host>?type=zrtcfg&zone=2&time=10 // change zone 2 default runtime to 10
204206
<host>?type=cron&zone=1&runtime=12&state=on' // Run zone 1 for 12 mins (calendar & 24hdelay settings overide this request)
205207

config.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,14 @@ void readCfg(char *inifile)
307307
//_sdconfig_.zonecfg[i].master_valve = ini_getl(str, "MASTER_VALVE", NO, inifile);
308308
_sdconfig_.zonecfg[i].default_runtime = ini_getl(str, "DEFAULT_RUNTIME", 10, inifile);
309309
//ini_gets(str, "NAME", NULL, _sdconfig_.zonecfg[idx].name, sizearray(_sdconfig_.zonecfg[idx].name), inifile);
310-
ini_gets(str, "NAME", NULL, _sdconfig_.zonecfg[i].name, sizearray(_sdconfig_.zonecfg[i].name), inifile);
310+
ini_gets(str, "NAME", NULL, _sdconfig_.zonecfg[i].name, sizearray(_sdconfig_.zonecfg[i].name), inifile);
311+
#ifndef USE_WIRINGPI
312+
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");
316+
}
317+
#endif
311318
/*
312319
logMessage (LOG_DEBUG,"Zone Config : %s\n%25s : %d\n%25s : %d\n%25s : %d\n%25s : %d\n%25s : %d\n",
313320
_sdconfig_.zonecfg[i].name,

net_services.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ int is_value_ON(char *buf) {
381381
return -1;
382382
}
383383

384+
bool is_value_flip(char *buf) {
385+
if (strncasecmp(buf, "flip", 4) == 0 || strncasecmp(buf, "toggle", 6) == 0 )
386+
return true;
387+
else
388+
return false;
389+
}
390+
384391
int serve_web_request(struct mg_connection *nc, struct http_message *http_msg, char *buffer, int size, bool *changedOption) {
385392
static int buflen = 50;
386393
char buf[buflen];
@@ -504,6 +511,8 @@ int serve_web_request(struct mg_connection *nc, struct http_message *http_msg, c
504511
} else if ( is_value_ON(buf) == false && zone <= _sdconfig_.zones) {
505512
zc_zone(type, zone, zcOFF, runtime);
506513
length = build_sprinkler_JSON(buffer, size);
514+
} else if ( is_value_flip(buf) == true && zone <= _sdconfig_.zones) {
515+
zc_zone(type, zone, !zc_state(zone), runtime);
507516
} else {
508517
if (zone > _sdconfig_.zones) {
509518
logMessage(LOG_WARNING, "Bad request unknown zone %d\n",zone);
@@ -519,10 +528,11 @@ int serve_web_request(struct mg_connection *nc, struct http_message *http_msg, c
519528
zone = atoi(buf);
520529
mg_get_http_var(&http_msg->query_string, "time", buf, buflen);
521530
runtime = atoi(buf);
522-
if (zone > 0 && zone <= _sdconfig_.zones && runtime > 0) {
531+
if (zone > 0 && zone <= _sdconfig_.zones && runtime > -1) {
523532
_sdconfig_.zonecfg[zone].default_runtime = runtime;
524533
logMessage(LOG_DEBUG, "changed default runtime on zone %d, to %d\n",zone, runtime);
525534
length = build_sprinkler_JSON(buffer, size);
535+
zc_update_runtime(zone);
526536
*changedOption = true;
527537
} else
528538
length += sprintf(buffer, "{ \"error\": \"bad request zone %d runtime %d\"}",zone,runtime);
@@ -707,6 +717,7 @@ void action_mqtt_message(struct mg_connection *nc, struct mg_mqtt_message *msg){
707717
int v = str2int(msg->payload.p, msg->payload.len);
708718
_sdconfig_.zonecfg[zone].default_runtime = v / 60;
709719
_sdconfig_.eventToUpdateHappened = true;
720+
zc_update_runtime(zone);
710721
logMessage(LOG_DEBUG, "MQTT: Default runtime zone %d is %d\n",zone,_sdconfig_.zonecfg[zone].default_runtime);
711722
} else {
712723
logMessage(LOG_DEBUG, "MQTT: BAD Default runtime zone %d is %d\n",zone,_sdconfig_.zonecfg[zone].default_runtime);

release/sprinklerd

-32.6 KB
Binary file not shown.

release/sprinklerd.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LOG_LEVEL = NOTICE
3232
# PUD_UP 2
3333

3434
#NAME = name of zone
35-
#GPIO_PIN = GPIO Pin # This is the GPIO# not the pin#, so (17 = GPIO17 = Pin 11) or another example (5 = GPIO5 = Pin 29)
35+
#GPIO_PIN = GPIO # This is the GPIO# not the pin#, so (17 = GPIO17 = Pin 11) or another example (5 = GPIO5 = Pin 29)
3636
#WPI_PIN = use instead of GPIO_PIN if compiled with USE_WIRINGPI flag, This is WiringPi Pin#, not Raspberry Pi board pin#
3737
#GPIO_PULL_UPDN = setup pull up pull down resistor PUD_OFF|PUD_DOWN|PUD_UP
3838
#GPIO_ON_STATE = State GPIO reads when relay for zone is on. HIGH or LOW 1 or 0

release/sprinklerd.test.conf

+47-38
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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
99

1010
# mqtt stuff
1111
MQTT_ADDRESS = trident:1883
@@ -75,49 +75,58 @@ GPIO_ON_STATE=0
7575
DOMOTICZ_IDX=202
7676

7777
[ZONE:4]
78-
NAME=Front Flowerbeds
78+
NAME=Diningroom error
7979
DEFAULT_RUNTIME=10
80-
GPIO_PIN=23
81-
WPI_PIN=4
80+
GPIO_PIN=28
81+
WPI_PIN=3
8282
GPIO_PULL_UPDN=1
8383
GPIO_ON_STATE=0
84-
DOMOTICZ_IDX=203
84+
DOMOTICZ_IDX=202
8585

86-
[ZONE:5]
87-
NAME=Backgarden Left
88-
DEFAULT_RUNTIME=10
89-
GPIO_PIN=24
90-
WPI_PIN=5
91-
GPIO_PULL_UPDN=1
92-
GPIO_ON_STATE=0
93-
DOMOTICZ_IDX=204
86+
#[ZONE:4]
87+
#NAME=Front Flowerbeds
88+
#DEFAULT_RUNTIME=10
89+
#GPIO_PIN=23
90+
#WPI_PIN=4
91+
#GPIO_PULL_UPDN=1
92+
#GPIO_ON_STATE=0
93+
#DOMOTICZ_IDX=203
9494

95-
[ZONE:6]
96-
NAME=Backgarden Right
97-
DEFAULT_RUNTIME=10
98-
GPIO_PIN=25
99-
WPI_PIN=6
100-
GPIO_PULL_UPDN=1
101-
GPIO_ON_STATE=0
102-
DOMOTICZ_IDX=205
95+
#[ZONE:5]
96+
#NAME=Backgarden Left
97+
#DEFAULT_RUNTIME=10
98+
#GPIO_PIN=24
99+
#WPI_PIN=5
100+
#GPIO_PULL_UPDN=1
101+
#GPIO_ON_STATE=0
102+
#DOMOTICZ_IDX=204
103103

104-
[ZONE:7]
105-
NAME=Garage Flowerbeds
106-
DEFAULT_RUNTIME=10
107-
GPIO_PIN=5
108-
WPI_PIN=21
109-
GPIO_PULL_UPDN=1
110-
GPIO_ON_STATE=0
111-
DOMOTICZ_IDX=206
104+
#[ZONE:6]
105+
#NAME=Backgarden Right
106+
#DEFAULT_RUNTIME=10
107+
#GPIO_PIN=25
108+
#WPI_PIN=6
109+
#GPIO_PULL_UPDN=1
110+
#GPIO_ON_STATE=0
111+
#DOMOTICZ_IDX=205
112112

113-
[ZONE:8]
114-
NAME=Golfcart path
115-
DEFAULT_RUNTIME=10
116-
GPIO_PIN=6
117-
WPI_PIN=22
118-
GPIO_PULL_UPDN=1
119-
GPIO_ON_STATE=0
120-
DOMOTICZ_IDX=207
113+
#[ZONE:7]
114+
#NAME=Garage Flowerbeds
115+
#DEFAULT_RUNTIME=10
116+
#GPIO_PIN=5
117+
#WPI_PIN=21
118+
#GPIO_PULL_UPDN=1
119+
#GPIO_ON_STATE=0
120+
#DOMOTICZ_IDX=206
121+
122+
#[ZONE:8]
123+
#NAME=Golfcart path
124+
#DEFAULT_RUNTIME=10
125+
#GPIO_PIN=6
126+
#WPI_PIN=22
127+
#GPIO_PULL_UPDN=1
128+
#GPIO_ON_STATE=0
129+
#DOMOTICZ_IDX=207
121130

122131
#
123132
# This is for future support of sensors, not implimented yet

sd_GPIO.c

+37-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@
1515
#include "utils.h"
1616
#include "sd_GPIO.h"
1717

18+
const char *_piModelNames [16] =
19+
{
20+
"Model A", // 0
21+
"Model B", // 1
22+
"Model A+", // 2
23+
"Model B+", // 3
24+
"Pi 2", // 4
25+
"Alpha", // 5
26+
"CM", // 6
27+
"Unknown07", // 07
28+
"Pi 3", // 08
29+
"Pi Zero", // 09
30+
"CM3", // 10
31+
"Unknown11", // 11
32+
"Pi Zero-W", // 12
33+
"Pi 3+", // 13
34+
"Unknown New 14", // 14
35+
"Unknown New 15", // 15
36+
} ;
37+
1838
static bool _ever = false;
1939
void gpioDelay (unsigned int howLong);
2040

@@ -68,22 +88,26 @@ int piBoardId ()
6888
logMessage (LOG_ERR, "piBoardId: Unknown \"Revision\" line (no hex digit at start of revision)") ;
6989

7090
revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x
71-
91+
7292
// Check for new way:
7393

7494
if ((revision & (1 << 23)) != 0) // New way
7595
{/*
7696
bRev = (revision & (0x0F << 0)) >> 0 ;*/
7797
bType = (revision & (0xFF << 4)) >> 4 ;
78-
return bType;
7998
/*
8099
bProc = (revision & (0x0F << 12)) >> 12 ; // Not used for now.
81100
bMfg = (revision & (0x0F << 16)) >> 16 ;
82101
bMem = (revision & (0x07 << 20)) >> 20 ;
83102
bWarranty = (revision & (0x03 << 24)) != 0 ;
84103
*/
104+
105+
logMessage (LOG_DEBUG, "piBoard Model: %s\n", _piModelNames[bType]) ;
106+
107+
return bType;
85108
}
86109

110+
logMessage (LOG_ERR, "piBoard Model: UNKNOWN\n");
87111
return PI_MODEL_UNKNOWN;
88112
}
89113

@@ -93,11 +117,15 @@ bool gpioSetup() {
93117

94118
switch ( piBoardId() )
95119
{
96-
case PI_MODEL_A: case PI_MODEL_B:
97-
case PI_MODEL_AP: case PI_MODEL_BP:
98-
case PI_ALPHA: case PI_MODEL_CM:
99-
case PI_MODEL_ZERO: case PI_MODEL_ZERO_W:
100-
case PI_MODEL_UNKNOWN:
120+
case PI_MODEL_A:
121+
case PI_MODEL_B:
122+
case PI_MODEL_AP:
123+
case PI_MODEL_BP:
124+
case PI_ALPHA:
125+
case PI_MODEL_CM:
126+
case PI_MODEL_ZERO:
127+
case PI_MODEL_ZERO_W:
128+
//case PI_MODEL_UNKNOWN:
101129
piGPIObase = (GPIO_BASE_P1 + GPIO_OFFSET);
102130
break ;
103131

@@ -572,16 +600,15 @@ bool registerGPIOinterrupt(int pin, int mode, void (*function)(void *args), void
572600

573601
//#define TEST_HARNESS
574602

603+
#ifdef TEST_HARNESS
604+
575605
#define GPIO_OFF 0x00005000 /* Offset from IO_START to the GPIO reg's. */
576606

577607
/* IO_START and IO_BASE are defined in hardware.h */
578608

579609
#define GPIO_START (IO_START_2 + GPIO_OFF) /* Physical addr of the GPIO reg. */
580610
#define GPIO_BASE_NEW (IO_BASE_2 + GPIO_OFF) /* Virtual addr of the GPIO reg. */
581611

582-
583-
#ifdef TEST_HARNESS
584-
585612
#include <stdarg.h>
586613
#include <errno.h>
587614
#include <string.h>

sd_GPIO.h

+7
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@
6565
#define PI_MODEL_ZERO 9
6666
#define PI_MODEL_CM3 10
6767
#define PI_MODEL_ZERO_W 12
68+
#define PI_MODEL_3P 13
69+
6870
#endif
6971

72+
// check number is between 2 and 27
73+
#define GPIO_MIN 2
74+
#define GPIO_MAX 27
75+
76+
#define validGPIO(X) ((X) <= (GPIO_MAX) ? ( ((X) >= (GPIO_MIN) ? (1) : (0)) ) : (0))
7077

7178

7279
//#ifndef SYSFS_MODE

utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void logMessage(int level, char *format, ...)
114114
//if (_debuglog_ == false && level == LOG_DEBUG)
115115
// return;
116116

117-
char buffer[MXPRNT];
117+
char buffer[MXPRNT+1];
118118
va_list args;
119119
va_start(args, format);
120120
strncpy(buffer, " ", 8);

version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef SD_VERSION_H
22
#define SD_VERSION_H
33

4-
#define SD_VERSION "1.0d"
4+
#define SD_VERSION "1.0e"
55

66
#endif

0 commit comments

Comments
 (0)