Skip to content

Commit c881c3e

Browse files
authored
Merge pull request #38 from lkankowski/develop
Release 2.4.0
2 parents 6b2f9a1 + e90d1ef commit c881c3e

24 files changed

+1071
-494
lines changed

.github/workflows/main.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is a basic workflow to help you get started with Actions
22

3-
name: PlatformIO CI
3+
name: Build & Test
44

55
# Controls when the workflow will run
66
on:
@@ -39,15 +39,25 @@ jobs:
3939
with:
4040
path: ~/.platformio
4141
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
42+
4243
- name: Set up Python
4344
uses: actions/setup-python@v2
45+
4446
- name: Install PlatformIO
4547
run: |
4648
python -m pip install --upgrade pip
4749
pip install --upgrade platformio
50+
4851
- name: Configure Multi-Relay
4952
run: cp include/config.h.sample include/config.h
50-
- name: PlatformIO - run build
51-
run: pio run -e mega2560 -e nano328 -e native
53+
54+
- name: PlatformIO - run build all env
55+
run: pio run `grep -Eo '^\[env:[a-z0-9\-]*' platformio.ini | cut -c6- | sed 's/^/-e /' | paste -sd ' ' -`
56+
57+
- name: PlatformIO - run build with DEBUG_*
58+
run: pio run -e mega2560-serial
59+
env:
60+
PLATFORMIO_BUILD_FLAGS: -D DEBUG_COMMUNICATION -D DEBUG_ACTION -D DEBUG_STARTUP -D IGNORE_BUTTONS_START_MS=2000
61+
5262
- name: PlatformIO - run test
5363
run: pio test -e native

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ workspace.code-workspace
44
*.hex
55
include/config.h
66
include/config.h.local
7+
shared/platformio_local.ini

README.md

Lines changed: 126 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
1+
# Multi-Relay 2
2+
3+
Stable build Status ![](https://github.com/lkankowski/arduino-multi-relay2/actions/workflows/main.yml/badge.svg?branch=master),
4+
Develop build Status ![](https://github.com/lkankowski/arduino-multi-relay2/actions/workflows/main.yml/badge.svg?branch=develop)
5+
16
* [About](#about)
27
* [Get Started](#get-started)
38
* [Configuration](#configuration)
49
* [Debugging](#debugging)
510
* [Expander](#expander)
611
* [Troubleshoting](#troubleshoting)
712

8-
9-
# About
10-
Arduino program to handle relays and control them using switches with support for double-click and long-press. Integration with home automation systems is possible through MySensors integration.
11-
Configuration is very simple - one line for a single relay and one line for single switch
12-
Every switch support debouncing, multiple types of switches and additional actions like double-click and long-press - everything in a single line of configuration. Relays can be configured as LOW/HIGH level trigger, startup state ON or OFF and impulse type.
13+
## About
14+
Arduino program to handle relays and control them using switches with support for double-click and long-press. Integration with home automation systems is possible through MySensors integration over serial, LAN or MQTT.
15+
Configuration is very simple - one line for a single relay and one line for single switch.
16+
Every switch support debouncing, multiple types and additional actions like double-click and long-press - everything in a single line of configuration. Relays can be configured as LOW/HIGH level trigger, startup state ON or OFF and impulse type.
1317
One relay can have one or more switches, or not at all if you want to control it only by home automation system.
1418

15-
# Get Started
19+
### Supported platforms and hardware
20+
* Arduino Mega2560 and other AVR ATmega family
21+
* ESP8266
22+
* ESP32 - Experimental! Tests with LAN worked fine, but had no luck with MQTT
23+
* Ethernet (LAN or MQTT)
24+
* W5100
25+
* ENC28J60
26+
* expanders (described later in this doc)
27+
* MCP23017
28+
* PCF8574
29+
30+
31+
## Get Started
1632

17-
## Create config file
33+
### Download
34+
Most convinient is to clone the repo, but you have to have installed `git`:
35+
```
36+
git clone https://github.com/lkankowski/arduino-multi-relay2.git
37+
```
38+
You can also download zip file.
39+
40+
### Create config file
1841
Copy file "config.h.sample" into "config.h". There is sample configuration you need to examine and customize for your own needs.
1942

20-
## Build
43+
### Build
2144
You need PlatformIO - it is free and you can get it here https://platformio.org/platformio-ide. Arduino IDE is not supported.
22-
By default sketch is built for Arduino Mega 2560. Build options can be customized in `platformio.ini` - more information in separate sections.
45+
By default sketch is built for Arduino Mega 2560, but you choose environment that suits your needs.
46+
Build options can be customized in `platformio.ini` - more information in separate sections.
2347
Remote upload (ie. Arduino connected to Raspberry PI) is supported. For more information read https://docs.platformio.org/en/latest/core/userguide/remote/cmd_agent.html.
2448

25-
# Configuration
49+
### Updating
50+
If you have 'git', just type `git pull`. Otherwise download zip file and extract to new directory - remember, to backup 'config.h'.
51+
It is also convinient to have 'config.h' someware else, then you can use symbolic link. In Windows you have 2 options:
52+
53+
CMD:
54+
```
55+
mklink "<your local config directory>\config.h" "<your repo directory>\include\config.h"
56+
```
57+
or PowerShell (assuming that you run in main repo directory):
58+
```
59+
Start-Process -Verb RunAs -FilePath "powershell" -ArgumentList "-NoExit","-command","New-Item -Path '$(Get-Location)\include\config.h' -ItemType SymbolicLink -Value '<your local config directory>\config.h'"
60+
```
2661

27-
## Main config file "config.h"
62+
## Configuration
63+
64+
### Main config file "config.h"
2865
```
2966
const RelayConfigDef gRelayConfig[] PROGMEM = {
3067
{sensor id, relay pin, relay options, relay dependOn, relay description}
@@ -37,6 +74,7 @@ Params description:
3774
* RELAY_TRIGGER_LOW or RELAY_TRIGGER_HIGH - required, trigger level
3875
* RELAY_STARTUP_ON or RELAY_STARTUP_OFF - optional, startup state
3976
* RELAY_IMPULSE - optional, relay is turned on only for short period of time (defined in constant RELAY_IMPULSE_INTERVAL, 250ms by default), ignored for DING_DONG and REED_SWITCH buttons
77+
* RELAY_INDEPENDENT - described in (#dependent-relays)
4078
* relay dependOn - ID of relay that needs to be turned on before this one
4179
* relay description - reported on MySensor Gateway, can help identify device on initial configuration in Home Automation System, max. 30 chars, can be empty ("")
4280

@@ -57,23 +95,21 @@ Params description:
5795
* double-click relay id - sensor id used in relay configuration, -1 when not used, ignored for DING_DONG/REED_SWITCH
5896
* button description - debug only information, max. 30 chars, can be empty ("")
5997

60-
61-
## Example config with REED_SWITCH
98+
### Example config with REED_SWITCH
6299
```
63100
const RelayConfigDef gRelayConfig[] PROGMEM = {
64-
{26, 31, RELAY_TRIGGER_HIGH, "Garage Door"},
101+
{26, 31, RELAY_TRIGGER_HIGH, -1, "Garage Door"},
65102
...
66103
};
67104
const ButtonConfigDef gButtonConfig[] PROGMEM = {
68105
{43, REED_SWITCH, 26, -1, -1, "Garage Door reed switch"},
69106
...
70107
};
71108
```
72-
In this case relay 26 is always reported throught as S_DOOR sensor, i.e. in Home Assistant this relay can be found in entities as binary_sensor.multi_relay_0_26.
109+
In this case relay 26 is always reported throught as S_DOOR sensor, i.e. in Home Assistant this relay can be found in entities as binary_sensor.
73110

74-
75-
## Dependent relays
76-
The "dependOn" option in relays configuration is intended for turning ON and OFF power supplies, not to create scenes.
111+
### Dependent relays
112+
The "dependOn" option in relays configuration is intended for turning ON and OFF power supplies or simple scenes.
77113
For example, you have 12V power supply and two 12V LED lights:
78114
```
79115
...
@@ -85,8 +121,18 @@ For example, you have 12V power supply and two 12V LED lights:
85121
When you turn on _LED Strip_ and/or _Stairs light_, then _Power supply 12V_ will be automatically turned on.
86122
_Power supply 12V_ will be automatically turned off, when all parent devices will be turned off.
87123

124+
Additionaly there is one way option:
125+
```
126+
...
127+
{11, A1, RELAY_TRIGGER_LOW, 12, "Hall light"},
128+
{12, A2, RELAY_TRIGGER_LOW | RELAY_INDEPENDENT, -1, "Stairs light"},
129+
...
130+
```
131+
In this variant, when you turn on _Hall light_, also _Stairs light_ will turn on,
132+
but when you turn off _Hall light_, _Stairs light_ will remain on.
133+
88134

89-
## Additional config
135+
### Additional config
90136
Optional configuration only if you want to customize the script.
91137

92138
MONO_STABLE switches can trigger ralay when switch is pressed (LOW) or when switch is released (HIGH):
@@ -119,37 +165,59 @@ Sketch description reported via MySensors to Home Automation System:
119165
const char MULTI_RELAY_DESCRIPTION[] PROGMEM = "Multi Relay";
120166
```
121167

122-
123-
# Debugging
124-
In a `platformio.ini` file in section [common_env_data] you can uncomment (remove ";" at the beginning) some `build_flags`:
168+
### Network Configuration
169+
You can use network connection (Ethernet or WiFi) based on MySensors capabilities (ESP8266, ESP32, W5100, W5500, ENC28J60).
170+
This needs some additional configuration in `config.h`:
171+
* `#define MY_WIFI_SSID "<YOUR WIFI NAME>"` - WiFi SSID in case of ESP8266/ESP32
172+
* `#define MY_WIFI_PASSWORD "<YOUR WIFI PASSWORD>"` - WiFi password in case of ESP8266/ESP32
173+
* `#define MY_HOSTNAME "MULTI_RELAY_2"`
174+
* `#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED`
175+
* In case of static IP address (no DHCP) you have to define following parameters:
176+
* `#define MY_IP_ADDRESS 192,168,178,87` - IP address of the device
177+
* `#define MY_IP_GATEWAY_ADDRESS 192,168,178,1` - IP address of your router
178+
* `#define MY_IP_SUBNET_ADDRESS 255,255,255,0` - local network mask
179+
* `#define MY_PORT 5003` - if not using MQTT, MySensors gateway will listen on this port (if using default 5003 you dont need this in config.h)
180+
* `#define MY_USE_UDP` - if not using MQTT, you can choose UDP (default is TCP)
181+
182+
This are still experimental options and waiting for contribution with working config.
183+
184+
### MQTT Configuration
185+
* `#define MY_GATEWAY_MQTT_CLIENT` - enable MySensors MQTT support
186+
* `#define MY_MQTT_PUBLISH_TOPIC_PREFIX "multi-relay/out"` - gateway will send events to this topic
187+
* `#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "multi-relay/in"` - gateway will listen for commands on this topic
188+
* `#define MY_MQTT_CLIENT_ID "multi-relay-2"` - client id when connecting to MQTT broker
189+
* `#define MY_CONTROLLER_IP_ADDRESS 192,168,178,17` - MQTT broker IP address
190+
* `#define MY_CONTROLLER_URL_ADDRESS "test.mosquitto.org"` - MQTT broker URL instead of ip address
191+
* `#define MY_PORT 1883` - MQTT broker port
192+
* `#define MY_MQTT_USER "<YOUR MQTT USERNAME>"` - user name, if your MQTT broker requires authentication
193+
* `#define MY_MQTT_PASSWORD "<YOUR MQTT PASSWORD>"` - user password, if your MQTT broker requires authentication
194+
* `#define MY_NODE_ID 1` - may be required (need tests)
195+
196+
197+
## Debugging
198+
In a `platformio.ini` file in section [env] you can uncomment (remove ";" at the beginning) some `build_flags`:
125199
* `DEBUG_STATS=1000` - time statistics can be printed on serial, when they are triggered via appropriate MySensors command - read more in MySensors commands sections
126200
* `DEBUG_COMMUNICATION` - show some debug information about received MySensors commands on serial
127201
* `DEBUG_ACTION` - detailed information about button actions on serial
128202
* `DEBUG_STARTUP` - detaled information about configuration parameters. Usefull when you want report some problems with sketch.
129203

130-
131-
# Expander
204+
## Expander
205+
Expanders alow you to have more GPIO pins over I2C protocol. On a single I2C data line you can connect one or more expanders.
206+
It is recomended to use expanders only for relays, because they are much slower than internal GPIO, and switches are checked all the time.
132207
Only one expander library at a time is supported.
208+
To build expander version just select appropriate `env` with sufix `pcf` or `mcp`.
133209

134-
## PCF8574
135-
To use expander PCF8574 you have to install library:
136-
* download https://github.com/skywodd/pcf8574_arduino_library as zip archive
137-
* extract directory PCF8574 into `lib/PCF8574`
138-
Basic information about expander and library you can find here - https://youtu.be/JNmVREucfyc (PL, library in description)
139-
140-
And in a `platformio.ini` file in section [common_env_data] uncomment `EXPANDER_PCF8574` in `build_flags`.
210+
### PCF8574
211+
Popular expander with additional 8 GPIO.
212+
* Library `https://github.com/skywodd/pcf8574_arduino_library`.
213+
Basic information about expander and library you can find here - https://youtu.be/JNmVREucfyc (PL, library in description).
141214

142-
## MCP23017
143-
https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library
144-
145-
In a `platformio.ini` file in section [common_env_data] uncomment expander library in `lib_deps_builtin`:
146-
```
147-
adafruit/Adafruit MCP23017 Arduino Library @ ^1.2.0
148-
```
149-
and `EXPANDER_MCP23017` in `build_flags`.
215+
### MCP23017
216+
Popular expander with additional 16 GPIO.
217+
* Library: https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library
150218

151-
## Configuration
152219

220+
### Configuration
153221
Configure expander id in `config.h` file:
154222
```
155223
const uint8_t gExpanderAddresses[] = {0x20}; //PCF8574
@@ -175,17 +243,20 @@ To simplify using expanders, there is "E(a,b)" macro:
175243
E(0,0) - first pin on first expander
176244
```
177245

178-
## Relay config example
246+
### Relay config example
179247
```
180248
const RelayConfigDef gRelayConfig[] PROGMEM = {
181-
{1, E(0,3), RELAY_TRIGGER_LOW, "RELAY 1"}
249+
{1, E(0,3), RELAY_TRIGGER_LOW, -1, "RELAY 1"}
182250
};
183251
```
184252

185-
# Troubleshoting
186-
If you have problems with unstable relay or button states after startup, uncomment `IGNORE_BUTTONS_START_MS=2000` in your `platformio.ini`.
253+
## Troubleshoting
254+
1. If you have problems with unstable relay or button states after startup, uncomment `-D IGNORE_BUTTONS_START_MS=2000` in your `platformio.ini`.
255+
256+
2. Relays randomly turn on/off on startup - one reason could be eeprom memory corruption (it has limited number of writes).
257+
As a solution you can change eeprom area with `EEPROM_OFFSET` build flag (i.e. `-D EEPROM_OFFSET=100`).
187258

188-
# MySensors special commands
259+
## MySensors special commands
189260
Show debug stats
190261
```
191262
0;255;1;0;24;1
@@ -215,3 +286,13 @@ Reset
215286
```
216287
0;255;1;0;24;6
217288
```
289+
290+
Validate relays & eeprom state
291+
```
292+
0;255;1;0;24;7
293+
```
294+
295+
Free Memory
296+
```
297+
0;255;1;0;24;8
298+
```

changelog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# 2.4.0
2+
3+
New features:
4+
- Dependent relays
5+
- Additional architectures: ESP8266, ESP32 (experimental)
6+
- Ethernet (LAN or MQTT) with W5100 or ENC28J60
7+
- Add multiple hardware combinations to platformio.ini so the user doesn't need to customize it so often
8+
9+
Improvements:
10+
- Change button logic to be more independent from relays
11+
- Create wrapper for MySensors dependency so it can be better tested
12+
113
# 2.3.2 - Minor fixes
214
- improve Virtual pins
315
- typos fixes and revert remove "xstr" macro
@@ -16,6 +28,7 @@
1628
# 2.3.0 - Big architecture refactoring and new functionality - dependent relays
1729
New functionality:
1830
- Dependent relays and new configuration option "dependsOn"
31+
1932
Technical changes:
2033
- Completely new software architecture to separate responsibility and add hardware abstraction for unit testing:
2134
- New class ButtonService
@@ -35,6 +48,7 @@ Technical changes:
3548

3649
# 2.2.1 - Sensor reporting
3750
- reporting REED_SWITCH as S_DOOR in MySensors
51+
3852
# 2.2.0
3953
- Without sending V_ARMED
4054
- Support MCP23017

0 commit comments

Comments
 (0)