The RadioShuttle protocol

The protocol is designed to send little messages between two or more devices. For simplification, we call the pair node and station. Here is the communication order:

a) Simple on-demand message (RS_Node_Online/RS_Node_Checking/RS_Node_Offline)
1. Node sends a message request before sending the data, containing only the RadioHeader.
  “MF_Response” must be switched off in the flags. The header contains
  the msgSize in the used RadioHeader, declaring hereby the expected data size,
  the app ID, a msgID, and a response Window.

2. The response from the station should be sent immediately with the
   “MF_Response” flag. In case the response cannot be sent
   immediately, the response window is used by the station for the
   scheduled time to send the response. In case the station cannot
   handle the app it stays quiet and forgets about this request. The station
   response may contain the flag “MF_SwitchOptions” which allows turning on 
   additional options (channel, spreading factor and windowScale). An empty 
   options field means no change.

3. After the node has received the station response, it knows when it is allowed 
   to send the final message data. The stations provided respWindow tells
   the node when to send the data (usually when there is no other traffic scheduled).
   The data message can contain the “flag MF_MoreDataToCome”, to indicate that
   there are more messages pending for this app, In this case the station
   sends a confirmation message (see 4.) with a new respWindow to send the
   next data message.
   
4. Optional confirmation message. In case the request contains the 
   flag “MF_SentCompletedConfirmed” or “MF_MoreDataToCome” the station must
   confirm the reception using the “MF_RecvDataConfirmed” flag in a 
   radio header response when requested. In case of “MF_MoreDataToCome”
   the response message has be to sent with a new respWindow to
   allow the node to send the next message. 

Example:
Node	Station
- - - >		Node to Station message request (“RadioHeader” with 12 or 16 bytes)
< - - -		Station to Node response (only “RadioHeader” with response window time)
Channel switching may apply if “MF_SwitchOptions” is specified
- - - >		Node data to Station (communication completed, header + data)
< - - -		Optionally acknowledge (when RadioHeader contains “MF_NeedsConfirm”)

b) Simple on-demand message RS_StationBasic/RS_StationServer
As the stations have an own recording when the air is busy they can just send messages
anytime when there is no scheduled traffic for a given time window.

c) Receiving messages for RS_Node_Online
As these types of node are always powered on, they stay always in receive mode, which
means they can handle message requests as described. The station basically sends a 
message to the “RS_Node_Online” including the data because the station knows when 
the air is free to send messages.

Example:
Node	Station
< - - -		Station to Node message request (RadioHeader with 12 or 16 bytes)
Channel switching may apply if “MF_SwitchOptions” are specified
- - - >		Node to Station response (only RadioHeader with response window time = 0)
< - - -		Station to Node_Online (Request with data, header + data)
- - - >		Optionally acknowledge (when RadioHeader contains “MF_NeedsConfirm”)

d) Receiving messages for RS_Node_Offline/RS_Node_Checking
The node “RS_Node_Offline” is completely turned off (sleep mode) unless it starts. During the sleep period it will not be able to receive messages, unless it wakes up and sends a message request.

The “RS_Node_Checking” can send a checking window time slot where it repeatedly turns into receive
mode, to allow listening to a RadioHeader packet at a specified time, e.g. every 90.010 seconds. The response of the checking window includes the current timestamp in milliseconds to allow to use correct sending slots. From time to time the checking node should repeat the checking window requests to update its timestamp in milliseconds. The time slot resolution is in milliseconds.
In case “RS_Node_Checking” receives responses from multiple stations it should use the response from the station with the best rssi and the second best rssi signal. (Main and backup stations.)
The checking node should be able to request the specified checking window, e.g. 6500 ms,
and the station should respond with a window equal or less. The checking node should enter only in receive mode for reading the preamble and a few bytes (CAD detection). If no signal is active it
goes to sleep until the next checking period arrives. (The duration of the preamble detection depends in the spreading factor and bandwidth.)

Response windows
To keep it simple without syncing the time of all devices, the response window is specified in milliseconds, the window time starts counting after the complete packet has been received. The sender needs to take into account the air duration of the packet, the receiver starts counting the response window after it received the message. The packet RadioHeader response window allows windows of up to 2048 ms, the 
full RadioHeader allows 65536 ms. The option “MF_SwitchOptions” allows a winScale scaling which will multiply the windows size.
winScale 1 uses respWindow * 1
winScale 2 uses respWindow * 2
winScale 3 uses respWindow * 3
…
winScale 15 use respWindow * 15

Password authentication
Each app can use an optional password when specified with the RegisterApplication() call. The password can be a simple string or a block of binary data. For binary data it is required to specify the password length parameter. A 16 byte long random password is recommended or even 32 bytes to avoid simple password attacks. The password can be empty (NULL) which means there is no password authentication. If the app  password is specified it must be identical on all nodes and station communicating together. When the password is set, the node must call Connect() with the app ID and the remote station ID. The password is never transferred directly over the air, instead of the client receives a random number which is used to create a hash code of the password and send the hash product for authentication to the station which compares the product with its password/random number hash.
The RadioSecurityInterface specifies an API for providing the password hashing and data encryption algorithm. It uses SHA256 for passwords and AES128 for content encryption.

Message content encryption
If passwords are specified (see Password Authentication), message data encryption can be enabled per “SendMsg()” call specifying “MF_Encrypted” in the flags field. For encrypting the data the RadioSecurityInterface provided security implementation uses AES 128-bit which ensures nobody in the middle can decrypt the messages and send fake messages. For non-encrypted messages the size of an app message can be as little as one byte. Encrypted messages are automatically padded to a multiple of 128-bit which means at 16 bytes per message.

Encrypted messages considerations/disadvantages
- Minimum data size is 16 bytes (consider that this is a 50 ms data transfer overhead using SF7, with SF11 it is many times longer).
- The communication works only between one node and one station (connected pair)
  Non-encrypted messages can be sent to multiple stations (e.g.: broadcast messages for device ID 0)
  which can be processed by any station supporting this app ID, which allows failover solutions.
- For simple data like a temperature sensor, or similar, it may not be required to use encrypted messages, however for security concerned messages (e.g. door alarm, light switch) encrypted messages are a must have.

Device IDs
Each node communicating with the RadioShuttle protocol must have a unique number – each node as well as each station. Think about this like MAC addresses. This unique device IDs are required to allow secure and reliable communication. RadioShuttle licenses will find the device ID labeled on the RadioShuttle enabled board with an access code, or can purchase licenses at www.radioshuttle.de.

App IDs
Each node or station can support multiple different services which are called app IDs (application IDs) which are unique worldwide. These app IDs are, similar to TCP/IP port numbers, just an ID to route communication messages. The worldwide unique app IDs can be obtained free of charge for developers at www.radioshuttle.de by agreeing to stay compatible with the RadioShuttle protocol.
The central app registration has also the benefit to share the app data content with others, to ensure solution compatibility. However is not needed to share any app ID content details. Think about a basic communication that goes from one device ID (e.g. 1111) using app ID 1234 to device ID 2222 being received by app ID 1234 when available on this device. Node/stations receiving unknown app ID requests will automatically ignore these.

Message Retry Count considerations
The Radioshuttle protocol uses a retry count of three attempts to complete a message communication. It makes no sense to have this retry count adjustable because when there is not reliable communication the retry attempts just keeps the network busy. More over the message request/response is not retrying every single sent or acknowledge packet three times, if the message transaction does not complete it tries it again. Single packets like acknowledge  and a receives message are not retried, instead the entire message transaction is retried when needed.

In case the message transfers are not reliable and often time out check the following:
- Is the antenna and its connection correct?
- Is it a long distance than switch a a higher spreading factor (e.g. from SF7 to SF9 or up to SF11)
- Maybe the bandwidth setting is to high (e.g. 500 kHz  switch to a smaller bandwidth (125 kHz, lower than 125 kHz require a TCXO crystal)
- Is the station location optimal?
  Lets say in a case covering a multi-family house, it may be a smart to but the station across the building. Another option is to put the station into the middle of the building.