-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
marco
committed
Aug 28, 2016
1 parent
9f36792
commit 20f4260
Showing
6 changed files
with
692 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
/* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com | ||
// Get libraries at: https://github.com/LowPowerLab/ | ||
// Make sure you adjust the settings in the configuration section below !!! | ||
// ********************************************************************************** | ||
// Copyright Felix Rusu, LowPowerLab.com | ||
// Library and code by Felix Rusu - felix@lowpowerlab.com | ||
// ********************************************************************************** | ||
// License | ||
// ********************************************************************************** | ||
// This program is free software; you can redistribute it | ||
// and/or modify it under the terms of the GNU General | ||
// Public License as published by the Free Software | ||
// Foundation; either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will | ||
// be useful, but WITHOUT ANY WARRANTY; without even the | ||
// implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
// PARTICULAR PURPOSE. See the GNU General Public | ||
// License for more details. | ||
// | ||
// You should have received a copy of the GNU General | ||
// Public License along with this program. | ||
// If not, see <http://www.gnu.org/licenses></http:>. | ||
// | ||
// Licence can be viewed at | ||
// http://www.gnu.org/licenses/gpl-3.0.txt | ||
// | ||
// Please maintain this license information along with authorship | ||
// and copyright notices in any redistribution of this code | ||
// **********************************************************************************/ | ||
|
||
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69 | ||
#include <SPI.h> | ||
#include <RFM69_ATC.h> | ||
//********************************************************************************************* | ||
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************* | ||
//********************************************************************************************* | ||
#define NETWORKID 100 //the same on all nodes that talk to each other | ||
#define NODEID 2 | ||
|
||
//Match frequency to the hardware version of the radio on your Feather | ||
//#define FREQUENCY RF69_433MHZ | ||
//#define FREQUENCY RF69_868MHZ | ||
#define FREQUENCY RF69_433MHZ | ||
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes! | ||
#define IS_RFM69HCW false // set to 'true' if you are using an RFM69HCW module | ||
|
||
//********************************************************************************************* | ||
#define SERIAL_BAUD 115200 | ||
|
||
#define RFM69_CS 10 | ||
#define RFM69_IRQ 2 | ||
#define RFM69_IRQN 0 // Pin 2 is IRQ 0! | ||
#define RFM69_RST 3 | ||
|
||
#define LED 5 // onboard blinky | ||
|
||
int16_t packetnum = 0; // packet counter, we increment per xmission | ||
|
||
RFM69_ATC radio; | ||
|
||
|
||
|
||
boolean radio_enabled=1; | ||
|
||
|
||
unsigned long sync_time=0; | ||
|
||
|
||
char serial_number[13]="WLightSS0003"; | ||
|
||
char node_fw[]="5.13"; | ||
|
||
int this_node_address=254; //i start with 254 | ||
|
||
|
||
|
||
#define rx_msg_lenght 31 | ||
|
||
char received_message_type_of_onos_cmd; | ||
char received_message_flag; | ||
uint8_t received_message_first_pin_used; | ||
uint8_t received_message_second_pin_used; | ||
int received_message_value; | ||
char received_message_answer[rx_msg_lenght+6]="er00_#]"; | ||
char received_message_sn[13]=""; | ||
int received_message_address=0; //must be int.. | ||
|
||
uint8_t counter; | ||
boolean enable_answer_back=0; | ||
|
||
|
||
int freeRam () | ||
{ | ||
extern int __heap_start, *__brkval; | ||
int v; | ||
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); | ||
} | ||
|
||
|
||
|
||
|
||
void syncMessage(){ | ||
|
||
// onos_s3.05v1sProminiS0001f001_#] | ||
|
||
char syncMessage[serial_msg_lenght+3]; | ||
char str_this_node_address[4]; | ||
|
||
str_this_node_address[0]=(this_node_address/100)+'0'; | ||
str_this_node_address[1]=(this_node_address/10)+'0'; | ||
str_this_node_address[2]=(this_node_address/1)+'0'; | ||
|
||
strcpy(syncMessage, "onos_s "); | ||
strcat(syncMessage, node_fw); | ||
strcat(syncMessage, "v1s"); | ||
strcat(syncMessage, serial_number); | ||
strcat(syncMessage, "f"); | ||
strcat(syncMessage, str_this_node_address); | ||
|
||
strcat(syncMessage, "_#]"); | ||
|
||
for (uint8_t pointer = 0; pointer <= serial_msg_lenght; pointer++) { | ||
Serial.print(syncMessage[pointer]); | ||
|
||
if ((syncMessage[pointer-1]=='#')&&(syncMessage[pointer]==']') ) {// | ||
break; | ||
} | ||
} | ||
Serial.print('\n'); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
void getAddressFromGateway(){ | ||
|
||
char syncMessage[serial_msg_lenght+3]; | ||
char str_this_node_address[4]; | ||
|
||
while | ||
|
||
syncMessage[5]='g'; //modify the message to get a address instead of just sync. | ||
if (radio.sendWithRetry(gateway_address, syncMessage, strlen(syncMessage),10,200)) { | ||
//target node Id, message as string or byte array, message length,retries, milliseconds before retry | ||
//(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime) | ||
Serial.println("sent_get_address"); | ||
Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks | ||
} | ||
|
||
syncMessage[5]='s'; //modify the message back to original to just sync. | ||
|
||
//decode message | ||
|
||
|
||
if (radio.receiveDone()) | ||
{ | ||
//print message received to serial | ||
Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] "); | ||
Serial.print((char*)radio.DATA); | ||
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); | ||
|
||
//check if received message contains Hello World | ||
if (strstr((char *)radio.DATA, "Hello World")) | ||
{ | ||
//check if sender wanted an ACK | ||
if (radio.ACKRequested()) | ||
{ | ||
radio.sendACK(); | ||
Serial.println(" - ACK sent"); | ||
} | ||
Blink(LED, 40, 3); //blink LED 3 times, 40ms between blinks | ||
} | ||
} | ||
|
||
radio.receiveDone(); //put radio in RX mode | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
void setup() { | ||
while (!Serial); // wait until serial console is open, remove if not tethered to computer | ||
Serial.begin(SERIAL_BAUD); | ||
|
||
Serial.println("Feather RFM69HCW Receiver"); | ||
|
||
// Hard Reset the RFM module | ||
pinMode(RFM69_RST, OUTPUT); | ||
digitalWrite(RFM69_RST, HIGH); | ||
delay(100); | ||
digitalWrite(RFM69_RST, LOW); | ||
delay(100); | ||
|
||
// Initialize radio | ||
radio.initialize(FREQUENCY,NODEID,NETWORKID); | ||
if (IS_RFM69HCW) { | ||
radio.setHighPower(); // Only for RFM69HCW & HW! | ||
} | ||
radio.setPowerLevel(31); // power output ranges from 0 (5dBm) to 31 (20dBm) | ||
|
||
radio.encrypt(ENCRYPTKEY); | ||
|
||
pinMode(LED, OUTPUT); | ||
|
||
Serial.print("\nListening at "); | ||
Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915); | ||
Serial.println(" MHz"); | ||
} | ||
|
||
void loop() { | ||
//check if something was received (could be an interrupt from the radio) | ||
if (radio.receiveDone()) | ||
{ | ||
//print message received to serial | ||
Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] "); | ||
Serial.print((char*)radio.DATA); | ||
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); | ||
|
||
//check if received message contains Hello World | ||
if (radio.DATA[0]=='o') | ||
{ | ||
//check if sender wanted an ACK | ||
if (radio.ACKRequested()) | ||
{ | ||
radio.sendACK(); | ||
Serial.println(" - ACK sent"); | ||
} | ||
Blink(LED, 40, 3); //blink LED 3 times, 40ms between blinks | ||
} | ||
|
||
else{ | ||
|
||
Serial.println("serial_message_received_is_wrong"); | ||
|
||
} | ||
} | ||
|
||
radio.receiveDone(); //put radio in RX mode | ||
Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU | ||
} | ||
|
||
void Blink(byte PIN, byte DELAY_MS, byte loops) | ||
{ | ||
for (byte i=0; i<loops; i++) | ||
{ | ||
digitalWrite(PIN,HIGH); | ||
delay(DELAY_MS); | ||
digitalWrite(PIN,LOW); | ||
delay(DELAY_MS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.