Skip to content

Commit 0bb5e22

Browse files
author
Yveaux
committed
Fixed inclusion mode
1 parent 64e2800 commit 0bb5e22

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

libraries/MySensors/examples/Esp8266Gateway/Esp8266Gateway.ino

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
* - Connect GPIO2 via 10K resistor to VCC
5858
* - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
5959
*
60-
* Signing, RF69 radio, inclusion button and a separate SPI flash are not supported yet!
60+
* Inclusion mode button:
61+
* - Connect GPIO5 via switch to GND ('inclusion switch')
62+
*
63+
* * Signing, RF69 radio and a separate SPI flash are not supported yet!
6164
*
6265
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
6366
*/
@@ -78,8 +81,8 @@
7881
const char *ssid = "MySSID"; // cannot be longer than 32 characters!
7982
const char *pass = "MyVerySecretPassword"; //
8083

81-
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
82-
// #define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
84+
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
85+
#define INCLUSION_MODE_PIN 5 // Digital pin used for inclusion mode button
8386

8487
#define RADIO_CE_PIN 4 // radio chip enable
8588
#define RADIO_SPI_SS_PIN 15 // radio SPI serial select
@@ -127,9 +130,9 @@ void output(const char *fmt, ... ) {
127130
void setup()
128131
{
129132
// Setup console
130-
Serial.begin(115200);
133+
hw_init();
131134

132-
Serial.println();
135+
Serial.println(); Serial.println();
133136
Serial.println("ESP8266 MySensors Gateway");
134137
Serial.print("Connecting to "); Serial.println(ssid);
135138

@@ -142,15 +145,8 @@ void setup()
142145
Serial.print("IP: "); Serial.println(WiFi.localIP());
143146
Serial.flush();
144147

145-
#ifndef INCLUSION_MODE_PIN
146-
setupGateway(255, INCLUSION_MODE_TIME, output);
147-
#else
148148
setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
149149

150-
// Add interrupt for inclusion button to pin
151-
PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
152-
#endif
153-
154150
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
155151
gw.begin(incomingMessage, 0, true, 0);
156152

@@ -162,10 +158,8 @@ void setup()
162158
void loop() {
163159
gw.process();
164160

165-
#ifdef INCLUSION_MODE_PIN
166161
checkButtonTriggeredInclusion();
167162
checkInclusionFinished();
168-
#endif
169163

170164
//check if there are any new clients
171165
if (server.hasClient())

libraries/MySensors/examples/Esp8266Gateway/GatewayUtil.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
#ifndef __GATEWAYUTIL_H__
22
#define __GATEWAYUTIL_H__
33

4-
#include <MyTransport.h>
5-
6-
74
#ifdef ARDUINO
85

96

10-
uint8_t inclusionTime = 1; // Number of minutes inclusion mode is enabled
11-
uint8_t pinInclusion = 3; // Input pin that should trigger inclusion mode
7+
static uint8_t inclusionTime = 1; // Number of minutes inclusion mode is enabled
8+
static uint8_t pinInclusion = 3; // Input pin that should trigger inclusion mode
129

1310
#define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from controller
1411
#define MAX_SEND_LENGTH 120 // Max buffersize needed for messages destined for controller
1512

16-
volatile boolean buttonTriggeredInclusion;
17-
boolean inclusionMode; // Keeps track on inclusion mode
13+
static volatile boolean buttonTriggeredInclusion;
14+
static boolean inclusionMode; // Keeps track on inclusion mode
1815
bool inclusionButtonSupported = false;
1916
void (*serial)(const char *fmt, ... );
2017

@@ -26,6 +23,11 @@ char convBuf[MAX_PAYLOAD*2+1];
2623
char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera
2724
unsigned long inclusionStartTime;
2825

26+
27+
void startInclusionInterrupt() {
28+
buttonTriggeredInclusion = true;
29+
}
30+
2931
void setupGateway(uint8_t _inc, uint8_t _incTime, void (* _serial)(const char *, ... )) {
3032
inclusionMode = 0;
3133
buttonTriggeredInclusion = false;
@@ -36,17 +38,13 @@ void setupGateway(uint8_t _inc, uint8_t _incTime, void (* _serial)(const char *,
3638
if (inclusionButtonSupported)
3739
{
3840
pinInclusion = _inc;
39-
40-
// Setup digital in that triggers inclusion mode
41-
pinMode(pinInclusion, INPUT);
42-
digitalWrite(pinInclusion, HIGH);
43-
}
44-
}
45-
4641

42+
// Setup digital in that triggers inclusion mode
43+
pinMode(pinInclusion, INPUT_PULLUP);
4744

48-
void startInclusionInterrupt() {
49-
buttonTriggeredInclusion = true;
45+
// Add interrupt for inclusion button to pin
46+
attachInterrupt(pinInclusion, startInclusionInterrupt, FALLING);
47+
}
5048
}
5149

5250
void incomingMessage(const MyMessage &message) {

0 commit comments

Comments
 (0)