forked from jgromes/RadioLib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pager] Implemented POCSAG (jgromes#7)
- Loading branch information
Showing
8 changed files
with
1,186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.