Commit 8bf0952d authored by user2684's avatar user2684 Committed by GitHub
Browse files

Added capability to reboot by setting reboot pin (#133)

parent ac53650f
......@@ -3220,6 +3220,15 @@ void NodeManager::before() {
Serial.print(F("NodeManager v"));
Serial.println(VERSION);
#endif
// setup the reboot pin if needed
if (_reboot_pin > -1) {
#if DEBUG == 1
Serial.print("REB P=");
Serial.println(_reboot_pin);
#endif
pinMode(_reboot_pin, OUTPUT);
digitalWrite(_reboot_pin, HIGH);
}
// print out MySensors' library capabilities
#if DEBUG == 1
Serial.print(F("LIB R="));
......@@ -3476,6 +3485,7 @@ void NodeManager::process(Request & request) {
case 27: saveToMemory(0,request.getValueInt()); break;
case 28: setInterruptMinDelta(request.getValueInt()); break;
case 30: setSleepOrWait(request.getValueInt()); break;
case 31: setRebootPin(request.getValueInt()); break;
default: return;
}
_send(_msg.set(function));
......@@ -3519,12 +3529,17 @@ void NodeManager::reboot() {
#if DEBUG == 1
Serial.println(F("REBOOT"));
#endif
// Software reboot with watchdog timer. Enter Watchdog Configuration mode:
WDTCSR |= (1<<WDCE) | (1<<WDE);
// Reset enable
WDTCSR= (1<<WDE);
// Infinite loop until watchdog reset after 16 ms
while(true){}
if (_reboot_pin > -1) {
// reboot the board through the reboot pin which is connected to RST by setting it to low
digitalWrite(_reboot_pin, LOW);
} else {
// Software reboot with watchdog timer. Enter Watchdog Configuration mode:
WDTCSR |= (1<<WDCE) | (1<<WDE);
// Reset enable
WDTCSR= (1<<WDE);
// Infinite loop until watchdog reset after 16 ms
while(true){}
}
}
// send NodeManager's the version back to the controller
......@@ -3635,6 +3650,11 @@ void NodeManager::setSleepOrWait(bool value) {
_sleep_or_wait = value;
}
// set which pin is connected to RST of the board to reboot the board when requested. If not set the software reboot is used instead (default: -1)
void NodeManager::setRebootPin(int value) {
_reboot_pin = value;
}
// sleep if the node is a battery powered or wait if it is not for the given number of milliseconds
void NodeManager::sleepOrWait(long value) {
// if the node is sleeping, sleep-or-wait is enabled and we need to sleep for a decent amount of time, call sleep() otherwise wait()
......
......@@ -1433,6 +1433,8 @@ class NodeManager {
void setSleepOrWait(bool value);
// sleep if the node is a battery powered or wait if it is not for the given number of milliseconds
void sleepOrWait(long value);
// [31] set which pin is connected to RST of the board to reboot the board when requested. If not set the software reboot is used instead (default: -1)
void setRebootPin(int value);
// hook into the main sketch functions
void before();
void presentation();
......@@ -1484,6 +1486,7 @@ class NodeManager {
int _is_metric = 1;
int _report_interval_seconds = 10*60;
bool _sleep_or_wait = true;
int _reboot_pin = -1;
void _loadConfig();
void _saveConfig();
};
......
......@@ -56,17 +56,21 @@ Since NodeManager has to communicate with the MySensors gateway on your behalf,
#define MY_BAUD_RATE 9600
//#define MY_DEBUG
//#define MY_NODE_ID 100
//#define MY_SMART_SLEEP_WAIT_DURATION_MS 500
// NRF24 radio settings
#define MY_RADIO_NRF24
//#define MY_RF24_ENABLE_ENCRYPTION
//#define MY_RF24_CHANNEL 76
//#define MY_RF24_PA_LEVEL RF24_PA_HIGH
//#define MY_DEBUG_VERBOSE_RF24
//#define MY_RF24_DATARATE RF24_250KBPS
// RFM69 radio settings
//#define MY_RADIO_RFM69
//#define MY_RFM69_FREQUENCY RF69_868MHZ
//#define MY_IS_RFM69HW
//#define MY_DEBUG_VERBOSE_RFM69
//#define MY_RFM69_NEW_DRIVER
//#define MY_RFM69_ENABLE_ENCRYPTION
//#define MY_RFM69_NETWORKID 100
......@@ -74,6 +78,25 @@ Since NodeManager has to communicate with the MySensors gateway on your behalf,
//#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
//#define MY_RF69_SPI_CS D2
// RS485 serial transport settings
//#define MY_RS485
//#define MY_RS485_BAUD_RATE 9600
//#define MY_RS485_DE_PIN 2
//#define MY_RS485_MAX_MESSAGE_LENGTH 40
//#define MY_RS485_HWSERIAL Serial1
// Message signing settings
//#define MY_SIGNING_SOFT
//#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
//#define MY_SIGNING_REQUEST_SIGNATURES
//#define MY_SIGNING_ATSHA204
// OTA Firmware update settings
//#define MY_OTA_FIRMWARE_FEATURE
//#define OTA_WAIT_PERIOD 300
//#define FIRMWARE_MAX_REQUESTS 2
//#define MY_OTA_RETRY 2
/**********************************
* MySensors gateway configuration
*/
......@@ -88,8 +111,8 @@ Since NodeManager has to communicate with the MySensors gateway on your behalf,
// ESP8266 gateway settings
//#define MY_GATEWAY_ESP8266
//#define MY_ESP8266_SSID "MySSID"
//#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
//#define MY_ESP8266_SSID ""
//#define MY_ESP8266_PASSWORD ""
// Gateway networking settings
//#define MY_IP_ADDRESS 192,168,178,87
......@@ -317,6 +340,8 @@ The next step is to configure NodeManager with settings which will instruct how
void setReportIntervalSeconds(int value);
// [30] if set and when the board is battery powered, sleep() is always called instead of wait() (default: true)
void setSleepOrWait(bool value);
// [31] set which pin is connected to RST of the board to reboot the board when requested. If not set the software reboot is used instead (default: -1)
void setRebootPin(int value);
// sleep if the node is a battery powered or wait if it is not for the given number of milliseconds
void sleepOrWait(long value);
~~~
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment