Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions piGateway/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#
# Makefile for piGateway
#
# Supported devices:
# Arduino use -DARDUINO
# Raspberry Pi use -DRASPBERRY
# Odroid C1(+) use -DODROIDC1
#
# make sure only your device is defined in the g++ lines.

install : Gatewayd
cp Gatewayd /usr/local/bin
cp GatewaydService /etc/init.d/Gatewayd
Expand All @@ -13,11 +23,11 @@ uninstall:
rm /usr/local/bin/Gatewayd

Gatewayd : Gateway.c rfm69.cpp rfm69.h rfm69registers.h networkconfig.h
g++ Gateway.c rfm69.cpp -o Gatewayd -lwiringPi -lmosquitto -DRASPBERRY -DDAEMON
g++ Gateway.c rfm69.cpp -o Gatewayd -lwiringPi -lmosquitto -DODROIDC1 -DDAEMON

Gateway : Gateway.c rfm69.cpp rfm69.h rfm69registers.h networkconfig.h
g++ Gateway.c rfm69.cpp -o Gateway -lwiringPi -lmosquitto -DRASPBERRY
g++ Gateway.c rfm69.cpp -o Gateway -lwiringPi -lmosquitto -DODROIDC1 -DDEBUG

SenderReceiver : SenderReceiver.c rfm69.cpp rfm69.h rfm69registers.h networkconfig.h
g++ SenderReceiver.c rfm69.cpp -o SenderReceiver -lwiringPi -DRASPBERRY
g++ SenderReceiver.c rfm69.cpp -o SenderReceiver -lwiringPi -DODROIDC1

4 changes: 2 additions & 2 deletions piGateway/networkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ File: Gateway.c
This file hold the network configuration
*/

#define NWC_NETWORK_ID 101
#define NWC_NETWORK_ID 100
#define NWC_NODE_ID 1
// Frequency should be one of RF69_433MHZ RF69_868MHZ RF69_915MHZ
#define NWC_FREQUENCY RF69_433MHZ
// Set to 0 to disable encryption
#define NWC_KEY_LENGTH 16
// Must contain 16 characters
#define NWC_KEY "xxxxxxxxxxxxxxxx"
#define NWC_KEY "sampleEncryptKey"
// Set to true is the RFM69 is high power, false otherwise
#define NWC_RFM69H true
// Set to true if you want to listen to all messages on the network, even if for different nodes
Expand Down
57 changes: 41 additions & 16 deletions piGateway/rfm69.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
// **********************************************************************************
#include "rfm69.h"
#include "rfm69registers.h"
#ifdef RASPBERRY

#ifdef RASPBERRY // If RASPBERRY is defined in the make file.
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdio.h>
Expand All @@ -41,6 +42,16 @@
#include <unistd.h> //usleep
#define MICROSLEEP_LENGTH 15

#elif ODROIDC1 // If ODROIDC1 is defined in the make file.
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#include <unistd.h> //usleep
#define MICROSLEEP_LENGTH 15

#else
#include <SPI.h>
#endif
Expand Down Expand Up @@ -102,8 +113,15 @@ bool RFM69::initialize(uint8_t freqBand, uint8_t nodeID, uint8_t networkID)
{255, 0}
};

#ifdef RASPBERRY
// Initialize SPI device 0
#if defined(RASPBERRY) || defined(ODROIDC1)
wiringPiSetup();
pinMode (RF69_RST_PIN, OUTPUT);
digitalWrite (RF69_RST_PIN, LOW);
pinMode (RF69_CLK_PIN, INPUT);
pullUpDnControl (RF69_CLK_PIN, PUD_OFF);
pinMode (RF69_SPI_CS, OUTPUT);
digitalWrite (RF69_SPI_CS, LOW);
// Initialize SPI device 0
if(wiringPiSPISetup(SPI_DEVICE, SPI_SPEED) < 0) {
fprintf(stderr, "Unable to open SPI device\n\r");
exit(1);
Expand Down Expand Up @@ -132,7 +150,7 @@ bool RFM69::initialize(uint8_t freqBand, uint8_t nodeID, uint8_t networkID)
while (((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00) && millis()-start < timeout); // wait for ModeReady
if (millis()-start >= timeout)
return false;
#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
// Attach the Interupt
wiringPiSetup();
wiringPiISR(6, INT_EDGE_RISING, RFM69::isr0);
Expand Down Expand Up @@ -378,7 +396,7 @@ void RFM69::sendFrame(uint8_t toAddress, const void* buffer, uint8_t bufferSize,
else if (requestACK)
CTLbyte = RFM69_CTL_REQACK;

#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
unsigned char thedata[63];
uint8_t i;
for(i = 0; i < 63; i++) thedata[i] = 0;
Expand Down Expand Up @@ -418,7 +436,7 @@ void RFM69::sendFrame(uint8_t toAddress, const void* buffer, uint8_t bufferSize,
// internal function - interrupt gets called when a packet is received
void RFM69::interruptHandler() {

#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
unsigned char thedata[67];
char i;
for(i = 0; i < 67; i++) thedata[i] = 0;
Expand All @@ -431,7 +449,7 @@ void RFM69::interruptHandler() {
{
//RSSI = readRSSI();
setMode(RF69_MODE_STANDBY);
#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
thedata[0] = REG_FIFO & 0x7F;
thedata[1] = 0; // PAYLOADLEN
thedata[2] = 0; // TargetID
Expand All @@ -457,7 +475,7 @@ void RFM69::interruptHandler() {
//digitalWrite(4, 0);
return;
}
#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
DATALEN = PAYLOADLEN - 3;
thedata[0] = REG_FIFO & 0x77;
thedata[1] = 0; //SENDERID
Expand Down Expand Up @@ -531,7 +549,8 @@ void RFM69::receiveBegin() {
bool RFM69::receiveDone() {
//ATOMIC_BLOCK(ATOMIC_FORCEON)
//{
#ifndef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
// one or both define
noInterrupts(); // re-enabled in unselect() via setMode() or via receiveBegin()
#endif
if (_mode == RF69_MODE_RX && PAYLOADLEN > 0)
Expand All @@ -541,7 +560,9 @@ bool RFM69::receiveDone() {
}
else if (_mode == RF69_MODE_RX) // already in RX no payload yet
{
#ifndef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
// one or both defined, do nothing.
#else // neither defined
interrupts(); // explicitly re-enable interrupts
#endif
return false;
Expand All @@ -555,7 +576,7 @@ bool RFM69::receiveDone() {
// To disable encryption: radio.encrypt(null) or radio.encrypt(0)
// KEY HAS TO BE 16 bytes !!!
void RFM69::encrypt(const char* key) {
#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
unsigned char thedata[17];
char i;

Expand Down Expand Up @@ -601,7 +622,7 @@ int16_t RFM69::readRSSI(bool forceTrigger) {

uint8_t RFM69::readReg(uint8_t addr)
{
#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
unsigned char thedata[2];
thedata[0] = addr & 0x7F;
thedata[1] = 0;
Expand All @@ -622,7 +643,7 @@ uint8_t RFM69::readReg(uint8_t addr)

void RFM69::writeReg(uint8_t addr, uint8_t value)
{
#if RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
//printf("%x %x\n", addr, value);
unsigned char thedata[2];
thedata[0] = addr | 0x80;
Expand All @@ -641,7 +662,9 @@ void RFM69::writeReg(uint8_t addr, uint8_t value)
// select the RFM69 transceiver (save SPI settings, set CS low)
void RFM69::select() {
// printf(" diable Int ");
#ifndef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
// one or both defined, do nothing.
#else // if neither defined
noInterrupts();
// save current SPI settings
_SPCR = SPCR;
Expand All @@ -656,7 +679,9 @@ void RFM69::select() {

// unselect the RFM69 transceiver (set CS high, restore SPI settings)
void RFM69::unselect() {
#ifndef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
// one or both defined, do nothing.
#else // neither defined
digitalWrite(_slaveSelectPin, HIGH);
// restore SPI settings to what they were before talking to RFM69
SPCR = _SPCR;
Expand Down Expand Up @@ -699,7 +724,7 @@ void RFM69::setCS(uint8_t newSPISlaveSelect) {
// Serial.print all the RFM69 register values
void RFM69::readAllRegs()
{
#ifdef RASPBERRY
#if defined(RASPBERRY) || defined(ODROIDC1)
char thedata[2];
int i;
thedata[1] = 0;
Expand Down
12 changes: 12 additions & 0 deletions piGateway/rfm69.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
#define RF69_IRQ_PIN 6
#define RF69_IRQ_NUM 0

#define SPI_SPEED 500000
#define SPI_DEVICE 0
#elif ODROIDC1 // If ODROIDC1 is defined in the Makefile instead of RASPBERRY
#include <stdint.h>

#define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2 bytes crc)

#define RF69_SPI_CS 10 // SS is the SPI slave select pin, for instance D10 on atmega328, use the WiringPi numbering.
#define RF69_IRQ_PIN 6 // The interrupt pin on the OdroidC1, use WirintPi numbering.
#define RF69_IRQ_NUM 0
#define RF69_RST_PIN 5 // The reset pin should be pulled down by default, pull high for resetting
#define RF69_CLK_PIN 14 // The SPI CLK pin. Used for setting the pulldown and output mode.
#define SPI_SPEED 500000
#define SPI_DEVICE 0
#else
Expand Down