Update Gateway/Node examples to support MEGA
This commit is contained in:
parent
e8a0767849
commit
c6960e7de5
|
|
@ -17,11 +17,18 @@
|
||||||
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
|
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
|
||||||
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
|
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
|
||||||
#define ACK_TIME 30 // max # of ms to wait for an ack
|
#define ACK_TIME 30 // max # of ms to wait for an ack
|
||||||
#define LED 9 // Moteinos have LEDs on D9
|
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
|
|
||||||
|
#ifdef __AVR_ATmega1284P__
|
||||||
|
#define LED 15 // Moteino MEGAs have LEDs on D15
|
||||||
|
#define FLASH_SS 23 // and FLASH SS on D23
|
||||||
|
#else
|
||||||
|
#define LED 9 // Moteinos have LEDs on D9
|
||||||
|
#define FLASH_SS 8 // and FLASH SS on D8
|
||||||
|
#endif
|
||||||
|
|
||||||
RFM69 radio;
|
RFM69 radio;
|
||||||
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
|
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit Windbond chip (W25X40CL)
|
||||||
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network
|
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
@ -29,7 +36,7 @@ void setup() {
|
||||||
delay(10);
|
delay(10);
|
||||||
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
||||||
#ifdef IS_RFM69HW
|
#ifdef IS_RFM69HW
|
||||||
radio.setHighPower(); //uncomment only for RFM69HW!
|
radio.setHighPower(); //only for RFM69HW!
|
||||||
#endif
|
#endif
|
||||||
radio.encrypt(ENCRYPTKEY);
|
radio.encrypt(ENCRYPTKEY);
|
||||||
radio.promiscuous(promiscuousMode);
|
radio.promiscuous(promiscuousMode);
|
||||||
|
|
@ -37,7 +44,23 @@ void setup() {
|
||||||
sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
|
sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
|
||||||
Serial.println(buff);
|
Serial.println(buff);
|
||||||
if (flash.initialize())
|
if (flash.initialize())
|
||||||
Serial.println("SPI Flash Init OK!");
|
{
|
||||||
|
Serial.print("SPI Flash Init OK ... UniqueID (MAC): ");
|
||||||
|
flash.readUniqueId();
|
||||||
|
for (byte i=0;i<8;i++)
|
||||||
|
{
|
||||||
|
Serial.print(flash.UNIQUEID[i], HEX);
|
||||||
|
Serial.print(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
//alternative way to read it:
|
||||||
|
//byte* MAC = flash.readUniqueId();
|
||||||
|
//for (byte i=0;i<8;i++)
|
||||||
|
//{
|
||||||
|
// Serial.print(MAC[i], HEX);
|
||||||
|
// Serial.print(' ');
|
||||||
|
//}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Serial.println("SPI Flash Init FAIL! (is chip present?)");
|
Serial.println("SPI Flash Init FAIL! (is chip present?)");
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +98,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
if (input == 'D')
|
if (input == 'D')
|
||||||
{
|
{
|
||||||
Serial.print("Deleting Flash chip content... ");
|
Serial.print("Deleting Flash chip ... ");
|
||||||
flash.chipErase();
|
flash.chipErase();
|
||||||
while(flash.busy());
|
while(flash.busy());
|
||||||
Serial.println("DONE");
|
Serial.println("DONE");
|
||||||
|
|
@ -109,7 +132,7 @@ void loop() {
|
||||||
Serial.print((char)radio.DATA[i]);
|
Serial.print((char)radio.DATA[i]);
|
||||||
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
|
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
|
||||||
|
|
||||||
if (radio.ACK_REQUESTED)
|
if (radio.ACKRequested())
|
||||||
{
|
{
|
||||||
byte theNodeID = radio.SENDERID;
|
byte theNodeID = radio.SENDERID;
|
||||||
radio.sendACK();
|
radio.sendACK();
|
||||||
|
|
@ -128,7 +151,6 @@ void loop() {
|
||||||
Serial.print("ok!");
|
Serial.print("ok!");
|
||||||
else Serial.print("nothing");
|
else Serial.print("nothing");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Blink(LED,3);
|
Blink(LED,3);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
// It also looks for an onboard FLASH chip, if present
|
// It also looks for an onboard FLASH chip, if present
|
||||||
// Library and code by Felix Rusu - felix@lowpowerlab.com
|
// Library and code by Felix Rusu - felix@lowpowerlab.com
|
||||||
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/
|
// Get the RFM69 and SPIFlash library at: https://github.com/LowPowerLab/
|
||||||
|
|
||||||
#include <RFM69.h>
|
#include <RFM69.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <SPIFlash.h>
|
#include <SPIFlash.h>
|
||||||
|
|
@ -18,7 +17,14 @@
|
||||||
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
|
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
|
||||||
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
|
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
|
||||||
#define ACK_TIME 30 // max # of ms to wait for an ack
|
#define ACK_TIME 30 // max # of ms to wait for an ack
|
||||||
#define LED 9 // Moteinos have LEDs on D9
|
#ifdef __AVR_ATmega1284P__
|
||||||
|
#define LED 15 // Moteino MEGAs have LEDs on D15
|
||||||
|
#define FLASH_SS 23 // and FLASH SS on D23
|
||||||
|
#else
|
||||||
|
#define LED 9 // Moteinos have LEDs on D9
|
||||||
|
#define FLASH_SS 8 // and FLASH SS on D8
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
|
|
||||||
int TRANSMITPERIOD = 300; //transmit a packet to gateway so often (in ms)
|
int TRANSMITPERIOD = 300; //transmit a packet to gateway so often (in ms)
|
||||||
|
|
@ -26,7 +32,7 @@ char payload[] = "123 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
char buff[20];
|
char buff[20];
|
||||||
byte sendSize=0;
|
byte sendSize=0;
|
||||||
boolean requestACK = false;
|
boolean requestACK = false;
|
||||||
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
|
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit Windbond chip (W25X40CL)
|
||||||
RFM69 radio;
|
RFM69 radio;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
@ -41,7 +47,16 @@ void setup() {
|
||||||
Serial.println(buff);
|
Serial.println(buff);
|
||||||
|
|
||||||
if (flash.initialize())
|
if (flash.initialize())
|
||||||
Serial.println("SPI Flash Init OK!");
|
{
|
||||||
|
Serial.print("SPI Flash Init OK ... UniqueID (MAC): ");
|
||||||
|
flash.readUniqueId();
|
||||||
|
for (byte i=0;i<8;i++)
|
||||||
|
{
|
||||||
|
Serial.print(flash.UNIQUEID[i], HEX);
|
||||||
|
Serial.print(' ');
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Serial.println("SPI Flash Init FAIL! (is chip present?)");
|
Serial.println("SPI Flash Init FAIL! (is chip present?)");
|
||||||
}
|
}
|
||||||
|
|
@ -60,19 +75,20 @@ void loop() {
|
||||||
Serial.print(TRANSMITPERIOD);
|
Serial.print(TRANSMITPERIOD);
|
||||||
Serial.println("ms\n");
|
Serial.println("ms\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 'r') //d=dump register values
|
if (input == 'r') //d=dump register values
|
||||||
radio.readAllRegs();
|
radio.readAllRegs();
|
||||||
//if (input == 'E') //E=enable encryption
|
//if (input == 'E') //E=enable encryption
|
||||||
// radio.encrypt(KEY);
|
// radio.encrypt(KEY);
|
||||||
//if (input == 'e') //e=disable encryption
|
//if (input == 'e') //e=disable encryption
|
||||||
// radio.encrypt(null);
|
// radio.encrypt(null);
|
||||||
|
|
||||||
if (input == 'd') //d=dump flash area
|
if (input == 'd') //d=dump flash area
|
||||||
{
|
{
|
||||||
Serial.println("Flash content:");
|
Serial.println("Flash content:");
|
||||||
int counter = 0;
|
uint16_t counter = 0;
|
||||||
|
|
||||||
|
Serial.print("0-256: ");
|
||||||
while(counter<=256){
|
while(counter<=256){
|
||||||
Serial.print(flash.readByte(counter++), HEX);
|
Serial.print(flash.readByte(counter++), HEX);
|
||||||
Serial.print('.');
|
Serial.print('.');
|
||||||
|
|
@ -103,16 +119,15 @@ void loop() {
|
||||||
Serial.print((char)radio.DATA[i]);
|
Serial.print((char)radio.DATA[i]);
|
||||||
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
|
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
|
||||||
|
|
||||||
if (radio.ACK_REQUESTED)
|
if (radio.ACKRequested())
|
||||||
{
|
{
|
||||||
radio.sendACK();
|
radio.sendACK();
|
||||||
Serial.print(" - ACK sent");
|
Serial.print(" - ACK sent");
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
Blink(LED,5);
|
Blink(LED,5);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
//send FLASH id
|
//send FLASH id
|
||||||
if(sendSize==0)
|
if(sendSize==0)
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +136,7 @@ void loop() {
|
||||||
radio.sendWithRetry(GATEWAYID, buff, buffLen);
|
radio.sendWithRetry(GATEWAYID, buff, buffLen);
|
||||||
delay(TRANSMITPERIOD);
|
delay(TRANSMITPERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
int currPeriod = millis()/TRANSMITPERIOD;
|
int currPeriod = millis()/TRANSMITPERIOD;
|
||||||
if (currPeriod != lastPeriod)
|
if (currPeriod != lastPeriod)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue