forked and modified initial value for return values and changed timer definition to TIM1 instead of int(1)
This commit is contained in:
43
examples/raspi/rf95/rf95_client/Makefile
Normal file
43
examples/raspi/rf95/rf95_client/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_client
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_client.o: rf95_client.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_client: rf95_client.o RH_RF95.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_client
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_client
|
||||
|
||||
147
examples/raspi/rf95/rf95_client/rf95_client.cpp
Normal file
147
examples/raspi/rf95/rf95_client/rf95_client.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// rf95_client.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example app showing how to create a simple messaging client
|
||||
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_RF95 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example rf95_server.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_client.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_client.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
//Client and Server Addresses
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_client startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_client startup OK.\n" );
|
||||
printf( "\nRPI GPIO settings:\n" );
|
||||
printf("CS-> GPIO %d\n", (uint8_t) RFM95_CS_PIN);
|
||||
printf("IRQ-> GPIO %d\n", (uint8_t) RFM95_IRQ_PIN);
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!rf95.init())
|
||||
{
|
||||
printf( "\n\nRF95 driver failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client(This) Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address= %d\n", SERVER_ADDRESS);
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(CLIENT_ADDRESS);
|
||||
rf95.setHeaderFrom(CLIENT_ADDRESS);
|
||||
rf95.setHeaderTo(SERVER_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
/* Begin Datagram Client Code */
|
||||
while(!flag)
|
||||
{
|
||||
Serial.println("Sending to rf95_server");
|
||||
// Send a message to rf95_server
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
uint8_t data[] = "Hello World!";
|
||||
rf95.send(data, sizeof(data));
|
||||
|
||||
rf95.waitPacketSent();
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
// Now wait for a reply
|
||||
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
|
||||
if (rf95.waitAvailableTimeout(3000))
|
||||
{
|
||||
// Should be a reply message for us now
|
||||
if (rf95.recv(buf, &len))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got reply: ");
|
||||
Serial.println((char*)buf);
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf95_server running?");
|
||||
}
|
||||
gpioDelay(400000);
|
||||
}
|
||||
printf( "\nrf95_client Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
52
examples/raspi/rf95/rf95_mesh_client/Makefile
Normal file
52
examples/raspi/rf95/rf95_mesh_client/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_mesh_client
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_mesh_client.o: rf95_mesh_client.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHMesh.o: $(RADIOHEADBASE)/RHMesh.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_mesh_client: rf95_mesh_client.o RH_RF95.o RHMesh.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_mesh_client
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_mesh_client
|
||||
|
||||
151
examples/raspi/rf95/rf95_mesh_client/rf95_mesh_client.cpp
Normal file
151
examples/raspi/rf95/rf95_mesh_client/rf95_mesh_client.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
// rf95_mesh_client.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example application showing how to create a simple addressed, routed reliable messaging client
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf95_mesh_server*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_mesh_client.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_mesh_client.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(rf95, CLIENT_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_mesh_client startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_mesh_client startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nMesh Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client(This) Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address 1= %d\n", SERVER1_ADDRESS);
|
||||
printf("Server Address 2= %d\n", SERVER2_ADDRESS);
|
||||
printf("Server Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client->Server 3 is automatic in MESH.\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
Serial.println("Sending to manager_mesh_server3");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
|
||||
// Send a message to a rf95_mesh_server
|
||||
// A route to the destination will be automatically discovered.
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER3_ADDRESS) == RH_ROUTER_ERROR_NONE)
|
||||
{
|
||||
// It has been reliably delivered to the next node.
|
||||
// Now wait for a reply from the ultimate server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 3000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf95_mesh_server1, rf95_mesh_server2 and rf95_mesh_server3 running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed. Are the intermediate mesh servers running?");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
gpioDelay(400000);
|
||||
}
|
||||
printf( "\nrf95_mesh_client Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
52
examples/raspi/rf95/rf95_mesh_server1/Makefile
Normal file
52
examples/raspi/rf95/rf95_mesh_server1/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_mesh_server1
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_mesh_server1.o: rf95_mesh_server1.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHMesh.o: $(RADIOHEADBASE)/RHMesh.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_mesh_server1: rf95_mesh_server1.o RH_RF95.o RHMesh.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_mesh_server1
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_mesh_server1
|
||||
|
||||
138
examples/raspi/rf95/rf95_mesh_server1/rf95_mesh_server1.cpp
Normal file
138
examples/raspi/rf95/rf95_mesh_server1/rf95_mesh_server1.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
// rf95_mesh_server1.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf95_mesh_*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_mesh_server1.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_mesh_server1.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(rf95, SERVER1_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_mesh_server1 startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_mesh_server1 startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nMesh Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server(This) Address 1= %d\n", SERVER1_ADDRESS);
|
||||
printf("Server Address 2= %d\n", SERVER2_ADDRESS);
|
||||
printf("Server Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client->Server 3 is automatic in MESH.\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "And hello back to you from server1";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
printf( "\nrf95_mesh_server1 Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
52
examples/raspi/rf95/rf95_mesh_server2/Makefile
Normal file
52
examples/raspi/rf95/rf95_mesh_server2/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_mesh_server2
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_mesh_server2.o: rf95_mesh_server2.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHMesh.o: $(RADIOHEADBASE)/RHMesh.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_mesh_server2: rf95_mesh_server2.o RH_RF95.o RHMesh.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_mesh_server2
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_mesh_server2
|
||||
|
||||
138
examples/raspi/rf95/rf95_mesh_server2/rf95_mesh_server2.cpp
Normal file
138
examples/raspi/rf95/rf95_mesh_server2/rf95_mesh_server2.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
// rf95_mesh_server2.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf95_mesh_*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_mesh_server2.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_mesh_server2.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(rf95, SERVER2_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_mesh_server2 startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_mesh_server2 startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nMesh Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address 1= %d\n", SERVER1_ADDRESS);
|
||||
printf("Server(This) Address 2= %d\n", SERVER2_ADDRESS);
|
||||
printf("Server Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client->Server 3 is automatic in MESH.\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "And hello back to you from server2";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
printf( "\nrf95_mesh_server2 Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
52
examples/raspi/rf95/rf95_mesh_server3/Makefile
Normal file
52
examples/raspi/rf95/rf95_mesh_server3/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_mesh_server3
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_mesh_server3.o: rf95_mesh_server3.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHMesh.o: $(RADIOHEADBASE)/RHMesh.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_mesh_server3: rf95_mesh_server3.o RH_RF95.o RHMesh.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_mesh_server3
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_mesh_server3
|
||||
|
||||
138
examples/raspi/rf95/rf95_mesh_server3/rf95_mesh_server3.cpp
Normal file
138
examples/raspi/rf95/rf95_mesh_server3/rf95_mesh_server3.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
// rf95_mesh_server3.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHMesh class.
|
||||
// It is designed to work with the other examples rf95_mesh_*
|
||||
// Hint: you can simulate other network topologies by setting the
|
||||
// RH_TEST_NETWORK define in RHRouter.h
|
||||
|
||||
// Mesh has much greater memory requirements, and you may need to limit the
|
||||
// max message length to prevent wierd crashes
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_mesh_server3.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_mesh_server3.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHMesh.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
#define RH_MESH_MAX_MESSAGE_LEN 50
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHMesh manager(rf95, SERVER3_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_mesh_server3 startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_mesh_server2 startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nMesh Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address 1= %d\n", SERVER1_ADDRESS);
|
||||
printf("Server Address 2= %d\n", SERVER2_ADDRESS);
|
||||
printf("Server(This) Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client->Server 3 is automatic in MESH.\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "And hello back to you from server3";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
printf( "\nrf95_mesh_server3 Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
46
examples/raspi/rf95/rf95_reliable_datagram_client/Makefile
Normal file
46
examples/raspi/rf95/rf95_reliable_datagram_client/Makefile
Normal file
@@ -0,0 +1,46 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_reliable_datagram_client
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_reliable_datagram_client.o: rf95_reliable_datagram_client.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_reliable_datagram_client: rf95_reliable_datagram_client.o RH_RF95.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_reliable_datagram_client
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_reliable_datagram_client
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
// rf95_reliable_datagram_client.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example app showing how to create a simple addressed, reliable messaging client
|
||||
// with the RHReliableDatagram class, using the RH_RF95 driver to control a RF95 radio.
|
||||
// It is designed to work with the other example rf95_reliable_datagram_server.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_reliable_datagram_client.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_reliable_datagram_client.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
//Client and Server Addresses
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHReliableDatagram manager(rf95, CLIENT_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_reliable_datagram_client startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_reliable_datagram_client startup OK.\n" );
|
||||
printf( "\nRPI GPIO settings:\n" );
|
||||
printf("CS-> GPIO %d\n", (uint8_t) RFM95_CS_PIN);
|
||||
printf("IRQ-> GPIO %d\n", (uint8_t) RFM95_IRQ_PIN);
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!rf95.init())
|
||||
{
|
||||
printf( "\n\nRF95 Driver Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client(This) Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address= %d\n", SERVER_ADDRESS);
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(CLIENT_ADDRESS);
|
||||
rf95.setHeaderFrom(CLIENT_ADDRESS);
|
||||
rf95.setHeaderTo(SERVER_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
/* Begin Datagram Client Code */
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
Serial.println("Sending to rf95_reliable_datagram_server");
|
||||
// Send a message to manager_server
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
|
||||
{
|
||||
// Now wait for a reply from the server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf95_reliable_datagram_server running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
gpioDelay(500000);
|
||||
}
|
||||
printf( "\nrf95_reliable_datagram_client Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
46
examples/raspi/rf95/rf95_reliable_datagram_server/Makefile
Normal file
46
examples/raspi/rf95/rf95_reliable_datagram_server/Makefile
Normal file
@@ -0,0 +1,46 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_reliable_datagram_server
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_reliable_datagram_server.o: rf95_reliable_datagram_server.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_reliable_datagram_server: rf95_reliable_datagram_server.o RH_RF95.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_reliable_datagram_server
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_reliable_datagram_server
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// rf95_reliable_datagram_server.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example app showing how to create a simple addressed, reliable messaging server
|
||||
// with the RHReliableDatagram class, using the RH_RF95 driver to control a RF95 radio.
|
||||
// It is designed to work with the other example rf95_reliable_datagram_client.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_reliable_datagram_server.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_reliable_datagram_server.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
//Client and Server Addresses
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHReliableDatagram manager(rf95, SERVER_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_reliable_datagram_server startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_reliable_datagram_server startup OK.\n" );
|
||||
printf( "\nRPI GPIO settings:\n" );
|
||||
printf("CS-> GPIO %d\n", (uint8_t) RFM95_CS_PIN);
|
||||
printf("IRQ-> GPIO %d\n", (uint8_t) RFM95_IRQ_PIN);
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!rf95.init())
|
||||
{
|
||||
printf( "\n\nRF95 Driver Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server(This) Address= %d\n", SERVER_ADDRESS);
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(SERVER_ADDRESS);
|
||||
rf95.setHeaderFrom(SERVER_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
/* Begin Reliable Datagram Server Code */
|
||||
uint8_t data[] = "And hello back to you";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
if (manager.available())
|
||||
{
|
||||
// Wait for a message addressed to us from the client
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (!manager.sendtoWait(data, sizeof(data), from))
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
printf( "\nrf95_reliable_datagram_server Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
49
examples/raspi/rf95/rf95_router_client/Makefile
Normal file
49
examples/raspi/rf95/rf95_router_client/Makefile
Normal file
@@ -0,0 +1,49 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_router_client
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_router_client.o: rf95_router_client.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_router_client: rf95_router_client.o RH_RF95.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_router_client
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_router_client
|
||||
|
||||
155
examples/raspi/rf95/rf95_router_client/rf95_router_client.cpp
Normal file
155
examples/raspi/rf95/rf95_router_client/rf95_router_client.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
// rf95_router_client.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging client
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other examples rf95_router_server*.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_router_client.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_router_client.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Create an instance of a driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(rf95, CLIENT_ADDRESS);
|
||||
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_router_client startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_router_client startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nRouter Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client(This) Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address 1= %d\n", SERVER1_ADDRESS);
|
||||
printf("Server Address 2= %d\n", SERVER2_ADDRESS);
|
||||
printf("Server Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client-> Server 1-> Server 2-> Server 3\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(SERVER1_ADDRESS, SERVER1_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER3_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
Serial.println("Sending to rf95_router_server3");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
|
||||
// Send a message to a rf95_router_server
|
||||
// It will be routed by the intermediate
|
||||
// nodes to the destination node, accorinding to the
|
||||
// routing tables in each node
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER3_ADDRESS) == RH_ROUTER_ERROR_NONE)
|
||||
{
|
||||
// It has been reliably delivered to the next node.
|
||||
// Now wait for a reply from the ultimate server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 3000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is rf95_router_server1, rf95_router_server2 and rf95_router_server3 running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed. Are the intermediate router servers running?");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
gpioDelay(500000);
|
||||
}
|
||||
printf( "\nrf95_router_client Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
49
examples/raspi/rf95/rf95_router_server1/Makefile
Normal file
49
examples/raspi/rf95/rf95_router_server1/Makefile
Normal file
@@ -0,0 +1,49 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_router_server1
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_router_server1.o: rf95_router_server1.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_router_server1: rf95_router_server1.o RH_RF95.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_router_server1
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_router_server1
|
||||
|
||||
143
examples/raspi/rf95/rf95_router_server1/rf95_router_server1.cpp
Normal file
143
examples/raspi/rf95/rf95_router_server1/rf95_router_server1.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
// rf95_router_server1.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other example rf95_router_client.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_router_server1.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_router_server1.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Create an instance of a driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(rf95, SERVER1_ADDRESS);
|
||||
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_router_server1 startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_router_server1 startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nRouter Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server(This) Address 1= %d\n", SERVER1_ADDRESS);
|
||||
printf("Server Address 2= %d\n", SERVER2_ADDRESS);
|
||||
printf("Server Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client-> Server 1-> Server 2-> Server 3\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(SERVER1_ADDRESS);
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "And hello back to you from server1";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
printf( "\nrf95_router_server1 Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
49
examples/raspi/rf95/rf95_router_server2/Makefile
Normal file
49
examples/raspi/rf95/rf95_router_server2/Makefile
Normal file
@@ -0,0 +1,49 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_router_server2
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_router_server2.o: rf95_router_server2.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_router_server2: rf95_router_server2.o RH_RF95.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_router_server2
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_router_server2
|
||||
|
||||
143
examples/raspi/rf95/rf95_router_server2/rf95_router_server2.cpp
Normal file
143
examples/raspi/rf95/rf95_router_server2/rf95_router_server2.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
// rf95_router_server2.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other example rf95_router_client.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_router_server2.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_router_server2.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Create an instance of a driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(rf95, SERVER2_ADDRESS);
|
||||
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_router_server2 startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_router_server2 startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nRouter Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address 1 = %d\n", SERVER1_ADDRESS);
|
||||
printf("Server(This) Address 2 = %d\n", SERVER2_ADDRESS);
|
||||
printf("Server Address 3= %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client-> Server 1-> Server 2-> Server 3\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(SERVER2_ADDRESS);
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "And hello back to you from server2";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
printf( "\nrf95_router_server2 Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
49
examples/raspi/rf95/rf95_router_server3/Makefile
Normal file
49
examples/raspi/rf95/rf95_router_server3/Makefile
Normal file
@@ -0,0 +1,49 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_router_server3
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_router_server3.o: rf95_router_server3.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_router_server3: rf95_router_server3.o RH_RF95.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_router_server3
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_router_server3
|
||||
|
||||
143
examples/raspi/rf95/rf95_router_server3/rf95_router_server3.cpp
Normal file
143
examples/raspi/rf95/rf95_router_server3/rf95_router_server3.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
// rf95_router_server3.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, routed reliable messaging server
|
||||
// with the RHRouter class.
|
||||
// It is designed to work with the other example rf95_router_client.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_router_server3.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_router_server3.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
// In this small artifical network of 4 nodes,
|
||||
// messages are routed via intermediate nodes to their destination
|
||||
// node. All nodes can act as routers
|
||||
// CLIENT_ADDRESS <-> SERVER1_ADDRESS <-> SERVER2_ADDRESS<->SERVER3_ADDRESS
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER1_ADDRESS 2
|
||||
#define SERVER2_ADDRESS 3
|
||||
#define SERVER3_ADDRESS 4
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Create an instance of a driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(rf95, SERVER3_ADDRESS);
|
||||
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_router_server3 startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_router_server3 startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nRouter Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server Address 1 = %d\n", SERVER1_ADDRESS);
|
||||
printf("Server Address 2 = %d\n", SERVER2_ADDRESS);
|
||||
printf("Server(This) Address 3 = %d\n", SERVER3_ADDRESS);
|
||||
printf("Route: Client-> Server 1-> Server 2-> Server 3\n");
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(SERVER3_ADDRESS);
|
||||
|
||||
// Manually define the routes for this network
|
||||
manager.addRouteTo(CLIENT_ADDRESS, CLIENT_ADDRESS);
|
||||
manager.addRouteTo(SERVER2_ADDRESS, SERVER2_ADDRESS);
|
||||
manager.addRouteTo(SERVER3_ADDRESS, SERVER2_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
uint8_t data[] = "And hello back to you from server3";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ROUTER_MAX_MESSAGE_LEN];
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
|
||||
Serial.println("sendtoWait failed");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
printf( "\nrf95_router_server3 Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
49
examples/raspi/rf95/rf95_router_test/Makefile
Normal file
49
examples/raspi/rf95/rf95_router_test/Makefile
Normal file
@@ -0,0 +1,49 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_router_test
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_router_test.o: rf95_router_test.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHRouter.o: $(RADIOHEADBASE)/RHRouter.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHReliableDatagram.o: $(RADIOHEADBASE)/RHReliableDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_router_test: rf95_router_test.o RH_RF95.o RHRouter.o RHReliableDatagram.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_router_test
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_router_test
|
||||
|
||||
183
examples/raspi/rf95/rf95_router_test/rf95_router_test.cpp
Normal file
183
examples/raspi/rf95/rf95_router_test/rf95_router_test.cpp
Normal file
@@ -0,0 +1,183 @@
|
||||
// rf95_router_test.cpp
|
||||
// -*- mode: C++ -*-
|
||||
//
|
||||
// Test code used during library development, showing how
|
||||
// to do various things, and how to call various functions
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_router_test.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(10/6/2019) Contributed by Brody M. Based off rf22_router_tester.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RHRouter.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
void test_tx(void);
|
||||
void test_routes(void);
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
//uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define ROUTER_ADDRESS 2
|
||||
#define SERVER_ADDRESS 3
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHRouter manager(rf95, CLIENT_ADDRESS);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_router_tester startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_router_tester startup OK.\n" );
|
||||
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("\nINFO: LED on GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!manager.init())
|
||||
{
|
||||
printf( "\n\nRouter Manager Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client(This) Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Router Address = %d\n", ROUTER_ADDRESS);
|
||||
printf("Server Address = %d\n", SERVER_ADDRESS);
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
while(!flag)
|
||||
{
|
||||
Serial.println("Running test function...");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
// test_routes();
|
||||
test_tx();
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
gpioDelay(500000);
|
||||
}
|
||||
printf( "\nrf95_router_test Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
|
||||
void test_routes()
|
||||
{
|
||||
manager.clearRoutingTable();
|
||||
// manager.printRoutingTable();
|
||||
manager.addRouteTo(1, 101);
|
||||
manager.addRouteTo(2, 102);
|
||||
manager.addRouteTo(3, 103);
|
||||
RHRouter::RoutingTableEntry* e;
|
||||
e = manager.getRouteTo(0);
|
||||
if (e) // Should fail
|
||||
Serial.println("getRouteTo 0 failed");
|
||||
|
||||
e = manager.getRouteTo(1);
|
||||
if (!e)
|
||||
Serial.println("getRouteTo 1 failed");
|
||||
if (e->dest != 1)
|
||||
Serial.println("getRouteTo 2 failed");
|
||||
if (e->next_hop != 101)
|
||||
Serial.println("getRouteTo 3 failed");
|
||||
if (e->state != RHRouter::Valid)
|
||||
Serial.println("getRouteTo 4 failed");
|
||||
|
||||
e = manager.getRouteTo(2);
|
||||
if (!e)
|
||||
Serial.println("getRouteTo 5 failed");
|
||||
if (e->dest != 2)
|
||||
Serial.println("getRouteTo 6 failed");
|
||||
if (e->next_hop != 102)
|
||||
Serial.println("getRouteTo 7 failed");
|
||||
if (e->state != RHRouter::Valid)
|
||||
Serial.println("getRouteTo 8 failed");
|
||||
|
||||
if (!manager.deleteRouteTo(1))
|
||||
Serial.println("deleteRouteTo 1 failed");
|
||||
// Route to 1 should now be gone
|
||||
e = manager.getRouteTo(1);
|
||||
if (e)
|
||||
Serial.println("deleteRouteTo 2 failed");
|
||||
|
||||
Serial.println("-------------------");
|
||||
|
||||
// manager.printRoutingTable();
|
||||
delay(500);
|
||||
|
||||
}
|
||||
|
||||
void test_tx()
|
||||
{
|
||||
manager.addRouteTo(SERVER_ADDRESS, ROUTER_ADDRESS);
|
||||
uint8_t errorcode;
|
||||
errorcode = manager.sendtoWait(data, sizeof(data), 100); // Should fail with no route
|
||||
if (errorcode != RH_ROUTER_ERROR_NO_ROUTE)
|
||||
Serial.println("sendtoWait 1 failed");
|
||||
errorcode = manager.sendtoWait(data, 255, 10); // Should fail too big
|
||||
if (errorcode != RH_ROUTER_ERROR_INVALID_LENGTH)
|
||||
Serial.println("sendtoWait 2 failed");
|
||||
errorcode = manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS); // Should fail after timeouts to 110
|
||||
if (errorcode != RH_ROUTER_ERROR_UNABLE_TO_DELIVER)
|
||||
Serial.println("sendtoWait 3 failed");
|
||||
Serial.println("-------------------");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
43
examples/raspi/rf95/rf95_server/Makefile
Normal file
43
examples/raspi/rf95/rf95_server/Makefile
Normal file
@@ -0,0 +1,43 @@
|
||||
# Makefile
|
||||
# Example for RH_RF95 on Raspberry Pi
|
||||
# Requires pigpio to be installed: http://abyz.me.uk/rpi/pigpio/
|
||||
|
||||
CC = g++
|
||||
CFLAGS = -DRASPBERRY_PI -pthread
|
||||
LIBS = -lpigpio -lrt
|
||||
RADIOHEADBASE = ../../../..
|
||||
INCLUDE = -I$(RADIOHEADBASE)
|
||||
|
||||
all: rf95_server
|
||||
|
||||
RasPi.o: $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp
|
||||
$(CC) $(CFLAGS) -c $(RADIOHEADBASE)/RHutil_pigpio/RasPi.cpp $(INCLUDE)
|
||||
|
||||
rf95_server.o: rf95_server.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RH_RF95.o: $(RADIOHEADBASE)/RH_RF95.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHDatagram.o: $(RADIOHEADBASE)/RHDatagram.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHHardwareSPI.o: $(RADIOHEADBASE)/RHHardwareSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHSPIDriver.o: $(RADIOHEADBASE)/RHSPIDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericDriver.o: $(RADIOHEADBASE)/RHGenericDriver.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
RHGenericSPI.o: $(RADIOHEADBASE)/RHGenericSPI.cpp
|
||||
$(CC) $(CFLAGS) -c $(INCLUDE) $<
|
||||
|
||||
rf95_server: rf95_server.o RH_RF95.o RHDatagram.o RasPi.o RHHardwareSPI.o RHSPIDriver.o RHGenericDriver.o RHGenericSPI.o
|
||||
$(CC) $^ $(LIBS) -o rf95_server
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o rf95_server
|
||||
|
||||
134
examples/raspi/rf95/rf95_server/rf95_server.cpp
Normal file
134
examples/raspi/rf95/rf95_server/rf95_server.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// rf95_server.cpp
|
||||
// -*- mode: C++ -*-
|
||||
// Example app showing how to create a simple messageing server
|
||||
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
|
||||
// reliability, so you should only use RH_RF95 if you do not need the higher
|
||||
// level messaging abilities.
|
||||
// It is designed to work with the other example rf95_client.
|
||||
//
|
||||
// Requires Pigpio GPIO library. Install by downloading and compiling from
|
||||
// http://abyz.me.uk/rpi/pigpio/, or install via command line with
|
||||
// "sudo apt install pigpio". To use, run "make" at the command line in
|
||||
// the folder where this source code resides. Then execute application with
|
||||
// sudo ./rf95_server.
|
||||
// Tested on Raspberry Pi Zero and Zero W with LoRaWan/TTN RPI Zero Shield
|
||||
// by ElectronicTricks. Although this application builds and executes on
|
||||
// Raspberry Pi 3, there seems to be missed messages and hangs.
|
||||
// Strategically adding delays does seem to help in some cases.
|
||||
|
||||
//(9/20/2019) Contributed by Brody M. Based off rf22_server.pde.
|
||||
// Raspberry Pi mods influenced by nrf24 example by Mike Poublon,
|
||||
// and Charles-Henri Hallard (https://github.com/hallard/RadioHead)
|
||||
|
||||
#include <pigpio.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <RH_RF95.h>
|
||||
|
||||
//Function Definitions
|
||||
void sig_handler(int sig);
|
||||
|
||||
//Pin Definitions
|
||||
#define RFM95_CS_PIN 8
|
||||
#define RFM95_IRQ_PIN 25
|
||||
#define RFM95_LED 4
|
||||
|
||||
//Client and Server Addresses
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
//RFM95 Configuration
|
||||
#define RFM95_FREQUENCY 915.00
|
||||
#define RFM95_TXPOWER 14
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(RFM95_CS_PIN, RFM95_IRQ_PIN);
|
||||
|
||||
//Flag for Ctrl-C
|
||||
int flag = 0;
|
||||
|
||||
//Main Function
|
||||
int main (int argc, const char* argv[] )
|
||||
{
|
||||
if (gpioInitialise()<0)
|
||||
{
|
||||
printf( "\n\nRPI rf95_server startup Failed.\n" );
|
||||
return 1;
|
||||
}
|
||||
gpioSetSignalFunc(2, sig_handler); //2 is SIGINT. Ctrl+C will cause signal.
|
||||
|
||||
printf( "\nRPI rf95_server startup OK.\n" );
|
||||
printf( "\nRPI GPIO settings:\n" );
|
||||
printf("CS-> GPIO %d\n", (uint8_t) RFM95_CS_PIN);
|
||||
printf("IRQ-> GPIO %d\n", (uint8_t) RFM95_IRQ_PIN);
|
||||
#ifdef RFM95_LED
|
||||
gpioSetMode(RFM95_LED, PI_OUTPUT);
|
||||
printf("LED-> GPIO %d\n", (uint8_t) RFM95_LED);
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
gpioDelay(500000);
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
|
||||
if (!rf95.init())
|
||||
{
|
||||
printf( "\n\nRF95 Driver Failed to initialize.\n\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Begin Manager/Driver settings code */
|
||||
printf("\nRFM 95 Settings:\n");
|
||||
printf("Frequency= %d MHz\n", (uint16_t) RFM95_FREQUENCY);
|
||||
printf("Power= %d\n", (uint8_t) RFM95_TXPOWER);
|
||||
printf("Client Address= %d\n", CLIENT_ADDRESS);
|
||||
printf("Server(This) Address= %d\n", SERVER_ADDRESS);
|
||||
rf95.setTxPower(RFM95_TXPOWER, false);
|
||||
rf95.setFrequency(RFM95_FREQUENCY);
|
||||
rf95.setThisAddress(SERVER_ADDRESS);
|
||||
/* End Manager/Driver settings code */
|
||||
|
||||
/* Begin Datagram Server Code */
|
||||
while(!flag)
|
||||
{
|
||||
if (rf95.available())
|
||||
{
|
||||
// Should be a message for us now
|
||||
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
|
||||
uint8_t len = sizeof(buf);
|
||||
if (rf95.recv(buf, &len))
|
||||
{
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_ON);
|
||||
#endif
|
||||
// RF95::printBuffer("request: ", buf, len);
|
||||
Serial.print("got request: ");
|
||||
Serial.println((char*)buf);
|
||||
// Serial.print("RSSI: ");
|
||||
// Serial.println(rf95.lastRssi(), DEC);
|
||||
|
||||
//Send a reply
|
||||
uint8_t data[] = "And hello back to you";
|
||||
rf95.send(data, sizeof(data));
|
||||
rf95.waitPacketSent();
|
||||
Serial.println("Sent a reply");
|
||||
#ifdef RFM95_LED
|
||||
gpioWrite(RFM95_LED, PI_OFF);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("recv failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
/* End Datagram Server Code */
|
||||
printf( "\nrf95_server Tester Ending\n" );
|
||||
gpioTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sig_handler(int sig)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
Reference in New Issue
Block a user