Firmware for an ad-hoc mesh network of Internet-of-Things devices based on LoRa (Long Range radio) that can be deployed quickly and cheaply.
DuckLora.h
Go to the documentation of this file.
1 
11 #ifndef DUCKLORA_H_
12 #define DUCKLORA_H_
13 
14 #include <Arduino.h>
15 #include <RadioLib.h>
16 
17 #include "../DuckError.h"
18 
19 #include "LoraPacket.h"
20 #include "cdpcfg.h"
21 
22 const byte ping_B = 0xF4;
23 const byte senderId_B = 0xF5;
24 const byte topic_B = 0xE3;
25 const byte messageId_B = 0xF6;
26 const byte payload_B = 0xF7;
27 const byte iamhere_B = 0xF8;
28 const byte path_B = 0xF3;
29 
34 typedef struct {
36  float band;
38  int ss;
40  int rst;
42  int di0;
44  int di1;
46  int txPower;
48  void (*func)(void);
50 
58 class DuckLora {
59 public:
65  static DuckLora* getInstance();
66 
74  int setupLoRa(LoraConfigParams config, String deviceId);
75 
81  int handlePacket();
82 
89  String getPacketData(int pSize);
90 
102  int sendPayloadStandard(String msg = "", String topic = "",
103  String senderId = "", String messageId = "",
104  String path = "");
105 
112 
130  void couple(byte byteCode, String outgoing);
131 
138  bool idInPath(String path);
139 
146 
153 
160 
166  int getRSSI();
167 
172  void resetPacketIndex() { _packetIndex = 0; }
173 
179  int getPacketIndex() { return _packetIndex; }
180 
186  byte* getTransmissionBuffer() { return _transmission; }
187 
194  byte getTransmitedByte(int index) { return _transmission[index]; }
195 
201  int ping();
202 
209  int standBy();
210 
216 
217 private:
218  byte _transmission[CDPCFG_CDP_BUFSIZE];
219  int _packetIndex = 0;
220  Packet _lastPacket;
221  String _deviceId = "";
222  int _availableBytes = 0;
223  int _packetSize = 0;
224  void resetLastPacket();
225 
226  DuckLora();
227  DuckLora(DuckLora const&) = delete;
228  DuckLora& operator=(DuckLora const&) = delete;
229  static DuckLora* instance;
230 };
231 
232 #endif
topic_B
const byte topic_B
Definition: DuckLora.h:24
DuckLora::getRSSI
int getRSSI()
Get the current RSSI value.
DuckLora::getPacketData
String getPacketData(int pSize)
Get the last received LoRa packet.
DuckLora
Internal LoRa chip abstraction.
Definition: DuckLora.h:58
DuckLora::handlePacket
int handlePacket()
Handle a Duck LoRa packet.
DuckLora::getTransmissionBuffer
byte * getTransmissionBuffer()
Get the transmission buffer.
Definition: DuckLora.h:186
DuckLora::sendPayloadStandard
int sendPayloadStandard(String msg="", String topic="", String senderId="", String messageId="", String path="")
Send a message out into the LoRa mesh network.
LoraConfigParams::rst
int rst
chip reset pin
Definition: DuckLora.h:40
payload_B
const byte payload_B
Definition: DuckLora.h:26
path_B
const byte path_B
Definition: DuckLora.h:28
DuckLora::getLastPacket
Packet getLastPacket()
Get the last received LoRa packet.
DuckLora::startReceive
int startReceive()
Set the Duck to be ready to recieve LoRa packets.
LoraConfigParams::ss
int ss
slave select pin
Definition: DuckLora.h:38
iamhere_B
const byte iamhere_B
Definition: DuckLora.h:27
DuckLora::getInstance
static DuckLora * getInstance()
Get a singletom instance of the DuckLora class,.
DuckLora::getTransmitedByte
byte getTransmitedByte(int index)
Get the transmited byte at the given index in the transmission buffer.
Definition: DuckLora.h:194
DuckLora::getPacketIndex
int getPacketIndex()
Get the current packet buffer index.
Definition: DuckLora.h:179
senderId_B
const byte senderId_B
Definition: DuckLora.h:23
DuckLora::resetPacketIndex
void resetPacketIndex()
Reset the index of the received Packet buffer.
Definition: DuckLora.h:172
ping_B
const byte ping_B
Definition: DuckLora.h:22
Packet
Internal cluster duck LoRa message structure.
Definition: LoraPacket.h:11
LoraConfigParams::di0
int di0
dio0 interrupt pin
Definition: DuckLora.h:42
LoraPacket.h
LoraConfigParams::band
float band
radio frequency (i.e US915Mhz)
Definition: DuckLora.h:36
DuckLora::resetTransmissionBuffer
void resetTransmissionBuffer()
Clear and Reset the transmission buffer.
CDPCFG_CDP_BUFSIZE
#define CDPCFG_CDP_BUFSIZE
CDP message buffer max length.
Definition: cdpcfg.h:335
DuckLora::loraPacketReceived
bool loraPacketReceived()
Check if a received packet is available for processing.
DuckLora::idInPath
bool idInPath(String path)
Determine if a Duck device_id is present in the path.
LoraConfigParams
Internal structure to hold the LoRa module configuration.
Definition: DuckLora.h:34
DuckLora::setupLoRa
int setupLoRa(LoraConfigParams config, String deviceId)
Initialize the LoRa chip.
DuckLora::transmitData
int transmitData()
Set the Duck to be ready to transmit LoRa packets.
messageId_B
const byte messageId_B
Definition: DuckLora.h:25
LoraConfigParams::txPower
int txPower
transmit power
Definition: DuckLora.h:46
DuckLora::standBy
int standBy()
Set the LoRa chip in standby mode.
DuckLora::couple
void couple(byte byteCode, String outgoing)
Append a chunk to the packet.
LoraConfigParams::di1
int di1
dio1 interrupt pin
Definition: DuckLora.h:44
DuckLora::ping
int ping()
Transmit a ping message.
cdpcfg.h
CDP central compile-time configuration file.