{"id":29133296,"url":"https://github.com/namnamiot/ardulora","last_synced_at":"2025-06-30T07:02:53.330Z","repository":{"id":156899569,"uuid":"612598898","full_name":"NamNamIoT/ArduLora","owner":"NamNamIoT","description":"Examples for ArduLora board","archived":false,"fork":false,"pushed_at":"2025-06-29T17:43:52.000Z","size":23455,"stargazers_count":62,"open_issues_count":0,"forks_count":12,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-29T17:44:56.716Z","etag":null,"topics":["arduino","ardulora","canopus","lora","lora-application","lora-gateway","lorawan","lorawan-gateway","modbus","namnam","rak3172","rf","rs485","sht3x"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NamNamIoT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"paypal":"namcanopus@gmail.com"}},"created_at":"2023-03-11T12:34:20.000Z","updated_at":"2025-06-29T17:43:55.000Z","dependencies_parsed_at":"2023-12-01T08:39:19.786Z","dependency_job_id":"2e6fea08-eb5f-47b9-9a91-b5c457451e42","html_url":"https://github.com/NamNamIoT/ArduLora","commit_stats":{"total_commits":396,"total_committers":2,"mean_commits":198.0,"dds":"0.10858585858585856","last_synced_commit":"e28bc23175ca6f9f8cba45a39de1af3b866c3477"},"previous_names":["namnamiot/ardulora"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/NamNamIoT/ArduLora","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamNamIoT%2FArduLora","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamNamIoT%2FArduLora/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamNamIoT%2FArduLora/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamNamIoT%2FArduLora/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NamNamIoT","download_url":"https://codeload.github.com/NamNamIoT/ArduLora/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NamNamIoT%2FArduLora/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262727701,"owners_count":23354665,"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":["arduino","ardulora","canopus","lora","lora-application","lora-gateway","lorawan","lorawan-gateway","modbus","namnam","rak3172","rf","rs485","sht3x"],"created_at":"2025-06-30T07:02:52.464Z","updated_at":"2025-06-30T07:02:53.310Z","avatar_url":"https://github.com/NamNamIoT.png","language":null,"funding_links":["namcanopus@gmail.com"],"categories":[],"sub_categories":[],"readme":"\n# ArduLora Board Quick Start Guide  \n\u003cp align=\"left\"\u003e\n\u003ca href=\"https://fb.com/kuem0912\" target=\"blank\"\u003e\u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/facebook.svg\" alt=\"kuem0912\" \nheight=\"30\" width=\"40\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://wa.me/84969809444\" target=\"blank\"\u003e\u003cimg align=\"center\" src=\"https://raw.githubusercontent.com/rahuldkjain/github-profile-readme-generator/master/src/images/icons/Social/whatsapp.svg\" alt=\"84969809444\" height=\"30\" width=\"40\" /\u003e\u003c/a\u003e\n\u003c/p\u003e  \n\n## Content\n* [Information board](#Information-board)\n\t- [Version hardware log](#Version-hardware-log)\n\t- [Hardware Setup](#Hardware-Setup)\n\t- [ArduLora I/O pinout](#ArduLora-I/O-Pins)\n* [Examples](#Examples)\n\t- [How to Use Digital IO](#How-to-Use-Digital-IO)\n\t- [How to Use Analog Input](#How-to-Use-Analog-Input)\n\t- [How to Use Modbus RTU](#How-to-Use-Modbus-RTU)\n\t- [How to Use I2C](#How-to-Use-I2C)\n\t- [How to use Lora P2P](#Lora-P2P)\n\t- [How to use LoraWan](#LoraWan)\n\t- [How to get information System](#System)\n\n\n[![GitHub Repo stars](https://img.shields.io/badge/share%20on-facebook-1976D2?logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/NamNamIoT/ArduLora)\n\n##### Install ArduLora board in IDE Arduino:  \n-[*Install IDE arduino, add ArduLora to manager board and import Canopus library*](https://github.com/NamNamIoT/ArduLora/blob/main/Readme_extension.md)  \n  \n## Information board   \n#### Version hardware log   \n🏷️**Rev1.0: [July-2025].**  \n\n\n\u003cimg src=\"https://github.com/user-attachments/assets/e4db9297-9971-4c09-8c15-fc0017d1340d\" \n     style=\"max-width: 100%; height: auto; object-fit: contain;\"\u003e\n\n## Examples\n### How to Use Digital IO  \n##### Blink led  \n- Use Arduino [digitalWrite](https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/) to write a HIGH or a LOW value to a Digital I/O pin.\n  \n\u003e **tip 📝 NOTE:**  \n\u003e The GPIO Pin Name is the one to be used on the digitalRead and digitalWrite and NOT the pin numbers.\n  \n**Example code blink led on ArduLora board**\n\n```c\nvoid setup()\n{\n  pinMode(PA9, OUTPUT); //Change the PA9 to any digital pin you want. Also, you can set this to INPUT or OUTPUT\n}\n\nvoid loop()\n{\n  digitalWrite(PA9, HIGH); //Change the PA9 to any digital pin you want. Also, you can set this to HIGH or LOW state.\n  delay(1000); // delay for 1 second\n  digitalWrite(PA9, LOW); //Change the PA9 to any digital pin you want. Also, you can set this to HIGH or LOW state.\n  delay(1000); // delay for 1 second\n}\n```\n[Click go top](#Information-board)\n\n### How to Use Analog Input  \n##### Read analog  \nYou can use any of the pins below as Analog Input.\n\n| **Pin Name** | **Onboard** |\n| ------------ | ----------- |\n|  PB4         | AI1         |\n|  PA10        | AI2         |\n\n\nUse Arduino [analogRead](https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/) to read the value from the specified Analog Input pin.\n  \n**Example code read analog on ArduLora board**\n\n```c\nvoid setup() {\n  Serial.begin(115200);  // Initialize serial communication at 115200 baud rate.\n  Serial.println(\"ArduLora Analog Example\");  // Print a message indicating the start of the program.\n  Serial.println(\"------------------------------------------------------\");  // Print a separator line.\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n  analogReadResolution(12);  // Set analog read resolution to 12 bits.\n}\n\nvoid loop() {\n  float AI1 = analogRead(PB4)*2.58;         // Read analog voltage from pin PB4 and store it in AI1.\n  Serial.printf(\"AI1 = %0.0fmV\\r\\n\", AI1); // Print the analog voltage value of AI1 in millivolts.\n\n  float AI2 = analogRead(PA10)*2.58;         // Read analog voltage from pin PA10 and store it in AI2.\n  Serial.printf(\"AI2 = %0.0fmV\\r\\n\", AI2); // Print the analog voltage value of AI2 in millivolts.\n\n  delay(1000);  // Wait for 1 second before the next iteration of the loop.\n}\n\n```\n[Click go top](#Information-board)\n\n### How to Use Modbus RTU  \n##### Modbus master  \n*This example, our board is modbus master.*\n\nModbus RTU use Serial1 on ArduLora board\n\n| **Serial Port**   | **Serial Instance Assignment** |\n| ----------------- | ------------------------------ |\n| UART1 (pins 4, 5) | Serial1                        |\n\n![RAKmodbus](https://user-images.githubusercontent.com/49629370/224534542-f279d2f3-cd5c-4dbe-8af6-d8c383c315a0.PNG)\n\n\n**Example Code modbus master read slave**\n\n##### 📝Note: Make sure you have an ModbusRTU device connected to pin A and B on ArduLora board.\n\n```c\n#include \"Canopus_Modbus.h\"\nModbusMaster node;\nuint8_t result;\nvoid setup()\n{\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n\n  #Led PA8 as output\n  pinMode(PA8, OUTPUT);\n  Serial.begin(115200);\n  Serial.print(\"\\r\\n*****************ArduLora*******************\");\n  Serial_Canopus.begin(9600, SERIAL_8N1);\n}\nvoid loop()\n{\n  //***************READ node 1**************************\n  node.begin(1, Serial_Canopus); //slave ID node\n  Serial.printf(\"\");\n  Serial.printf(\"\\r\\n\\n\\nExample read modbus RTU for ArduLora board\");\n\n  result = node.readHoldingRegisters(0, 10);//Read 40000 to 40009\n  delay(10);\n  if (result == node.ku8MBSuccess) //Read success\n  {\n    for (uint8_t i = 0; i \u003c 10; i ++ )\n    {\n      Serial.printf(\"\\r\\nValue 4000%d: %d\", i, node.getResponseBuffer(i));\n    }\n  }\n  else Serial.print(\"Read Fail node 1\"); //read fail\n  digitalWrite(PA8, !digitalRead(PA8)); //blink led\n  delay(500);\n}\n\n```\n\nThe Arduino Serial Monitor shows the value of register:\n\n```c\nExample read modbus RTU for ArduLora board\nValue 40000: 1\nValue 40001: 2\nValue 40002: 3\nValue 40003: 4\nValue 40004: 5\nValue 40005: 6\nValue 40006: 7\nValue 40007: 8\nValue 40008: 9\nValue 40009: 10\n```\n[Click go top](#Information-board)\n  \n##### Modbus slave  \n*This example, our board is modbus **slave**. Board read analog at PB4 (AI1) and set value register 040001 (FC03, address 1)*  \n**Example Code modbus slave update value register**\n\n```c\n#include \"modbus.h\"\n#include \"modbusDevice.h\"\n#include \"modbusRegBank.h\"\n#include \"modbusSlave.h\"\nmodbusDevice regBank;\nmodbusSlave slave;\n\nvoid setup()\n{\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n\n  //Led PA8 as output\n  pinMode(PA8, OUTPUT);\n  Serial.begin(115200);\n  Serial.print(\"\\r\\n*****************ArduLora*******************\");\n  \n  regBank.setId(1);  //Set id slave\n  regBank.add(40001);  //Add register FC03, holding register, address 1\n  regBank.set(40001,0);  //Set default value for 40001 is 0\n  slave._device = \u0026regBank;\n  slave.setBaud(9600); //Set baudrate 9600\n  \n  analogReadResolution(12);  //Set Resolution adc is 12bit, can upto 14bit\n}\nvoid loop()\n{\n  int analog_In = analogRead(PB4); \n  \n  regBank.set(40001, analog_In);  //Update value for 40001 is analog_In\n  slave.run();  //Run service modbus RTU slave\n  digitalWrite(PA8, !digitalRead(PA8)); //blink led\n  delay(200);\n}\n```\n[Click go top](#Information-board)\n\n### How to Use I2C\n\nThere is one I2C peripheral available on ArduLora.\n\n| **I2C Pin Number** | **I2C Pin Name** |\n| ------------------ | ---------------- |\n| PA12               | I2C_SCL          |\n| PA11               | I2C_SDA          |\n\n\n- Use Arduino [Wire](https://www.arduino.cc/reference/en/language/functions/communication/wire/) library to communicate with I2C devices.\n\n**Example Code I2C**  \n***Scan I2C***  \nMake sure you have an I2C device connected to specified I2C pins to run the I2C scanner code below:\n\n```c\n#include \u003cWire.h\u003e\nvoid setup()\n{\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n  Wire.begin();\n  Serial.begin(115200);\n  while (!Serial);\n  Serial.println(\"\\nI2C Scanner\");\n}\n\nvoid loop()\n{\n  byte error, address;\n  int nDevices;\n  Serial.println(\"Scanning...\");\n  nDevices = 0;\n  for(address = 1; address \u003c 127; address++ )\n  {\n    // The i2c_scanner uses the return value of\n    // the Write.endTransmission to see if\n    // a device did acknowledge to the address.\n    Wire.beginTransmission(address);\n    error = Wire.endTransmission();\n    if (error == 0)\n    {\n      Serial.print(\"I2C device found at address 0x\");\n      if (address\u003c16)\n        Serial.print(\"0\");\n      Serial.print(address,HEX);\n      Serial.println(\"  !\");\n      nDevices++;\n    }\n    else if (error==4)\n    {\n      Serial.print(\"Unknown error at address 0x\");\n      if (address\u003c16)\n        Serial.print(\"0\");\n      Serial.println(address,HEX);\n    }\n  }\n  if (nDevices == 0)\n    Serial.println(\"No I2C devices found\\n\");\n  else\n    Serial.println(\"done\\n\");\n  delay(5000);           // wait 5 seconds for next scan\n}\n```\n\nThe Arduino Serial Monitor shows the I2C device found.\n\n```c\n17:29:15.690 -\u003e Scanning...\n17:29:15.738 -\u003e I2C device found at address 0x28  !\n17:29:15.831 -\u003e done\n17:29:15.831 -\u003e\n17:29:20.686 -\u003e Scanning...\n17:29:20.733 -\u003e I2C device found at address 0x28  !\n17:29:20.814 -\u003e done\n17:29:20.814 -\u003e\n```\n[Click go top](#Information-board)\n\n***Read sensor SHT3X***\n##### SHT3X  \n  ```c\n#include \u003cArduino.h\u003e  // Include the Arduino core library.\n#include \u003cWire.h\u003e  // Include the Wire library for I2C communication.\n#include \u003cArtronShop_SHT3x.h\u003e  // Include the SHT3x library.\nArtronShop_SHT3x sht3x(0x44, \u0026Wire);  // ADDR: 0 =\u003e 0x44, ADDR: 1 =\u003e 0x45\n\nvoid setup() {\n  Serial.begin(115200);  // Initialize serial communication at 115200 baud rate.\n  Serial.print(\"\\r\\n************ArduLora**************\");  // Print a message indicating the start of the program.\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n  delay(100);  // Wait for 100 milliseconds.\n  Wire.begin();  // Initialize the I2C communication.\n  while (!sht3x.begin()) {  // Check if SHT3x sensor is detected.\n    Serial.println(\"SHT3x not found !\");  // Print a message if SHT3x sensor is not detected.\n    delay(1000);  // Wait for 1 second before retrying.\n  }\n}\n\nvoid loop() {\n  if (sht3x.measure()) {  // Check if the measurement is successful.\n    Serial.print(\"Temperature: \");  // Print a label indicating the temperature measurement.\n    Serial.print(sht3x.temperature(), 1);  // Print the temperature value with one decimal place.\n    Serial.print(\" *C\\tHumidity: \");  // Print a label indicating the humidity measurement.\n    Serial.print(sht3x.humidity(), 1);  // Print the humidity value with one decimal place.\n    Serial.print(\" %RH\");  // Print unit (% relative humidity).\n    Serial.println();  // Print a newline character.\n  } else {\n    Serial.println(\"SHT3x read error\");  // Print a message if there is an error reading from the SHT3x sensor.\n  }\n  delay(1000);  // Wait for 1 second before the next measurement.\n}\n\n```\n\nThe Arduino Serial Monitor shows value.\n\n```c\n18:53:24.520 -\u003e Temperature: 33.2 *C\tHumidity: 76.1 %RH\n18:53:25.504 -\u003e Temperature: 33.2 *C\tHumidity: 75.8 %RH\n18:53:26.521 -\u003e Temperature: 33.2 *C\tHumidity: 76.0 %RH\n18:53:27.534 -\u003e Temperature: 33.2 *C\tHumidity: 76.3 %RH\n```\n[Click go top](#Information-board)\n\n***Read sensor BH1750***\n##### BH1750  \n```c\n#include \u003cArduino.h\u003e  // Include the Arduino core library.\n#include \u003cWire.h\u003e  // Include the Wire library for I2C communication.\n#include \u003cArtronShop_BH1750.h\u003e  // Include the BH1750 library.\n\nArtronShop_BH1750 bh1750(0x23, \u0026Wire); // Non Jump ADDR: 0x23, Jump ADDR: 0x5C\n\nvoid setup() {\n  Serial.begin(115200);  // Initialize serial communication at 115200 baud rate.\n  Serial.print(\"\\r\\n************ArduLora**************\");  // Print a message indicating the start of the program.\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n  Wire.begin();  // Initialize the I2C communication.\n  while (!bh1750.begin()) {  // Check if BH1750 sensor is detected.\n    Serial.println(\"BH1750 not found !\");  // Print a message if BH1750 sensor is not detected.\n    delay(1000);  // Wait for 1 second before retrying.\n  }\n}\n\nvoid loop() {\n  Serial.print(\"Light: \");  // Print a label indicating the light intensity measurement.\n  Serial.print(bh1750.light());  // Print the light intensity value.\n  Serial.print(\" lx\");  // Print unit (lux).\n  Serial.println();  // Print a newline character.\n  delay(1000);  // Wait for 1 second before the next measurement.\n}\n```\n\nThe Arduino Serial Monitor shows value.\n\n```c\n19:36:53.106 -\u003e Light: 0.83 lx\n19:36:54.088 -\u003e Light: 0.83 lx\n19:36:55.089 -\u003e Light: 0.83 lx\n19:36:56.103 -\u003e Light: 0.83 lx\n```\n[Click go top](#Information-board)\n\n### Lora P2P\n##### Sender\n```c\nlong startTime;\nbool rx_done = false;\ndouble myFreq = 868000000;\nuint16_t sf = 12, bw = 0, cr = 0, preamble = 8, txPower = 22;\n\nvoid hexDump(uint8_t* buf, uint16_t len) {\n  for (uint16_t i = 0; i \u003c len; i += 16) {\n    char s[len];\n    uint8_t iy = 0;\n    for (uint8_t j = 0; j \u003c 16; j++) {\n      if (i + j \u003c len) {\n        uint8_t c = buf[i + j];\n        if (c \u003e 31 \u0026\u0026 c \u003c 128)\n          s[iy++] = c;\n      }\n    }\n\n    String msg = String(s);\n    Serial.println(msg);\n  }\n}\n\nvoid recv_cb(rui_lora_p2p_recv_t data) {\n  rx_done = true;\n  if (data.BufferSize == 0) {\n    Serial.println(\"Empty buffer.\");\n    return;\n  }\n  digitalWrite(PB2, HIGH);\n  char buff[92];\n  sprintf(buff, \"Incoming message, length: %d, RSSI: %d, SNR: %d\",\n          data.BufferSize, data.Rssi, data.Snr);\n  Serial.println(buff);\n  hexDump(data.Buffer, data.BufferSize);\n  digitalWrite(PB2, LOW);\n}\n\nvoid send_cb(void) {\n  Serial.printf(\"P2P set Rx mode %s\\r\\n\",\n                api.lorawan.precv(65534) ? \"Success\" : \"Fail\");\n}\n\nvoid setup() {\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n\n  //Led PA8 as output\n  pinMode(PA8, OUTPUT);\n\n  //Led PB2 as output\n  pinMode(PB2, OUTPUT);\n  Serial.begin(115200);\n  Serial.println(\"ArduLora LoRaWan P2P Example\");\n  Serial.println(\"------------------------------------------------------\");\n  delay(2000);\n  startTime = millis();\n\n  if (api.lorawan.nwm.get() != 0) {\n    Serial.printf(\"Set Node device work mode %s\\r\\n\",\n                  api.lorawan.nwm.set(0) ? \"Success\" : \"Fail\");\n    api.system.reboot();\n  }\n\n  Serial.println(\"P2P Start\");\n  Serial.printf(\"Hardware ID: %s\\r\\n\", api.system.chipId.get().c_str());\n  Serial.printf(\"Model ID: %s\\r\\n\", api.system.modelId.get().c_str());\n  Serial.printf(\"RUI API Version: %s\\r\\n\",\n                api.system.apiVersion.get().c_str());\n  Serial.printf(\"Firmware Version: %s\\r\\n\",\n                api.system.firmwareVersion.get().c_str());\n  Serial.printf(\"AT Command Version: %s\\r\\n\",\n                api.system.cliVersion.get().c_str());\n  Serial.printf(\"Set P2P mode frequency %3.3f: %s\\r\\n\", (myFreq / 1e6),\n                api.lorawan.pfreq.set(myFreq) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode spreading factor %d: %s\\r\\n\", sf,\n                api.lorawan.psf.set(sf) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode bandwidth %d: %s\\r\\n\", bw,\n                api.lorawan.pbw.set(bw) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode code rate 4/%d: %s\\r\\n\", (cr + 5),\n                api.lorawan.pcr.set(cr) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode preamble length %d: %s\\r\\n\", preamble,\n                api.lorawan.ppl.set(preamble) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode tx power %d: %s\\r\\n\", txPower,\n                api.lorawan.ptp.set(txPower) ? \"Success\" : \"Fail\");\n  api.lorawan.registerPRecvCallback(recv_cb);\n  api.lorawan.registerPSendCallback(send_cb);\n  Serial.printf(\"P2P set Rx mode %s\\r\\n\",\n                api.lorawan.precv(65534) ? \"Success\" : \"Fail\");\n}\n\nvoid loop() {\n  uint8_t payload[] = \"payload\";\n  bool send_result = false;\n  while (!send_result) {\n    send_result = api.lorawan.psend(sizeof(payload), payload);\n    if (!send_result) {\n      api.lorawan.precv(0);\n      delay(1000);\n    }\n  }\n  Serial.printf(\"P2P send Success\\r\\n\");\n  delay(1000);\n  digitalWrite(PA8, !digitalRead(PA8));\n}\n```\n[Click go top](#Information-board)\n\n##### Receive\n```c\nlong startTime;\nbool rx_done = false;\ndouble myFreq = 868000000;\nuint16_t sf = 12, bw = 0, cr = 0, preamble = 8, txPower = 22;\n\nvoid recv_cb(rui_lora_p2p_recv_t data) {\n  rx_done = true;\n  if (data.BufferSize == 0) {\n    Serial.println(\"Empty buffer.\");\n    return;\n  }\n  digitalWrite(PB2, HIGH);\n  char buff[92];\n  sprintf(buff, \"Incoming message, length: %d, RSSI: %d, SNR: %d\",\n          data.BufferSize, data.Rssi, data.Snr);\n  Serial.println(buff);\n  digitalWrite(PB2, LOW);\n}\n\nvoid send_cb(void) {\n  Serial.printf(\"P2P set Rx mode %s\\r\\n\",\n                api.lorawan.precv(65534) ? \"Success\" : \"Fail\");\n}\n\nvoid setup() {\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n\n  //Led PA8 as output\n  pinMode(PA8, OUTPUT);\n  //Led PA9 as output\n  pinMode(PA9, OUTPUT);\n  //Led PB2 as output\n  pinMode(PB2, OUTPUT);\n  Serial.begin(115200);\n  Serial.println(\"ArduLora LoRaWan P2P Example\");\n  Serial.println(\"------------------------------------------------------\");\n  delay(2000);\n  startTime = millis();\n\n  if (api.lorawan.nwm.get() != 0) {\n    Serial.printf(\"Set Node device work mode %s\\r\\n\",\n                  api.lorawan.nwm.set(0) ? \"Success\" : \"Fail\");\n    api.system.reboot();\n  }\n\n  Serial.println(\"P2P Start\");\n  Serial.printf(\"Hardware ID: %s\\r\\n\", api.system.chipId.get().c_str());\n  Serial.printf(\"Model ID: %s\\r\\n\", api.system.modelId.get().c_str());\n  Serial.printf(\"RUI API Version: %s\\r\\n\",\n                api.system.apiVersion.get().c_str());\n  Serial.printf(\"Firmware Version: %s\\r\\n\",\n                api.system.firmwareVersion.get().c_str());\n  Serial.printf(\"AT Command Version: %s\\r\\n\",\n                api.system.cliVersion.get().c_str());\n  Serial.printf(\"Set P2P mode frequency %3.3f: %s\\r\\n\", (myFreq / 1e6),\n                api.lorawan.pfreq.set(myFreq) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode spreading factor %d: %s\\r\\n\", sf,\n                api.lorawan.psf.set(sf) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode bandwidth %d: %s\\r\\n\", bw,\n                api.lorawan.pbw.set(bw) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode code rate 4/%d: %s\\r\\n\", (cr + 5),\n                api.lorawan.pcr.set(cr) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode preamble length %d: %s\\r\\n\", preamble,\n                api.lorawan.ppl.set(preamble) ? \"Success\" : \"Fail\");\n  Serial.printf(\"Set P2P mode tx power %d: %s\\r\\n\", txPower,\n                api.lorawan.ptp.set(txPower) ? \"Success\" : \"Fail\");\n  api.lorawan.registerPRecvCallback(recv_cb);\n  api.lorawan.registerPSendCallback(send_cb);\n  Serial.printf(\"P2P set Rx mode %s\\r\\n\",\n                api.lorawan.precv(65534) ? \"Success\" : \"Fail\");\n}\n\nvoid loop() {\n  uint8_t payload[] = \"payload_B\";\n  bool send_result = false;\n  if (rx_done) {\n    rx_done = false;\n    while (!send_result) {\n      digitalWrite(PA9, HIGH);\n      send_result = api.lorawan.psend(sizeof(payload), payload);\n      Serial.printf(\"P2P send %s\\r\\n\", send_result ? \"Success\" : \"Fail\");\n      if (!send_result) {\n        Serial.printf(\"P2P finish Rx mode %s\\r\\n\", api.lorawan.precv(0) ? \"Success\" : \"Fail\");\n        delay(1000);\n      }\n    }\n    digitalWrite(PA9, LOW);\n  }\n  delay(500);\n  digitalWrite(PA8, !digitalRead(PA8));\n}\n```\n[Click go top](#Information-board)\n\n### System\n##### Powersave\n```c\nvoid setup()\n{\n    Serial.begin(115200);\n    Serial.println(\"RAKwireless System Powersave Example\");\n    Serial.println(\"------------------------------------------------------\");\n}\n\nvoid loop()\n{\n    Serial.print(\"The timestamp before sleeping: \");\n    Serial.print(millis());\n    Serial.println(\" ms\");\n    Serial.println(\"(Wait 10 seconds or Press any key to wakeup)\");\n    api.system.sleep.all(10000);\n    Serial.print(\"The timestamp after sleeping: \");\n    Serial.print(millis());\n    Serial.println(\" ms\");\n}\n```\n[Click go top](#Information-board)\n\n##### Time\n```c\n/***\n *  This example shows time function, including millis, micros, delay, delayMicroseconds.\n***/\nlong delayTime = 1000;\t\t// variable for setting the delay time \n\nvoid setup()\n{\n    // initialize serial communication at 115200 bits per second\n    Serial.begin(115200);\n    Serial.println(\"RAKwireless Arduino Time Example\");\n    Serial.println(\"------------------------------------------------------\");\n}\n\nvoid loop()\n{\n    Serial.println(\"Now Time:\");\n    Serial.print(\"millis(): \");\n    Serial.println(millis());\t// show the time with millis\n    Serial.print(\"micros(): \");\n    Serial.println(micros());\t// show the time with micros\n  \n    Serial.printf(\"After Delay %d milliseconds\\n\", delayTime);\n    delay(delayTime);\t\t// delay time (second)\n    Serial.print(\"millis(): \");\n    Serial.println(millis());\t// show the time with millis\n    Serial.print(\"micros(): \");\n    Serial.println(micros());\t// show the time with micros\n  \n    Serial.printf(\"After Delay %d microseconds\\n\", delayTime);\n    delayMicroseconds(delayTime);\t// delay time (Microseconds)\n    Serial.print(\"millis(): \");\n    Serial.println(millis());\t// show the time with millis\n    Serial.print(\"micros(): \");\n    Serial.println(micros());\t// show the time with micros\n  \n    Serial.println(\"\");\n  \n    delayTime += 1000;\t\t// delay time add 1000\n  \n    delay(5000);\n}\n```\n[Click go top](#Information-board)\n\n##### Timer\n```c\nvoid handler(void *data)\n{\n    Serial.printf(\"[%lu]This is the handler of timer #%d\\r\\n\", millis(), (int)data);\n    /* Actually, the handler is not executed in interrupt context. The real ISR for timer just sends an event to the system event queue.\n     * If main loop found there is any event in the event queue, the handler for that event will be processed. */\n}\n\nvoid setup()\n{\n    Serial.begin(115200);\n    Serial.println(\"RAKwireless System Timer Example\");\n    Serial.println(\"------------------------------------------------------\");\n  \n    for (int i = 0 ; i \u003c RAK_TIMER_ID_MAX ; i++) {\n        if (api.system.timer.create((RAK_TIMER_ID)i, (RAK_TIMER_HANDLER)handler, RAK_TIMER_PERIODIC) != true) {\n            Serial.printf(\"Creating timer #%d failed.\\r\\n\", i);\n            continue;\n        }\n        if (api.system.timer.start((RAK_TIMER_ID)i, (i+1)*1000, (void *)i) != true) {\n            Serial.printf(\"Starting timer #%d failed.\\r\\n\", i);\n            continue;\n        }\n    }\n}\n\nvoid loop()\n{\n}\n```\n[Click go top](#Information-board)\n\n##### General\n```c\n/***\n *  This example print the device information.\n***/\nint i;\nvoid setup()\n{\n    Serial.begin(115200);\n    Serial.println(\"RAKwireless System General Example\");\n    Serial.println(\"------------------------------------------------------\");\n    api.system.restoreDefault();\n}\n\nvoid loop()\n{\n    if (++i == 20) {\n        Serial.printf(\"Reboot now..\\r\\n\");\n        api.system.reboot();\n    }\n    Serial.printf(\"===Loop %d==\\r\\n\", i);\n    Serial.printf(\"Firmware Version: %s\\r\\n\",\n\t\tapi.system.firmwareVersion.get().c_str());\n    Serial.printf(\"AT Command Version: %s\\r\\n\",\n\t\tapi.system.cliVersion.get().c_str());\n    Serial.printf(\"RUI API Version: %s\\r\\n\",\n\t\tapi.system.apiVersion.get().c_str());\n    Serial.printf(\"Model ID: %s\\r\\n\", api.system.modelId.get().c_str());\n    Serial.printf(\"Hardware ID: %s\\r\\n\", api.system.chipId.get().c_str());\n    Serial.printf(\"Battery Level: %0.1f\\r\\n\", api.system.bat.get());\n    delay(1000);\n}\n```\n\n##### GPS\n```c\n#include \u003cTinyGPSPlus.h\u003e\n\nTinyGPSPlus gps; //GPS ATGM336H\nvoid setup() {\n  Serial.begin(115200);\n  Serial1.begin(9600);\n  //Enable power for external sensor\n  pinMode(PB5, OUTPUT);\n  digitalWrite(PB5, HIGH);\n  while (Serial1.available()) {\n    Serial1.read();\n  }\n}\n\nvoid loop() {\n  while (Serial1.available() \u003e 0) {\n    gps.encode(Serial1.read());\n  }\n  float gps_lat = gps.location.lat();\n  float gps_lng = gps.location.lng();\n  float gps_speed = gps.speed.mps();\n}\n```\n\n  \n### Continue update  \n[Click go top](#Information-board)  \n  \n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/NamNamIoT/ArduLora/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamnamiot%2Fardulora","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnamnamiot%2Fardulora","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamnamiot%2Fardulora/lists"}