Detect if initialization fails for RFM69 radio
Correct problem with define HW-variant Clean up GatewayESP8266 comments Change the debug message at startup (include version)
This commit is contained in:
@@ -321,8 +321,10 @@
|
||||
#endif
|
||||
|
||||
// Enable this if you're running the RFM69HW model
|
||||
#ifndef MY_IS_RFM69HW
|
||||
#define MY_IS_RFM69HW false
|
||||
#ifdef MY_IS_RFM69HW
|
||||
#define MY_RFM69HW true
|
||||
#else
|
||||
#define MY_RFM69HW false
|
||||
#endif
|
||||
|
||||
// Default network id. Use the same for all nodes that will talk to each other
|
||||
|
||||
@@ -64,19 +64,22 @@ void _begin() {
|
||||
hwInit();
|
||||
#endif
|
||||
|
||||
debug(PSTR("Starting...\n"));
|
||||
debug(PSTR("Starting " MY_NODE_TYPE " (" LIBRARY_VERSION ")\n"));
|
||||
|
||||
#if defined(MY_RADIO_FEATURE)
|
||||
_failedTransmissions = 0;
|
||||
|
||||
// Setup radio
|
||||
if (!transportInit()) {
|
||||
debug(PSTR("Radio init fail\n"));
|
||||
debug(PSTR("Radio init failed. Check wiring.\n"));
|
||||
// Nothing more we can do
|
||||
while(1) {
|
||||
#if defined(MY_GATEWAY_ESP8266)
|
||||
yield();
|
||||
#endif
|
||||
};
|
||||
} else {
|
||||
debug(PSTR("Radio init successful.\n"));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -159,7 +162,7 @@ void _begin() {
|
||||
#endif
|
||||
if (presentation)
|
||||
presentation();
|
||||
debug(PSTR("%s started, id=%d, parent=%d, distance=%d\n"), MY_NODE_TYPE, _nc.nodeId, _nc.parentNodeId, _nc.distance);
|
||||
debug(PSTR("Init complete, id=%d, parent=%d, distance=%d\n"), _nc.nodeId, _nc.parentNodeId, _nc.distance);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,17 +22,19 @@
|
||||
#include <stdint.h>
|
||||
#include "drivers/RFM69/RFM69.h"
|
||||
|
||||
RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_IS_RFM69HW, MY_RF69_IRQ_NUM);
|
||||
RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_RFM69HW, MY_RF69_IRQ_NUM);
|
||||
uint8_t _address;
|
||||
|
||||
|
||||
bool transportInit() {
|
||||
// Start up the radio library (_address will be set later by the MySensors library)
|
||||
_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID);
|
||||
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
||||
_radio.encrypt(RFM69_ENCRYPTKEY);
|
||||
#endif
|
||||
return true;
|
||||
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
|
||||
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
||||
_radio.encrypt(RFM69_ENCRYPTKEY);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void transportSetAddress(uint8_t address) {
|
||||
|
||||
@@ -44,8 +44,13 @@ volatile byte RFM69::ACK_RECEIVED; /// Should be polled immediately after sendin
|
||||
volatile int RFM69::RSSI; //most accurate RSSI during reception (closest to the reception)
|
||||
RFM69* RFM69::selfPointer;
|
||||
|
||||
// Set time out to 50ms
|
||||
#define TIME_OUT 50
|
||||
|
||||
|
||||
bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||
{
|
||||
unsigned long start_to;
|
||||
const byte CONFIG[][2] =
|
||||
{
|
||||
/* 0x01 */ { REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY },
|
||||
@@ -90,8 +95,14 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||
pinMode(_slaveSelectPin, OUTPUT);
|
||||
SPI.begin();
|
||||
|
||||
do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa);
|
||||
do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55);
|
||||
|
||||
start_to = millis();
|
||||
do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa && millis()-start_to < TIME_OUT);
|
||||
if (millis()-start_to >= TIME_OUT) return (false);
|
||||
|
||||
start_to = millis() ;
|
||||
do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55 && millis()-start_to < TIME_OUT);
|
||||
if (millis()-start_to >= TIME_OUT) return (false);
|
||||
|
||||
for (byte i = 0; CONFIG[i][0] != 255; i++)
|
||||
writeReg(CONFIG[i][0], CONFIG[i][1]);
|
||||
@@ -102,7 +113,12 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||
|
||||
setHighPower(_isRFM69HW); //called regardless if it's a RFM69W or RFM69HW
|
||||
setMode(RF69_MODE_STANDBY);
|
||||
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
|
||||
|
||||
|
||||
start_to = millis() ;
|
||||
while (((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00) && millis()-start_to < TIME_OUT); // Wait for ModeReady
|
||||
if (millis()-start_to >= TIME_OUT) return (false);
|
||||
|
||||
attachInterrupt(_interruptNum, RFM69::isr0, RISING);
|
||||
|
||||
selfPointer = this;
|
||||
|
||||
@@ -103,25 +103,27 @@
|
||||
// Controller ip address. Enables client mode (default is "server" mode).
|
||||
// Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
|
||||
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
||||
/*
|
||||
// Flash leds on rx/tx/err
|
||||
#define MY_LEDS_BLINKING_FEATURE
|
||||
// Set blinking period
|
||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||
|
||||
// Enable inclusion mode
|
||||
#define MY_INCLUSION_MODE_FEATURE
|
||||
|
||||
// Enable Inclusion mode button on gateway
|
||||
#define MY_INCLUSION_BUTTON_FEATURE
|
||||
// #define MY_INCLUSION_BUTTON_FEATURE
|
||||
// Set inclusion mode duration (in seconds)
|
||||
#define MY_INCLUSION_MODE_DURATION 60
|
||||
// Digital pin used for inclusion mode button
|
||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||
|
||||
|
||||
// Flash leds on rx/tx/err
|
||||
// #define MY_LEDS_BLINKING_FEATURE
|
||||
// Set blinking period
|
||||
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||
|
||||
// Led pins used if blinking feature is enabled above
|
||||
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
|
||||
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
|
||||
*/
|
||||
|
||||
#if defined(MY_USE_UDP)
|
||||
#include <WiFiUDP.h>
|
||||
|
||||
Reference in New Issue
Block a user