-
-
Save solars/f82d097b2b54a76cb2bf1a17dba95130 to your computer and use it in GitHub Desktop.
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
WARNING: Spurious .github folder in 'Adafruit BME280 Library' library | |
WARNING: Spurious .github folder in 'DHT sensor library' library | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp: In member function 'void SPIFlash::select()': | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp:59:11: error: 'SPCR' was not declared in this scope | |
_SPCR = SPCR; | |
^ | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp:60:11: error: 'SPSR' was not declared in this scope | |
_SPSR = SPSR; | |
^ | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp: In member function 'void SPIFlash::unselect()': | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp:83:3: error: 'SPCR' was not declared in this scope | |
SPCR = _SPCR; | |
^ | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp:84:3: error: 'SPSR' was not declared in this scope | |
SPSR = _SPSR; | |
^ | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp: In member function 'boolean SPIFlash::initialize()': | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp:90:11: error: 'SPCR' was not declared in this scope | |
_SPCR = SPCR; | |
^ | |
/home/sol/software/arduino-1.6.9/libraries/spiflash/SPIFlash.cpp:91:11: error: 'SPSR' was not declared in this scope | |
_SPSR = SPSR; | |
^ | |
exit status 1 | |
Error compiling for board WeMos D1 R2 & mini. |
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
#include <SoftwareSerial.h> | |
// Sample RFM69 receiver/gateway sketch, with ACK and optional encryption, and Automatic Transmission Control | |
// Passes through any wireless received messages to the serial port & responds to ACKs | |
// It also looks for an onboard FLASH chip, if present | |
// RFM69 library and sample code by Felix Rusu - http://LowPowerLab.com/contact | |
// Copyright Felix Rusu (2015) | |
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69 | |
#include <RFM69_ATC.h>//get it here: https://www.github.com/lowpowerlab/rfm69 | |
#include <SPI.h> //comes with Arduino IDE (www.arduino.cc) | |
#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash | |
//********************************************************************************************* | |
//************ IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE ************* | |
//********************************************************************************************* | |
#define NODEID 1 //unique for each node on same network | |
#define NETWORKID 100 //the same on all nodes that talk to each other | |
//Match frequency to the hardware version of the radio on your Moteino (uncomment one): | |
#define FREQUENCY RF69_433MHZ | |
//#define FREQUENCY RF69_868MHZ | |
//#define FREQUENCY RF69_915MHZ | |
#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 ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL | |
//********************************************************************************************* | |
#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 | |
#ifdef ENABLE_ATC | |
RFM69_ATC radio; | |
#else | |
RFM69 radio; | |
#endif | |
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 | |
void setup() { | |
Serial.begin(SERIAL_BAUD); | |
delay(10); | |
radio.initialize(FREQUENCY,NODEID,NETWORKID); | |
#ifdef IS_RFM69HW | |
radio.setHighPower(); //only for RFM69HW! | |
#endif | |
radio.encrypt(ENCRYPTKEY); | |
radio.promiscuous(promiscuousMode); | |
//radio.setFrequency(919000000); //set frequency to some custom frequency | |
char buff[50]; | |
sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915); | |
Serial.println(buff); | |
if (flash.initialize()) | |
{ | |
Serial.print("SPI Flash Init OK. Unique MAC = ["); | |
flash.readUniqueId(); | |
for (byte i=0;i<8;i++) | |
{ | |
Serial.print(flash.UNIQUEID[i], HEX); | |
if (i!=8) Serial.print(':'); | |
} | |
Serial.println(']'); | |
//alternative way to read it: | |
//byte* MAC = flash.readUniqueId(); | |
//for (byte i=0;i<8;i++) | |
//{ | |
// Serial.print(MAC[i], HEX); | |
// Serial.print(' '); | |
//} | |
} | |
else | |
Serial.println("SPI Flash MEM not found (is chip soldered?)..."); | |
#ifdef ENABLE_ATC | |
Serial.println("RFM69_ATC Enabled (Auto Transmission Control)"); | |
#endif | |
} | |
byte ackCount=0; | |
uint32_t packetCount = 0; | |
void loop() { | |
//process any serial input | |
if (Serial.available() > 0) | |
{ | |
char input = Serial.read(); | |
if (input == 'r') //d=dump all register values | |
radio.readAllRegs(); | |
if (input == 'E') //E=enable encryption | |
radio.encrypt(ENCRYPTKEY); | |
if (input == 'e') //e=disable encryption | |
radio.encrypt(null); | |
if (input == 'p') | |
{ | |
promiscuousMode = !promiscuousMode; | |
radio.promiscuous(promiscuousMode); | |
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 == 'D') | |
{ | |
Serial.print("Deleting 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 (input == 't') | |
{ | |
byte temperature = radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient | |
byte fTemp = 1.8 * temperature + 32; // 9/5=1.8 | |
Serial.print( "Radio Temp is "); | |
Serial.print(temperature); | |
Serial.print("C, "); | |
Serial.print(fTemp); //converting to F loses some resolution, obvious when C is on edge between 2 values (ie 26C=78F, 27C=80F) | |
Serial.println('F'); | |
} | |
} | |
if (radio.receiveDone()) | |
{ | |
Serial.print("#["); | |
Serial.print(++packetCount); | |
Serial.print(']'); | |
Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] "); | |
if (promiscuousMode) | |
{ | |
Serial.print("to [");Serial.print(radio.TARGETID, DEC);Serial.print("] "); | |
} | |
for (byte i = 0; i < radio.DATALEN; i++) | |
Serial.print((char)radio.DATA[i]); | |
Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); | |
if (radio.ACKRequested()) | |
{ | |
byte theNodeID = radio.SENDERID; | |
radio.sendACK(); | |
Serial.print(" - ACK sent."); | |
// When a node requests an ACK, respond to the ACK | |
// 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 | |
if (ackCount++%3==0) | |
{ | |
Serial.print(" Pinging node "); | |
Serial.print(theNodeID); | |
Serial.print(" - ACK..."); | |
delay(3); //need this when sending right after reception .. ? | |
if (radio.sendWithRetry(theNodeID, "ACK TEST", 8, 0)) // 0 = only 1 attempt, no retries | |
Serial.print("ok!"); | |
else Serial.print("nothing"); | |
} | |
} | |
Serial.println(); | |
Blink(LED,3); | |
} | |
} | |
void Blink(byte PIN, int DELAY_MS) | |
{ | |
pinMode(PIN, OUTPUT); | |
digitalWrite(PIN,HIGH); | |
delay(DELAY_MS); | |
digitalWrite(PIN,LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment