changed on pairing stuff
This commit is contained in:
parent
5f8bd87214
commit
078765c06a
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
.pio
|
||||||
|
.pioenvs
|
||||||
|
.piolibdeps
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/
|
@ -22,17 +22,17 @@ void printDeviceData(SBNetworkDevice &device){
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print(F("Master MAC = "));
|
Serial.print(F("Master MAC = "));
|
||||||
printAddress(device.MasterMAC.Bytes);
|
printAddress(device.MasterMAC.Bytes);
|
||||||
Serial.println("");
|
Serial.println();
|
||||||
Serial.print(F("NetKey = "));
|
Serial.print(F("NetKey = "));
|
||||||
Serial.print(device.NetworkKey, DEC);
|
Serial.print(device.NetworkKey, DEC);
|
||||||
Serial.println("");
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
SBNetwork::SBNetwork(bool client, uint8_t cePin, uint8_t csPin) : radio(cePin, csPin){
|
SBNetwork::SBNetwork(bool client, uint8_t cePin, uint8_t csPin) : radio(cePin, csPin){
|
||||||
RunAsClient = client;
|
RunAsClient = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBNetwork::initialize(SBMacAddress mac){
|
int8_t SBNetwork::initialize(SBMacAddress mac){
|
||||||
Serial.print(F("SBNetwork Version "));
|
Serial.print(F("SBNetwork Version "));
|
||||||
Serial.println(F(SB_VERSION));
|
Serial.println(F(SB_VERSION));
|
||||||
Serial.println(F("===================="));
|
Serial.println(F("===================="));
|
||||||
@ -58,7 +58,7 @@ void SBNetwork::initialize(SBMacAddress mac){
|
|||||||
|
|
||||||
// Set the PA Level low to prevent power supply related issues since this is a
|
// Set the PA Level low to prevent power supply related issues since this is a
|
||||||
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
|
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
|
||||||
this->radio.setPALevel(RF24_PA_HIGH);
|
this->radio.setPALevel(RF24_PA_LOW);
|
||||||
this->radio.enableDynamicPayloads();
|
this->radio.enableDynamicPayloads();
|
||||||
|
|
||||||
//this->radio.enableDynamicAck();
|
//this->radio.enableDynamicAck();
|
||||||
@ -76,16 +76,25 @@ void SBNetwork::initialize(SBMacAddress mac){
|
|||||||
this->radio.startListening();
|
this->radio.startListening();
|
||||||
Serial.println(F("Done"));
|
Serial.println(F("Done"));
|
||||||
|
|
||||||
|
unsigned long startConnect = millis();
|
||||||
|
|
||||||
if (this->RunAsClient) {
|
if (this->RunAsClient) {
|
||||||
// Connect to a master
|
// Connect to a master
|
||||||
_Connected = false;
|
_Connected = false;
|
||||||
while (!_Connected) {
|
while (!_Connected && millis() - startConnect <= CONNECT_TIMEOUT) {
|
||||||
_Connected = connectToNetwork();
|
_Connected = connectToNetwork();
|
||||||
delay(500); // This can be an endless loop in case of no connection to master is available
|
delay(500); // This can be an endless loop in case of no connection to master is available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!_Connected) {
|
||||||
|
Serial.println(F("Timeout on connect to network..."));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void SBNetwork::initializeNetworkDevice(SBNetworkDevice &device, SBMacAddress mac){
|
void SBNetwork::initializeNetworkDevice(SBNetworkDevice &device, SBMacAddress mac){
|
||||||
Serial.print(F("Try to read device config from internal flash..."));
|
Serial.print(F("Try to read device config from internal flash..."));
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
@ -219,7 +228,9 @@ bool SBNetwork::sendToDeviceInternal(SBNetworkFrame frame) {
|
|||||||
Serial.print(millis());
|
Serial.print(millis());
|
||||||
Serial.println(F(" Sending physical data"));
|
Serial.println(F(" Sending physical data"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bSuccess = radio.write(buffer, bufferSize);
|
bSuccess = radio.write(buffer, bufferSize);
|
||||||
|
|
||||||
radio.openReadingPipe(0, this->NetworkDevice.MAC);
|
radio.openReadingPipe(0, this->NetworkDevice.MAC);
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
@ -361,7 +372,7 @@ bool SBNetwork::connectToNetwork(){
|
|||||||
unsigned long started_waiting_at = millis();
|
unsigned long started_waiting_at = millis();
|
||||||
boolean timeout = false;
|
boolean timeout = false;
|
||||||
while (!this->receive(&frame)) {
|
while (!this->receive(&frame)) {
|
||||||
if ((millis() - started_waiting_at) > 1000) {
|
if ((millis() - started_waiting_at) > 2500) {
|
||||||
timeout = true;
|
timeout = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -394,12 +405,13 @@ bool SBNetwork::connectToNetwork(){
|
|||||||
conFrame.Header.PackageId = millis();
|
conFrame.Header.PackageId = millis();
|
||||||
conFrame.Header.ToAddress = frame.Header.FromAddress;
|
conFrame.Header.ToAddress = frame.Header.FromAddress;
|
||||||
conFrame.MessageSize = 0;
|
conFrame.MessageSize = 0;
|
||||||
|
started_waiting_at = millis();
|
||||||
if (!this->sendToDeviceInternal(conFrame)) {
|
if (!this->sendToDeviceInternal(conFrame)) {
|
||||||
Serial.println(F("Failed - Sending pairing request"));
|
Serial.println(F("Failed - Sending pairing request"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
while (!this->receive(&frame)) {
|
while (!this->receive(&frame)) {
|
||||||
if (millis() - started_waiting_at > 1000) {
|
if (millis() - started_waiting_at > 5000) {
|
||||||
timeout = true;
|
timeout = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -686,3 +698,10 @@ uint8_t SBNetwork::removeMac(SBMacAddress mac){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SBNetwork::shutdown() {
|
||||||
|
radio.stopListening();
|
||||||
|
delay(10);
|
||||||
|
radio.powerDown();
|
||||||
|
return true;
|
||||||
|
}
|
@ -115,9 +115,10 @@ public:
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializes the sensor / master
|
* Initializes the sensor / master
|
||||||
|
* Return 0 if success and 1 on timeout
|
||||||
*/
|
*/
|
||||||
void initialize(SBMacAddress mac);
|
int8_t initialize(SBMacAddress mac);
|
||||||
void initialize(byte mac[]) { initialize(SBMacAddress(mac[0], mac[1], mac[2], mac[3], mac[4])); }
|
int8_t initialize(byte mac[]) { initialize(SBMacAddress(mac[0], mac[1], mac[2], mac[3], mac[4])); }
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -195,5 +196,10 @@ public:
|
|||||||
return SB_NETWORK_FLASH_SIZE;
|
return SB_NETWORK_FLASH_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Stops Listening and power down NRF Device.
|
||||||
|
*/
|
||||||
|
bool shutdown();
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
// Generates details debug messages about sending and receiving data packages
|
// Generates details debug messages about sending and receiving data packages
|
||||||
|
|
||||||
//#define _DEBUG
|
#define _DEBUG
|
||||||
|
|
||||||
// All slaves will ping the master every xxx milliseconds. if set to 0, they will not ping the master
|
// All slaves will ping the master every xxx milliseconds. if set to 0, they will not ping the master
|
||||||
#define MASTER_CHECK_INTERVAL 0
|
#define MASTER_CHECK_INTERVAL 0
|
||||||
@ -13,10 +13,12 @@
|
|||||||
|
|
||||||
#define CLIENT_TIMEOUT 60000
|
#define CLIENT_TIMEOUT 60000
|
||||||
|
|
||||||
|
#define CONNECT_TIMEOUT 10000
|
||||||
|
|
||||||
// Milliseconds to wait for fragmented packages
|
// Milliseconds to wait for fragmented packages
|
||||||
#define FRAGMENT_TIMEOUT 80
|
#define FRAGMENT_TIMEOUT 150
|
||||||
|
|
||||||
// Milliseconds to wait between two fragment sendings
|
// Milliseconds to wait between two fragment sendings
|
||||||
#define FRAGMENT_DELAY 10
|
#define FRAGMENT_DELAY 20
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,6 +37,7 @@ typedef struct {
|
|||||||
uint8_t PackageId; // The unique ID of the package. Will be
|
uint8_t PackageId; // The unique ID of the package. Will be
|
||||||
uint8_t FragmentCount; // How many fragments will be sent
|
uint8_t FragmentCount; // How many fragments will be sent
|
||||||
uint8_t FragmentNr; // Which fragment is this package
|
uint8_t FragmentNr; // Which fragment is this package
|
||||||
|
bool writeFast;
|
||||||
} SBNetworkHeader;
|
} SBNetworkHeader;
|
||||||
|
|
||||||
#define MAX_PACKAGE_SIZE (32 - sizeof(SBNetworkHeader))
|
#define MAX_PACKAGE_SIZE (32 - sizeof(SBNetworkHeader))
|
||||||
|
Loading…
Reference in New Issue
Block a user