add example back in, dont include in cc
This commit is contained in:
parent
24fdbf4a15
commit
3bfe8f1be7
|
|
@ -1,188 +1,185 @@
|
||||||
//// **********************************************************************************************************
|
// GarageMote garage door controller base receiver sketch that works with Moteinos equipped with HopeRF RFM69W/RFM69HW
|
||||||
//// NEEDED TO COMMENT THIS WHOLE SKETCH OUT BECAUSE OF THE LCD LIBRARY IS CAUSING A CC BUILD FAIL
|
// Can be adapted to use Moteinos using RFM12B
|
||||||
/// **********************************************************************************************************
|
// This is the sketch for the base, not the controller itself, and meant as another example on how to use a
|
||||||
//// GarageMote garage door controller base receiver sketch that works with Moteinos equipped with HopeRF RFM69W/RFM69HW
|
// Moteino as a gateway/base/receiver
|
||||||
//// Can be adapted to use Moteinos using RFM12B
|
// 2014-07-14 (C) felix@lowpowerlab.com, http://www.LowPowerLab.com
|
||||||
//// This is the sketch for the base, not the controller itself, and meant as another example on how to use a
|
// **********************************************************************************************************
|
||||||
//// Moteino as a gateway/base/receiver
|
// Creative Commons Attrib Share-Alike License
|
||||||
//// 2014-07-14 (C) felix@lowpowerlab.com, http://www.LowPowerLab.com
|
// You are free to use/extend this code/library but please abide with the CCSA license:
|
||||||
//// **********************************************************************************************************
|
// http://creativecommons.org/licenses/by-sa/4.0/
|
||||||
//// Creative Commons Attrib Share-Alike License
|
// **********************************************************************************
|
||||||
//// You are free to use/extend this code/library but please abide with the CCSA license:
|
|
||||||
//// http://creativecommons.org/licenses/by-sa/4.0/
|
#include <RFM69.h> //get it here: http://github.com/lowpowerlab/rfm69
|
||||||
//// **********************************************************************************
|
#include <SPIFlash.h> //get it here: http://github.com/lowpowerlab/spiflash
|
||||||
//
|
#include <WirelessHEX69.h> //get it here: https://github.com/LowPowerLab/WirelessProgramming
|
||||||
//#include <RFM69.h> //get it here: http://github.com/lowpowerlab/rfm69
|
#include <SPI.h> //comes with Arduino IDE (www.arduino.cc)
|
||||||
//#include <SPIFlash.h> //get it here: http://github.com/lowpowerlab/spiflash
|
#include "ST7036.h" //get it from here: https://bitbucket.org/fmalpartida/st7036-display-driver/src/
|
||||||
//#include <WirelessHEX69.h> //get it here: https://github.com/LowPowerLab/WirelessProgramming
|
#include "LCD_C0220BiZ.h" //get it from here: https://bitbucket.org/fmalpartida/st7036-display-driver/src/
|
||||||
//#include <SPI.h> //comes with Arduino IDE (www.arduino.cc)
|
#include <Wire.h> //comes with Arduino
|
||||||
//#include "ST7036.h" //get it from here: https://bitbucket.org/fmalpartida/st7036-display-driver/src/
|
|
||||||
//#include "LCD_C0220BiZ.h" //get it from here: https://bitbucket.org/fmalpartida/st7036-display-driver/src/
|
//*****************************************************************************************************************************
|
||||||
//#include <Wire.h> //comes with Arduino
|
// ADJUST THE SETTINGS BELOW DEPENDING ON YOUR HARDWARE/SITUATION!
|
||||||
//
|
//*****************************************************************************************************************************
|
||||||
////*****************************************************************************************************************************
|
#define NODEID 1
|
||||||
//// ADJUST THE SETTINGS BELOW DEPENDING ON YOUR HARDWARE/SITUATION!
|
#define NETWORKID 200
|
||||||
////*****************************************************************************************************************************
|
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
|
||||||
//#define NODEID 1
|
#define ENCRYPTKEY "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
|
||||||
//#define NETWORKID 200
|
#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
|
||||||
//#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
|
#define LED 9
|
||||||
//#define ENCRYPTKEY "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
|
#define FLASH_CS 8
|
||||||
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
|
#define SERIAL_BAUD 115200
|
||||||
//#define LED 9
|
#define SERIAL_EN //comment out if you don't want any serial verbose output
|
||||||
//#define FLASH_CS 8
|
#define ACK_TIME 30 // # of ms to wait for an ack
|
||||||
//#define SERIAL_BAUD 115200
|
#define BACKLIGHTPIN 5 //3=R,5=G,6=B
|
||||||
//#define SERIAL_EN //comment out if you don't want any serial verbose output
|
//*****************************************************************************************************************************
|
||||||
//#define ACK_TIME 30 // # of ms to wait for an ack
|
|
||||||
//#define BACKLIGHTPIN 5 //3=R,5=G,6=B
|
#ifdef SERIAL_EN
|
||||||
////*****************************************************************************************************************************
|
#define DEBUG(input) {Serial.print(input); delay(1);}
|
||||||
//
|
#define DEBUGln(input) {Serial.println(input); delay(1);}
|
||||||
//#ifdef SERIAL_EN
|
#else
|
||||||
// #define DEBUG(input) {Serial.print(input); delay(1);}
|
#define DEBUG(input);
|
||||||
// #define DEBUGln(input) {Serial.println(input); delay(1);}
|
#define DEBUGln(input);
|
||||||
//#else
|
#endif
|
||||||
// #define DEBUG(input);
|
|
||||||
// #define DEBUGln(input);
|
RFM69 radio;
|
||||||
//#endif
|
SPIFlash flash(FLASH_CS, 0xEF30); //EF40 for 16mbit windbond chip
|
||||||
//
|
|
||||||
//RFM69 radio;
|
//initialize LCD
|
||||||
//SPIFlash flash(FLASH_CS, 0xEF30); //EF40 for 16mbit windbond chip
|
ST7036 lcd = ST7036(2, 20, 0x78, BACKLIGHTPIN); //row count, column count, I2C addr, pin for backlight PWM
|
||||||
//
|
byte battChar[8] = {0b00000,0b01110,0b11111,0b11111,0b11111,0b11111,0b11111,0};
|
||||||
////initialize LCD
|
byte rssiChar[8] = {0b00000,0b00100,0b10101,0b01110,0b00100,0b00100,0b00100,0};
|
||||||
//ST7036 lcd = ST7036(2, 20, 0x78, BACKLIGHTPIN); //row count, column count, I2C addr, pin for backlight PWM
|
|
||||||
//byte battChar[8] = {0b00000,0b01110,0b11111,0b11111,0b11111,0b11111,0b11111,0};
|
void setup() {
|
||||||
//byte rssiChar[8] = {0b00000,0b00100,0b10101,0b01110,0b00100,0b00100,0b00100,0};
|
Serial.begin(SERIAL_BAUD);
|
||||||
//
|
delay(10);
|
||||||
//void setup() {
|
radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
||||||
// Serial.begin(SERIAL_BAUD);
|
#ifdef IS_RFM69HW
|
||||||
// delay(10);
|
radio.setHighPower(); //uncomment only for RFM69HW!
|
||||||
// radio.initialize(FREQUENCY,NODEID,NETWORKID);
|
#endif
|
||||||
//#ifdef IS_RFM69HW
|
radio.encrypt(ENCRYPTKEY);
|
||||||
// radio.setHighPower(); //uncomment only for RFM69HW!
|
char buff[50];
|
||||||
//#endif
|
sprintf(buff, "\nListening @ %dmhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
|
||||||
// radio.encrypt(ENCRYPTKEY);
|
DEBUGln(buff);
|
||||||
// char buff[50];
|
if (flash.initialize())
|
||||||
// sprintf(buff, "\nListening @ %dmhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
|
{
|
||||||
// DEBUGln(buff);
|
DEBUGln("SPI Flash Init OK!");
|
||||||
// if (flash.initialize())
|
}
|
||||||
// {
|
else
|
||||||
// DEBUGln("SPI Flash Init OK!");
|
DEBUGln("SPI Flash Init FAIL! (is chip present?)");
|
||||||
// }
|
|
||||||
// else
|
lcd.init();
|
||||||
// DEBUGln("SPI Flash Init FAIL! (is chip present?)");
|
lcd.setContrast(10);
|
||||||
//
|
lcd.clear();
|
||||||
// lcd.init();
|
lcd.load_custom_character(0, battChar);
|
||||||
// lcd.setContrast(10);
|
lcd.load_custom_character(1, rssiChar);
|
||||||
// lcd.clear();
|
lcd.setCursor(0,0);
|
||||||
// lcd.load_custom_character(0, battChar);
|
lcd.print(buff);
|
||||||
// lcd.load_custom_character(1, rssiChar);
|
}
|
||||||
// lcd.setCursor(0,0);
|
|
||||||
// lcd.print(buff);
|
byte ackCount=0;
|
||||||
//}
|
byte inputLen=0;
|
||||||
//
|
char input[64];
|
||||||
//byte ackCount=0;
|
byte buff[61];
|
||||||
//byte inputLen=0;
|
char LO[20];
|
||||||
//char input[64];
|
char BAT[20];
|
||||||
//byte buff[61];
|
char temp[25];
|
||||||
//char LO[20];
|
String inputstr;
|
||||||
//char BAT[20];
|
void loop() {
|
||||||
//char temp[25];
|
inputLen = readSerialLine(input, 10, 64, 10); //readSerialLine(char* input, char endOfLineChar=10, byte maxLength=64, uint16_t timeout=10);
|
||||||
//String inputstr;
|
inputstr = String(input);
|
||||||
//void loop() {
|
inputstr.toUpperCase();
|
||||||
// inputLen = readSerialLine(input, 10, 64, 10); //readSerialLine(char* input, char endOfLineChar=10, byte maxLength=64, uint16_t timeout=10);
|
|
||||||
// inputstr = String(input);
|
if (inputLen > 0)
|
||||||
// inputstr.toUpperCase();
|
{
|
||||||
//
|
if (inputstr.equals("KEY?"))
|
||||||
// if (inputLen > 0)
|
{
|
||||||
// {
|
DEBUG("ENCRYPTKEY:");
|
||||||
// if (inputstr.equals("KEY?"))
|
DEBUG(ENCRYPTKEY);
|
||||||
// {
|
}
|
||||||
// DEBUG("ENCRYPTKEY:");
|
|
||||||
// DEBUG(ENCRYPTKEY);
|
byte targetId = inputstr.toInt(); //extract ID if any
|
||||||
// }
|
byte colonIndex = inputstr.indexOf(":"); //find position of first colon
|
||||||
//
|
if (targetId > 0) inputstr = inputstr.substring(colonIndex+1); //trim "ID:" if any
|
||||||
// byte targetId = inputstr.toInt(); //extract ID if any
|
if (targetId > 0 && targetId != NODEID && targetId != RF69_BROADCAST_ADDR && colonIndex>0 && colonIndex<4 && inputstr.length()>0)
|
||||||
// byte colonIndex = inputstr.indexOf(":"); //find position of first colon
|
{
|
||||||
// if (targetId > 0) inputstr = inputstr.substring(colonIndex+1); //trim "ID:" if any
|
|
||||||
// if (targetId > 0 && targetId != NODEID && targetId != RF69_BROADCAST_ADDR && colonIndex>0 && colonIndex<4 && inputstr.length()>0)
|
inputstr.getBytes(buff, 61);
|
||||||
// {
|
//DEBUGln((char*)buff);
|
||||||
//
|
//DEBUGln(targetId);
|
||||||
// inputstr.getBytes(buff, 61);
|
//DEBUGln(colonIndex);
|
||||||
// //DEBUGln((char*)buff);
|
if (radio.sendWithRetry(targetId, buff, inputstr.length()))
|
||||||
// //DEBUGln(targetId);
|
{
|
||||||
// //DEBUGln(colonIndex);
|
DEBUGln("ACK:OK");
|
||||||
// if (radio.sendWithRetry(targetId, buff, inputstr.length()))
|
}
|
||||||
// {
|
else
|
||||||
// DEBUGln("ACK:OK");
|
DEBUGln("ACK:NOK");
|
||||||
// }
|
}
|
||||||
// else
|
}
|
||||||
// DEBUGln("ACK:NOK");
|
|
||||||
// }
|
if (radio.receiveDone())
|
||||||
// }
|
{
|
||||||
//
|
int rssi = radio.RSSI;
|
||||||
// if (radio.receiveDone())
|
DEBUG('[');DEBUG(radio.SENDERID);DEBUG("] ");
|
||||||
// {
|
if (radio.DATALEN > 0)
|
||||||
// int rssi = radio.RSSI;
|
{
|
||||||
// DEBUG('[');DEBUG(radio.SENDERID);DEBUG("] ");
|
for (byte i = 0; i < radio.DATALEN; i++)
|
||||||
// if (radio.DATALEN > 0)
|
DEBUG((char)radio.DATA[i]);
|
||||||
// {
|
DEBUG(" [RSSI:");DEBUG(rssi);DEBUG("]");
|
||||||
// for (byte i = 0; i < radio.DATALEN; i++)
|
}
|
||||||
// DEBUG((char)radio.DATA[i]);
|
|
||||||
// DEBUG(" [RSSI:");DEBUG(rssi);DEBUG("]");
|
CheckForWirelessHEX(radio, flash, false); //non verbose DEBUG
|
||||||
// }
|
|
||||||
//
|
if (radio.ACKRequested())
|
||||||
// CheckForWirelessHEX(radio, flash, false); //non verbose DEBUG
|
{
|
||||||
//
|
byte theNodeID = radio.SENDERID;
|
||||||
// if (radio.ACKRequested())
|
radio.sendACK();
|
||||||
// {
|
DEBUG("[ACK-sent]");
|
||||||
// byte theNodeID = radio.SENDERID;
|
}
|
||||||
// radio.sendACK();
|
DEBUGln();
|
||||||
// DEBUG("[ACK-sent]");
|
Blink(LED,3);
|
||||||
// }
|
|
||||||
// DEBUGln();
|
lcd.clear();
|
||||||
// Blink(LED,3);
|
lcd.setCursor(0,0);
|
||||||
//
|
|
||||||
// lcd.clear();
|
//if (radio.DATALEN < RF69_MAX_DATA_LEN) radio.DATA[radio.DATALEN]=0;
|
||||||
// lcd.setCursor(0,0);
|
byte matches = sscanf((const char*)radio.DATA, "%s BAT:%s", LO, BAT);
|
||||||
//
|
if (matches==2)
|
||||||
// //if (radio.DATALEN < RF69_MAX_DATA_LEN) radio.DATA[radio.DATALEN]=0;
|
{
|
||||||
// byte matches = sscanf((const char*)radio.DATA, "%s BAT:%s", LO, BAT);
|
lcd.print(LO);
|
||||||
// if (matches==2)
|
lcd.setCursor(0,14);
|
||||||
// {
|
lcd.print(char(0));
|
||||||
// lcd.print(LO);
|
lcd.setCursor(0,15);
|
||||||
// lcd.setCursor(0,14);
|
lcd.print(BAT);
|
||||||
// lcd.print(char(0));
|
}
|
||||||
// lcd.setCursor(0,15);
|
else lcd.print((const char*)radio.DATA);
|
||||||
// lcd.print(BAT);
|
|
||||||
// }
|
lcd.setCursor(1,14);
|
||||||
// else lcd.print((const char*)radio.DATA);
|
lcd.print(char(1));
|
||||||
//
|
lcd.setCursor(1,16);
|
||||||
// lcd.setCursor(1,14);
|
lcd.print(rssi);
|
||||||
// lcd.print(char(1));
|
}
|
||||||
// lcd.setCursor(1,16);
|
}
|
||||||
// lcd.print(rssi);
|
|
||||||
// }
|
void Blink(byte PIN, int DELAY_MS)
|
||||||
//}
|
{
|
||||||
//
|
pinMode(PIN, OUTPUT);
|
||||||
//void Blink(byte PIN, int DELAY_MS)
|
digitalWrite(PIN,HIGH);
|
||||||
|
delay(DELAY_MS);
|
||||||
|
digitalWrite(PIN,LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
//readSerialLine already defined in WirelessHEX69
|
||||||
|
// reads a line feed (\n) terminated line from the serial stream
|
||||||
|
// returns # of bytes read, up to 255
|
||||||
|
// timeout in ms, will timeout and return after so long
|
||||||
|
//byte readSerialLine(char* input, char endOfLineChar=10, byte maxLength=64, uint16_t timeout=10);
|
||||||
|
//byte readSerialLine(char* input, char endOfLineChar, byte maxLength, uint16_t timeout)
|
||||||
//{
|
//{
|
||||||
// pinMode(PIN, OUTPUT);
|
// byte inputLen = 0;
|
||||||
// digitalWrite(PIN,HIGH);
|
// Serial.setTimeout(timeout);
|
||||||
// delay(DELAY_MS);
|
// inputLen = Serial.readBytesUntil(endOfLineChar, input, maxLength);
|
||||||
// digitalWrite(PIN,LOW);
|
// input[inputLen]=0;//null-terminate it
|
||||||
|
// Serial.setTimeout(0);
|
||||||
|
// //Serial.println();
|
||||||
|
// return inputLen;
|
||||||
//}
|
//}
|
||||||
//
|
|
||||||
////readSerialLine already defined in WirelessHEX69
|
|
||||||
//// reads a line feed (\n) terminated line from the serial stream
|
|
||||||
//// returns # of bytes read, up to 255
|
|
||||||
//// timeout in ms, will timeout and return after so long
|
|
||||||
////byte readSerialLine(char* input, char endOfLineChar=10, byte maxLength=64, uint16_t timeout=10);
|
|
||||||
////byte readSerialLine(char* input, char endOfLineChar, byte maxLength, uint16_t timeout)
|
|
||||||
////{
|
|
||||||
//// byte inputLen = 0;
|
|
||||||
//// Serial.setTimeout(timeout);
|
|
||||||
//// inputLen = Serial.readBytesUntil(endOfLineChar, input, maxLength);
|
|
||||||
//// input[inputLen]=0;//null-terminate it
|
|
||||||
//// Serial.setTimeout(0);
|
|
||||||
//// //Serial.println();
|
|
||||||
//// return inputLen;
|
|
||||||
////}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue