MeshNet
1.0.0
|
MeshNet is a sensory mesh network designed for microcontrollers with Arduino core. Nodes of the network are called MNodes. It isn't designed to transfer large amounts of data at high speed, but to collect data from sensor nodes. The code was optimized for microcontrollers with at least 20kB of RAM (tables and buffers cannot be further reduced :cry:) and at least 90kB of FLASH memory. It was tested on STM32L432KC microcontroller.
doxygen.exe
in console in folder to generate documentation. Open file in html/index.htmlMeshNet
.MeshNet
folder is located. It is recommended to use variables in path.MeshNet
folder, then click OK./${ProjName}/MeshNet/Mesh/Inc /${ProjName}/MeshNet/RadioInterfaces/Inc
SerialConsole is project, which allows easy implementation of console for microcontrollers using serial UART interface. With this console you can control and monitor MeshNet
class using specified commands or using GUI. Project with application for windows and linux (with mono) is located here.
Almost any radio can be used with this mesh network, but those requirements has to be met:
Optional requirements for radio, which increases performance:
To create custom radio interface first create inherited class from RFInterface
and continue with those steps:
RFInterface
with all arguments. Some of those arguments describes radio features and behavior.deInit()
function is called.init()
function setup radio.deInit()
function disable or power off radio and unregister interrupt callback (set it to NULL
) if set.hasError()
has to return true, when radio has some error or is not connected to MCU.send()
function perform frame transmission. It must return true when frame was sent without any error. It has to be checked here, if radio is connected and if not, it has return false.available()
function check if any frame was received and return size of frame. If not, it must return 0.recv()
function read received bytes from radio buffer and write it to buffer specified in arguments. If it failed, return false. If RSSI cannot be established, set it to -60dBm.uint8_t
array with same size as MaxMessageLength
and in function getInternalTemporaryBuffer()
return pointer to that array.sleep()
and wakeUp()
functions. As its name says, those functions should be able to temporary power off and power on radio. When the radio is in sleep mode, it may not be able to receive data. If not implemented, just return true in both functions.checkInterference()
function, which returns true, when carried wave is present.setChannel()
function to check specific channel. If channel cannot be changed, just return false.setPower()
function, which can set power mode. If power modes cannot be set, return false.setFullSpeed()
function, which has to be able to set low speed or full speed. Only two speed modes are supported. Return false if not implemented.setReceiveInterruptCallback()
, which registers callback function, that is called when interrupt is fired because frame was received. If not implemented, return false.interruptHandle()
function, which will be called in callback function from previous step. In this function flags in radio should be cleared.handle()
function is periodically called. It may contain a code for radio handling, which must be called often.printDetails()
may be able to print radio details in pretty form to specified stream. It is recommended to implement this function.scanChannels()
function, which checks carrier wave on each channel and returns best channel number with the smallest chance of an interference. If stream is specified, it must print chance of an interference for each scanned channel. Format of printed data is strictly specified: Example for nRF24L01:
scanChannelsWorking()
function, which returns true if radio is busy, because scanning in progress.getChannelsWidth()
which returns width of channels in kHz.Behavior of MeshNet
can be configured in meshConfig.h
file with those macros:
Size configuration
Packet payload size
MESH_PACKET_PAYLOAD_SIZE_LIMIT
- Size limit of packet payload. By default, set to 512 bytes, but can be set from 128 bytes to 1024 bytes. When changing this macro do not forget to change MESH_PACKET_PAYLOAD_SIZE_LIMIT_txt
and MESH_PING_PAYLOAD_SIZE_LIMIT_txt
macros.Tables sizes and life times
ROUTETABLE_SIZE
- count of rows in route table. By default, set to 64, but for gateway node it is recommended to set higher value. When changing this macro do not forget to change ROUTETABLE_SIZE_txt
and ROUTETABLE_MAX_IND_txt
macros.ROUTETABLE_ROW_LIFETIME
- maximum lifetime of each row in route table in milliseconds. By default, set to 30 minutes.IDTABLE_SIZE
- count of rows in IDTable. By default, set to 64, but for gateway node it is recommended to set higher value. When changing this macro do not forget to change IDTABLE_SIZE_txt
and IDTABLE_MAX_IND_txt
macros.IDTABLE_ROW_LIFETIME
- maximum lifetime of each row in IDTable in milliseconds. By default, set to 5 minutes.FIDTABLE_SIZE
- count of rows in FIDTable. By default, set to 8, but for gateway node it is recommended to set higher value. When changing this macro do not forget to change FIDTABLE_SIZE_txt
and FIDTABLE_MAX_IND_txt
macros.FIDTABLE_ROW_LIFETIME
- maximum lifetime of each row in FIDTable in milliseconds. By default, set to 5 minutes.OIDTABLE_SIZE
- count of rows in OIDTable. By default, set to 64, but for gateway node it is recommended to set higher value. When changing this macro do not forget to change OIDTABLE_SIZE_txt
and OIDTABLE_MAX_IND_txt
macros.DHCPTABLE_VALID_ROW_LIFETIME
- lifetime of each row in DHCP table in milliseconds. By default, set to one day. After this time, row stays in DHCP table for same time as life time, but is marked as reserved.Buffers sizes
MESH_OFIFO_HIGH_SIZE
- size of high priority part (Route and Unicast packets) of output FIFO. By default, set to 3.MESH_OFIFO_LOW_SIZE
- size of low priority part (Flood and Broadcast packets) of output FIFO. By default, set to 4.MESH_WFIFO_SIZE
- size of waitingFIFO buffer. By default, set to 8.Miscellaneous
MESH_INST_ARRAY_SIZE
- size of instance array. This array stores all created instances of current class. Number of created instances of MeshNet in this program cannot exceed this number. By default, set to 2, but can be set to higher value if multiple instances are defined on one MCU.Timing
Frame receive timing
MESH_NEXT_FRAME_TIMEOUT
- timeout in milliseconds. If header frame was received and next frame is expected, until this timeout all other frames are ignored. By default, set to 40ms.Frame send timing
MESH_ROUTE_RETR_TIME
- after this time in milliseconds routed frame (Type: Route or Unicast) can be retransmitted when ACK was not received. By default, set to 50ms.MESH_FRAME_SEND_DELAY
- after this time in milliseconds from last frame send, broadcasted frame (Type: Flood or Broadcast) can be sent. By default, set to 15ms.Clear to send time
MESH_ACK_CTS_TIME
- this time in microseconds is added to CTS time, when ACK is expected. By default, set to 15ms.MESH_FRAME_CTS_TIME
- this time in microseconds is added to CTS time, when another frame is expected. By default, set to 20ms.Clear to send random time
MESH_RANDOM_ROUTED_CTS_TIME
- random value between 0 and this time in microseconds is added to CTS time, when routed frame (Type: Route or Unicast) was received. By default, set to 5ms.MESH_RANDOM_UNROUTED_CTS_TIME
- random value between 0 and this time in microseconds is added to CTS time, when broadcasted frame (Type: Flood or Broadcast) was received. By default, set to 10ms.Miscellaneous
MESH_PATH_DISC_TIMEOUT
- timeout in milliseconds for path discovery. By default, set to 5 seconds.Settings
Packet relaying limit
MESH_HOP_RELAY_LIMIT
- maximum count of hops, that can one packet do. After exceeding this limit, packet is discarded. By default, set to 25.Retransmissions limits
MESH_ROUTE_RETR_CNT
- maximum count of routed frame (Type: Route or Unicast) retransmission when ACK was not received. When this limit exceeds, node is marked as inacessible. By default, set to 4, so frame can be sent in worst case 5 times.MESH_FLOOD_RETR_CNT
- count of guaranteed retransmittments for every broadcasted frame (Type: Flood or Broadcast). Those frames are broadcasted multiple times, because there is higher chance, that they will be received by all neighbor nodes. This is by default set to 1, so broadcasted frame will be sent 2 times. Set to 0 to disable retransmittment of broadcasted frames.RSSI threshold
MESH_RSSI_THRESHOLD
- RSSI threshold. If RSSI of any frame (excepts ACK) exceeds this threshold it is ignored. RSSI threshold is by default set to -70dBm.Connection settings
MESH_SYS_NET_SCAN_TIMEOUT
- system network scan timeout in milliseconds. By default, set to 1.5ms.MESH_CONNECT_TIMEOUT
- connect process timeout including system network scan before connection in milliseconds. By default, set to 7.5s.Disconnection settings
MESH_DISCONNECT_TIMEOUT
- after this time in milliseconds node is definitely disconnected from network and all packets in FIFO for that network are cleared. By default, set to 5s.MESH_REQ_DISCONNECT_TIMEOUT
- until this time in milliseconds, node, the gateway requested disconnection, must respond with disconnect packet, which says, it is disconnecting. By default, set to 7.5s.Miscellaneous
MESH_IMPL_CONSOLE_ITEM
- if set to 0, SerialConsole interface won't be implemented to MeshNet. This setting can significantly reduce FLASH memory usage. By default, set to 1.MESH_NO_STATISTICS
- if uncommented, statistics will not be recorded. This setting can slightly reduce RAM memory usage. By default, commented out.mesh.h
- Main file with the MeshNet class. This file must be included to use MeshNet
.meshNetGateway.h
- Main file with the MeshNetGateway
class, which is inherited from the MeshNet
class and implements functionality of MGN.meshBuffers.h
- File, which contains implementations of all used buffers in mesh protocol.meshTables.h
- File, which contains implementations of all used tables in mesh protocol.meshFrame.h
- Contains class MeshFrame
, which represents frames to be sent or received. Frames data part is dynamically allocated.meshPacket.h
- Contains class MeshPacket
, which represents packet, that are split to multiple frames, which are sent. Payload is dynamically allocated, same as MeshFrame
and its length can be up to 512B.meshPacketBuilder.h
- Contains class MeshPacketBuilder
, which builds packet from multiple received frames.meshPacketSplitter.h
- Contains class MeshPacketSplitter
, which splits packet to multiple frames, that are sent.meshPacketDecoders
- Contains functions, that decodes or encodes system packets fields.meshPacketFlags
- Contains structures, that represents flags in MeshPacket
or MeshFrame
headers and other flags used in code.meshConfig.h
- Configuration file.meshHelper.h
- File, which contains helper function or classes for MeshNet
. For example, MeshMAC
is located here.meshVariableArray.h
- File, which contains class, that behaves as dynamically allocated array. This array can be used to create packet payload to be send. Best performance can be achieved when using send()
method in conjunction with std::move
and MeshVariableArray
with payload data.RFInterface.h
- Contains abstract class, that act as interface with almost any radio.NRF24L01_interface.h
- Contains class inherited from the RFInterface
. This class acts as interface with nRF24L01 or nRF24L01+ radio.Simulation_interface.h
- Contains class inherited from the RFInterface
. This class acts as interface with virtual radio, which is used with MeshProtocolSimulator.Simple example of basic node with nRF24L01+, which sends data over network:
Macro
MESH_IMPL_CONSOLE_ITEM
inmeshConfig.h
must be set to 0
Simple example of main gateway node with nRF24L01+, which received data from network:
Macro
MESH_IMPL_CONSOLE_ITEM
inmeshConfig.h
must be set to 0
Simple example of basic node with nRF24L01+, which is controlled using SerialConsole interface through serial port:
Macro
MESH_IMPL_CONSOLE_ITEM
inmeshConfig.h
must be set to 1
Copyright 2022 Matej Fitoš
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Created by Matej Fitoš
Copyright © 2022 Matej Fitoš