- Addressing
- Configuration
- Data reception
- Data structures
- Data transmission
- Error handling
- Routing
- IO setup
PJON objects can operate in local or shared mode. The PJON protocol v4.0 in local mode supports connectivity for up to 254 devices using a 8bits device identifier, in shared 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.
The simples way to instantiate PJON in local mode is the following:
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:
PJONSoftwareBitBang bus(44);
bus
receives packets for device identifier 44 and ignores all others.
Device id can be set or changed after instantiation using set_id
:
bus.set_id(44);
0 or PJON_BROADCAST
is reserved for broadcasting and should not be used as a device identifier.
The device identifier of an object can be read after instantiation using device_id
:
uint8_t id = bus.device_id(); // Get device id
device_id
returns PJON_NOT_ASSIGNED
or 255 if the instance is initialised without configuring its device identifier.
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.
Instantiation in shared mode:
uint8_t bus_id[4] = {1, 2, 3, 4};
PJONSoftwareBitBang bus(bus_id, 44);
// Device id 44, bus id 1.2.3.4 in shared mode
Use get_bus_id
to get a pointer to the bus id used by the instance:
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 set after initialisation using set_bus_id
:
uint8_t bus_id[4] = {0, 0, 0, 1};
bus.set_bus_id(bus_id); // Set bus id
PJON can optionally operate using the MAC address of the device:
// 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 includ_mac
:
bus.include_mac(false);
Use get_mac
to get a pointer to the mac address used by the instance:
uint8_t mac[6];
memcpy(mac, bus.get_mac(mac), 6); // Copy mac in variable
The mac address can set after initialisation using set_mac
:
uint8_t mac[6] = {0, 0, 0, 0, 0, 1};
bus.set_mac(mac); // Set mac