diff --git a/LICENSE.md b/LICENSE.md
index 7c67cd6df8..68d4263ced 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,6 +1,6 @@
-All the software included in this project is experimental and it is distributed "AS IS" without any warranty, use it at your own risk. All specifications, all related software implementations and documentation released as a part of this repository are and will always remain free for personal, educational, experimental and commercial purposes.
+All the software included in this project is experimental and it is distributed "AS IS" without any warranty, use it at your own risk.
-Giovanni Blu Mitolo (gioscarab@gmail.com) Copyright 2010-2020
+Giovanni Blu Mitolo (gioscarab@gmail.com) Copyright 2010-2025
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
diff --git a/README.md b/README.md
index 61ac521b31..0708bc136c 100644
--- a/README.md
+++ b/README.md
@@ -1,48 +1,40 @@
+
-
-## PJON 12.1
-PJON® (Padded Jittering Operative Network) is an arduino-compatible, multi-master, multi-media network protocol. It proposes a new Open Standard, it is designed as a framework and implements a totally software-defined network protocol stack that can be easily cross-compiled on many MCUs and architectures like ATtiny, ATmega, SAMD, ESP8266, ESP32, STM32, Teensy, Raspberry Pi, Linux, Windows x86, Apple and Android. PJON operates on a wide range of media and protocols like TCP, UDP, MQTT, ESPNOW, USB, Serial, RS485, LoRa, PJDL, PJDLR and PJDLS.
+## PJON 13.1
+
+PJON (Padded Jittering Operative Network) is an experimental, multi-master, software-defined network protocol that can be easily cross-compiled for many microcontrollers and real-time operating systems such as ATtiny, ATmega, SAMD, ESP8266, ESP32, STM32, Teensy, Raspberry Pi, Zephyr, Linux, Windows x86, Apple, and Android. PJON operates over a wide range of media, data links, and existing protocols like PJDL, PJDLR, PJDLS, Serial, RS485, USB, ASK/FSK, LoRa, UDP, TCP, MQTT, and ESPNOW. For more information, visit the [documentation](documentation/README.md), the [specification](specification/PJON-protocol-specification-v4.0.md), or the [wiki](https://github.com/gioblu/PJON/wiki).
-[](http://www.pjon.org/get-bus-id.php)
[](https://gitter.im/gioblu/PJON?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-PJON is used in thousands of devices and its community has spread worldwide because of the following 5 key factors:
-- **New technology**: [PJON](specification/PJON-protocol-specification-v3.2.md) is an experimental network protocol stack crafted in 10 years of research and experimentation. It was originally developed as an open-source alternative to i2c and 1-Wire but during development its scope and features have been extended to cover use cases where IP is generally applied. PJON has been engineered to have a variable footprint (4.2-8.2 kB program memory) and overhead (5-22 bytes per packet) depending on its configuration.
-- **Multi-media support**: PJON operates on a wide range of media and protocols like TCP, UDP, MQTT, ESPNOW, USB, Serial, RS485 and LoRa. The PJON network protocol stack specifies and implements also [PJDL](src/strategies/SoftwareBitBang/specification/PJDL-specification-v4.1.md) able to communicate data over a single wire shared by up to 255 devices, [PJDLR](src/strategies/OverSampling/specification/PJDLR-specification-v3.0.md) able to operate with many ASK/FSK/OOK radio modules and also [PJDLS](src/strategies/AnalogSampling/specification/PJDLS-specification-v2.0.md), able to communicate wirelessly with light pulses using off the shelf LEDs and laser diodes.
-- **Increased reliability**: Many protocols massively applied worldwide expose dangerous vulnerabilities, have weak error detection algorithms and are not resilient to interference. PJON is based on years of analysis and study not to make the same mistakes present in most alternatives and provide with a set of simpler and more efficient solutions.
-- **High flexibility**: PJON is totally software-defined and its implementation is designed to be easily extensible. it builds out-of-the-box in all supported devices and operates transparently on top of any supported protocol or medium.
-- **Low cost**: Without any additional hardware needed to operate, minimal network wiring requirements and direct pin-to-pin or LED-to-LED communication, PJON is extremely energy efficient, cheap to be implemented and maintained. This implementation is kept updated and meticulously tested thanks to the strong commitment of its growing community of end users, testers and developers.
+### Why PJON?
+- **New technology**: [PJON](specification/PJON-protocol-specification-v4.0.md) is an experimental network protocol stack crafted through 10 years of research and experimentation. It was originally developed as an open-source alternative to i2c and 1-Wire, but during development, its scope and features were extended to cover use cases where IP is generally applied. PJON has been engineered to have a variable footprint (4.2–8.2 kB program memory) and overhead (5–35 bytes per packet) depending on its configuration.
+- **Multi-media support**: PJON operates over a wide range of protocols including TCP, UDP, MQTT, ESPNOW, USB, Serial, RS485, and LoRa. The PJON network protocol stack also specifies and implements [PJDL](src/strategies/SoftwareBitBang/specification/PJDL-specification-v5.0.md) that operates over a single wire of up to 2000m shared by up to 255 devices, [PJDLR](src/strategies/OverSampling/specification/PJDLR-specification-v3.0.md) that operates with many ASK/FSK/OOK radio modules and [PJDLS](src/strategies/AnalogSampling/specification/PJDLS-specification-v2.0.md) that operates wirelessly with light pulses using off-the-shelf LEDs and laser diodes.
+- **Increased reliability**: Many widely applied protocols expose significant vulnerabilities, have weak error detection algorithms, and are not resilient to interference. PJON is based on years of analysis and study to avoid the mistakes present in most alternatives and provide with a simpler and more efficient solution.
+- **High flexibility**: PJON is fully software-defined and designed to be easily extensible. It builds out-of-the-box on all supported devices and operates transparently on top of any supported protocol or medium.
+- **Low cost**: With no additional hardware needed to operate, minimal network wiring requirements, and direct pin-to-pin or LED-to-LED communication, PJON is extremely energy-efficient, inexpensive to implement, and maintain. This experimental reference implementation is kept up to date thanks to the strong commitment of its growing community.
### Features
-- Cross-compilation support with the [interfaces](src/interfaces) system calls abstraction
-- Multi-media support with the [strategies](src/strategies) data link layer abstraction
-- Hot-swap support, no need of system reset or shut down when replacing or adding devices
-- Configurable synchronous and/or asynchronous [acknowledgement](specification/PJON-protocol-acknowledge-specification-v1.0.md)
-- Configurable 2 level addressing (device and bus id) for scalable applications
-- Configurable 1 or 2 bytes packet length (max 255 or 65535 bytes)
-- Configurable CRC8 or CRC32 table-less cyclic redundancy check
-- Packet manager to handle, track and if necessary retransmit a packet sending in background
-- Error handling
-
-### Specifications
-- [PJON v3.2](specification/PJON-protocol-specification-v3.2.md)
-- [PJON Acknowledge v1.0](specification/PJON-protocol-acknowledge-specification-v1.0.md)
-- [PJDL v4.1](src/strategies/SoftwareBitBang/specification/PJDL-specification-v4.1.md) - [PJDLR v3.0](src/strategies/OverSampling/specification/PJDLR-specification-v3.0.md) - [PJDLS v2.0](src/strategies/AnalogSampling/specification/PJDLS-specification-v2.0.md) - [TSDL v2.1](src/strategies/ThroughSerial/specification/TSDL-specification-v2.1.md)
-
-### Publications
-- [PJON protocol handbook](https://www.pjon-technologies.com/collections/frontpage/products/pjon-protocol-hand-book) by Giovanni Blu Mitolo - Distributed by [PJON Technologies srl](https://www.pjon-technologies.com)
-- [PJON 12.0 big box](https://www.pjon-technologies.com/collections/frontpage/products/pjon-protocol-12-0-big-box) by Giovanni Blu Mitolo - Distributed by [PJON Technologies srl](https://www.pjon-technologies.com)
+- Cross-compilation support with the [interfaces](src/interfaces) system calls abstraction.
+- Multi-media support with the [strategies](src/strategies) data link layer abstraction.
+- Modular packet format that includes only the fields used (overhead 5–35 bytes).
+- Hot-swap support, no need for a system reset or shutdown when replacing or adding devices.
+- Flexible local (device ID) and shared (bus ID) network identification.
+- Safe error detection using modern CRC8 and CRC32 polynomials.
+- Optional inclusion of MAC addresses.
+- Optional acknowledgement.
+- Error handling.
### Academic studies
-Researchers are active in many universities worldwide using PJON in different environments. The following list contains all the known published academic studies about PJON:
-- [Definition and Application of PJON-PLC for sensor networks](https://repositorio.unican.es/xmlui/bitstream/handle/10902/14012/408952.pdf?sequence=1) by Jorge Gómez Segurola, Ingeniería de Tecnologías de
-Telecomunicación - [Universidad de Cantabria](https://web.unican.es/) (ES)
-- [Biomimetic electronics](http://c.harl.ie/biomimetic.html) by Charlie Williams with scientific input from researchers Vítor Martins dos Santos, Diana Machado de Sousa and Sabine Vreeburg - Artist in Residency at [Wageningen University](https://www.wur.nl/en.htm) (NL)
+Researchers are active in many universities worldwide using PJON in different environments. The following list contains known published academic studies about PJON:
+- [Definition and Application of PJON-PLC for sensor networks](https://repositorio.unican.es/xmlui/bitstream/handle/10902/14012/408952.pdf?sequence=1) by Jorge Gómez Segurola, Ingeniería de Tecnologías de Telecomunicación - [Universidad de Cantabria](https://web.unican.es/) (ES).
+- [Biomimetic electronics](https://charliewilliams.org/portfolio/biomimetic/) by Charlie Williams with scientific input from researchers Vítor Martins dos Santos, Diana Machado de Sousa, and Sabine Vreeburg - Artist in Residency at [Wageningen University](https://www.wur.nl/en.htm) (NL).
+- [LANC Video Camera Control](http://jda.tel/pdf/lanc_video_camera_control.pdf) by [Jack Anderson](https://github.com/jdaandersj) - Department of Computer Science [Loughborough University](https://www.lboro.ac.uk/departments/compsci/) (UK).
+- [Implementation of a PJON hardware peripheral for the Croc SoC](https://github.com/piussieber/pjon_on_croc) by [Pius Sieber](https://github.com/piussieber/) - [ETH Zurich](https://ethz.ch/) (CH)
### Contribute
Feel free to send a pull request sharing something you have made that could help, if you want to support this project you can also try to solve an [issue](https://github.com/gioblu/PJON/issues). Thanks to support, expertise, kindness and talent of the following contributors, the protocol's documentation, specification and implementation have been strongly tested, enhanced and verified:
-[Fred Larsen](https://github.com/fredilarsen), [Zbigniew Zasieczny](https://github.com/girgitt), [Matheus Garbelini](https://github.com/Matheus-Garbelini), [sticilface](https://github.com/sticilface), [Felix Barbalet](https://github.com/xlfe), [Oleh Halitskiy](https://github.com/Halytskyi), [fabpolli](https://github.com/fabpolli), [Adrian Sławiński](https://github.com/4ib3r), [Osman Selçuk Aktepe](https://github.com/osman-aktepe), [Jorgen-VikingGod](https://github.com/Jorgen-VikingGod), [drtrigon](https://github.com/drtrigon), [Endre Karlson](https://github.com/ekarlso), [Wilfried Klaas](https://github.com/willie68), [budaics](https://github.com/budaics), [ibantxo](https://github.com/ibantxo), [gonnavis](https://github.com/gonnavis), [maxidroms83](https://github.com/maxidroms83), [Evgeny Dontsov](https://github.com/dontsovcmc), [zcattacz](https://github.com/zcattacz), [Valerii Koval](https://github.com/valeros), [Ivan Kravets](https://github.com/ivankravets), [Esben Soeltoft](https://github.com/EsbenSoeltoft), [Alex Grishin](https://github.com/240974a), [Andrew Grande](https://github.com/aperepel), [Michael Teeww](https://github.com/MichMich), [Paolo Paolucci](https://github.com/PaoloP74), [per1234](https://github.com/per1234), [Santiago Castro](https://github.com/bryant1410), [pacproduct](https://github.com/pacproduct), [elusive-code](https://github.com/elusive-code), [Emanuele Iannone](https://github.com/eiannone), [Christian Pointner](https://github.com/equinox0815), [Fabian Gärtner](https://github.com/TeeTrizZz), [Mauro Mombelli](https://github.com/MauroMombelli), [Remo Kallio](https://github.com/shacal), [hyndruide](https://github.com/hyndruide), [sigmaeo](https://github.com/sigmaeo), [filogranaf](https://github.com/filogranaf), [Maximiliano Duarte](https://github.com/domonetic), [Viktor Szépe](https://github.com/szepeviktor), [Shachar Limor](), [Pantovich](), [Mauro Zancarlin](), [Franketto](), [jzobac](), [DanRoad](), [fcastrovilli](https://github.com/fcastrovilli), [Andrei Volkau](https://github.com/andrei-volkau), [maniekq](https://github.com/maniekq), [DetAtHome](https://github.com/DetAtHome), [Michael Branson](https://github.com/mxbranson), [chestwood96](https://github.com/chestwood96), [Mattze96](https://github.com/Mattze96), [Steven Bense](https://github.com/justoke), [Jack Anderson](https://github.com/jdaandersj) and [callalilychen](https://github.com/callalilychen).
+[Fred Larsen](https://github.com/fredilarsen), [Zbigniew Zasieczny](https://github.com/girgitt), [Matheus Garbelini](https://github.com/Matheus-Garbelini), [sticilface](https://github.com/sticilface), [Felix Barbalet](https://github.com/xlfe), [Oleh Halitskiy](https://github.com/Halytskyi), [fotosettore](https://github.com/fotosettore), [fabpolli](https://github.com/fabpolli), [Adrian Sławiński](https://github.com/4ib3r), [Osman Selçuk Aktepe](https://github.com/osman-aktepe), [Jorgen-VikingGod](https://github.com/Jorgen-VikingGod), [drtrigon](https://github.com/drtrigon), [Endre Karlson](https://github.com/ekarlso), [Wilfried Klaas](https://github.com/willie68), [budaics](https://github.com/budaics), [ibantxo](https://github.com/ibantxo), [gonnavis](https://github.com/gonnavis), [maxidroms83](https://github.com/maxidroms83), [Evgeny Dontsov](https://github.com/dontsovcmc), [zcattacz](https://github.com/zcattacz), [Valerii Koval](https://github.com/valeros), [Ivan Kravets](https://github.com/ivankravets), [Esben Soeltoft](https://github.com/EsbenSoeltoft), [Alex Grishin](https://github.com/240974a), [Andrew Grande](https://github.com/aperepel), [Michael Teeww](https://github.com/MichMich), [Paolo Paolucci](https://github.com/PaoloP74), [per1234](https://github.com/per1234), [Santiago Castro](https://github.com/bryant1410), [pacproduct](https://github.com/pacproduct), [elusive-code](https://github.com/elusive-code), [Emanuele Iannone](https://github.com/eiannone), [Christian Pointner](https://github.com/equinox0815), [Fabian Gärtner](https://github.com/TeeTrizZz), [Mauro Mombelli](https://github.com/MauroMombelli), [Remo Kallio](https://github.com/shacal), [hyndruide](https://github.com/hyndruide), [sigmaeo](https://github.com/sigmaeo), [filogranaf](https://github.com/filogranaf), [Maximiliano Duarte](https://github.com/domonetic), [Viktor Szépe](https://github.com/szepeviktor), [Shachar Limor](), [Pantovich](), [Mauro Zancarlin](), [Franketto](), [jzobac](), [DanRoad](), [fcastrovilli](https://github.com/fcastrovilli), [Andrei Volkau](https://github.com/andrei-volkau), [maniekq](https://github.com/maniekq), [DetAtHome](https://github.com/DetAtHome), [Michael Branson](https://github.com/mxbranson), [chestwood96](https://github.com/chestwood96), [Mattze96](https://github.com/Mattze96), [Steven Bense](https://github.com/justoke), [Jack Anderson](https://github.com/jdaandersj), [callalilychen](https://github.com/callalilychen), [Julio Aguirre](https://github.com/jcallano), [Cimex97](https://github.com/Cimex97), [der-schne](https://github.com/der-schne), [porkyneal](https://github.com/porkyneal), [der-schne](https://github.com/der-schne), [Rainer Schoenberger](https://github.com/rainerschoe), [jgOhYeah](https://github.com/jgOhYeah) and [kuchendieb](https://github.com/kuchendieb).
### Compliant tools
- [ModuleInterface](https://github.com/fredilarsen/ModuleInterface) - easy config and value sync between IoT modules by Fred Larsen
@@ -50,9 +42,10 @@ Feel free to send a pull request sharing something you have made that could help
- [PJON-piper](https://github.com/Girgitt/PJON-piper) - command line wrapper by Zbigniew Zasieczny
- [PJON-python](https://github.com/Girgitt/PJON-python) - python interface by Zbigniew Zasieczny
- [PJON-gRPC](https://github.com/Halytskyi/PJON-gRPC) - gRPC server-client by Oleh Halytskyi
+- [PjonHL](https://github.com/rainerschoe/PjonHL) - PjonHL is a highlevel wrapper around PJON
### License
-All the software included in this project is experimental and it is distributed "AS IS" without any warranty, use it at your own risk. [Licensed](https://github.com/gioblu/PJON/blob/master/LICENSE.md) under the Apache License, Version 2.0. PJON® and its brand are registered trademarks, property of Giovanni Blu Mitolo gioscarab@gmail.com
+All the software included in this project is experimental and it is distributed "AS IS" without any warranty, use it at your own risk. [Licensed](https://github.com/gioblu/PJON/blob/master/LICENSE.md) under the Apache License, Version 2.0.
### Safety warning
-When installing or maintaining a PJON network, extreme care must be taken to avoid any danger. If devices are connected to AC power you are exposed to a high chance of being electrocuted if hardware is not installed carefully and properly. If you are not experienced enough ask the support of a skilled technician and consider that many countries prohibit uncertified installations. When a [SoftwareBitBang](/src/strategies/SoftwareBitBang) bus is installed [interference mitigation](https://github.com/gioblu/PJON/wiki/Mitigate-interference) and [protective circuitry](https://github.com/gioblu/PJON/wiki/Protective-circuitry) guidelines must be followed. When working with an [AnalogSampling](/src/strategies/AnalogSampling) LED or laser based setup safety glasses must be worn and transceivers must be operated cautiously to avoid potential eye injuries. Before any practical test or a hardware purchase for a wireless [OverSampling](/src/strategies/OverSampling), [ThroughSerial](/src/strategies/ThroughSerial) or [ThroughLoRa](/src/strategies/ThroughLoRa) radio setup, compliance with government requirements and regulations must be ensured. When connecting a local bus to the internet all devices must be considered potentially compromised, manipulated or remotely actuated against your will. It should be considered a good practice not to connect to the internet systems that may create a damage (fire, flood, data-leak) if hacked.
+When testing PJON, take extreme care to avoid any danger. The implementation is experimental and may not behave as expected; use it at your own risk. If devices are connected to AC power, you face a high risk of electrocution unless the hardware is installed carefully and correctly. If you lack sufficient experience, seek assistance from a qualified technician, and be aware that many countries prohibit uncertified installations. When testing a [SoftwareBitBang](/src/strategies/SoftwareBitBang) bus follow [interference-mitigation](https://github.com/gioblu/PJON/wiki/Mitigate-interference) and [protective-circuitry](https://github.com/gioblu/PJON/wiki/Protective-circuitry) guidelines. When experimenting with an AnalogSampling setup, wear safety glasses and operate transceivers cautiously to prevent eye injuries. Before testing [OverSampling](/src/strategies/OverSampling), [ThroughSerial](/src/strategies/ThroughSerial) or [ThroughLoRa](/src/strategies/ThroughLoRa) radio communication, ensure that the frequency, power, and hardware comply with local regulations. When connecting a local bus to the Internet, treat all devices as potentially compromised, manipulated, or remotely actuated against your will. As a best practice, avoid connecting to the internet systems that could cause damage (fire, flood, data leakage) if hacked.
diff --git a/SECURITY.md b/SECURITY.md
index 9054f1c040..c0823f531e 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -4,7 +4,7 @@ PJON is still in experimental phase and it distributed "AS IS" without any warra
The security of a system that uses PJON for communication mostly depends on the vulnerabilities exposed by the hardware and by the physical layer used. Consider that **only air-gapped wired local buses are undoubtely secure**. When connecting a local bus to the internet using [ESPNOW](/src/strategies/ESPNOW), [EthernetTCP](/src/strategies/EthernetTCP) or [LocalUDP](/src/strategies/LocalUDP), [GlobalUDP](/src/strategies/GlobalUDP) or [DualUDP](/src/strategies/DualUDP), all connected devices must be considered potentially compromised. It should be considered a good practice not to connect to the internet systems that may cause damage (fire, flood, data-leak) if hacked.
### Safety warning
-When installing or maintaining a PJON network, extreme care must be taken to avoid any danger. If devices are connected to AC power you are exposed to a high chance of being electrocuted if hardware is not installed carefully and properly. If you are not experienced enough ask the support of a skilled technician and consider that many countries prohibit uncertified installations. When a [SoftwareBitBang](/src/strategies/SoftwareBitBang) bus is installed [interference mitigation](https://github.com/gioblu/PJON/wiki/Mitigate-interference) and [protective circuitry](https://github.com/gioblu/PJON/wiki/Protective-circuitry) guidelines must be followed. When working with an [AnalogSampling](/src/strategies/AnalogSampling) LED or laser based setup safety glasses must be worn and transceivers must be operated cautiously to avoid potential eye injuries. Before any practical test or a hardware purchase for a wireless [OverSampling](/src/strategies/OverSampling), [ThroughSerial](/src/strategies/ThroughSerial) or [ThroughLoRa](/src/strategies/ThroughLoRa) radio setup, compliance with government requirements and regulations must be ensured.
+When testing PJON, take extreme care to avoid any danger. The implementation is experimental and may not behave as expected; use it at your own risk. If devices are connected to AC power, you face a high risk of electrocution unless the hardware is installed carefully and correctly. If you lack sufficient experience, seek assistance from a qualified technician, and be aware that many countries prohibit uncertified installations. When testing a [SoftwareBitBang](/src/strategies/SoftwareBitBang) bus follow [interference-mitigation](https://github.com/gioblu/PJON/wiki/Mitigate-interference) and [protective-circuitry](https://github.com/gioblu/PJON/wiki/Protective-circuitry) guidelines. When experimenting with an AnalogSampling setup, wear safety glasses and operate transceivers cautiously to prevent eye injuries. Before testing [OverSampling](/src/strategies/OverSampling), [ThroughSerial](/src/strategies/ThroughSerial) or [ThroughLoRa](/src/strategies/ThroughLoRa) radio communication, ensure that the frequency, power, and hardware comply with local regulations. When connecting a local bus to the Internet, treat all devices as potentially compromised, manipulated, or remotely actuated against your will. As a best practice, avoid connecting to the internet systems that could cause damage (fire, flood, data leakage) if hacked.
### Reporting a Vulnerability
If you discover a vulnerability in the specification or in the implementation please report it as soon as possible opening an [issue](https://github.com/gioblu/PJON/issues). If you have developed a fix, feel free to open a [pull request](https://github.com/gioblu/PJON/pulls).
diff --git a/devices/sensors/LEDAR/README.md b/devices/sensors/LEDAR/README.md
index 92f9bca418..ed0bbde058 100644
--- a/devices/sensors/LEDAR/README.md
+++ b/devices/sensors/LEDAR/README.md
@@ -18,7 +18,7 @@ Many LEDARs can be connected to the same [SoftwareBitBang](/src/strategies/Softw
Its detection method is based on two interesting characteristics of LEDs:
- If hit by light, LEDs produce a tiny amount of electricity, thanks to the photo-electric effect
-- LEDs used as detectors are generally more sensitive to the frequency they emit if used as emitters, making a couple of identical LEDs generally used for lighting, in two extremely efficient wireless transceivers that can be used for reflectometry or also for wireless communication using the [AnalogSampling](/src/strategies/AnalogSampling/README.md) strategy
+- LEDs used as detectors are generally more sensitive to the frequency they emit if used as emitters, so a couple of identical LEDs generally used for lighting can be used successfully as wireless transceivers for reflectometry or optical wireless communication using the [AnalogSampling](/src/strategies/AnalogSampling/README.md) strategy
Its sampling method is based on two different samples:
- Background noise or ambient light sample `B`
@@ -79,6 +79,6 @@ The case is made by two elements and it has been printed using a customized Prus
Once crafted, ATtiny85 has to be flashed with the [LEDAR](software/LEDAR/LEDAR.ino) sketch using an ISP programmer, see [ATtiny85 interfacing](https://github.com/gioblu/PJON/wiki/ATtiny-interfacing)
-LEDAR has been engineered with the strong feeling that, in the future, "smart houses" will not necessarily host a multitude of inefficient and convoluted embedded real-time operative systems, in whatever "thing", consuming a lot of power running Ethernet over WiFi and exposing vulnerabilities also out of the physical boundaries of houses. Otherwise, more probably, will host many dedicated microcontrollers connected to a wired, common, open-source, lightweight and less power consuming communication bus, unhackable without direct physical access to its wiring.
+LEDAR has been engineered with the strong feeling that, in the future, "smart houses" will not necessarily host a multitude of inefficient embedded real-time operating systems in whatever "thing" while exposing vulnerabilities out of the physical boundaries of houses. Otherwise, more probably, will host many simple, less power-hungy microcontrollers, connected to a wired communication bus, unhackable without direct physical access to its wiring.
LEDAR should be considered as a general "guideline" on how PJON compatible devices can be published and shared with other PJON users through the [devices](../../README.md) directory. Feel free to make a pull request proposing a new device you have engineered.
diff --git a/documentation/README.md b/documentation/README.md
index 302d10532a..0ef24a499a 100644
--- a/documentation/README.md
+++ b/documentation/README.md
@@ -1,13 +1,21 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
-
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Documentation
diff --git a/documentation/addressing.md b/documentation/addressing.md
index b84d5f9269..312a64392f 100644
--- a/documentation/addressing.md
+++ b/documentation/addressing.md
@@ -1,27 +1,36 @@
### Documentation index
- **[Addressing](/documentation/addressing.md)**
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Addressing
-PJON objects can operate in local or shared mode. The PJON protocol v3.2 in [local](/specification/PJON-protocol-specification-v3.2.md#local-mode) mode supports connectivity for up to 254 devices using a 8bits device identifier, in [shared](/specification/PJON-protocol-specification-v3.2.md#shared-mode) mode supports connectivity for up to 4.294.967.295 buses (groups of devices) and up to 1.090.921.692.930 devices using a 32bits bus identifier and a 8bits device identifier.
+PJON objects can operate in local or shared mode. The PJON protocol v4.0 in [local](/specification/PJON-protocol-specification-v4.0.md#local-mode) mode supports connectivity for up to 254 devices using a 8bits device identifier, in [shared](/specification/PJON-protocol-specification-v4.0.md#shared-mode) mode supports connectivity for up to 4.294.967.295 buses (groups of devices) and up to 1.090.921.692.930 devices using a 32bits bus identifier and a 8bits device identifier.
### Local mode
-The simples way to instantiate PJON in local mode is the following:
+The simplest way to instantiate PJON in local mode is as follows:
```cpp
- PJON bus;
+ PJONSoftwareBitBang bus;
```
When the object is instantiated without passing parameters it operates in local mode and the device identifier is set to 255 or `PJON_NOT_ASSIGNED`. PJON objects can be instantiated passing the device identifier:
```cpp
- PJON bus(44);
+ PJONSoftwareBitBang bus(44);
```
`bus` receives packets for device identifier 44 and ignores all others.
@@ -39,21 +48,60 @@ The device identifier of an object can be read after instantiation using `device
```cpp
uint8_t id = bus.device_id(); // Get device id
```
-`device_id` returns 255 or `PJON_NOT_ASSIGNED` if the instance is initialised without configuring its device identifier.
+`device_id` returns `PJON_NOT_ASSIGNED` or 255 if the instance is initialised without configuring its device identifier.
### Shared mode
-if the medium used is private and not accessible from the outside world (wired network in home, business, industry) any bus indexing scheme can be used without worrying about bus id collision; if instead the network uses a shared medium, such as commonly used radio frequencies like LoRa, it is strongly suggested to request a unique PJON bus id [here](http://www.pjon.org/get-bus-id.php) to avoid collisions.
+if the medium used is private and not accessible from the outside world (wired network in home, business, industry), bus ids can be used arbitrarily without any risk of collision; if instead the network uses a shared medium, for example on unlicensed radio frequencies with [ThroughLoRa](/src/strategies/ThroughLoRa).
Instantiation in shared mode:
```cpp
uint8_t bus_id[4] = {1, 2, 3, 4};
-PJON bus(bus_id, 44);
+PJONSoftwareBitBang bus(bus_id, 44);
// Device id 44, bus id 1.2.3.4 in shared mode
```
### Get or set bus identifier
-The bus id can be read and set after initialisation using `bus_id`:
+Use `get_bus_id` to get a pointer to the bus id used by the instance:
+```cpp
+ uint8_t bus_id[4];
+ memcpy(bus_id, bus.get_bus_id(bus_id), 4); // Copy bus id in bus_id
+```
+
+The bus id can be set after initialisation using `set_bus_id`:
+```cpp
+ uint8_t bus_id[4] = {0, 0, 0, 1};
+ bus.set_bus_id(bus_id); // Set bus id
+```
+
+### Hardware identifier
+
+PJON can optionally operate using the MAC address of the device:
+```cpp
+// Include MAC address feature
+#define PJON_INCLUDE_MAC
+
+// MAC address of the device
+uint8_t mac[6] = {1, 2, 3, 4, 5, 6};
+
+PJONSoftwareBitBang bus(mac);
+// Local mode, device id PJON_NOT_ASSIGNED
+```
+This instantiation sets the MAC address, the device id set to `PJON_NOT_ASSIGNED` or 255 but can be changed afterwards as required. Packets containing a recipient's MAC address that is not equal to the one configured are discarded. PJON can operate in both local and shared mode while including MAC addresses. The feature can be disabled using `include_mac`:
+
+```cpp
+bus.include_mac(false);
+```
+### Get or set hardware identifier
+
+Use `get_mac` to get a pointer to the mac address used by the instance:
+```cpp
+ uint8_t mac[6];
+ memcpy(mac, bus.get_mac(mac), 6); // Copy mac in variable
+```
+
+The mac address can be set after initialisation using `set_mac`:
```cpp
- bus.bus_id; // Get or set bus id
+ uint8_t mac[6] = {0, 0, 0, 0, 0, 1};
+ bus.set_mac(mac); // Set mac
```
diff --git a/documentation/configuration.md b/documentation/configuration.md
index d64233da6c..dab04a7431 100644
--- a/documentation/configuration.md
+++ b/documentation/configuration.md
@@ -1,89 +1,85 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- **[Configuration](/documentation/configuration.md)**
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
-
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Configuration
PJON uses predefined constants, setters and getters to support features and constraints configuration.
### Buffers configuration
-Before instantiating PJON it is possible to define the length of its buffers. Predefining `PJON_MAX_PACKETS` and `PJON_PACKET_MAX_LENGTH` it is possible to configure this constraints to reach the project memory requirements. Obviously, the less memory is dedicated to buffers, the more memory can be used for something else:
+Before including the library, it is possible to define the length of its buffers by defining the `PJON_MAX_PACKETS` and `PJON_PACKET_MAX_LENGTH` constants:
```cpp
-#define PJON_MAX_PACKETS 1
-#define PJON_PACKET_MAX_LENGTH 20
-#include
-/* PJON can store up to 1 packet of up to
- 20 bytes - packet overhead
- (from 5 to 22 bytes depending by configuration) */
+ #define PJON_MAX_PACKETS 1
+ #define PJON_PACKET_MAX_LENGTH 20
+ /* PJON can dispatch up to 1 packet with a payload of up to
+ 20 bytes - packet overhead (5-35 bytes depending on configuration) */
```
-### Data link configuration
-PJON is instantiated passing a [strategy](/src/strategies/README.md) template parameter:
-```cpp
- PJON bus;
+### Strategy configuration
+Strategies are classes that abstract the physical transmission of data. `PJON` uses [strategies](/src/strategies/README.md) as template parameters although since version 13.0 that complexity is hidden behind a [macro](../src/PJONSoftwareBitBang.h):
+```cpp
+ #include
+ PJONSoftwareBitBang bus;
+```
+In the example above, the PJON object is instantiated using the [SoftwareBitBang](/src/strategies/SoftwareBitBang/README.md) strategy. It is possible to instantiate more than one PJON object using different strategies in the same program:
+```cpp
+#include
+#include
+
+PJONSoftwareBitBang wiredBus;
+PJONEthernetTCP tcpBus;
+```
+
+The table below lists the strategies available:
+
+| Strategy | Physical layer | Protocol | Inclusion |
+| ------------- | -------------- | -------- | --------- |
+| [AnalogSampling](/src/strategies/AnalogSampling) | Light | [PJDLS](../src/strategies/AnalogSampling/specification/PJDLS-specification-v2.0.md) | `#include ` |
+| [Any](/src/strategies/Any) | Virtual inheritance | Any | `#include ` |
+| [DualUDP](/src/strategies/DualUDP) | Ethernet/WiFi | [UDP](https://tools.ietf.org/html/rfc768) | `#include ` |
+| [ESPNOW](/src/strategies/ESPNOW) | WiFi | [ESPNOW](https://www.espressif.com/en/products/software/esp-now/overview) | `#include ` |
+| [EthernetTCP](/src/strategies/EthernetTCP) | Ethernet/WiFi | [TCP](https://tools.ietf.org/html/rfc793) | `#include ` |
+| [GlobalUDP](/src/strategies/GlobalUDP) | Ethernet/WiFi | [UDP](https://tools.ietf.org/html/rfc768) | `#include ` |
+| [LocalFile](/src/strategies/LocalFile) | File system | None | `#include ` |
+| [LocalUDP](/src/strategies/LocalUDP) | Ethernet/WiFi | [UDP](https://tools.ietf.org/html/rfc768) | `#include ` |
+| [MQTTTranslate](/src/strategies/MQTTTranslate) | Ethernet/WiFi | [MQTT](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.pdf) | `#include ` |
+| [OverSampling](/src/strategies/OverSampling) | Radio | [PJDLR](../src/strategies/OverSampling/specification/PJDLR-specification-v3.0.md) | `#include ` |
+| [SoftwareBitBang](/src/strategies/SoftwareBitBang) | Wire | [PJDL](../src/strategies/SoftwareBitBang/specification/PJDL-specification-v5.0.md) | `#include ` |
+| [ThroughLoRa](/src/strategies/ThroughLoRa) | Radio | [LoRa](https://lora-alliance.org/sites/default/files/2018-07/lorawan1.0.3.pdf) | `#include ` |
+| [ThroughSerial](/src/strategies/ThroughSerial) | Wire | [TSDL](../src/strategies/ThroughSerial/specification/TSDL-specification-v3.0.md) | `#include ` |
+
+Before using `ThroughLoRa` be sure to have [arduino-LoRa](https://github.com/sandeepmistry/arduino-LoRa) library available. Before using `ESPNOW` be sure to have installed the required tools as described [here](/src/strategies/ESPNOW/README.md). Before using `MQTTTranslate` be sure to have the [ReconnectingMqttClient](https://github.com/fredilarsen/ReconnectingMqttClient) library available.
+
+### Random seed
+When `begin` is called an analog pin is used to sample the seed for the random generator. By default PJON uses pin `A0` to sample the seed, if you need to use another pin call `set_random_seed` as shown below:
+```cpp
+ bus.set_random_seed(A1); // A1 is used to sample the seed
+ bus.begin(); // Seed sampling occurs
```
-In the example above the PJON object is instantiated passing [SoftwareBitBang](/src/strategies/SoftwareBitBang/README.md) strategy. Strategies are classes abstracting the data link layer, making PJON easy to be used on different media. It is possible to instantiate more than one PJON object using different strategies in the same program:
-```cpp
- PJON wiredBus;
- PJON tcpBus;
-```
-
-| Strategy | Physical layer | Protocol | Pins needed |
-| ------------- | -------------- | -------- | ------------- |
-| [SoftwareBitBang](/src/strategies/SoftwareBitBang) | Electrical impulses over wire | [PJDL](../src/strategies/SoftwareBitBang/specification/PJDL-specification-v4.1.md) | 1 or 2 |
-| [OverSampling](/src/strategies/OverSampling) | Electrical/radio impulses over wire/air | [PJDLR](../src/strategies/OverSampling/specification/PJDLR-specification-v3.0.md) | 1 or 2 |
-| [AnalogSampling](/src/strategies/AnalogSampling) | Light pulses over air or optic fiber | [PJDLS](../src/strategies/AnalogSampling/specification/PJDLS-specification-v2.0.md) | 1 or 2 |
-| [ThroughSerial](/src/strategies/ThroughSerial) | Electrical/radio impulses over wire/air | [TSDL](../src/strategies/ThroughSerial/specification/TSDL-specification-v2.1.md) | 1 or 2 |
-| [ThroughSerialAsync](/src/strategies/ThroughSerialAsync) | Electrical/radio impulses over wire/air | [TSDL](../src/strategies/ThroughSerial/specification/TSDL-specification-v2.1.md) | 1 or 2 |
-| [ThroughLoRa](/src/strategies/ThroughLoRa) | Radio impulses over air | [LoRa](https://lora-alliance.org/sites/default/files/2018-07/lorawan1.0.3.pdf) | 3 or 4 |
-| [EthernetTCP](/src/strategies/EthernetTCP) | Electrical/radio impulses over wire/air | [TCP](https://tools.ietf.org/html/rfc793) | Ethernet or WiFi |
-| [LocalUDP](/src/strategies/LocalUDP) | Electrical/radio impulses over wire/air | [UDP](https://tools.ietf.org/html/rfc768) | Ethernet or WiFi |
-| [GlobalUDP](/src/strategies/GlobalUDP) | Electrical/radio impulses over wire/air | [UDP](https://tools.ietf.org/html/rfc768) | Ethernet or WiFi |
-| [DualUDP](/src/strategies/DualUDP) | Electrical/radio impulses over wire/air | [UDP](https://tools.ietf.org/html/rfc768) | Ethernet or WiFi |
-| [MQTTTranslate](/src/strategies/MQTTTranslate) | Electrical/radio impulses over wire/air | [MQTT](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.pdf) | Ethernet or WiFi |
-| [ESPNOW](/src/strategies/ESPNOW) | Radio impulses over air | [ESPNOW](https://www.espressif.com/en/products/software/esp-now/overview) | WiFi link |
-| [LocalFile](/src/strategies/LocalFile) | Shared file system in memory | None | None |
-| [Any](/src/strategies/Any) | Virtual inheritance, any of the above | Any of the above | Any of the above |
-
-By default all strategies are included except `MQTTTranslate`, `LocalFile`, `ThroughLoRa` and `ESPNOW`. To reduce memory footprint add for example `#define PJON_INCLUDE_SWBB` before including the library to select only the `SoftwareBitBang` strategy. More than one strategy related constants can defined in the same program if that is required.
-
-Supported definitions:
-- `PJON_INCLUDE_SWBB` includes `SoftwareBitBang`
-- `PJON_INCLUDE_AS` includes `AnalogSampling`
-- `PJON_INCLUDE_ETCP` includes `EthernetTCP`
-- `PJON_INCLUDE_LUDP` includes `LocalUDP`
-- `PJON_INCLUDE_GUDP` includes `GlobalUDP`
-- `PJON_INCLUDE_OS` includes `OverSampling`
-- `PJON_INCLUDE_TS` includes `ThroughSerial`
-- `PJON_INCLUDE_TSA` includes `ThroughSerialAsync`
-- `PJON_INCLUDE_TL` includes `ThroughLoRa`
-- `PJON_INCLUDE_MQTT` includes `MQTTTranslate`
-- `PJON_INCLUDE_EN` includes `ESPNOW`
-- `PJON_INCLUDE_ANY` includes `Any`
-- `PJON_INCLUDE_LF` includes `LocalFile`
-- `PJON_INCLUDE_NONE` does not include any strategy
-
-Before using `ThroughLoRa` be sure to have [arduino-LoRa](https://github.com/sandeepmistry/arduino-LoRa) library available and to have defined the `PJON_INCLUDE_TL` constant before including `PJON.h`.
-
-Before using `ESPNOW` be sure to have installed the required tools as described [here](/src/strategies/ESPNOW/README.md) and to have defined the `PJON_INCLUDE_EN` constant before including `PJON.h`.
-
-Before using `MQTTTranslate` be sure to have the [ReconnectingMqttClient](https://github.com/fredilarsen/ReconnectingMqttClient) library available and to have defined the `PJON_INCLUDE_MQTT` constant before including `PJON.h`.
### Network mode
-The network mode can be changed with `set_shared_network` during runtime, for example moving from [local](/specification/PJON-protocol-specification-v3.2.md#local-mode) to [shared](https://github.com/gioblu/PJON/blob/master/specification/PJON-protocol-specification-v3.2.md#shared-mode) mode:
+The network mode can be changed with `set_shared_network` during runtime, for example moving from [local](/specification/PJON-protocol-specification-v4.0.md#local-mode) to [shared](https://github.com/gioblu/PJON/blob/master/specification/PJON-protocol-specification-v4.0.md#shared-mode) mode:
```cpp
bus.set_shared_network(true);
```
### Communication mode
-The communication mode can be configured using the `set_communication_mode` passing `PJON_SIMPLEX` for simplex or mono-directional mode or `PJON_HALF_DUPLEX` for half-duplex or bidirectional mode:
+The communication mode can be configured using `set_communication_mode` passing `PJON_SIMPLEX` for simplex or mono-directional mode or `PJON_HALF_DUPLEX` for half-duplex or bidirectional mode:
```cpp
// Run in mono-directional PJON_SIMPLEX mode
bus.set_communication_mode(PJON_SIMPLEX);
@@ -92,7 +88,7 @@ The communication mode can be configured using the `set_communication_mode` pass
```
### Router mode
-Use `set_router` to configure the device in router mode, simply receiving all the incoming packets:
+When an instance is configured in router mode it is able to receive all incoming packets without any bus or device id filtering. Use `set_router` to configure the router mode:
```cpp
bus.set_router(true);
```
@@ -116,47 +112,56 @@ If manual packet handling is required, packet automatic deletion can be avoided
```
### Acknowledgement
-The [synchronous acknowledgement](/specification/PJON-protocol-acknowledge-specification-v1.0.md#synchronous-acknowledge) is by default enabled but can be disabled if required:
+With the acknowledgement enabled the transmitter has reception certainty. It is by default enabled but can be disabled:
```cpp
- bus.set_synchronous_acknowledge(false);
+ bus.set_acknowledge(false);
```
-If the [asynchronous acknowledgement](/specification/PJON-protocol-acknowledge-specification-v1.0.md#asynchronous-acknowledge) feature is required you need to define the `PJON_INCLUDE_ASYNC_ACK` as following. The use of a constant has been chosen to save more than 1kB on sketches where this feature is not used (the packet id is used by the asynchronous acknowledgement process, so if necessary, play with that responsibly):
-```cpp
-#define PJON_INCLUDE_ASYNC_ACK true
-// Max number of old packet ids stored to avoid duplication
-#define PJON_MAX_RECENT_PACKET_IDS 10 // by default 10
-// If packet duplication occurs, higher PJON_MAX_RECENT_PACKET_IDS
-#include
-```
-Use `set_asynchronous_acknowledge` to enable the asynchronous acknowledgement:
+### Packet identification
+The instance can be configured to include a 16 bits [packet identifier](/specification/PJON-protocol-specification-v4.0.md#packet-identification) to guarantee packet uniqueness. Define `PJON_INCLUDE_PACKET_ID` as described below, if this constant is not present the feature is not included and around 300 bytes of program memory and 80 bytes of RAM are spared:
```cpp
- // Enable async ack
- bus.set_asynchronous_acknowledge(true);
-```
-See the [AsyncAck](/examples/ARDUINO/Network/SoftwareBitBang/AsyncAck) example to see more in detail how the asynchronous acknowledgement can be used.
+ // Include the packet id feature
+ #define PJON_INCLUDE_PACKET_ID
+ // Max number of old packet ids stored to avoid duplication
+ // If packet duplication occurs, higher PJON_MAX_RECENT_PACKET_IDS
+ #define PJON_MAX_RECENT_PACKET_IDS 10 // By default 10
-### Packet identification
-If packet duplication avoidance is required it is possible to add a 2 bytes [packet identifier](/specification/PJON-protocol-specification-v3.2.md#packet-identification) to guarantee uniqueness.
-define the `PJON_INCLUDE_PACKET_ID` as following. The use of a constant has been chosen to save more than 1kB on sketches where this feature is not used:
-```cpp
-#define PJON_INCLUDE_PACKET_ID true
-// Max number of old packet ids stored to avoid duplication
-#define PJON_MAX_RECENT_PACKET_IDS 10 // by default 10
-// If packet duplication occurs, higher PJON_MAX_RECENT_PACKET_IDS
-#include
+ #include
```
-Use `set_packet_id` to enable the packet identification feature:
+Use `set_packet_id` to enable the packet identification:
```cpp
bus.set_packet_id(true);
```
See the [UsePacketId](/examples/ARDUINO/Local/SoftwareBitBang/UsePacketId) example to see more in detail how the packet id can be used.
### Network service identification
-Configure the instance to include a [network service identifier](/specification/PJON-protocol-specification-v3.2.md#network-services) in the packet. Ports from 0 to 8000 are reserved to known network services which index is present in the [known network services list](/specification/PJON-network-services-list.md), ports from 8001 to 65535 are free for custom use cases:
+The instance can be configured to include a [network service identifier](/specification/PJON-protocol-specification-v4.0.md#network-services) in the packet. Ports from 0 to 8000 are reserved to known network services which index is present in the [known network services list](/specification/PJON-network-services-list.md), ports from 8001 to 65535 are free for custom use cases. Define `PJON_INCLUDE_PORT` as described below, if this constant is not present the feature is not used and around 100 bytes of program memory and 2 bytes of RAM are spared:
+```cpp
+ // Include the port id feature
+ #define PJON_INCLUDE_PORT
+ #include
+```
+Use `include_port` to enable the network service identification:
+```cpp
+ bus.include_port(false); // Avoid port inclusion (default)
+ bus.include_port(8001); // Include a port
+```
+When a port is configured, packets that contain a different port are discarded. See the [PortsUseExample](/examples/ARDUINO/Network/SoftwareBitBang/PortsUseExample) to see more in detail how the port feature can be used.
+
+### Hardware identification
+The instance can be configured to include the [hardware identification](/specification/PJON-protocol-specification-v4.0.md#hardware-identification). If the feature is used both recipient's and sender's MAC addresses are included in the packet. Define `PJON_INCLUDE_MAC` as described below, if this constant is not present the feature is not included and around 200 bytes of program memory and 20 bytes of RAM are spared:
+```cpp
+ // Include the port id feature
+ #define PJON_INCLUDE_MAC
+ #include
+
+ // Device's MAC address
+ uint8_t mac[6] = {0, 0, 0, 0, 0, 0};
+ PJONSoftwareBitBang bus(mac);
+```
+Use `include_mac` to enable the network service identification by default:
```cpp
- bus.include_port(false); // Avoid port inclusion (default)
- bus.include_port(true, 8001); // Include custom port
+ bus.include_mac(true); // Include MAC address by default
```
-See the [PortsUseExample](/examples/ARDUINO/Network/SoftwareBitBang/PortsUseExample) example to see more in detail how the port feature can be used.
+See the [BlinkTestMAC](/examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC) example to see more in detail how the MAC feature can be used.
diff --git a/documentation/data-reception.md b/documentation/data-reception.md
index 3dcc182811..ab0c45e256 100644
--- a/documentation/data-reception.md
+++ b/documentation/data-reception.md
@@ -1,65 +1,86 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- **[Data reception](/documentation/data-reception.md)**
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
-
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Data reception
-A function of type `void` can be defined and register to be called by the PJON object when a packet is received. This function receives 3 parameters: the received payload of type `uint8_t *`, its length of type `uint16_t` and a pointer to a data structure of type `const PJON_Packet_Info` that contains all packet's metadata:
+A function of type `void` is called by the PJON object when a packet is received. This function receives 3 parameters: the received payload of type `uint8_t *`, its length of type `uint16_t` and a pointer to a data structure of type [`const PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info) that contains all packet's metadata:
+
```cpp
-void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
- /* Make use of the payload before sending something, the buffer where payload points to is
- overwritten when a new message is dispatched */
+void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &info) {
+ // Print received data in the serial monitor
+ for(uint16_t i = 0; i < length; i++)
+ Serial.print(payload[i]);
+};
+```
+
+Register the `receiver_function` as the receiver callback:
+```cpp
+PJONSoftwareBitBang bus;
+bus.set_receiver(receiver_function);
+```
+
+Within `receiver_function` it is possible to process data and meta-data when a packet is received. The [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info) struct contains all the protocol fields present in the packet:
+
+The code below is part of the Arduino compatible [PortsUseExample](/examples/ARDUINO/Network/SoftwareBitBang/PortsUseExample/Receiver/Receiver.ino). When the `receiver_function` is called meta-data present in the `info` parameter is printed in the serial monitor:
+```cpp
+void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &info) {
Serial.print("Header: ");
- Serial.print(packet_info.header, BIN);
+ Serial.print(info.header, BIN);
// If packet formatted for a shared medium
- if(packet_info.header & PJON_MODE_BIT) {
+ if(info.header & PJON_MODE_BIT) {
Serial.print(" Receiver bus id: ");
- Serial.print(packet_info.receiver_bus_id[0]);
- Serial.print(packet_info.receiver_bus_id[1]);
- Serial.print(packet_info.receiver_bus_id[2]);
- Serial.print(packet_info.receiver_bus_id[3]);
+ Serial.print(info.rx.bus_id[0]);
+ Serial.print(info.rx.bus_id[1]);
+ Serial.print(info.rx.bus_id[2]);
+ Serial.print(info.rx.bus_id[3]);
Serial.print(" Receiver id: ");
- Serial.print(packet_info.receiver_id);
+ Serial.print(info.rx.id);
// If sender info is included
- if(packet_info.header & PJON_TX_INFO_BIT) {
+ if(info.header & PJON_TX_INFO_BIT) {
Serial.print(" Sender bus id: ");
- Serial.print(packet_info.sender_bus_id[0]);
- Serial.print(packet_info.sender_bus_id[1]);
- Serial.print(packet_info.sender_bus_id[2]);
- Serial.print(packet_info.sender_bus_id[3]);
+ Serial.print(info.tx.bus_id[0]);
+ Serial.print(info.tx.bus_id[1]);
+ Serial.print(info.tx.bus_id[2]);
+ Serial.print(info.tx.bus_id[3]);
}
}
// If sender device id is included
- if(packet_info.header & PJON_TX_INFO_BIT) {
+ if(info.header & PJON_TX_INFO_BIT) {
Serial.print(" Sender id: ");
- Serial.print(packet_info.sender_id);
+ Serial.print(info.tx.id);
}
// Payload Length
Serial.print(" Length: ");
Serial.print(length);
// If port id is included
- if(packet_info.header & PJON_PORT_BIT) {
+ if(info.header & PJON_PORT_BIT) {
Serial.print(" Port bit: ");
- Serial.print(packet_info.port);
+ Serial.print(info.port);
}
Serial.println();
-}
-```
-Register the `receiver_function` as the receiver callback:
-```cpp
-bus.set_receiver(receiver_function);
+};
```
+Use `payload` before any transmission, the buffer where `payload` points to is overwritten when a new packet is dispatched.
-To pass custom data to the receiver callback function, se the [ClassMemberCallback](../examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback) example. This feature can be used for a lot of different use cases. Could be used to let multiple PJON objects call the same callback function, passing an `int` specifying which PJON instance has to be called, or a pointer to the PJON object, or an `enum` or whatever.
+To understand how to pass custom data to the receiver callback function, see the [ClassMemberCallback](../examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback) example. This feature can be used to link other classes or instances passing any sort of data structure.
-To receive the `receive` function must be called at least once per loop cycle:
+To receive data the `receive` function must be called as often as possible:
```cpp
uint16_t response = bus.receive();
```
@@ -69,8 +90,8 @@ uint16_t response = bus.receive();
- `PJON_BUSY` (666) if a transmission for other devices is occurring
- `PJON_FAIL` (65535) if no data is received
-If you want to dedicate a certain timeframe to reception call the `receive` function passing the maximum reception time in microseconds:
+If it is required to dedicate a certain time to reception call the `receive` function passing the maximum reception time in microseconds:
```cpp
uint16_t response = bus.receive(1000);
```
-Consider that SoftwareBitBang, OverSampling or AnalogSampling are strategies able receive data only while `bus.receive` is being executed, otherwise data is lost and transmitter will try again in future. In this particular case it is mandatory to dedicate a certain timeframe, depending on the duration of the other tasks, to efficiently receive data and avoid repetitions.
+Consider that SoftwareBitBang, OverSampling or AnalogSampling are strategies able to receive data only while `bus.receive` is being executed, otherwise data is lost and transmitter will try again in future. In this particular case it is mandatory to dedicate a certain timeframe, depending on the duration of the other tasks, to efficiently receive data and avoid repetitions.
diff --git a/documentation/data-structures.md b/documentation/data-structures.md
new file mode 100644
index 0000000000..0d309bfc5e
--- /dev/null
+++ b/documentation/data-structures.md
@@ -0,0 +1,50 @@
+
+### Documentation index
+- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
+- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
+- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- **[Data structures](/documentation/data-structures.md)**
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
+- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
+- [Error handling](/documentation/error-handling.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
+- [Routing](/documentation/routing.md)
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
+---
+
+## Data structures
+
+### `PJON_Endpoint`
+`PJON_Endpoint` contains the device id, bus id and MAC address of a device:
+```cpp
+struct PJON_Endpoint {
+ uint8_t id = PJON_NOT_ASSIGNED;
+ uint8_t bus_id[4] = {0, 0, 0, 0};
+ uint8_t mac[6] = {0, 0, 0, 0, 0, 0};
+};
+```
+`PJON_Endpoint` contains `mac` if [`PJON_INCLUDE_MAC`](/documentation/configuration.md#hardware-identification) is defined. The conditional inclusion is present to reduce the footprint of programs where the MAC address is not used.
+
+### `PJON_Packet_Info`
+`PJON_Packet_Info` contains all meta-data supported by the PJON packet format. The `tx` and `rx` data structures of type `PJON_Endpoint` contain the transmitter and receiver information.
+
+```cpp
+struct PJON_Packet_Info {
+ PJON_Endpoint tx;
+ PJON_Endpoint rx;
+ void *custom_pointer;
+ uint8_t header = PJON_NO_HEADER;
+ uint8_t hops = 0;
+ uint16_t id = 0;
+ uint16_t port = PJON_BROADCAST;
+};
+```
+`PJON_Packet_Info` contains `port` if [`PJON_INCLUDE_PORT`](/documentation/configuration.md#network-service-identification) is defined and `id` if [`PJON_INCLUDE_PACKET_ID`](/documentation/configuration.md#packet-identification) is defined. The conditional inclusion is present to reduce the footprint of programs where the port and the packet id are not used.
+
+The `custom_pointer` can be used to link other classes or instances passing any sort of data structure. To understand how to use it see the [ClassMemberCallback](../examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback) example.
diff --git a/documentation/data-transmission.md b/documentation/data-transmission.md
index ac40cc2f9d..2c7cc76e5d 100644
--- a/documentation/data-transmission.md
+++ b/documentation/data-transmission.md
@@ -1,125 +1,218 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- **[Data transmission](/documentation/data-transmission.md)**
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
-
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Data transmission
-The begin function must be called before starting communication, the lack of this call can lead to collisions after boot, so be sure to call it before making use of the instance.
+
+### `begin`
+The `begin` method must be called before starting communication, the lack of this call can lead to collisions so be sure not to forget it:
```cpp
bus.begin();
```
-The simplest way to send data is to use `send_packet`, this method composes the packet and tries to send it once. The first parameter is the device id of the recipient of type `uint8_t`, optionally you can pass the bus id of type `uint8_t *`, then follows the payload of type `const void *` and its length of type `uint16_t`. This call implies a single attempt and has no guarantee of success, but logs the result of the attempted transmission:
-```cpp
-// Local
+### `send_packet`
+
+| Buffered | Blocking | Attempts |
+| -------- | -------- | -------- |
+| No | Yes | 1 |
+
+The simplest way to send data is to use `send_packet`, this method composes the packet and tries to send it once. Consider that if the bus is busy or interference is present the transmission may not be attempted. The method returns the result of its operation. The first parameter is the device id of the recipient of type `uint8_t`, the second is the payload of type `const void *` and the third is the length of type `uint16_t`. This call implies a single attempt and has no guarantee of success, but logs the result of the attempted transmission:
+```cpp
// Send to device id 10 the string "Hi!"
bus.send_packet(10, "Hi!", 3);
-
+```
+ The `send_packet` method can receive 3 optional parameters, the header of type `uint8_t`, a packet id of type `uint16_t` (pass 0 if you want to avoid the packet id inclusion) and a port of type `uint16_t`. In the example below a packet containing the payload "Hello" is sent to device id 10 using the actual instance's header configuration, without including the packet id and including the port `8002`.
+```cpp
// All optional parameters available
bus.send_packet(
10, // Device id (uint8_t)
"Hello", // Payload (const void *)
- 12, // Length (uint16_t)
+ 5, // Length (uint16_t)
bus.config, // Header (uint8_t) - Use default config
0, // Packet id (uint16_t) - Don't include packet id
8002 // Port (uint16_t)
);
+```
+
+The `send_packet` method accepts any kind of data, in the example below a custom `struct` is sent to device id 1:
+```cpp
+// Define a custom data type
+struct voltage_record { uint16_t v1; uint16_t v2; };
+// Fill it with information
+voltage_record record;
+record.v1 = analogRead(A1);
+record.v2 = analogRead(A2);
+// Send to device id 1 the record struct
+bus.send_packet(1, &record, sizeof(record));
+```
+
+`send_packet` returns the following values:
+- `PJON_ACK` (6) if transmission occurred and acknowledgement is received if requested
+- `PJON_BUSY` (666) if bus is busy
+- `PJON_FAIL` (65535) if transmission failed
+
+The `send_packet` return value, of type `uint16_t`, can be used to determine if the transmission occurred successfully or not:
+```cpp
+uint16_t result = bus.send_packet(10, "All is ok?!", 11);
+
+if(result == PJON_ACK) Serial.println("10 is ok!");
+```
+
+To broadcast a message to all connected devices, use the `PJON_BROADCAST` constant as recipient ID:
+```cpp
+bus.send_packet(PJON_BROADCAST, "Message for all connected devices.", 34);
+```
+
+If you need to transmit in shared mode or configure other protocol fields you can use `send_packet` passing a struct of type [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info), the payload of type `const void *` and the length of type `uint16_t`:
+```cpp
+uint8_t bus_id[4] = {0, 0, 0, 1};
+PJON_Packet_Info info;
+info.rx.id = 10; // The recipient's device id is 10
+info.rx.port = 8000; // The packet includes the port 8000
+memcpy(info.rx.bus_id, bus_id, 4); // Copy recipient's bus id in info
+bus.send_packet(info, "Ciao!", 5);
+```
-// Shared or using bus indexing
+### `send_packet_blocking`
-// Send to bus id 0.0.0.1 - device id 10 the string "Hi!"
-uint8_t bus_id[] = {0, 0, 0, 1};
-bus.send_packet(10, bus_id, "Hi!", 3);
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| No | Yes | `strategy.get_max_attempts()` |
+Use `send_packet_blocking` if it is necessary to try until the packet is effectively received by the recipient or a maximum amount of retries is reached. Consider that the method may block the operation of the program for up to 4 seconds in case of transmission failure.
+
+```cpp
+// Send to device id 10 the string "Hi!"
+bus.send_packet_blocking(10, "Hi!", 3);
+```
+The `send_packet_blocking` method can receive 4 optional parameters, the header of type `uint8_t`, a packet id of type `uint16_t` (pass 0 if you want to avoid the packet id inclusion), a port of type `uint16_t` and a timeout of type `uint32_t`. In the example below a packet containing the payload "Hello" is sent to device id 10 using the actual instance's header configuration, without including the packet id, including the port `8002` and passing a maximum timeout of 1 second:
+```cpp
// All optional parameters available
-bus.send_packet(
+bus.send_packet_blocking(
10, // Device id (uint8_t)
- bus_id, // Bus id (uint8_t *)
"Hello", // Payload (const void *)
- 12, // Length (uint16_t)
+ 5, // Length (uint16_t)
bus.config, // Header (uint8_t) - Use default config
0, // Packet id (uint16_t) - Don't include packet id
- 8002 // Port (uint16_t)
+ 8002, // Port (uint16_t)
+ 1000000 // Timeout (uint32_t) - 1 second
);
```
-The sending is executed as soon as the method is called and it returns the following values:
+The `send_packet_blocking` method accepts any type of data, in the example below a custom `struct` is sent to device id 1:
+```cpp
+// Define a custom data type
+struct voltage_record { uint16_t v1; uint16_t v2; };
+// Fill it with information
+voltage_record record;
+record.v1 = analogRead(A1);
+record.v2 = analogRead(A2);
+// Send to device id 1 the record struct
+bus.send_packet_blocking(1, &record, sizeof(record));
+```
+
+`send_packet_blocking` returns the following values:
- `PJON_ACK` (6) if transmission occurred and acknowledgement is received if requested
- `PJON_BUSY` (666) if bus is busy
- `PJON_FAIL` (65535) if transmission failed
+The `send_packet_blocking` return value, of type `uint16_t`, can be used to determine if the transmission occurred successfully or not:
```cpp
-// Use the value returned by send_packet to determine transmission result
-
-// Local
-if(bus.send_packet(10, "All is ok?!", 11) == PJON_ACK)
- Serial.println("10 is ok!");
+uint16_t result = bus.send_packet_blocking(10, "All is ok?!", 11);
-// Shared or using bus indexing
-if(bus.send_packet(10, bus_id, "All is ok?!", 11) == PJON_ACK)
- Serial.println("10 is ok!");
+if(result == PJON_ACK) Serial.println("10 is ok!");
```
-To broadcast a message to all connected devices, use the `PJON_BROADCAST` constant as recipient ID:
+If you need to transmit in shared mode or configure other protocol fields you can use `send_packet_blocking` passing a struct of type [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info), the payload of type `const void *` and the length of type `uint16_t`:
```cpp
-bus.send_packet(PJON_BROADCAST, "Message for all connected devices.", 34);
+uint8_t bus_id[4] = {0, 0, 0, 1};
+PJON_Packet_Info info;
+info.rx.id = 10; // The recipient's device id is 10
+info.rx.port = 8000; // The packet includes the port 8000
+memcpy(info.rx.bus_id, bus_id, 4); // Copy recipient's bus id in info
+bus.send_packet_blocking(info, "Ciao!", 5);
```
-Use `send_packet_blocking` if it is necessary to try until the packet is effectively received by the recipient and so comply with the specified back-off.
-```cpp
-// Send to device id 10 the string "Hi!"
-bus.send_packet_blocking(10, "Hi!", 3);
+### `send`
-// Use the value returned by send_packet to determine transmission result
-if(bus.send_packet_blocking(10, "All is ok?!", 11) == PJON_ACK)
- Serial.println("10 is ok!");
-```
-`send_packet_blocking` returns the result of transmission as `send_packet` does.
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| Yes | No | `strategy.get_max_attempts()` |
-PJON can also optionally handle packets for you, although a little more memory is required. The first thing to do and never forget is to call the `update()` function once per loop cycle:
+When using the `send` method, PJON operates using its internal buffer, although a little more memory is required, this call is non-blocking and automatically handles back-off. The first thing to do and never forget is to call the `update` method once per loop cycle:
```cpp
bus.update();
```
-To send data to another device connected to the bus simply call `send` passing the recipient's id (and its bus id if necessary), the payload you want to send and its length:
+Every time `update` is called the transmission is attempted for each packet present in the buffer.
+
+To send data to another device connected to the bus simply call `send` passing the device id of the recipient of type `uint8_t` then the payload of type `const void *` and its length of type `uint16_t`. The return value of `send` of type `uint16_t` is the index of the packet in the `packets` buffer or `PJON_FAIL` in case of error.
```cpp
-// Local
bus.send(100, "Ciao, this is a test!", 21);
-
-// Shared or using bus indexing
-uint8_t bus_id[] = {0, 0, 0, 1};
-bus.send(100, bus_id, "Ciao, this is a test!", 21);
-
-// All optional parameters available
-
-// Local mode
-bus.send(
- 100, // (uint8_t) Recipient device id
- "Test port id", // (const void *) Payload
- 23, // (uint16_t) Length
- bus.config, // (uint8_t) Packet header
- 1, // (uint16_t) Packet id
- 8002 // (uint16_t) Port identification
-);
-
+```
+`send` can receive 3 optional parameters, the header of type `uint8_t`, a packet id of type `uint16_t` (pass 0 if you want to avoid the packet id inclusion) and a port of type `uint16_t`. In the example below a packet containing the payload "Hello" is sent to device id 2 using the actual instance's header configuration, without including the packet id and including the port `8002`:
+```cpp
// Shared mode or using bus indexing
bus.send(
- 100, // (uint8_t) Recipient device id
- bus_id, // (uint8_t *) Recipient bus id
- "Test port id", // (const void *) Payload
- 23, // (uint16_t) Length
- bus.config, // (uint8_t) Packet header
- 1, // (uint16_t) Packet id
- 8002 // (uint16_t) Port identification
+ 2, // (uint8_t) Recipient device id
+ "Hello", // (const void *) Payload
+ 5, // (uint16_t) Length
+ bus.config, // (uint8_t) Packet header
+ 0, // (uint16_t) Packet id
+ 8002 // (uint16_t) Port identification
);
+```
+
+The `send` method accepts any type of data, in the example below a custom `struct` is sent to device id 1:
+```cpp
+// Define a custom data type
+struct voltage_record { uint16_t v1; uint16_t v2; };
+// Fill it with information
+voltage_record record;
+record.v1 = analogRead(A1);
+record.v2 = analogRead(A2);
+// Send to device id 1 the record struct
+bus.send(1, &record, sizeof(record));
+```
+
+To use the return value of `send` just save it in a variable of type `uint16_t`:
+```cpp
+uint16_t packet = bus.send(100, "Ciao, this is a test!", 21);
+if(packet == PJON_FAIL) Serial.print("Something went wrong");
```
-Payload length is boring to be added but is there to prevent buffer overflow. If sending arbitrary values `NULL` terminator strategy based on `strlen` is not safe to detect the end of a string. The `send` call returns an id, that is the reference to the packet you have dispatched. To send a value repeatedly simply call `send_repeatedly` and pass as last parameter the interval in microseconds you want between every sending:
+
+If you need to transmit in shared mode or configure other protocol fields you can use `send` passing a struct of type [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info), the payload of type `const void *` and the length of type `uint16_t`:
+```cpp
+uint8_t bus_id[4] = {0, 0, 0, 1};
+PJON_Packet_Info info;
+info.rx.id = 10; // The recipient's device id is 10
+info.rx.port = 8000; // The packet includes the port 8000
+memcpy(info.rx.bus_id, bus_id, 4); // Copy recipient's bus id in info
+bus.send(info, "Ciao!", 5);
+```
+
+### `send_repeatedly`
+
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| Yes | No | `strategy.get_max_attempts()` |
+
+The `send_repeatedly` method can be used when it is required to schedule a repeated transmission. The first parameter is the device id of the recipient of type `uint8_t` then follows the payload of type `const void *`, its length of type `uint16_t` and the interval of type `uint32_t`:
```cpp
// Local sending example
uint16_t one_second_test =
@@ -127,20 +220,138 @@ uint16_t one_second_test =
/* IMPORTANT: maximum interval supported is
4293014170 microseconds or 71.55 minutes */
-// Shared sending example including all optional parameters
-uint16_t one_second_test_shared =
- bus.send_repeatedly(
- 100, // (uint8_t) Recipient device id
- bus_id, // (uint8_t *) Recipient bus id
- "Test port id", // (const void *) Payload
- 23, // (uint16_t) Length
- 1000000, // (uint32_t) Interval in microseconds
- bus.config, // (uint8_t) Packet header
- 1, // (uint16_t) Packet id
- 8002 // (uint16_t) Port identification
- );
-```
-`send_repeatedly` returns the id of the packet in the packet's buffer as `send` does, to remove this repeated transmission simply:
+```
+`send_repeatedly` returns the index of the packet in the `packets` buffer as `send` does, to remove the repeated transmission simply call:
```cpp
bus.remove(one_second_test);
```
+`send_repeatedly` can receive 3 optional parameters: the header of type `uint8_t`, a packet id of type `uint16_t` (pass 0 if you want to avoid the packet id inclusion) and a port of type `uint16_t`. In the example below a packet containing the payload "Hello" is sent to device id 2 every second using the actual instance's header configuration, without including the packet id and including the port `8002`:
+```cpp
+// Shared mode or using bus indexing
+bus.send_repeatedly(
+ 2, // (uint8_t) Recipient device id
+ "Hello", // (const void *) Payload
+ 5, // (uint16_t) Length
+ 1000000 // (uint32_t) Interval
+ bus.config, // (uint8_t) Packet header
+ 0, // (uint16_t) Packet id
+ 8002 // (uint16_t) Port identification
+);
+```
+The `send_repeatedly` method accepts any type of data, in the example below a custom `struct` is sent to device id 1:
+```cpp
+// Define a custom data type
+struct voltage_record { uint16_t v1; uint16_t v2; };
+// Fill it with information
+voltage_record record;
+record.v1 = analogRead(A1);
+record.v2 = analogRead(A2);
+// Send to device id 1 the record struct
+bus.send_repeatedly(1, &record, sizeof(record));
+```
+
+If you need to transmit in shared mode or configure other protocol fields you can use `send_repeatedly` passing a struct of type [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info), the payload of type `const void *`, the length of type `uint16_t` and the interval of type `uint32_t`:
+```cpp
+uint8_t bus_id[4] = {0, 0, 0, 1};
+PJON_Packet_Info info;
+info.rx.id = 10; // The recipient's device id is 10
+info.rx.port = 8000; // The packet includes the port 8000
+memcpy(info.rx.bus_id, bus_id, 4); // Copy recipient's bus id in info
+bus.send_repeatedly(info, "Ciao!", 5, 1000000); // Send "Ciao!" every second
+```
+
+### `reply`
+
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| Yes | No | `strategy.get_max_attempts()` |
+
+The `reply` method can be called within the [receiver function](/documentation/data-reception.md#data-reception) to reply to a packet received previously:
+```cpp
+bus.reply("All fine!", 9);
+```
+Consider that `reply` dispatches a packet in the buffer like `send` or `send_repeatedly`. To use the return value of `send` just save it in a variable of type `uint16_t`:
+```cpp
+uint16_t packet = bus.reply("Ciao, this is a test!", 21);
+if(packet == PJON_FAIL) Serial.print("Something went wrong");
+```
+The `reply` method accepts any type of data, in the example below a custom struct is sent to device id 1:
+```cpp
+// Define a custom data type
+struct voltage_record { uint16_t v1; uint16_t v2; };
+// Fill it with information
+voltage_record record;
+record.v1 = analogRead(A1);
+record.v2 = analogRead(A2);
+// Reply with the record struct
+bus.reply(&record, sizeof(record));
+```
+
+### `reply_blocking`
+
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| No | Yes | `strategy.get_max_attempts()` |
+
+The `reply_blocking` method can be called within the [receiver function](/documentation/data-reception.md#data-reception) to reply to a packet received previously:
+```cpp
+bus.reply_blocking("All fine!", 9);
+```
+Consider that `reply_blocking` is a blocking procedure that in case of failure can last a considerable amount of time. The `reply_blocking` result, of type `uint16_t`, can be used to determine if the transmission occurred successfully or not:
+```cpp
+uint16_t result = bus.reply_blocking("All is ok!", 11);
+if(result == PJON_ACK) Serial.println("Responded successfully!");
+```
+The `reply_blocking` method accepts any type of data, in the example below a custom `struct` is sent to device id 1:
+```cpp
+// Define a custom data type
+struct voltage_record { uint16_t v1; uint16_t v2; };
+// Fill it with information
+voltage_record record;
+record.v1 = analogRead(A1);
+record.v2 = analogRead(A2);
+// Reply with the record struct
+bus.reply_blocking(&record, sizeof(record));
+```
+
+### `forward`
+
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| Yes | No | `strategy.get_max_attempts()` |
+
+The `forward` method can retransmit a packet received previously to another device using its original sender's identification. It is useful to implement switching or routing features:
+```cpp
+void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &info) {
+ bus.forward(info, payload, length);
+ // Forward each packet is received
+};
+```
+
+Consider that `forward` dispatches a packet in the buffer like `send` or `send_repeatedly`. To use the return value of `forward` just save it in a variable of type `uint16_t`:
+```cpp
+uint16_t packet = bus.forward(info, payload, length);
+if(packet == PJON_FAIL) Serial.print("Something went wrong");
+```
+The `forward` method accepts any type of data like `send` or `send_repeatedly`.
+
+### `forward_blocking`
+
+| Buffered | Blocking | Attempts |
+| -------- | -------- | ----------------------------- |
+| No | Yes | `strategy.get_max_attempts()` |
+
+The `forward_blocking` method can retransmit a packet received previously to another device using its original sender's identification. It is useful to implement switching or routing features:
+```cpp
+void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &info) {
+ bus.forward_blocking(info, payload, length);
+ // Forward each packet is received
+};
+```
+
+Consider that `forward_blocking` is a blocking procedure that in case of failure can last a considerable amount of time. The `forward_blocking` result, of type `uint16_t`, can be used to determine if the transmission occurred successfully or not:
+```cpp
+uint16_t result = bus.forward_blocking(info, payload, length);
+if(result == PJON_ACK) Serial.println("Responded successfully!");
+```
+The `forward_blocking` method accepts any type of data like `send` or `send_repeatedly`.
diff --git a/documentation/error-handling.md b/documentation/error-handling.md
index f3e9f122d5..54e6d528b3 100644
--- a/documentation/error-handling.md
+++ b/documentation/error-handling.md
@@ -1,22 +1,30 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- **[Error handling](/documentation/error-handling.md)**
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
-
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Error handling
PJON is designed to inform the user if an error is detected. A function of type `void` can be defined and registered to be called by the PJON object in case of error; it receives 3 parameters, the first is the error code of type `uint8_t`, the second is additional data related to the error of type `uint16_t` and the third is a general purpose custom pointer of type `void *`.
Error types:
-- `PJON_CONNECTION_LOST` (value 101), `data` parameter contains lost packet's index in the packets buffer.
-- `PJON_PACKETS_BUFFER_FULL` (value 102), `data` parameter contains buffer length.
-- `PJON_CONTENT_TOO_LONG` (value 104), `data` parameter contains content length.
+- `PJON_CONNECTION_LOST` or 101, `data` parameter contains lost packet's index in the buffer.
+- `PJON_PACKETS_BUFFER_FULL` or 102, `data` parameter contains buffer length.
+- `PJON_CONTENT_TOO_LONG` or 104, `data` parameter contains content length.
```cpp
void error_handler(uint8_t code, uint16_t data, void *custom_pointer) {
diff --git a/documentation/io-setup.md b/documentation/io-setup.md
index 911c3dfa0e..f4fe9f822b 100644
--- a/documentation/io-setup.md
+++ b/documentation/io-setup.md
@@ -1,31 +1,39 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- **[IO setup](/documentation/io-setup.md)**
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- [Routing](/documentation/routing.md)
-
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- **[IO setup](/documentation/io-setup.md)**
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## IO setup
The physical layer configuration is handled by the [strategy](/src/strategies/README.md) entity, if you want to communicate bi-directionally on a single pin with [SoftwareBitBang](/src/strategies/SoftwareBitBang) or [AnalogSampling](/src/strategies/AnalogSampling) use:
```cpp
- PJON bus;
+ PJONSoftwareBitBang bus;
bus.strategy.set_pin(12);
```
With this setup it is possible to communicate in `PJON_HALF_DUPLEX` mode with up to 254 different devices on the same physical pin. If for some reason you need to keep separate the two lines, for example if using [OverSampling](/src/strategies/OverSampling) with separate radio transmitter and receiver modules, you can pass 2 separate pins:
```cpp
- PJON bus;
+ PJONOverSampling bus;
bus.strategy.set_pins(11, 12);
```
If you don't need bidirectional communication and you have only the transmitter on one side and the receiver on the other side you can use the `PJON_NOT_ASSIGNED` constant:
```cpp
- PJON bus;
+ PJONOverSampling bus;
// Operate in simplex mode
bus.set_communication_mode(PJON_SIMPLEX);
// Use only receiver pin
diff --git a/documentation/routing.md b/documentation/routing.md
index 1f88ac6252..e366af1186 100644
--- a/documentation/routing.md
+++ b/documentation/routing.md
@@ -1,89 +1,67 @@
### Documentation index
- [Addressing](/documentation/addressing.md)
+ - [`set_id`](/documentation/addressing.md#local-mode) [`device_id`](/documentation/addressing.md#local-mode) [`get_bus_id`](/documentation/addressing.md#shared-mode) [`set_bus_id`](/documentation/addressing.md#shared-mode) [`get_mac`](/documentation/addressing.md#get-or-set-hardware-identifier) [`set_mac`](/documentation/addressing.md#get-or-set-hardware-identifier)
- [Configuration](/documentation/configuration.md)
+ - [`set_communication_mode`](/documentation/configuration.md#communication-mode) [`set_shared_network`](/documentation/configuration.md#network-mode) [`set_router`](/documentation/configuration.md#router-mode) [`include_sender_info`](/documentation/configuration.md#sender-information) [`set_crc_32`](/documentation/configuration.md#crc-configuration) [`set_packet_auto_deletion`](/documentation/configuration.md#packet-handling) [`set_acknowledge`](/documentation/configuration.md#acknowledgement) [`set_packet_id`](/documentation/configuration.md#packet-identification) [`include_port`](/documentation/configuration.md#network-service-identification) [`include_mac`](/documentation/configuration.md#hardware-identification)
- [Data reception](/documentation/data-reception.md)
+ - [`set_receiver`](/documentation/data-reception.md#data-reception) [`receive`](/documentation/data-reception.md#data-reception)
+- [Data structures](/documentation/data-structures.md)
+ - [`PJON_Endpoint`](/documentation/data-structures.md#pjon_endpoint) [`PJON_Packet_Info`](/documentation/data-structures.md#pjon_packet_info)
- [Data transmission](/documentation/data-transmission.md)
+ - [`begin`](/documentation/data-transmission.md#begin) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`send`](/documentation/data-transmission.md#send) [`send_packet`](/documentation/data-transmission.md#send_packet) [`send_packet_blocking`](/documentation/data-transmission.md#send_packet_blocking) [`send_repeatedly`](/documentation/data-transmission.md#send_repeatedly) [`reply`](/documentation/data-transmission.md#reply) [`reply_blocking`](/documentation/data-transmission.md#reply_blocking) [`forward`](/documentation/data-transmission.md#forward) [`forward_blocking`](/documentation/data-transmission.md#forward_blocking)
- [Error handling](/documentation/error-handling.md)
-- [IO setup](/documentation/io-setup.md)
+ - [`set_error`](/documentation/error-handling.md#error-handling)
- **[Routing](/documentation/routing.md)**
+ - [`PJONSimpleSwitch`](/documentation/routing.md#simpleswitch) [`PJONSwitch`](/documentation/routing.md#switch) [`PJONRouter`](/documentation/routing.md#router) [`PJONDynamicRouter`](/documentation/routing.md#dynamicrouter) [`PJONInteractiveRouter`](/documentation/routing.md#interactiverouter)
+- [IO setup](/documentation/io-setup.md)
+ - [`strategy`](/documentation/io-setup.md#io-setup)
---
## Routing
-Transparent routing based on a tree topology has been implemented by Fred Larsen with the [PJONSimpleSwitch](#simpleswitch), [PJONSwitch](#switch), [PJONRouter](#router), [PJONDynamicRouter](#dynamicrouter), [PJONInteractiveRouter](#interactiverouter) and [PJONVirtualBusRouter](#virtual-bus).
+Transparent routing based on a tree topology that may include loops has been implemented by Fred Larsen with the [PJONSimpleSwitch](#simpleswitch), [PJONSwitch](#switch), [PJONRouter](#router), [PJONDynamicRouter](#dynamicrouter), [PJONInteractiveRouter](#interactiverouter) and [PJONVirtualBusRouter](#virtual-bus).
### SimpleSwitch
-The [PJONSimpleSwitch](/examples/ARDUINO/Local/SoftwareBitBang/Switch/SimpleSwitch) class connects two buses using the same strategy. In this example a `SoftwareBitBang` <=> `SoftwareBitBang` switch is created. It can be used to amplify signals and so extend the maximum range or in more complex setups selectively switch packets as requested by its configuration. It can be used instead of `PJONSwitch` to save memory when the same strategy is used in all buses. It avoids virtual inheritance so it is faster and has a smaller footprint.
+The [PJONSimpleSwitch](/examples/routing/ARDUINO/Network/Switch/SimpleSwitch/SimpleSwitch.ino) class connects two or more buses using the same strategy. In this example a `SoftwareBitBang` <=> `SoftwareBitBang` switch is created. It can be used to amplify signals and so extend the maximum range or in more complex setups selectively switch packets as requested by its configuration. It can be used instead of `PJONSwitch` to save memory when the same strategy is used in all buses. It avoids virtual inheritance so it is faster and has a smaller footprint.
```cpp
- __________ ________ __________
-| | SWBB bus | | SWBB bus | |
-| DEVICE 1 |___________| SWITCH |____________| DEVICE 2 |
-|__________| |________| |__________|
+/* __________ ________ __________
+ | | Pin 7 | | Pin 12 | |
+ | DEVICE 1 |_______________| SWITCH |_______________| DEVICE 2 |
+ |__________| Bus 0.0.0.1 |________| Bus 0.0.0.2 |__________| */
+
```
-The first thing to do is to include the `PJONSimpleSwitch` class:
+The first thing to do is to include `PJONSimpleSwitch` and the required strategy:
```cpp
#include
+#include
```
-The `SimpleSwitch` class provides with configurable transparent packet switching between buses using the same strategy. `SimpleSwitch` requires a tree topology (it does not contain any loop detection procedure). The `SimpleSwitch` class receives as a parameter the length and the array of 2 or more `PJONBus` instances:
-```cpp
-/* In both cases the switch does not have an assigned id it is
- transparently switching packets in both directions */
-PJONBus bus1(PJON_NOT_ASSIGNED);
-PJONBus bus2(PJON_NOT_ASSIGNED);
-```
-Polling time can be optionally configured:
-```cpp
-PJONBus bus2(
- PJON_NOT_ASSIGNED, // Switch device id
- 1000 // Polling time in microseconds
-);
-```
-Device id ranges can be optionally configured:
-```cpp
-PJONBus bus2(
- PJON_NOT_ASSIGNED, // Switch device id
- 1000, // Polling time in microseconds
- 2, // 2 ranges present (1-127, 128-254)
- 0, // range 1 in use here (1-127)
-);
-```
-After the `PJONBus` definitions, a `PJONSimpleSwitch` instance can be created:
+The `SimpleSwitch` class provides with configurable transparent packet switching between buses using the same strategy:
```cpp
-// PJONSimpleSwitch definition:
-PJONSimpleSwitch router(
- 2, // Length of the bus array
- (PJONBus*[2]){&bus1,&bus2} // Bus array
-);
-```
-A default gateway can be optionally configured:
-```cpp
-PJONSimpleSwitch router(
- 2, // Length of the bus array
- (PJONBus*[2]){&bus1,&bus2}, // Bus array
- 122 // Statically defined default gateway device id
-);
+PJON bus1((const uint8_t[4]){0, 0, 0, 1}, PJON_NOT_ASSIGNED),
+ bus2((const uint8_t[4]){0, 0, 0, 2}, PJON_NOT_ASSIGNED);
+
+PJONSimpleSwitch router(bus1, bus2);
+
```
-Configure each strategy and the `router` instance as required:
+In the example above two PJON instances using SoftwareBitBang, operating in shared mode, with bus id `0.0.0.1` and `0.0.0.2` are merged with the `SimpleSwitch` instance. Packets are switched between the two buses. In the `setup` just include strategy related configuration, for example the pin used for communication:
+
```cpp
void setup() {
- // Set each SoftwareBitBang bus pin connection
bus1.strategy.set_pin(7);
bus2.strategy.set_pin(12);
router.begin();
}
-```
-Call the `loop` function as often as possible to achieve optimal performance:
-```cpp
void loop() {
router.loop();
-};
+}
```
+Then the `PJONSimpleSwitch` should work transparently. `PJONSimpleSwitch` can be used also in local mode, although, because the hop count field is not included, the network topology cannot include loops.
### Switch
-The [PJONSwitch](/examples/ARDUINO/Local/SoftwareBitBang/Switch/Switch) class transparently switches packets between locally attached buses also if different strategies or media are in use. It supports a default gateway to be able to act as a leaf in a larger network setup. Thanks to the `PJONSwitch` class, with few lines of code, a switch that operates multiple strategies can be created. In this example a `SoftwareBitBang` <=> `AnalogSampling` switch is created:
+[PJONSwitch](/examples/routing/ARDUINO/Network/Switch/Switch) transparently switches packets between locally attached buses also if different strategies or media are in use. It supports a default gateway to be able to act as a leaf in a larger network setup. Thanks to the `PJONSwitch` class, with few lines of code, a switch that operates multiple strategies can be created. In this example a `SoftwareBitBang` <=> `AnalogSampling` switch is created:
```cpp
/* Connect SoftwareBitBang bus with an AnalogSampling bus:
@@ -92,51 +70,25 @@ The [PJONSwitch](/examples/ARDUINO/Local/SoftwareBitBang/Switch/Switch) class tr
|DEVICE1|_______________|SWITCH| _ _ _ _ _ _ _|DEVICE2|
|_______|BUS ID 0.0.0.1 |______|BUS ID 0.0.0.2|_______| */
```
-The first thing to do is to include the `PJONSwitch` class:
+First include the `PJONSwitch` class and the strategies used:
```cpp
#include
+#include
+#include
```
-Create `StrategyLink` instances with the selected strategies:
-```cpp
-StrategyLink link1;
-StrategyLink link2;
-```
-Create `PJONAny` instances configuring the bus id:
+The simplest way to use the `PJONSwitch` class is to use `PJONSwitch2` that is able to handle up to 2 buses:
```cpp
-PJONAny bus1(&link1, (uint8_t[4]){0, 0, 0, 1});
-PJONAny bus2(&link2, (uint8_t[4]){0, 0, 0, 2});
+PJONSwitch2 router;
```
-Polling time can be optionally configured:
+Use `get_strategy_0` and `get_strategy_1` to access one of the two strategies:
```cpp
-PJONAny bus1(
- &link1,
- (uint8_t[4]){0,0,0,1},
- PJON_NOT_ASSIGNED, // Switch device id
- 1000 // Polling in microseconds
-);
+router.get_strategy_0().set_pin(12); // SoftwareBitBang pin used is 12
+router.get_strategy_1().set_pin(A0); // AnalogSampling pin used is A0
```
-Device id ranges can be optionally configured:
+Use `get_bus` to access one of the two instances:
```cpp
-PJONAny bus1(
- &link1,
- (uint8_t[4]){0,0,0,1},
- PJON_NOT_ASSIGNED, // Switch device id
- 1000, // Polling in microseconds
- 2, // 2 ranges present (1-127, 128-254)
- 0 // Range 1 in use (1-127)
-);
-```
-Create the `PJONSwitch` instance passing the `PJONAny` instances:
-```cpp
-PJONSwitch router(2, (PJONAny*[2]){&bus1, &bus2});
-```
-Configure each strategy and the `router` instance as required:
-```cpp
-void setup() {
- link1.strategy.set_pin(12);
- link2.strategy.set_pin(A0);
- router.begin();
-}
+router.get_bus(0).set_bus_id((const uint8_t[4]){0, 0, 0, 1});
+router.get_bus(1).set_bus_id((const uint8_t[4]){0, 0, 0, 2});
```
Call the `loop` function as often as possible to achieve optimal performance:
```cpp
@@ -144,8 +96,11 @@ void loop() {
router.loop();
}
```
+
+Consider that there is also `PJONSwitch3` able to handle up to 3 buses, and `PJONSwitch` able to handle an array of buses. `PJONSwitch` can be used also in local mode, although, because the hop count field is not included, the network topology cannot include loops.
+
### Router
-The [PJONRouter](/examples/ARDUINO/Network/SoftwareBitBang/Router) class routes between both locally attached buses also if different strategies or media are in use, and remote buses reachable through the locally attached buses. In this example simple a router is created:
+The [PJONRouter](/examples/routing/ARDUINO/Network/Router/Router) class routes between both locally attached buses also if different strategies or media are in use, and remote buses reachable through the locally attached buses using a static routing table. In this example simple a router is created:
```cpp
________
Bus 0.0.0.3 | | Bus 0.0.0.4
@@ -158,33 +113,20 @@ ________________| ROUTER |________________
| DEVICE 1 | | DEVICE 2 |
|__________| |__________|
```
-The first thing to do is to include the `PJONRouter` class:
+The first thing to do is to include the `PJONRouter` class and include the required strategy:
```cpp
#include
+#include
```
-Create `StrategyLink` instances with the selected strategies:
-```cpp
-StrategyLink link1;
-StrategyLink link2;
-```
-Create `PJONAny` instances configuring the bus id:
+The simplest way to use the `PJONRouter` class is to use `PJONRouter2` that is able to handle up to 2 buses:
```cpp
-PJONAny bus1(&link1, (uint8_t[4]){0, 0, 0, 3});
-PJONAny bus2(&link2, (uint8_t[4]){0, 0, 0, 4});
-```
-Create the `PJONRouter` instance passing the `PJONAny` instances:
-```cpp
-PJONRouter router(2, (PJONAny*[2]){&bus1, &bus2});
+PJONRouter2 router;
```
Configure each strategy and the `router` instance as required:
```cpp
void setup() {
- link1.strategy.set_pin(7);
- link2.strategy.set_pin(12);
-
- router.add((const uint8_t[4]){0,0,0,1}, 0);
- router.add((const uint8_t[4]){0,0,0,2}, 1);
-
+ router.get_strategy_0().set_pin(7);
+ router.get_strategy_1().set_pin(12);
router.begin();
}
```
@@ -198,8 +140,10 @@ void loop() {
router.loop();
}
```
+Consider that there is also `PJONRouter3` able to handle up to 3 buses, and `PJONRouter` able to handle an array of buses. `PJONRouter` can be used also in local mode, although, because the hop count field is not included, the network topology cannot include loops.
+
### DynamicRouter
-The [PJONDynamicRouter](/examples/ARDUINO/Network/SoftwareBitBang/Router/DynamicRouter) is a router that also populates a routing table of remote (not directly attached) buses observing traffic. It can offer the same features provided by the `PJONRouter` class with no need of manual configuration. To do so, the `PJONDynamicRouter` class uses a routing table that is dynamically updated, for this reason uses more memory if compared with `PJONRouter`. Use the `PJON_ROUTER_TABLE_SIZE` constant to configure the number of entries that are `100` by default.
+The [PJONDynamicRouter](/examples/routing/ARDUINO/Network/DynamicRouter/DynamicRouter.ino) is a router that also populates a routing table of remote (not directly attached) buses observing traffic. It can offer the same features provided by the `PJONRouter` class with no need of manual configuration. To do so, the `PJONDynamicRouter` class uses a routing table that is dynamically updated, for this reason uses more memory if compared with `PJONRouter`. Use the `PJON_ROUTER_TABLE_SIZE` constant to configure the number of entries that are `100` by default.
```cpp
________
Bus 0.0.0.3 | | Bus 0.0.0.4
@@ -212,29 +156,21 @@ ________________| ROUTER |________________
| DEVICE 1 | | DEVICE 2 |
|__________| |__________|
```
-The first thing to do is to include the `PJONDynamicRouter` class:
+The first thing to do is to include the `PJONDynamicRouter` class and the required strategies:
```cpp
#include
+#include
+#include
```
-Create `StrategyLink` instances with the selected strategies:
-```cpp
-StrategyLink link1;
-StrategyLink link2;
-```
-Create `PJONAny` instances configuring the bus id:
-```cpp
-PJONAny bus1(&link1, (uint8_t[4]){0, 0, 0, 3});
-PJONAny bus2(&link2, (uint8_t[4]){0, 0, 0, 4});
-```
-Create the `PJONRouter` instance passing the `PJONAny` instances:
+The simplest way to use the `PJONDynamicRouter` class is to use `PJONDynamicRouter2` that is able to handle up to 2 buses:
```cpp
-PJONDynamicRouter router(2, (PJONAny*[2]){&bus1, &bus2});
+PJONDynamicRouter2 router;
```
Configure each strategy and the `router` instance as required:
```cpp
void setup() {
- link1.strategy.set_pin(7);
- link2.strategy.set_pin(12);
+ router.get_strategy_0().set_pin(7);
+ router.get_strategy_1().set_pin(12);
router.begin();
}
```
@@ -245,8 +181,17 @@ void loop() {
}
```
+Consider that there is also `PJONDynamicRouter3` able to handle up to 3 buses, and `PJONDynamicRouter` able to handle an array of buses. `PJONDynamicRouter` can be used also in local mode, although, because the hop count field is not included, the network topology cannot include loops.
+
### InteractiveRouter
-[Interactive router](/examples/ARDUINO/Network/SoftwareBitBang/Switch/BlinkingSwitch) routes packets as a switch or router but it is also able to act as a device and have user-defined receive and error call-back.
+[Interactive router](/examples/routing/ARDUINO/Network/Switch/BlinkingSwitch) routes packets as a switch or router but it is also able to act as a device and have user-defined receive and error call-back.
+
+This class implements functionality that can be added to any of the routing classes except PJONSimpleSwitch. Adding the functionality to PJONDynamicRouter can be done as:
+```cpp
+PJONInteractiveRouter> router;
+```
### Virtual bus
-[Virtual bus](/examples/ARDUINO/Local/SoftwareBitBang/Tunneler) is a bus where multiple buses using potentially different media or strategies, connected through a router, have the same bus id (including the local bus case), and where the location of each device is automatically registered observing traffic.
+[Virtual bus](/examples/routing/ARDUINO/Local/Tunneler) is a bus where multiple buses using potentially different media or strategies, connected through a router, have the same bus id (including the local bus case), and where the location of each device is automatically registered observing traffic. Just like `PJONInteractiveRouter`, this class implements functionality that can be added to any of the routing classes except `PJONSimpleSwitch`. It can also be combined with the functionality added by `PJONInteractiveRouter`.
+
+This class makes it easy to create a bus that consists of multiple physical buses using one or more strategies. It can for example connect several clusters of SWBB local buses together through another strategy like DualUDP, to form one larger local bus. also including DualUDP devices.
diff --git a/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Receiver/Receiver.ino b/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Receiver/Receiver.ino
index 28c771a724..817ca115c0 100644
--- a/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Receiver/Receiver.ino
@@ -1,11 +1,11 @@
-#include
+#include
/* Use a couple of visible light / IR / UV LEDs as wireless bidirectional transceivers
To know how to wire up the circuit see the AnalogSampling README:
https://github.com/gioblu/PJON/tree/master/src/strategies/AnalogSampling */
-// bus(selected device id)
-PJON bus(44);
+
+PJONAnalogSampling bus(44);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
diff --git a/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Transmitter/Transmitter.ino
index c970c61979..071fe3c817 100644
--- a/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/AnalogSampling/BlinkTest/Transmitter/Transmitter.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONAnalogSampling bus(45);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
diff --git a/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Receiver/Receiver.ino b/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Receiver/Receiver.ino
index 96ca6b86d7..53a01e1284 100644
--- a/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Receiver/Receiver.ino
@@ -3,10 +3,10 @@
To know how to wire up the circuit see the AnalogSampling README:
https://github.com/gioblu/PJON/tree/master/src/strategies/AnalogSampling */
-#include
+#include
-// bus(selected device id)
-PJON bus(44);
+
+PJONAnalogSampling bus(44);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
diff --git a/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Transmitter/Transmitter.ino
index 2bff1ccd0f..b061fc9cd1 100644
--- a/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/AnalogSampling/NetworkAnalysis/Transmitter/Transmitter.ino
@@ -6,15 +6,15 @@
Try different resistor values to find the optimal to maximize range
Higher resistance can higher the range but can also higher background noise. */
-#include
+#include
float test;
float mistakes;
int busy;
int fail;
-// bus(selected device id)
-PJON bus(45);
+
+PJONAnalogSampling bus(45);
int packet;
uint8_t content[] = "01234567890123456789";
diff --git a/examples/ARDUINO/Local/Any/MultiStrategyLink/Receiver/Receiver.ino b/examples/ARDUINO/Local/Any/MultiStrategyLink/Receiver/Receiver.ino
index 00f0a37eaa..95bc5444ba 100644
--- a/examples/ARDUINO/Local/Any/MultiStrategyLink/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/Any/MultiStrategyLink/Receiver/Receiver.ino
@@ -1,4 +1,4 @@
-#include
+#include
/* Defining strategies using StrategyLink template class it is possible to
leverage of virtual inheritance to handle PJON instances dynamically, for
@@ -7,10 +7,10 @@
StrategyLink link1;
StrategyLink link2;
-PJON bus1(44), bus2(45);
+PJONAny bus1(44), bus2(45);
const uint8_t bus_count = 2;
-PJON *buses[] = { &bus1, &bus2 };
+PJONAny *buses[] = { &bus1, &bus2 };
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
diff --git a/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter1/Transmitter1.ino b/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter1/Transmitter1.ino
index 77dd0ae64a..fa328f64dd 100644
--- a/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter1/Transmitter1.ino
+++ b/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter1/Transmitter1.ino
@@ -1,20 +1,13 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
+// Transmission speed modes (see Timing.h)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
+#include
-//#define SWBB_RESPONSE_TIMEOUT 1000
-#include
-
-// bus(selected device id)
PJON bus(1);
void error_handler(uint8_t code, uint16_t data, void *custom_pointer) {
diff --git a/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter2/Transmitter2.ino b/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter2/Transmitter2.ino
index 72b5706876..0ec637a37f 100644
--- a/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter2/Transmitter2.ino
+++ b/examples/ARDUINO/Local/Any/MultiStrategyLink/Transmitter2/Transmitter2.ino
@@ -1,20 +1,13 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
+// Transmission speed modes (see Timing.h)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
+#include
-//#define SWBB_RESPONSE_TIMEOUT 1000
-#include
-
-// bus(selected device id)
PJON bus(1);
void error_handler(uint8_t code, uint16_t data, void *custom_pointer) {
diff --git a/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Receiver/Receiver.ino b/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Receiver/Receiver.ino
index e1ce1e65c5..8738606b92 100644
--- a/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Receiver/Receiver.ino
@@ -1,4 +1,4 @@
-#include
+#include
/* Defining strategies using StrategyLink template class it is possible to
leverage of virtual inheritance to handle PJON instances dynamically, for
@@ -6,7 +6,7 @@
StrategyLink link;
-PJON bus(44);
+PJONAny bus(44);
void setup() {
link.strategy.set_pin(12);
diff --git a/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Transmitter/Transmitter.ino
index 0428463830..4f84e840de 100644
--- a/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/Any/StrategyLinkNetworkAnalysis/Transmitter/Transmitter.ino
@@ -1,17 +1,11 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
+// Transmission speed modes (see Timing.h)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
-//#define SWBB_RESPONSE_TIMEOUT 1000
-
-#include
+#include
float test;
float mistakes;
@@ -20,7 +14,7 @@ int fail;
StrategyLink link;
-PJON bus(44);
+PJONAny bus(44);
int packet;
uint8_t content[] = "01234567890123456789";
diff --git a/examples/ARDUINO/Local/DualUDP/PingPong/Receiver/Receiver.ino b/examples/ARDUINO/Local/DualUDP/PingPong/Receiver/Receiver.ino
index 84cfa298d7..4d600baa16 100644
--- a/examples/ARDUINO/Local/DualUDP/PingPong/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/DualUDP/PingPong/Receiver/Receiver.ino
@@ -1,10 +1,10 @@
-#include
+#include
// Ethernet configuration for this device
byte mac[] = {0xDA, 0x5A, 0x4E, 0xEF, 0xAE, 0xED};
-// bus(selected device id)
-PJON bus(44);
+
+PJONDualUDP bus(44);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/DualUDP/PingPong/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/DualUDP/PingPong/Transmitter/Transmitter.ino
index 64810133e5..d62bca99a2 100644
--- a/examples/ARDUINO/Local/DualUDP/PingPong/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/DualUDP/PingPong/Transmitter/Transmitter.ino
@@ -1,10 +1,10 @@
-#include
+#include
// Ethernet configuration for this device
byte mac[] = {0xDA, 0xCA, 0x7E, 0xEF, 0xFE, 0x5D};
-// bus(selected device id)
-PJON bus(45);
+
+PJONDualUDP bus(45);
uint32_t cnt = 0, wait_for_reply = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/EthernetTCP/PingPong/Receiver/Receiver.ino b/examples/ARDUINO/Local/EthernetTCP/PingPong/Receiver/Receiver.ino
index 682d5718c3..3880b4a92b 100644
--- a/examples/ARDUINO/Local/EthernetTCP/PingPong/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/EthernetTCP/PingPong/Receiver/Receiver.ino
@@ -1,4 +1,4 @@
-#include
+#include
// Ethernet configuration for this device
byte gateway[] = { 192, 1, 1, 1 };
@@ -7,8 +7,8 @@ byte mac[] = {0xDE, 0x5D, 0x4E, 0xEF, 0xAE, 0xED};
uint8_t local_ip[] = { 192, 1, 1, 144 },
remote_ip[] = { 192, 1, 1, 145 };
-// bus(selected device id)
-PJON bus(44);
+
+PJONEthernetTCP bus(44);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/EthernetTCP/PingPong/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/EthernetTCP/PingPong/Transmitter/Transmitter.ino
index bb64946980..138651700a 100644
--- a/examples/ARDUINO/Local/EthernetTCP/PingPong/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/EthernetTCP/PingPong/Transmitter/Transmitter.ino
@@ -1,4 +1,4 @@
-#include
+#include
// Ethernet configuration for this device
byte gateway[] = { 192, 1, 1, 1 };
@@ -7,8 +7,8 @@ byte mac[] = {0xDE, 0xCD, 0x7E, 0xEF, 0xFE, 0x5D};
uint8_t local_ip[] = { 192, 1, 1, 145 },
remote_ip[] = { 192, 1, 1, 144 };
-// bus(selected device id)
-PJON bus(45);
+
+PJONEthernetTCP bus(45);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/RemoteWorker/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/RemoteWorker/Transmitter/Transmitter.ino
index e18243c6b6..815259b7ef 100644
--- a/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/RemoteWorker/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/RemoteWorker/Transmitter/Transmitter.ino
@@ -25,10 +25,10 @@
#define ETCP_SINGLE_DIRECTION
//#define ETCP_SINGLE_SOCKET_WITH_ACK
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONEthernetTCP bus(45);
// Ethernet configuration for this device
uint8_t gateway[] = { 192, 1, 1, 1 };
diff --git a/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/Surrogate/Surrogate.ino b/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/Surrogate/Surrogate.ino
index dd27c61cab..20b35258f3 100644
--- a/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/Surrogate/Surrogate.ino
+++ b/examples/ARDUINO/Local/EthernetTCP/SoftwareBitBangSurrogate/Surrogate/Surrogate.ino
@@ -14,14 +14,14 @@
#define ETCP_SINGLE_DIRECTION
//#define ETCP_SINGLE_SOCKET_WITH_ACK
-#include
+#include
+#include
const uint8_t DEVICE_ID = 45;
// SWBB Device ID for this device and the RemoteWorker
-// bus(selected device id)
-PJON busA(DEVICE_ID);
-PJON busB(1);
+PJONSoftwareBitBang busA(DEVICE_ID);
+PJONEthernetTCP busB(1);
// Ethernet configuration for this device
uint8_t gateway[] = { 192, 1, 1, 1 };
@@ -55,38 +55,22 @@ void setup() {
void receiver_functionA(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
// Forward packet to RemoteWorker on bus B, preserving the original sender id
- busB.send_from_id(
- packet_info.sender_id,
- packet_info.sender_bus_id,
- DEVICE_ID,
- PJONTools::localhost(),
- (uint8_t *)payload,
- length,
- packet_info.header,
- packet_info.id,
- packet_info.port
- );
-}
+ PJON_Packet_Info p = packet_info;
+ p.rx.id = DEVICE_ID;
+ busB.forward(p, (uint8_t *)payload, length);
+};
void receiver_functionB(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
// All packets sent by the RemoteWorker is delivered to this device, when in the
// single_initiate_direction listening mode.
// Forward packet to specified target device on bus A
- busA.send_packet_blocking(
- packet_info.receiver_id,
- packet_info.receiver_bus_id,
- (uint8_t *)payload,
- length,
- packet_info.header,
- packet_info.id,
- packet_info.port
- );
+ busA.send_packet_blocking(packet_info, (uint8_t *)payload, length);
}
void loop() {
busA.receive(1000);
busB.update();
- busB.receive(1000);
+ busB.receive();
busA.update();
// Show the number of sockets created after startup
@@ -97,4 +81,4 @@ void loop() {
Serial.print(F("CONNECT COUNT: "));
Serial.println(busB.strategy.link.get_connection_count());
}
-};
\ No newline at end of file
+};
diff --git a/examples/ARDUINO/Local/GlobalUDP/PingPong/Receiver/Receiver.ino b/examples/ARDUINO/Local/GlobalUDP/PingPong/Receiver/Receiver.ino
index 43d9b88813..14e5aaa765 100644
--- a/examples/ARDUINO/Local/GlobalUDP/PingPong/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/GlobalUDP/PingPong/Receiver/Receiver.ino
@@ -1,4 +1,4 @@
-#include
+#include
// Ethernet configuration for this device
byte gateway[] = { 192, 1, 1, 1 };
@@ -9,8 +9,8 @@ uint8_t local_ip[] = { 192, 1, 1, 151 };
// Address of remote device
uint8_t remote_ip[] = { 192, 1, 1, 150 };
-// bus(selected device id)
-PJON bus(44);
+
+PJONGlobalUDP bus(44);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/GlobalUDP/PingPong/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/GlobalUDP/PingPong/Transmitter/Transmitter.ino
index 055f4c9423..9812b1c17b 100644
--- a/examples/ARDUINO/Local/GlobalUDP/PingPong/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/GlobalUDP/PingPong/Transmitter/Transmitter.ino
@@ -1,4 +1,4 @@
-#include
+#include
// Ethernet configuration for this device
byte gateway[] = { 192, 1, 1, 1 };
@@ -9,8 +9,8 @@ uint8_t local_ip[] = { 192, 1, 1, 150 };
// Address of remote device
uint8_t remote_ip[] = { 192, 1, 1, 151 };
-// bus(selected device id)
-PJON bus(45);
+
+PJONGlobalUDP bus(45);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/LocalUDP/PingPong/Receiver/Receiver.ino b/examples/ARDUINO/Local/LocalUDP/PingPong/Receiver/Receiver.ino
index 4940e4113f..5782ad0a3b 100644
--- a/examples/ARDUINO/Local/LocalUDP/PingPong/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/LocalUDP/PingPong/Receiver/Receiver.ino
@@ -1,4 +1,4 @@
-#include
+#include
// Ethernet configuration for this device
byte gateway[] = { 192, 1, 1, 1 };
@@ -6,8 +6,8 @@ byte subnet[] = { 255, 255, 255, 0 };
byte mac[] = {0xDA, 0x5A, 0x4E, 0xEF, 0xAE, 0xED};
uint8_t local_ip[] = { 192, 1, 1, 151 };
-// bus(selected device id)
-PJON bus(44);
+
+PJONLocalUDP bus(44);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/LocalUDP/PingPong/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/LocalUDP/PingPong/Transmitter/Transmitter.ino
index e82a56db93..dda176f7f4 100644
--- a/examples/ARDUINO/Local/LocalUDP/PingPong/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/LocalUDP/PingPong/Transmitter/Transmitter.ino
@@ -1,4 +1,4 @@
-#include
+#include
// Ethernet configuration for this device
byte gateway[] = { 192, 1, 1, 1 };
@@ -6,8 +6,8 @@ byte subnet[] = { 255, 255, 255, 0 };
byte mac[] = {0xDA, 0xCA, 0x7E, 0xEF, 0xFE, 0x5D};
uint8_t local_ip[] = { 192, 1, 1, 150 };
-// bus(selected device id)
-PJON bus(45);
+
+PJONLocalUDP bus(45);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/MQTTTranslate/PingPong/Receiver/Receiver.ino b/examples/ARDUINO/Local/MQTTTranslate/PingPong/Receiver/Receiver.ino
index 804812720b..a570ee0ec6 100644
--- a/examples/ARDUINO/Local/MQTTTranslate/PingPong/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/MQTTTranslate/PingPong/Receiver/Receiver.ino
@@ -1,12 +1,12 @@
-#define PJON_INCLUDE_MQTT
-#include
+
+#include
// Ethernet configuration for this device
byte mac[] = {0xDE, 0x5A, 0x4E, 0xEF, 0xAE, 0xED};
uint8_t broker_ip[] = { 192, 1, 1, 71 };
-// bus(selected device id)
-PJON bus(44);
+
+PJONMQTTTranslate bus(44);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/MQTTTranslate/PingPong/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/MQTTTranslate/PingPong/Transmitter/Transmitter.ino
index ed9dff6bc8..2f44de591a 100644
--- a/examples/ARDUINO/Local/MQTTTranslate/PingPong/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/MQTTTranslate/PingPong/Transmitter/Transmitter.ino
@@ -1,12 +1,12 @@
-#define PJON_INCLUDE_MQTT
-#include
+
+#include
// Ethernet configuration for this device
byte mac[] = {0xDA, 0xCA, 0x7E, 0xEF, 0xFE, 0x5D};
uint8_t broker_ip[] = { 192, 1, 1, 71 };
-// bus(selected device id)
-PJON bus(45);
+
+PJONMQTTTranslate bus(45);
uint32_t cnt = 0;
uint32_t start = millis();
diff --git a/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/Gateway/Gateway.ino b/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/Gateway/Gateway.ino
index fd852c995c..dc6f556714 100644
--- a/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/Gateway/Gateway.ino
+++ b/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/Gateway/Gateway.ino
@@ -1,17 +1,18 @@
-#define PJON_INCLUDE_MQTT
+
#define MQTTT_MODE MQTTT_MODE_MIRROR_DIRECT
-#define PJON_INCLUDE_SWBB
+
#define PJON_MAX_PACKETS 2
-#include
+#include
+#include
// Ethernet configuration for this device
byte mac[] = {0xDA, 0xCA, 0x7E, 0xEF, 0xFE, 0x5D};
uint8_t broker_ip[] = { 192, 168, 1, 71 };
-// bus(selected device id)
+
#define PJON_GATEWAY_ID 254
-PJON bus(PJON_GATEWAY_ID);
-PJON mqtt;
+PJONSoftwareBitBang bus(PJON_GATEWAY_ID);
+PJONMQTTTranslate mqtt;
uint32_t cnt_to_mqtt = 0, cnt_from_mqtt = 0;
uint32_t start = millis();
@@ -23,15 +24,13 @@ bool router = false;
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
const char *msg = (const char *)payload;
// Forward to MQTT topic pjon/device45/output if from device 45
- mqtt.send_from_id(packet_info.sender_id, PJONTools::localhost(),
- packet_info.receiver_id, PJONTools::localhost(),
- payload, length, packet_info.header, packet_info.id, packet_info.port);
- cnt_to_mqtt++;
+ mqtt.forward(packet_info, payload, length);
+ cnt_to_mqtt++;
};
void receiver_function_mqtt(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
// Send to device 45 if source topic is pjon/device45/input
- bus.send(packet_info.receiver_id, payload, length);
+ bus.send(packet_info.rx.id, payload, length);
cnt_from_mqtt++;
};
@@ -64,8 +63,8 @@ void loop() {
if(millis() - start > 1000) {
start = millis();
- Serial.print("Routed packets to MQTT: "); Serial.print(cnt_to_mqtt);
+ Serial.print("Routed packets to MQTT: "); Serial.print(cnt_to_mqtt);
Serial.print(", from MQTT: "); Serial.println(cnt_from_mqtt);
cnt_from_mqtt = cnt_to_mqtt = 0;
}
-};
\ No newline at end of file
+};
diff --git a/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/SomeDevice/SomeDevice.ino b/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/SomeDevice/SomeDevice.ino
index 06e9a5f874..8eaf356b06 100644
--- a/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/SomeDevice/SomeDevice.ino
+++ b/examples/ARDUINO/Local/MQTTTranslate/SWBB-MQTT-Gateway/SomeDevice/SomeDevice.ino
@@ -1,24 +1,23 @@
// This PJON device is a simulated environmental controller, trying to change
-// temperature so that measurement is equal to the target that can be set
+// temperature so that measurement is equal to the target that can be set
// from other devices. In this case we will let it send messages to and receive
// messages from another device which is this setup is an MQTT gateway.
-// Using the free MQTT Explorer or similar, publish the value "temperature=24"
+// Using the free MQTT Explorer or similar, publish the value "temperature=24"
// to the topic pjon/device42/input. Observe the value of the topic
// pjon/device42/output change gradually from "temperature=20" to "temperature=24".
// NOTE: The gateway used in this setup is using MIRROR_DIRECT mode, just forwarding
// packets both ways without trying to locate or translate variable names,
-// therefore packets are sent to pjon/device42/output instead of
-// pjon/device42/output/temperature as would have been the case with
+// therefore packets are sent to pjon/device42/output instead of
+// pjon/device42/output/temperature as would have been the case with
// the MIRROR_TRANSLATE mode.
-#include
+#include
#define PJON_GATEWAY_ID 254
-// bus(selected device id)
-PJON bus(42);
+PJONSoftwareBitBang bus(42);
float temperature = 20.0; // "Measurement"
float temperature_target = 20.0; // "Target"
@@ -31,7 +30,8 @@ void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info
strncpy(buf, (const char *)payload, len);
buf[len -1] = 0;
Serial.print("Received from broker: "); Serial.println(buf);
- if (strncmp("temperature=", buf, 12)==0) temperature_target = atof(&buf[12]);
+ if(strncmp("temperature=", buf, 12) == 0)
+ temperature_target = atof(&buf[12]);
}
}
@@ -58,4 +58,4 @@ void loop() {
// Adjust to get closer to target, simulate a regulator
temperature += (temperature_target - temperature) / 20;
}
-};
\ No newline at end of file
+};
diff --git a/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device1/Device1.ino b/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device1/Device1.ino
index 7b9bf66102..ec95f5c3fe 100644
--- a/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device1/Device1.ino
+++ b/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device1/Device1.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(44);
+
+PJONOverSampling bus(44);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
diff --git a/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device2/Device2.ino b/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device2/Device2.ino
index db103c94d4..dee08b91b4 100644
--- a/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device2/Device2.ino
+++ b/examples/ARDUINO/Local/OverSampling/HalfDuplex/Device2/Device2.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONOverSampling bus(45);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
diff --git a/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device1/Device1.ino b/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device1/Device1.ino
index 8769d7adab..ae54176c86 100644
--- a/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device1/Device1.ino
+++ b/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device1/Device1.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(44);
+
+PJONOverSampling bus(44);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
@@ -24,7 +24,7 @@ void setup() {
a different port group to avoid cross-talk. */
bus.strategy.set_pins(7, 12);
- bus.set_synchronous_acknowledge(false);
+ bus.set_acknowledge(false);
bus.set_receiver(receiver_function);
bus.begin();
diff --git a/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device2/Device2.ino b/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device2/Device2.ino
index d5f5831460..a75fda6674 100644
--- a/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device2/Device2.ino
+++ b/examples/ARDUINO/Local/OverSampling/HalfDuplexNoAcknowledge/Device2/Device2.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONOverSampling bus(45);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
@@ -24,7 +24,7 @@ void setup() {
a different port group to avoid cross-talk. */
bus.strategy.set_pins(7, 12);
- bus.set_synchronous_acknowledge(false);
+ bus.set_acknowledge(false);
bus.set_receiver(receiver_function);
bus.begin();
diff --git a/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Receiver/Receiver.ino b/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Receiver/Receiver.ino
index fa8e50c7dc..bb3aeccf27 100644
--- a/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Receiver/Receiver.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(44);
+
+PJONOverSampling bus(44);
void setup() {
/* When using more than one pin always use pins connected to
diff --git a/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Transmitter/Transmitter.ino
index 670254bff8..9318e1f2f3 100644
--- a/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/OverSampling/NetworkAnalysis/Transmitter/Transmitter.ino
@@ -1,12 +1,12 @@
-#include
+#include
float test;
float mistakes;
int busy;
int fail;
-// bus(selected device id)
-PJON bus(45);
+
+PJONOverSampling bus(45);
int packet;
uint8_t content[] = "01234567890123456789";
diff --git a/examples/ARDUINO/Local/OverSampling/Simplex/Receiver/Receiver.ino b/examples/ARDUINO/Local/OverSampling/Simplex/Receiver/Receiver.ino
index a404782ff4..3d32bfcbf6 100644
--- a/examples/ARDUINO/Local/OverSampling/Simplex/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/OverSampling/Simplex/Receiver/Receiver.ino
@@ -1,5 +1,5 @@
-#include
+#include
float test;
float mistakes;
@@ -7,8 +7,8 @@ int busy;
int fail;
-// bus(selected device id)
-PJON bus(44);
+
+PJONOverSampling bus(44);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
// Do nothing to avoid affecting speed analysis
diff --git a/examples/ARDUINO/Local/OverSampling/Simplex/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/OverSampling/Simplex/Transmitter/Transmitter.ino
index 10c7dbb86d..1b13596aef 100644
--- a/examples/ARDUINO/Local/OverSampling/Simplex/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/OverSampling/Simplex/Transmitter/Transmitter.ino
@@ -1,8 +1,8 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONOverSampling bus(45);
uint8_t content[] = "01234567890123456789";
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Receiver/Receiver.ino
index 7db2f3a433..f6457aa152 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Receiver/Receiver.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(44);
+
+PJONSoftwareBitBang bus(44);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Transmitter/Transmitter.ino
index 2778f9ac16..f774ed0d16 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTest/Transmitter/Transmitter.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONSoftwareBitBang bus(45);
void setup() {
bus.strategy.set_pin(12);
diff --git a/examples/ARDUINO/Network/SoftwareBitBang/AsyncAck/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC/Receiver/Receiver.ino
similarity index 61%
rename from examples/ARDUINO/Network/SoftwareBitBang/AsyncAck/Receiver/Receiver.ino
rename to examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC/Receiver/Receiver.ino
index 7e4148f3cb..0e839025d5 100644
--- a/examples/ARDUINO/Network/SoftwareBitBang/AsyncAck/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC/Receiver/Receiver.ino
@@ -1,35 +1,34 @@
-/* Include Async ACK code setting PJON_INCLUDE_ASYNC_ACK as true before including PJON.h */
-#define PJON_INCLUDE_ASYNC_ACK true
+#define PJON_INCLUDE_MAC
+#include
-#include
-
-uint8_t bus_id[] = {0, 0, 0, 1};
-
-// bus(selected device id)
-PJON bus(bus_id, 44);
+// bus(mac address of the network interface)
+const uint8_t mac[6] = {1, 2, 3, 4, 5, 6};
+PJONSoftwareBitBang bus(mac);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
overwritten when a new message is dispatched */
if(payload[0] == 'B') {
+ Serial.print("BLINK sent by MAC ");
+ for(uint8_t i = 0; i < 6; i++)
+ Serial.print(packet_info.tx.mac[i], DEC);
+ Serial.println();
digitalWrite(LED_BUILTIN, HIGH);
- delay(3);
+ delay(30);
digitalWrite(LED_BUILTIN, LOW);
- delay(3);
}
};
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW); // Initialize LED 13 to be off
-
bus.strategy.set_pin(12);
bus.begin();
bus.set_receiver(receiver_function);
+ Serial.begin(115200);
};
void loop() {
- bus.update();
bus.receive(1000);
};
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC/Transmitter/Transmitter.ino
new file mode 100644
index 0000000000..9fa75cce71
--- /dev/null
+++ b/examples/ARDUINO/Local/SoftwareBitBang/BlinkTestMAC/Transmitter/Transmitter.ino
@@ -0,0 +1,20 @@
+#define PJON_INCLUDE_MAC
+#include
+
+// bus(mac address of the network interface)
+const uint8_t mac[6] = {2, 3, 4, 5, 6, 7};
+const uint8_t rx_mac[6] = {1, 2, 3, 4, 5, 6};
+PJONSoftwareBitBang bus(mac);
+
+void setup() {
+ bus.strategy.set_pin(12);
+ bus.begin();
+ PJON_Packet_Info info;
+ info.header = bus.config | PJON_MAC_BIT;
+ memcpy(info.rx.mac, rx_mac, 6);
+ bus.send_repeatedly(info, "B", 1, 1000000); // Send B to MAC 1,2,3,4,5,6 every second
+}
+
+void loop() {
+ bus.update();
+};
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Receiver/Receiver.ino
index efe013f2e6..490ebd7b59 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Receiver/Receiver.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(44);
+
+PJONSoftwareBitBang bus(44);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Transmitter/Transmitter.ino
index faed57ceaf..09616ccec9 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/BlinkWithResponse/Transmitter/Transmitter.ino
@@ -1,7 +1,7 @@
-#include
+#include
-// bus(selected device id)
-PJON bus(45);
+
+PJONSoftwareBitBang bus(45);
void receiver_function(uint8_t *payload, uint16_t length, const PJON_Packet_Info &packet_info) {
/* Make use of the payload before sending something, the buffer where payload points to is
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Receiver/Receiver.ino
index f5963244b7..894fb2868f 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Receiver/Receiver.ino
@@ -1,20 +1,14 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
-
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
-//#define SWBB_RESPONSE_TIMEOUT 1000
-
-#include
-
-// bus(selected device id)
-PJON bus(44);
+// Uncomment to use the mode you prefer (default SWBB_MODE 1)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
+
+#include
+
+
+PJONSoftwareBitBang bus(44);
// Custom class
class MyClass {
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Transmitter/Transmitter.ino
index 8732e49d4f..a2e6fb81fa 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/ClassMemberCallback/Transmitter/Transmitter.ino
@@ -1,20 +1,14 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
-
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
-//#define SWBB_RESPONSE_TIMEOUT 1000
-
-#include
-
-// bus(selected device id)
-PJON bus(45);
+// Uncomment to use the mode you prefer (default SWBB_MODE 1)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
+
+#include
+
+
+PJONSoftwareBitBang bus(45);
int packet;
uint8_t content[] = "01234567890123456789";
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/README.md b/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/README.md
index ec62477834..eab3fc58f3 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/README.md
+++ b/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/README.md
@@ -21,10 +21,10 @@ The test result can be evaluated thanks to the following terms:
* `Mistakes` or how many errors detected with CRC
* `Fail` or number of transmission failures occurred in the test window
* `Busy` or how many times the channel is found busy
-* `Accuracy` or ratio between correct packets and packets that contain mistakes
+* `Delivery success rate` or ratio between packets sent successfully and transmission failures
The result can be interpreted as follows:
-- Many `Fail` and or `Mistakes` may mean that the maximum communication range between devices has been reached
-- Many `Busy` and or `Mistakes` and or low `Bandwidth` may mean that interference is present, see [mitigate interference](https://github.com/gioblu/PJON/wiki/Mitigate-interference)
-- Many `Fail` and or `Mistakes` and or low `Bandwidth` may indicate a bad timing configuration, if you are porting a new MCU/architecture to [SoftwareBitBang](/src/strategies/SoftwareBitBang) consider that a different timing configuration may be required because of system discrepancies. Try tweaking `SWBB_BIT_WIDTH`, `SWBB_BIT_SPACER`, `SWBB_READ_DELAY` and `SWBB_ACCEPTANCE` in [src/strategies/SoftwareBitBang/Timing.h](/src/strategies/SoftwareBitBang/Timing.h)
+- If the success rate is low that may mean that the maximum range between devices has been reached
+- If the channel is found many times `busy` and or the bandwidth is low, that may mean that interference is present, see [mitigate interference](https://github.com/gioblu/PJON/wiki/Mitigate-interference)
+- A low success rate and or low bandwidth may indicate a bad timing configuration, if you are porting a new MCU/architecture to [SoftwareBitBang](/src/strategies/SoftwareBitBang) consider that a different timing configuration may be required because of system discrepancies. Try tweaking `SWBB_BIT_WIDTH`, `SWBB_BIT_SPACER`, `SWBB_READ_DELAY` and `SWBB_ACCEPTANCE` in [src/strategies/SoftwareBitBang/Timing.h](/src/strategies/SoftwareBitBang/Timing.h)
- Low performance also after painstaking timing tweaks may indicate that the new MCU/architecture may not be fast enough to run SoftwareBitBang at the mode you are working with, try using a faster clock or optimize digital I/O perfomance or choosing a slower mode.
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Receiver/Receiver.ino
index f2d9a3e554..fa29611400 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Receiver/Receiver.ino
@@ -1,20 +1,14 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
+// Uncomment to use the mode you prefer (default SWBB_MODE 1)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
-//#define SWBB_RESPONSE_TIMEOUT 1000
+#include
-#include
-// bus(selected device id)
-PJON bus(44);
+PJONSoftwareBitBang bus(44);
void setup() {
bus.strategy.set_pin(12);
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Transmitter/Transmitter.ino
index 9b0377c30f..b0500cb7b7 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/NetworkAnalysis/Transmitter/Transmitter.ino
@@ -1,25 +1,18 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
+// Uncomment to use the mode you prefer (default SWBB_MODE 1)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
-//#define SWBB_RESPONSE_TIMEOUT 1000
-
-#include
+#include
float test;
-float mistakes;
int busy;
int fail;
-// bus(selected device id)
-PJON bus(45);
+
+PJONSoftwareBitBang bus(45);
int packet;
uint8_t content[] = "01234567890123456789";
@@ -44,8 +37,6 @@ void loop() {
unsigned int response = bus.send_packet(44, content, 20);
if(response == PJON_ACK)
test++;
- if(response == PJON_NAK)
- mistakes++;
if(response == PJON_BUSY)
busy++;
if(response == PJON_FAIL)
@@ -65,21 +56,18 @@ void loop() {
Serial.println("B/s");
Serial.print("Packets sent: ");
Serial.println((unsigned int)test);
- Serial.print("Mistakes (error found with CRC): ");
- Serial.println((unsigned int)mistakes);
Serial.print("Fail (no acknowledge from receiver): ");
Serial.println(fail);
Serial.print("Busy (Channel is busy or affected by interference): ");
Serial.println(busy);
- Serial.print("Accuracy: ");
- Serial.print(100 - (100 / (test / mistakes)));
+ Serial.print("Delivery success rate: ");
+ Serial.print(100 - (100 / (test / fail)));
Serial.println(" %");
Serial.println("---------------------");
// Avoid Serial interference during test flushing
Serial.flush();
test = 0;
- mistakes = 0;
busy = 0;
fail = 0;
};
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Receiver/Receiver.ino
index 6efb630b2f..1ed39160e8 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Receiver/Receiver.ino
@@ -1,11 +1,10 @@
-// Include only SoftwareBitBang
-#define PJON_INCLUDE_SWBB
// Set maximum packet length
#define PJON_PACKET_MAX_LENGTH 10
-// Include PJONLocal
-#include
-// bus(selected device id)
+
+#include // Include PJONLocal
+#include // Include only SoftwareBitBang
+
PJONLocal bus(44);
uint8_t data[PJON_PACKET_MAX_LENGTH];
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Transmitter/Transmitter.ino
index bad8ab65bb..b764612121 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/BlinkTest/Transmitter/Transmitter.ino
@@ -1,10 +1,8 @@
-// Include only SoftwareBitBang
-#define PJON_INCLUDE_SWBB
-// Set maximum packet length
-#define PJON_PACKET_MAX_LENGTH 10
-// Include PJONLocal
-#include
+#define PJON_PACKET_MAX_LENGTH 10 // Set maximum packet length
+
+#include // Include PJONLocal
+#include // Include only SoftwareBitBang
/* Create PJONLocal object:
Class name instance name ( device id ) */
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Receiver/Receiver.ino
index abf9b513c9..a73e0d83dd 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Receiver/Receiver.ino
@@ -1,9 +1,15 @@
+// Uncomment to use the mode you prefer (default SWBB_MODE 1)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
+
// Include only SoftwareBitBang
-#define PJON_INCLUDE_SWBB
-// Include PJONLocal
-#include
-// bus(selected device id)
+
+#include // Include PJONLocal
+#include // Include only SoftwareBitBang
+
PJONLocal bus(44);
uint8_t data[PJON_PACKET_MAX_LENGTH];
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Transmitter/Transmitter.ino
index 53bf65fc43..d878ba29f0 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/NetworkAnalysis/Transmitter/Transmitter.ino
@@ -1,21 +1,12 @@
-// Uncomment to run SoftwareBitBang in MODE 2
-// #define SWBB_MODE 2
-// Uncomment to run SoftwareBitBang in MODE 3
-// #define SWBB_MODE 3
+// Uncomment to use the mode you prefer (default SWBB_MODE 1)
+// #define SWBB_MODE 1 // 1.95kB/s - 15625Bd
+// #define SWBB_MODE 2 // 2.21kB/s - 17696Bd
+// #define SWBB_MODE 3 // 2.94kB/s - 23529Bd
+// #define SWBB_MODE 4 // 3.40kB/s - 27210Bd
-/* Acknowledge Latency maximum duration (1000 microseconds default).
- Can be necessary to higher SWBB_RESPONSE_TIMEOUT to leave enough time to
- receiver to compute the CRC and to respond with a synchronous acknowledgement
- SWBB_RESPONSE_TIMEOUT can be reduced to higher communication speed if
- devices are near and able to compute CRC fast enough. */
-
-//#define SWBB_RESPONSE_TIMEOUT 1000
-
-// Include only SoftwareBitBang
-#define PJON_INCLUDE_SWBB
-// Include PJONLocal
-#include
+#include // Include PJONLocal
+#include // Include only SoftwareBitBang
/* Create PJONLocal object:
Class name instance name ( device id ) */
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Receiver/Receiver.ino b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Receiver/Receiver.ino
index 9b45ae532e..ea20b87e42 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Receiver/Receiver.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Receiver/Receiver.ino
@@ -2,11 +2,9 @@
This sketch contains the receiver side. In the Serial monitor
is printed the record transmitted by the other device. */
-// Include only SoftwareBitBang
-#define PJON_INCLUDE_SWBB
-// Include PJONLocal
-#include
-// bus(selected device id)
+#include // Include PJONLocal
+#include // Include only SoftwareBitBang
+
PJONLocal bus(44);
uint8_t data[PJON_PACKET_MAX_LENGTH];
@@ -36,9 +34,9 @@ void loop() {
if(length) {
uint8_t *payload = bus.get_payload(data);
Serial.print("Receiver device id: ");
- Serial.print(info.receiver_id);
+ Serial.print(info.rx.id);
Serial.print(" | Transmitter device id: ");
- Serial.println(info.sender_id);
+ Serial.println(info.tx.id);
/* Copy received data in buffer */
memcpy(&r, payload, sizeof(r));
diff --git a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Transmitter/Transmitter.ino b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Transmitter/Transmitter.ino
index ac880b218e..a392e192ab 100644
--- a/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Transmitter/Transmitter.ino
+++ b/examples/ARDUINO/Local/SoftwareBitBang/PJONLocal/SendArbitraryDataType/Transmitter/Transmitter.ino
@@ -1,10 +1,8 @@
/* ARBITRARY DATA TYPE TRANSMISSION EXAMPLE
This sketch contains the transmitter side. */
-// Include only SoftwareBitBang
-#define PJON_INCLUDE_SWBB
-// Include PJONLocal
-#include
+#include