{"id":13673741,"url":"https://github.com/sudomesh/LoRaLayer2","last_synced_at":"2025-04-28T11:30:41.710Z","repository":{"id":45914413,"uuid":"220480418","full_name":"sudomesh/LoRaLayer2","owner":"sudomesh","description":"Layer 2 routing protocol for LoRa connected devices","archived":false,"fork":false,"pushed_at":"2021-11-28T20:54:40.000Z","size":188,"stargazers_count":89,"open_issues_count":6,"forks_count":30,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-15T02:44:02.039Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudomesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-08T14:12:33.000Z","updated_at":"2025-03-21T02:27:52.000Z","dependencies_parsed_at":"2022-09-23T09:33:15.174Z","dependency_job_id":null,"html_url":"https://github.com/sudomesh/LoRaLayer2","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudomesh%2FLoRaLayer2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudomesh%2FLoRaLayer2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudomesh%2FLoRaLayer2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudomesh%2FLoRaLayer2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudomesh","download_url":"https://codeload.github.com/sudomesh/LoRaLayer2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251304677,"owners_count":21567919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T11:00:20.818Z","updated_at":"2025-04-28T11:30:41.082Z","avatar_url":"https://github.com/sudomesh.png","language":"C++","funding_links":[],"categories":["C++","Libraries"],"sub_categories":[],"readme":"Layer 2 routing protocol for LoRa connected devices \n\nThis library is a general purpose, minimal routing protocol. It is intended for use with https://github.com/sudomesh/disaster-radio and was designed using https://github.com/sudomesh/disaster-radio-simulator.\n\nFor documentation on the technical details of the LoRaLayer2 protocol, visit the disaster-radio wiki [Protocol page](https://github.com/sudomesh/disaster-radio/wiki/Protocol).\n\n## Installation\n\n### Using the Arduino IDE Library Manager\n* Choose `Sketch` -\u003e `Include Library' -\u003e 'Manage Libraries...'\n* Type `LoRaLayer2` into the search box.\n* Click the row to select the library.\n* Click the `Install` button to install the library.\n\n### Using Git\n```\ncd ~/Documents/Arduino/libraries/\ngit clone https://github.com/sudomesh/LoRaLayer2\n```\n\n### Using PlatformIO\nInclude the following line in your `platformio.ini` file,\n```\nlib_deps = LoRaLayer2\n```\nor\n```\nlib_deps = https://github.com/sudomesh/LoRaLayer2\n```\nYou can also specify a certain release or commit in either of these options like so,\n```\nlib_deps = LoRaLayer2@1.0.1\n```\nor\n```\nlib_deps = https://github.com/sudomesh/LoRaLayer2#5fc98c99706b7883b49ece82d9a7abc1b35e0bae\n```\n\n## Description of library files\n\n`Layer1_LoRa.cpp` - connection between the physical layer LoRa transceiver and the Layer 2 routing logic. Is little more than a wrapper around https://github.com/sandeepmistry/arduino-LoRa. Should work with all transceivers supported by arudion-LoRa.  \n\n`Layer1_SX1276.cpp` - connection between a physical layer SX1276 LoRa transceiver and the Layer 2 routing logic. Is little more than a wrapper around https://github.com/jgromes/RadioLib. Only works with SX1276 transceivers, should be easy to add additional wrappers for other RadioLib supported transceivers. Is required for dual-lora module support.\n\n`Layer1_Sim.cpp` - connection between simulated Layer1 found in https://github.com/sudomesh/disaster-radio-simulator and the Layer 2 routing logic.  \n\n`LoRaLayer2.cpp` - routing logic, management the routing tables, interfaces with main sketch or Layer3 applications.  \n\n`packetBuffer.cpp`  - 16 entry circular FIFO buffer, read/write logic, used internally to communicate between Layer1 and LL2, as well as between LL2 and the main sketch or Layer3 application.\n\n## API\n\nThis library consists of two closely related classes. The Layer1 class and the LoRaLayer2 (or LL2) class. See the most basic example of their usage in [examples/router_beacon](https://github.com/sudomesh/LoRaLayer2/tree/master/examples/router_beacon).\n\nTo build this library, you must define one of the following constants depending on your target system,\n\n```\n#define ARDUINO_LORA    // to use arduino-LoRa compatible transceivers\n#define RL_SX1276       // to use RadioLib with an SX1276 transceiver\n#define SIM             // to use disaster-radio-simulator \n```\n\nThese may also be passed as build flags when compiling.\n\n### Creating Layer1 and LL2 objects\n\nTo create the Layer1Class and LL2Class objects,\n\n```\nLayer1Class *Layer1 = new Layer1Class();\nLL2Class *LL2 = new LL2Class(Layer1);\n```\n\n### Layer1\n\nPrior to initializing the Layer1 object, there are a number of setting you can optionally set.\n\n#### LoRa pins\n\nOverride the default `CS`, `RESET`, and `DIO0` pins used by the library.\n```\nLayer1-\u003esetPins(int cs, int reset, int dio);\n```\n * `cs` - chip select pin to use, defaults to `18`\n * `reset` - reset pin to use, defaults to `23`\n * `dio0` - DIO0 pin to use, defaults to `26`.  **Must** be interrupt capable via [attachInterrupt(...)](https://www.arduino.cc/en/Reference/AttachInterrupt).\n\nThis function is optional and only needs to be used if you need to change the default pins. If you choose you use it, it must be called before `Layer1-\u003einit()`.\n\n#### SPI Frequency\n\nSet the frequency of the SPI bus connected to the LoRa transceiver.\n```\nLayer1-\u003esetSPIFrequency(uint32_t frequency);\n```\n * `frequency` - SPI frequency to use, defaults to `100E3`.\n\n#### LoRa frequency\n\nSet the frequency at which the LoRa transceiver transmits\n```\nLayer1-\u003esetLoRaFrequency(uint32_t frequency);\n```\n * `frequency` - LoRa frequency to use, defaults to `915E6`.\n\nTypically 915E6 for NA/SA/AU/NZ or 866E6 for EU, 433E6 is also an option.\n\n#### LoRa spreading factor\n\nSet the spreading factor for the LoRa transceiver.\n```\nLayer1-\u003esetSpreadingFactor(uint8_t spreadingFactor);\n```\n * `spreadingFactor` - LoRa modulation setting, \"the duration of the chirp\" [reference](https://docs.exploratory.engineering/lora/dr_sf/), defaults to `9`\n\n#### LoRa transmit power\n\nSet the transmit power for the LoRa transceiver\n```\nLayer1-\u003esetTxPower(int txPower);\n```\n * `txPower` - TX power in dB, defaults to `17`\n\n#### Initialize\nTo initialize your Layer 1 interface,  \n```\nLayer1-\u003einit();\n```\n\n#### Other Layer 1 features\n\nThere are few public funtions that are used by LoRaLayer2 and should not need to be called from the main sketch, \n\nCheck outgoing packet buffer and transmit if packet is available,\n```\nint ret = Layer1-\u003etransmit();\n```\n * returns the sequence number of the packet transmitted, if no packet is transmitted, returns `-1`\n\nGet the current time on your Layer 1 device as this may change from device to device (to simulator), \n```\nint time = Layer1-\u003egetTime()\n```\n* returns time in milliseconds.\n\nSend a packet using Layer 1 interface. This will bypass LoRaLayer2 buffers and immeadiately transmit the packet. It should only be used if you know what you are doing,\n```\nLayer1-\u003esendPacket(char* data, int len)\n```\n\n## LoRaLayer2 (LL2)\n\n#### Set node address\n\nManually set the local address of your node, should be run before initializing,\n```\nLL2-\u003esetLocalAddress(char* macString)\n```\n * `macString` - a char array containing the node's address in string form\n\n#### Initialize\n\nIntialize LoRaLayer2,\n```\nLL2-\u003einit()\n```\n\n#### Set broadcast interval\n\nAt any point during operation, you can set the interval between broadcasts of routing packets. To turn off routing packet broadcasts, set the interval to 0. \n```\nLL2-\u003esetInterval(long interval)\n```\n\n * `interval` - in milliseconds, defaults to 1500ms if not called.\n\n#### Routing daemon\n\nCheck in with the LL2 protocol to see if any packets have been received or if any packets need to be sent out. This should be called once inside of your `loop()`. It is non-blocking and acts as a psuedo-asynchronous method for monitoring your packet buffers.\n```\nLL2-\u003edaemon()\n```\n * returns `1` if a packet has been received and is read out of the incoming packet buffer\n * returns `0` if incoming packet buffer is empty.\n\n#### Sending datagrams\n\nSend a datagram to LL2. The datagram will be inspected for a destination, will be given a header with the apporiate next hop and then will be added to outgoing packet buffer and eventually transmitted over the Layer1 interface.\n```\nint ret = LL2-\u003ewriteData(Datagram data, size_t length)\n```\n * `data` - is a datagram, as outlined on [our wiki](https://github.com/sudomesh/disaster-radio/wiki/Layered-Model#layer-3)\n * `len` - length of the entire datagram, typically header length + message length\n * returns `int` representing the packet's place in outgoing buffer\n\n#### Receiving datagrams\n\nTo receive the latest datagram, you must pop the latest packet meant for Layer3 from its LL2 buffer and then extract the datagram\n```\nstruct Packet packet = LL2-\u003ereadData()\n```\n * returns entire LL2 packet, if there is one available\n * returns 0, if there are no packets in the buffer\n\nThe datagram contained in the returned packet can be then be accessed at `packet.datagram`.\n\n#### Other LL2 features\n\nGet current message count,\n```\nuint8_t count = LL2-\u003emessageCount()\n```\n * returnx the number of messages sent by the device since last boot\n\nGet current count of routes,\n```\nint routes = LL2-\u003egetRouteEntry()\n```\n * returns the entry to the routing table at which the next route will be added, which corresponds to a count of discovered routes\n\nRetreive the current local address of your node,\n```\nunint8_t* mac = LL2-\u003elocalAddress()\n```\n * returns a pointer to byte array containing local address of your node\n\nRetreive the loopback address of your node,\n```\nunint8_t* mac = LL2-\u003eloopbackAddr()\n```\n * returns a pointer to byte array containing {0x00, 0x00, 0x00, 0x00}\n\nRetreive the broadcast address of your node,\n```\nunint8_t* mac = LL2-\u003ebroadcastAddr()\n```\n * returns a pointer to byte array containing {0xff, 0xff, 0xff, 0xff}\n\nRetreive the broadcast address of your node,\n```\nunint8_t* mac = LL2-\u003eroutingAddr()\n```\n * returns a pointer to byte array containing {0xaf, 0xff, 0xff, 0xff}\n\nGet neighbor table information,\n```\nLL2-\u003egetNeighborTable(char *out);\n```\n * `out` - a pointer to char array where neighbor table information can be written\n\nGet routing table information,\n```\nLL2-\u003egetRoutingTable(char *out);\n```\n * `out` - a pointer to char array where routing table information can be written\n\n## License and copyright\n* Copyright 2020 Sudo Mesh\n* All files in this repository are dual-licensed under both GPLv3 and AGPLv3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudomesh%2FLoRaLayer2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudomesh%2FLoRaLayer2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudomesh%2FLoRaLayer2/lists"}