{"id":32104843,"url":"https://github.com/meshtastic/LoRaLayer2","last_synced_at":"2025-10-20T05:02:40.439Z","repository":{"id":104330700,"uuid":"254989774","full_name":"meshtastic/LoRaLayer2","owner":"meshtastic","description":"Layer 2 routing protocol for LoRa connected devices","archived":false,"fork":true,"pushed_at":"2020-04-23T04:30:09.000Z","size":171,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-08T00:34:34.139Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"sudomesh/LoRaLayer2","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meshtastic.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,"governance":null}},"created_at":"2020-04-12T01:51:08.000Z","updated_at":"2025-09-25T19:09:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"7422bcd1-9b73-4087-b10c-b85574163d31","html_url":"https://github.com/meshtastic/LoRaLayer2","commit_stats":{"total_commits":67,"total_committers":6,"mean_commits":"11.166666666666666","dds":"0.22388059701492535","last_synced_commit":"14646145af43b79100c4f415b4749fda4ea8fca9"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/meshtastic/LoRaLayer2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshtastic%2FLoRaLayer2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshtastic%2FLoRaLayer2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshtastic%2FLoRaLayer2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshtastic%2FLoRaLayer2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meshtastic","download_url":"https://codeload.github.com/meshtastic/LoRaLayer2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meshtastic%2FLoRaLayer2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280014593,"owners_count":26258647,"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","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-20T05:01:33.920Z","updated_at":"2025-10-20T05:02:40.409Z","avatar_url":"https://github.com/meshtastic.png","language":"C++","funding_links":[],"categories":["C++"],"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.0\n```\nor\n```\nlib_deps = https://github.com/sudomesh/LoRaLayer2#ae513036dc0aa1c7aa002726139052a80e07e617\n```\n\n## Description of library files\n\n`Layer1.h` contains the public functions for the hardware layer 1 and the simulated layer 1. The change of a single variable to swap which Layer 1 code they is being used. Declaring `#define LORA` will enable Layer1_LoRa, while `#define SIM` will enable Layer1_Sim. Theoretically, additional Layer 1 options could be added as they are developed.  \n\n`Layer1_LoRa.cpp` takes features from the real disaster.radio firmware. Acts as the 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  \n\n`Layer1_Sim.cpp` acts as the connection between simulated Layer1 found in https://github.com/sudomesh/disaster-radio-simulator and the Layer 2 routing logic.  \n\n`LoRaLayer2.cpp` and `LoRaLayer2.h` contain the routing logic and manage the routing tables for the main sketch.  \n\n## API\n\nThis library consists of two closely related classes. The Layer1 class and the LoRaLayer2 (or LL2) class.\n\n### Layer1\n\n#### LoRa pins\n\nOverride the default `CS`, `RESET`, and `DIO0` pins used by the library.\n```\nLayer1.setPins(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.init()`.\n\n#### SPI Frequency\n\nSet the frequency of the SPI bus connected to the LoRa transceiver.\n```\nLayer1.setSPIFrequency(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.setLoRaFrequency(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.setSpreadingFactor(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.setTxPower(int txPower);\n```\n * `txPower` - TX power in dB, defaults to `17`\n\n#### Initialize\nTo initialize your Layer 1 interface,  \n```\nLayer1.init();\n```\n\n#### Transmit\nCheck outgoing packet buffer and transmit if packet is available,\n```\nint ret = Layer1.transmit();\n```\n * returns the sequence number of the packet transmitted, if no packet is transmitted, returns `-1`\n\n#### Other Layer 1 features\nGet the current time on your Layer 1 device as this may change from device to device (to simulator), \n```\nint time = Layer1.getTime()\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.sendPacket(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.setLocalAddress(char* macString)\n```\n * `macString` - a char array containing the node's address in string form\n\n#### Initialize\n\nIntialize LoRaLayer2,\n```\nLL2.init()\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.setInterval(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 acts as a psuedo-asynchronous method for monitoring your packet buffers.\n```\nLL2.daemon()\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.writeData(uint8_t* data, size_t length)\n```\n * `data` - byte array formatted as 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 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.readData()\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 can be then be accessed at `packet.data`.\n\n#### Other LL2 features\n\nGet current message count,\n```\nuint8_t count = LL2.messageCount()\n```\n * returnx the number of messages sent by the device since last boot\n\nGet current count of routes,\n```\nint routes = LL2.getRouteEntry()\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.localAddress()\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.loopbackAddr()\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.broadcastAddr()\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.routingAddr()\n```\n * returns a pointer to byte array containing {0xaf, 0xff, 0xff, 0xff}\n\nGet neighbor table information,\n```\ngetNeighborTable(char *out);\n```\n * `out` - a pointer to char array where neighbor table information can be written\n\nGet routing table information,\n```\ngetRoutingTable(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%2Fmeshtastic%2FLoRaLayer2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeshtastic%2FLoRaLayer2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeshtastic%2FLoRaLayer2/lists"}