LORA class contains simplified functions to send and receive message using LoRa protocol. Just use begin function to inizialize and send/receive functions. Messages are protecetd by AES256 cryptography algorithm. The starting key is provided by a unsigned number (seed) that produces 32 pseudo random bytes that are finally used to produce the real 240 bytes long key. ![]() This class is based on network structure. So messages contains addressee and sender. Besides, message contains a random byte as marker for further protection implementation. Network can by made by a network address and device address. But this partition is variable. So, you can decide to have a long net address and short device address range or viceversa. That is because the total address field is word wide (16 bits). For example if you decide to settle devices range to 64 slots, your net address can be decided inside the 1-2047 range.
Starting functionStart shield in LoRa mode and prepare key for AES256 crypto. This function verifies if shield is reachable. If it is not present it returns "false". Transmission power is set to 10dBm (code 2) for default. bool begin(unsigned int keyval); void setModeLora(unsigned int keyval); Define networkSet a network address if you like to create a network with net address and a range of device addresses. In this case device adresses range must be a 2 power value (8,16,32,64,128,256 ecc.). Besides net address value must be lower than 0xFFFF/device_range(I.E. 0x1FFF,0xFFF,0x7FF,0x3FF,0x1FF,0xFF ecc) This function MUST be called before calling sender and receiver functions that use sub-net adressess! This function returns "false" if address is incorrect with regard to the devices range. (I.E. the network structure is inconsistent). bool setNetAddress(unsigned int netAdd, unsigned int devRange); SendSend buffer mess adding a word as addressee (destAdd) and a word as sending address. Adresses are automatically calculated by net address and local address. A random byte is added just to make message unique. Sending address, random byte and message are encoded with AES256 cryptography using predefined 32 key. Length of encoded segment is a multiple of 16 bytes blocks. Destination word (two bytes) is not encoded (for fast recognising).int sendNetMess(unsigned int destSubAdd, unsigned int sendSubAdd, byte *mess, int lmess); ReceiveFirst of all set SX1278 in continuous LoRa receive mode. Set shield in continuous receiving mode. Use dataRead function
to verify if data arrived
Then call in a loop next function, that returns 0 if no message are available. Receive incoming message into the buffer buff. If no message is incoming, return 0. If message is incoming compare addressee. If addressee is not correct return 0. (I.E is not a message for the receiver). Then decode message and compare sender with sendAdd. If sender is not correct return -1. But if sendAdd parameter is 0 all messages are accepted. Finally, return the length of the sole message (without addresses). The message pointer can be obtained by getMess() function. The sender address can be obtained by getSender() function.
Next functions return message characteristics. Get sender sub-address in case of network address systemunsigned int getSubNetSender(); Get the clean message buffer (without any other prefix) of last message received. byte* getMessage(); Get random marker for further uses. byte getMarker();
Other basic functions are described in LORA.h files. For particular uses you can see this file. Inside LORA class you can call SX1278 functions with prefix SX because SX1278 class is referenced by external name SX.
|
IndexFunctionsExamples |