diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.gitignore b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.gitignore new file mode 100644 index 0000000000..2de98aba16 --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.gitignore @@ -0,0 +1,6 @@ +.pio +.pioenvs +.piolibdeps +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.travis.yml b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.travis.yml new file mode 100644 index 0000000000..7c486f183c --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.vscode/extensions.json b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.vscode/extensions.json new file mode 100644 index 0000000000..e80666bfb1 --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.vscode/settings.json b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.vscode/settings.json new file mode 100644 index 0000000000..d97133835a --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "terminal.integrated.env.windows": { + "PATH": "C:\\Users\\MXB\\.platformio\\penv\\Scripts;C:\\Users\\MXB\\.platformio\\penv;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Users\\MXB\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\MXB\\AppData\\Local\\atom\\bin;C:\\Program Files\\LLVM\\bin;C:\\Users\\MXB\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\MXB\\Programs\\VSCodium\\bin;C:\\Program Files (x86)\\Nmap;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\iCLS\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Users\\MXB\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\MXB\\AppData\\Local\\atom\\bin;C:\\Program Files\\LLVM\\bin;C:\\Users\\MXB\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\MXB\\Programs\\VSCodium\\bin;C:\\Program Files (x86)\\Nmap", + "PLATFORMIO_CALLER": "vscode" + } +} \ No newline at end of file diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/TTGO LoRa32 OLED.JPG b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/TTGO LoRa32 OLED.JPG new file mode 100644 index 0000000000..b60ca17e1a Binary files /dev/null and b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/TTGO LoRa32 OLED.JPG differ diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/include/README b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/include/README new file mode 100644 index 0000000000..194dcd4325 --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/lib/README b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/lib/README new file mode 100644 index 0000000000..6debab1e8b --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/platformio.ini b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/platformio.ini new file mode 100644 index 0000000000..497945367c --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/platformio.ini @@ -0,0 +1,21 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev ;heltec_wifi_lora_32_V2 +framework = arduino +monitor_speed = 115200 + +lib_deps = + https://github.com/gioblu/PJON.git + https://github.com/ThingPulse/esp8266-oled-ssd1306 + https://github.com/sandeepmistry/arduino-LoRa.git + diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/src/main.cpp b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/src/main.cpp new file mode 100644 index 0000000000..5bbfeff078 --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/src/main.cpp @@ -0,0 +1,108 @@ +/** + * @file main.cpp + * @author Michael Branson + * @brief TTGO Lora32 Example of PJON. + * Upload the same code to two devices and they will PJON_BROADCAST to each other, displaying round trip time on the OLED. + * @version 0.1 + * @date 2020-04-18 + * + * @copyright Copyright (c) 2020 + * + */ + +#include +#include + +#define USE_OLED // load screen code +#include "oled.h" + +#define SCK 5 // GPIO5 -- SX1278's SCK +#define MISO 19 // GPIO19 -- SX1278's MISO +#define MOSI 27 // GPIO27 -- SX1278's MOSI +#define SS 18 // GPIO18 -- SX1278's CS +#define RST 14 // GPIO14 -- SX1278's RESET +#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request) + +#define BAND 915000000UL // Match your boards Lora frequencies! + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +#define PJON_INCLUDE_TL +// #define PJON_PACKET_MAX_LENGTH 1024 +#define PJON_INCLUDE_PACKET_ID true + +#include +const uint8_t bus_id[] = {0, 0, 0, 0}; +const uint8_t dev_id = (int)random(1, 255); +PJON bus(bus_id,dev_id); + +int32_t timer2 = millis(); +int32_t dev_heartbeat_frequency = 5000; +uint32_t packet_id{}; +uint32_t timer{}; + +void PrintHex8(uint8_t *data, uint16_t length) // prints 8-bit data in hex with leading zeroes +{ + for (int i=0; i dev_heartbeat_frequency){ + bus.send(0, "P",1,bus.config,++packet_id); + timer = millis(); + timer2 = timer; + oled("Ping "+String(packet_id), 0, true); + + } + bus.update(); + bus.receive(); +} \ No newline at end of file diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/src/oled.h b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/src/oled.h new file mode 100644 index 0000000000..4bda6dfd51 --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/src/oled.h @@ -0,0 +1,46 @@ +#ifndef _OLED_ +#define _OLED_ + +#include + + #define SCREEN_WIDTH 128 // OLED display width, in pixels + #define SCREEN_HEIGHT 64 // OLED display height, in pixels + // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) + #define OLED_RESET 16 // Reset pin # (or -1 if sharing Arduino reset pin) + +#ifdef USE_OLED + #include + SSD1306 display(0x3c, 21, 22); + +#endif + +void oled_setup(){ + #ifdef USE_OLED + pinMode(OLED_RESET,OUTPUT); + digitalWrite(OLED_RESET,LOW); + delay(50); + digitalWrite(OLED_RESET,HIGH); + display.init(); + display.flipScreenVertically(); + display.setFont(ArialMT_Plain_16); + #endif +} + +void oled(String text, int8_t line, bool clear){ + #ifdef USE_OLED + if(clear){ + display.clear(); + } + //display.setTextAlignment(TEXT_ALIGN_LEFT); + //display.setFont(ArialMT_Plain_10); + display.drawStringMaxWidth(0 , (line*20) , 128, " "); + display.drawStringMaxWidth(0 , (line*20) , 128, text); + // for(int8_t x=0;x<5;x++){ + // //display.drawString(0 , (x*15) , lines[x]); + // } + + display.display(); + #endif +} + +#endif \ No newline at end of file diff --git a/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/test/README b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/test/README new file mode 100644 index 0000000000..df5066e64d --- /dev/null +++ b/examples/ESP32/LoRa/PlatformIO/TTGO V2 PJON TX-RX/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html diff --git a/src/PJON.h b/src/PJON.h index 2d6b69b687..c73b338eac 100644 --- a/src/PJON.h +++ b/src/PJON.h @@ -886,6 +886,29 @@ class PJON { strategy.back_off(packets[i].attempts) ) ) { + + #ifdef PJON_INJECT_ATTEMPTS + //mxb added to replace last byte of payload with packet[i].attempts and recalculate checksum + uint16_t new_length = packets[i].length; + if(packets[i].content[1] & PJON_CRC_BIT) { + packets[i].content[packets[i].length-5] = packets[i].attempts; + uint32_t computed_crc = + PJON_crc32::compute((uint8_t *)packets[i].content, new_length - 4); + packets[i].content[new_length - 4] = + (uint8_t)((uint32_t)(computed_crc) >> 24); + packets[i].content[new_length - 3] = + (uint8_t)((uint32_t)(computed_crc) >> 16); + packets[i].content[new_length - 2] = + (uint8_t)((uint32_t)(computed_crc) >> 8); + packets[i].content[new_length - 1] = + (uint8_t)((uint32_t)computed_crc); + } else { + packets[i].content[packets[i].length-1] = packets[i].attempts; + packets[i].content[new_length - 1] = + PJON_crc8::compute((uint8_t *)packets[i].content, new_length - 1); + } + #endif + if(!(sync_ack && async_ack && packets[i].state == PJON_ACK)) packets[i].state = // Avoid resending sync-acked async ack packets send_packet(packets[i].content, packets[i].length);