Skip to content

Commit

Permalink
[Pager] Implemented POCSAG (jgromes#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes authored and phretor committed Nov 15, 2022
1 parent 8c2e8a4 commit a5ef54f
Show file tree
Hide file tree
Showing 8 changed files with 1,186 additions and 0 deletions.
121 changes: 121 additions & 0 deletions examples/Pager/Pager_Receive/Pager_Receive.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
RadioLib Pager (POCSAG) Receive Example
This example shows how to receive FSK packets without using
SX127x packet engine.
This example receives POCSAG messages using SX1278's
FSK modem in direct mode.
Other modules that can be used to receive POCSAG:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/

// include the library
#include <RadioLib.h>

// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(5, 2, 9, 3);

// DIO2 pin: 5
const int pin = 4;

// create Pager client instance using the FSK module
PagerClient pager(&radio);

// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;

void setup() {
Serial.begin(9600);

// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();

// when using one of the non-LoRa modules
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();

if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}

// initalize Pager client
Serial.print(F("[Pager] Initializing ... "));
// base (center) frequency: 434.0 MHz
// speed: 1200 bps
state = pager.begin(434.0, 1200);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}

// start receiving POCSAG messages
Serial.print(F("[Pager] Starting to listen ... "));
// address of this "pager": 1234567
state = pager.startReceive(pin, 1234567);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}

}

void loop() {
// the number of batches to wait for
// 2 batches will usually be enough to fit short and medium messages
if (pager.available() >= 2) {
Serial.print(F("[Pager] Received pager data, decoding ... "));

// you can read the data as an Arduino String
String str;
int state = pager.readData(str);

// you can also receive data as byte array
/*
byte byteArr[8];
size_t numBytes = 0;
int state = radio.receive(byteArr, &numBytes);
*/

if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));

// print the received data
Serial.print(F("[Pager] Data:\t"));
Serial.println(str);

} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);

}
}
}
102 changes: 102 additions & 0 deletions examples/Pager/Pager_Transmit/Pager_Transmit.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
RadioLib Pager (POCSAG) Transmit Example
This example sends POCSAG messages using SX1278's
FSK modem.
Other modules that can be used to send POCSAG:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- SX126x
- nRF24
- Si443x/RFM2x
- SX128x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/

// include the library
#include <RadioLib.h>

// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(5, 2, 9, 3);

// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;

// create Pager client instance using the FSK module
PagerClient pager(&radio);

void setup() {
Serial.begin(9600);

// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();

// when using one of the non-LoRa modules
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();

if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}

// initalize Pager client
Serial.print(F("[Pager] Initializing ... "));
// base (center) frequency: 434.0 MHz
// speed: 1200 bps
state = pager.begin(434.0, 1200);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}

void loop() {
Serial.print(F("[Pager] Transmitting messages ... "));

// the simples form of "message" is just a tone on the destination pager
int state = pager.sendTone(1234567);
delay(500);

// next, transmit numeric (BCD) message to the destination pager
// NOTE: Only characters 0123456789*U-() and space
// can be sent in a BCD message!
state |= pager.transmit("0123456789*U -()", 1234567);
delay(500);

// finally, let's transmit an ASCII message now
state |= pager.transmit("Hello World!", 1234567, RADIOLIB_PAGER_ASCII);
delay(500);

// we can also send only a tone

if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}

// wait for a second before transmitting again
delay(3000);
}
7 changes: 7 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ HellClient KEYWORD1
AFSKClient KEYWORD1
FSK4Client KEYWORD1
APRSClient KEYWORD1
PagerClient KEYWORD1

# SSTV modes
Scottie1 KEYWORD1
Expand Down Expand Up @@ -239,6 +240,9 @@ noTone KEYWORD2
sendPosition KEYWORD2
sendMicE KEYWORD2

# Pager
sendTone KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
Expand Down Expand Up @@ -330,3 +334,6 @@ RADIOLIB_ERR_INVALID_NUM_REPEATERS LITERAL1
RADIOLIB_ERR_INVALID_REPEATER_CALLSIGN LITERAL1

RADIOLIB_ERR_RANGING_TIMEOUT LITERAL1

RADIOLIB_ERR_INVALID_PAYLOAD LITERAL1
RADIOLIB_ERR_ADDRESS_NOT_FOUND LITERAL1
1 change: 1 addition & 0 deletions src/RadioLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "protocols/AX25/AX25.h"
#include "protocols/Hellschreiber/Hellschreiber.h"
#include "protocols/Morse/Morse.h"
#include "protocols/Pager/Pager.h"
#include "protocols/RTTY/RTTY.h"
#include "protocols/SSTV/SSTV.h"
#include "protocols/FSK4/FSK4.h"
Expand Down
12 changes: 12 additions & 0 deletions src/TypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,18 @@
*/
#define RADIOLIB_ERR_RANGING_TIMEOUT (-901)

// Pager-specific status codes

/*!
\brief The provided payload data configuration is invalid.
*/
#define RADIOLIB_ERR_INVALID_PAYLOAD (-1001)

/*!
\brief The requested address was not found in the received data.
*/
#define RADIOLIB_ERR_ADDRESS_NOT_FOUND (-1002)

/*!
\}
*/
Expand Down
Loading

0 comments on commit a5ef54f

Please sign in to comment.