Sketch updates, minor fixes
This commit is contained in:
parent
d23a4c95b9
commit
404a5add1d
|
|
@ -1,25 +1,33 @@
|
||||||
#include <RFM69.h>
|
#include <RFM69.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <SPIFlash.h>
|
||||||
|
|
||||||
#define NODEID 1
|
#define NODEID 1
|
||||||
#define NETWORKID 100
|
#define NETWORKID 100
|
||||||
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_915MHZ)
|
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
|
||||||
#define KEY "thisIsEncryptKey"
|
#define KEY "thisIsEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
|
||||||
#define LED 9
|
#define LED 9
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
#define ACK_TIME 10 // # of ms to wait for an ack
|
#define ACK_TIME 30 // # of ms to wait for an ack
|
||||||
|
|
||||||
RFM69 radio;
|
RFM69 radio;
|
||||||
|
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
|
||||||
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() {
|
||||||
Serial.begin(SERIAL_BAUD);
|
Serial.begin(SERIAL_BAUD);
|
||||||
|
delay(10);
|
||||||
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
||||||
|
//radio.setHighPower(); //uncomment only for RFM69HW!
|
||||||
radio.encrypt(KEY);
|
radio.encrypt(KEY);
|
||||||
radio.promiscuous(promiscuousMode);
|
radio.promiscuous(promiscuousMode);
|
||||||
char buff[50];
|
char buff[50];
|
||||||
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())
|
||||||
|
Serial.println("SPI Flash Init OK!");
|
||||||
|
else
|
||||||
|
Serial.println("SPI Flash Init FAIL! (is chip present?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
byte ackCount=0;
|
byte ackCount=0;
|
||||||
|
|
@ -28,7 +36,7 @@ void loop() {
|
||||||
if (Serial.available() > 0)
|
if (Serial.available() > 0)
|
||||||
{
|
{
|
||||||
char input = Serial.read();
|
char input = Serial.read();
|
||||||
if (input == 'd') //d=dump all register values
|
if (input == 'r') //d=dump all register values
|
||||||
radio.readAllRegs();
|
radio.readAllRegs();
|
||||||
if (input == 'E') //E=enable encryption
|
if (input == 'E') //E=enable encryption
|
||||||
radio.encrypt(KEY);
|
radio.encrypt(KEY);
|
||||||
|
|
@ -40,6 +48,32 @@ void loop() {
|
||||||
radio.promiscuous(promiscuousMode);
|
radio.promiscuous(promiscuousMode);
|
||||||
Serial.print("Promiscuous mode ");Serial.println(promiscuousMode ? "on" : "off");
|
Serial.print("Promiscuous mode ");Serial.println(promiscuousMode ? "on" : "off");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input == 'd') //d=dump flash area
|
||||||
|
{
|
||||||
|
Serial.println("Flash content:");
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
while(counter<=256){
|
||||||
|
Serial.print(flash.readByte(counter++), HEX);
|
||||||
|
Serial.print('.');
|
||||||
|
}
|
||||||
|
while(flash.busy());
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
if (input == 'e')
|
||||||
|
{
|
||||||
|
Serial.print("Erasing Flash chip ... ");
|
||||||
|
flash.chipErase();
|
||||||
|
while(flash.busy());
|
||||||
|
Serial.println("DONE");
|
||||||
|
}
|
||||||
|
if (input == 'i')
|
||||||
|
{
|
||||||
|
Serial.print("DeviceID: ");
|
||||||
|
word jedecid = flash.readDeviceId();
|
||||||
|
Serial.println(jedecid, HEX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radio.receiveDone())
|
if (radio.receiveDone())
|
||||||
|
|
@ -62,18 +96,17 @@ void loop() {
|
||||||
// When a node requests an ACK, respond to the ACK
|
// When a node requests an ACK, respond to the ACK
|
||||||
// and also send a packet requesting an ACK (every 3rd one only)
|
// and also send a packet requesting an ACK (every 3rd one only)
|
||||||
// This way both TX/RX NODE functions are tested on 1 end at the GATEWAY
|
// This way both TX/RX NODE functions are tested on 1 end at the GATEWAY
|
||||||
/*
|
if (ackCount++%3==0)
|
||||||
if (ackCount++%3)
|
|
||||||
{
|
{
|
||||||
Serial.print(" Sending packet to node ");
|
Serial.print(" Pinging node ");
|
||||||
Serial.print(theNodeID);
|
Serial.print(theNodeID);
|
||||||
delay(5);
|
delay(5);
|
||||||
radio.send(theNodeID, "ACK TEST", 8, true);
|
radio.send(theNodeID, "ACK TEST", 8, true);
|
||||||
Serial.print(" - waiting for ACK...");
|
Serial.print(" - ACK...");
|
||||||
if (waitForAck(theNodeID)) Serial.print("ok!");
|
if (waitForAck(theNodeID)) Serial.print("ok!");
|
||||||
else Serial.print("nothing...");
|
else Serial.print("nothing");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Blink(LED,3);
|
Blink(LED,3);
|
||||||
|
|
@ -90,10 +123,10 @@ static bool waitForAck(byte theNodeID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blink(byte PIN, int delay_ms)
|
void Blink(byte PIN, int DELAY_MS)
|
||||||
{
|
{
|
||||||
pinMode(PIN, OUTPUT);
|
pinMode(PIN, OUTPUT);
|
||||||
digitalWrite(PIN,HIGH);
|
digitalWrite(PIN,HIGH);
|
||||||
delay(delay_ms);
|
delay(DELAY_MS);
|
||||||
digitalWrite(PIN,LOW);
|
digitalWrite(PIN,LOW);
|
||||||
}
|
}
|
||||||
|
|
@ -1,29 +1,35 @@
|
||||||
#include <RFM69.h>
|
#include <RFM69.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <SPIFlash.h>
|
||||||
|
|
||||||
#define NODEID 25
|
#define NODEID 99
|
||||||
#define NETWORKID 100
|
#define NETWORKID 100
|
||||||
#define GATEWAYID 1
|
#define GATEWAYID 1
|
||||||
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_915MHZ)
|
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
|
||||||
#define KEY "thisIsEncryptKey"
|
#define KEY "thisIsEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
|
||||||
#define LED 9
|
#define LED 9
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
#define ACK_TIME 10 // # of ms to wait for an ack
|
#define ACK_TIME 30 // # of ms to wait for an ack
|
||||||
|
|
||||||
int TRANSMITPERIOD = 500; //transmit a packet to gateway so often (in ms)
|
int TRANSMITPERIOD = 300; //transmit a packet to gateway so often (in ms)
|
||||||
char payload[] = "123 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
char payload[] = "123 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
byte sendSize=0;
|
byte sendSize=0;
|
||||||
boolean requestACK = false;
|
boolean requestACK = false;
|
||||||
|
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
|
||||||
RFM69 radio;
|
RFM69 radio;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(SERIAL_BAUD);
|
Serial.begin(SERIAL_BAUD);
|
||||||
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
||||||
//radio.setHighPower(); //only for RFM69HW!
|
//radio.setHighPower(); //uncomment only for RFM69HW!
|
||||||
radio.encrypt(KEY);
|
radio.encrypt(KEY);
|
||||||
char buff[50];
|
char buff[50];
|
||||||
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
|
sprintf(buff, "\nTransmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
|
||||||
Serial.println(buff);
|
Serial.println(buff);
|
||||||
|
if (flash.initialize())
|
||||||
|
Serial.println("SPI Flash Init OK!");
|
||||||
|
else
|
||||||
|
Serial.println("SPI Flash Init FAIL! (is chip present?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
long lastPeriod = -1;
|
long lastPeriod = -1;
|
||||||
|
|
@ -41,12 +47,38 @@ void loop() {
|
||||||
Serial.println("ms\n");
|
Serial.println("ms\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 'd') //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
|
||||||
|
{
|
||||||
|
Serial.println("Flash content:");
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
while(counter<=256){
|
||||||
|
Serial.print(flash.readByte(counter++), HEX);
|
||||||
|
Serial.print('.');
|
||||||
|
}
|
||||||
|
while(flash.busy());
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
if (input == 'e')
|
||||||
|
{
|
||||||
|
Serial.print("Erasing Flash chip ... ");
|
||||||
|
flash.chipErase();
|
||||||
|
while(flash.busy());
|
||||||
|
Serial.println("DONE");
|
||||||
|
}
|
||||||
|
if (input == 'i')
|
||||||
|
{
|
||||||
|
Serial.print("DeviceID: ");
|
||||||
|
word jedecid = flash.readDeviceId();
|
||||||
|
Serial.println(jedecid, HEX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for any received packets
|
//check for any received packets
|
||||||
|
|
@ -60,7 +92,8 @@ void loop() {
|
||||||
if (radio.ACK_REQUESTED)
|
if (radio.ACK_REQUESTED)
|
||||||
{
|
{
|
||||||
radio.sendACK();
|
radio.sendACK();
|
||||||
Serial.print(" - ACK sent.");
|
Serial.print(" - ACK sent");
|
||||||
|
delay(10);
|
||||||
}
|
}
|
||||||
Blink(LED,5);
|
Blink(LED,5);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
@ -97,11 +130,11 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blink(byte PIN, int delay_ms)
|
void Blink(byte PIN, int DELAY_MS)
|
||||||
{
|
{
|
||||||
pinMode(PIN, OUTPUT);
|
pinMode(PIN, OUTPUT);
|
||||||
digitalWrite(PIN,HIGH);
|
digitalWrite(PIN,HIGH);
|
||||||
delay(delay_ms);
|
delay(DELAY_MS);
|
||||||
digitalWrite(PIN,LOW);
|
digitalWrite(PIN,LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,4 +146,4 @@ void Blink(byte PIN, int delay_ms)
|
||||||
// return true;
|
// return true;
|
||||||
// }
|
// }
|
||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
|
|
@ -162,7 +162,6 @@ void RFM69::send(byte toAddress, const void* buffer, byte bufferSize, bool reque
|
||||||
// replies usually take only 5-8ms at 50kbps@915Mhz
|
// replies usually take only 5-8ms at 50kbps@915Mhz
|
||||||
bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries, byte retryWaitTime) {
|
bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries, byte retryWaitTime) {
|
||||||
long sentTime;
|
long sentTime;
|
||||||
byte howLong=0;
|
|
||||||
for (byte i=0; i<=retries; i++)
|
for (byte i=0; i<=retries; i++)
|
||||||
{
|
{
|
||||||
send(toAddress, buffer, bufferSize, true);
|
send(toAddress, buffer, bufferSize, true);
|
||||||
|
|
|
||||||
2
RFM69.h
2
RFM69.h
|
|
@ -49,7 +49,7 @@ class RFM69 {
|
||||||
_isRFM69HW = isRFM69HW;
|
_isRFM69HW = isRFM69HW;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialize(byte ID, byte freqBand, byte networkID=1);
|
bool initialize(byte freqBand, byte ID, byte networkID=1);
|
||||||
void setAddress(byte addr);
|
void setAddress(byte addr);
|
||||||
bool canSend();
|
bool canSend();
|
||||||
void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false);
|
void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue