GEX thesis source code, full text, references

ch.wireless.tex 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. \chapter{Wireless Interface} \label{sec:wireless}
  2. Four methods of a wireless connection were considered: Bluetooth (perhaps with the Texas Instruments CC2541), WiFi with the Espressif ESP8266, a 868\,MHz long range radio link with the Semtech SX1276, and a 2.4\,GHz radio link with the nRF24L01+. Bluetooth was dismissed early for its complexity, and the ESP8266 for its high power consumption, although both solutions might be viable for certain applications and with more development time.
  3. \begin{figure}[h]
  4. \centering
  5. \includegraphics[width=.7\textwidth]{img/nrf-testing.jpg}
  6. \caption{Test setup with a GEX prototype controlling two nRF24L01+ modules}
  7. \end{figure}
  8. \section{Modulations Overview}
  9. A brief overview of the different signal modulation techniques is presented here to aid the reader with the understanding of \cref{fig:nrf_sx_comparison} and the rest of the chapter.
  10. \subsection{On-Off Keying (OOK)}
  11. In \gls{OOK}, the carrier generator is switched on and off to transmit ones and zeros.
  12. \subsection{Frequency Shift Keying (FSK)}
  13. \Gls{FSK} uses a change of the carrier frequency to transmit data. The simplest form of \gls{FSK} is \gls{BFSK}, which uses a pair of alternating frequencies to transmit ones and zeros.
  14. \subsection{Gaussian Frequency Shift Keying (GFSK)}
  15. \Gls{GFSK} is an improvement over basic \gls{FSK} which does not switch between the different frequencies instantaneously, but uses a Gaussian filter to make the changes less abrupt, which reduces the side-band interference otherwise generated by the sharp edges. This scheme can be imagined as sending the binary waveform through a Gaussian filter and then modulating a \gls{VCO} with its output, rather than changing the \gls{VCO}'s control voltage discretely. \Gls{GFSK} is used in the Bluetooth standard.
  16. \subsection{Minimum-Shift Keying (MSK)}
  17. \Gls{MSK} is another \gls{FSK}-based modulation scheme. In \gls{MSK}, the frequencies representing different symbols are chosen such that there are no sharp changes in the phase of the output waveform, the modulation is \textit{phase-coherent}. This is another way to reduce side-band interference.
  18. \subsection{Gaussian Minimum-Shift Keying (GMSK)}
  19. \Gls{GMSK} is a variant of \gls{MSK} which uses a Gaussian filter to shape the digital signal before sending it to the oscillator. The principle is similar to \gls{GFSK}, and it is a yet another way to reduce side-band interference and increase spectral efficiency. %\gls{GMSK} is used in the \gls{GSM}. this is on wikipedia, but cant find a source
  20. \subsection{LoRa Modulation}
  21. LoRa uses a direct sequence frequency hopping spread spectrum modulation scheme and can achieve very long range transmission. A higher-level specification defines how the devices using LoRa should behave in a large area network, though the modulation may be used for point-to-point connections as well.
  22. LoRa is a proprietary technology developed by Semtech; it is free to use, but is available only with transceiver \glspl{IC} produced by the company.
  23. \section{Comparing SX1276 and nRF24L01+}
  24. The SX1276and nRF24L01+ transceivers have both been tested using the first GEX prototype, proving its usefulness as a hardware development tool, they proved capable of fulfilling the requirements of the GEX radio link use-case. We compared them in \cref{fig:nrf_sx_comparison} using data from their datasheets~\cite{semtech-manual,nrf-manual}. It is apparent, after inspecting the table, that each has its strengths and weaknesses and the choice depends on the particular application's needs.
  25. \begin{table}[h]
  26. \centering
  27. \begin{tabulary}{\textwidth}{lLL}
  28. \toprule
  29. \textbf{Parameter} & \textbf{SX1276} & \textbf{nRF24L01+} \\
  30. \midrule
  31. \textbf{Connection} & SPI (4 pins) + up to 6 IRQ & SPI (4 pins), CE, IRQ \\
  32. \textbf{Frequency band} & 868\,MHz or 433\,MHz & 2.4\,GHz \\
  33. \textbf{Data rate} & up to 300\,kbps & 250--2000\,kbps \\
  34. \textbf{Modulation} & (G)FSK, (G)MSK, OOK, LoRa & GFSK \\
  35. % \textbf{Bandwidth} & 7--500\,kHz per channel & 0.7--2\,MHz per channel \\
  36. \textbf{Range (est.)} & over 10\,km & up to 1\,km \\
  37. \textbf{Consumption Rx} & 10.8--12\,mA & 12.6--13.5\,mA \\
  38. \textbf{Consumption Tx} & 20--120\,mA & 7--11.3\,mA \\
  39. \textbf{Idle power (max)} & 1\,$\mu$A sleep, 2\,mA stand-by & 0.9\,$\mu$A sleep, 320\,$\mu$A stand-by \\
  40. \textbf{Max packet size} & 300 bytes & 32 bytes \\
  41. \textbf{Software reset} & NRESET pin & not available \\
  42. \textbf{Extra} & LoRa FHSS, packet engine & ShockBurst protocol engine \\
  43. \textbf{Price} & \$7.3 & \$1.6 \\
  44. \bottomrule
  45. \end{tabulary}
  46. \caption[Comparison of the SX1276 and nRF24L01+ wireless transceivers]{\label{fig:nrf_sx_comparison}Comparison of the SX1276 and nRF24L01+ wireless transceivers, using data from their datasheets (price in USD from DigiKey in a 10\,pcs. quantity, recorded on May 6th 2018)}
  47. \end{table}
  48. The SX1276 supports additional modulation modes, including the proprietary LoRa scheme that can be received at long distances. The power consumption required to achieve this long-range communication makes it impractical for continuous operation on battery or solar power.
  49. The nRF24L01+ provides higher data rates at short distances. Its power consumption is comparable or lower than that of the SX1276. It lacks a dedicated reset pin, but that can be worked around using an external transistor to momentarily disconnect it from the power supply.
  50. Both devices implement some form of a packet engine with error checking; that of the nRF24L01+, called ShockBurst, is more advanced, as it implements acknowledgment responses and automatic re-transmission, leading to potentially more robust communication without additional overhead in the control software.
  51. \section{Wireless Link with the nRF24L01+}
  52. We chose the nRF24L01+ to be integrated into GEX for its inclusion of the ShockBurst engine, higher possible data rates, and significantly lower price. The SX1276, nonetheless, remains an interesting option, should the need for a long range communication arise.
  53. A pair of these radio modules can form a bidirectional data connection, functionally replacing \gls{USB} or \gls{UART} as a communication interface. However, we need to connect the second module to the \gls{PC} to control GEX through the radio link. A separate \gls{USB} device, a \textit{wireless gateway}, was developed for this purpose; its hardware will be presented in \cref{sec:rfgateway}.
  54. \subsection{The Wireless Gateway}
  55. \begin{wrapfigure}[18]{r}{0.38\textwidth}
  56. \vspace{-1em}
  57. \centering
  58. \includegraphics[scale=0.9]{img/rf-gw.pdf}
  59. \caption{Wireless connection block diagram}
  60. \end{wrapfigure}
  61. The gateway presents itself to the host as a \gls{CDCACM} device, much like the GEX modules themselves (here called \textit{nodes}) when connected over \gls{USB}. However, the standard GEX communication protocol cannot be used directly, as the gateway itself needs to be managed through the interface, and it can connect to more than one GEX module at once, necessitating an addressing scheme. This problem could be solved by adding a side channel, additional \gls{USB} endpoints, to interact with the gateway itself; that option was not explored further, but it is clear that it would compromise our ability to use the simple virtual COM port \gls{USB} driver.
  62. The gateway has a 4-byte \textit{network ID}, a number derived from the \gls{MCU}'s unique ID number. The network ID must be entered into the system settings file of all nodes that wish to communicate with the gateway. Additionally, each module is assigned a 1-byte number serving as its address in the network. These addresses are loaded into the gateway by the user application, and are used to configure the nRF24L01+ to listen to messages from the corresponding nodes. The nRF24L01+ uses 5-byte addressing; the full node addresses are composed of the network ID and the one additional address byte.
  63. \subsection{The Gateway Protocol} \label{sec:gw_protocol}
  64. The gateway protocol, when used to communicate with a node, encapsulates the raw binary data sent to or from connected nodes; the wrapped TinyFrame protocol remains unchanged.
  65. All messages sent to or from the gateway are a multiple of 64 bytes long, padded with zeros if shorter. A message starts with a control byte determining its type, as summarized in the following table, listing the structure of all supported messages.
  66. \newpage
  67. {
  68. \tabulinesep=5pt
  69. \begin{longtabu} to \textwidth {P{5em} X[5] X[4,l]}
  70. \toprule
  71. \textbf{First byte} & \textbf{Function} & \textbf{Structure} \\
  72. \midrule
  73. \endhead
  74. \bottomrule
  75. \endfoot
  76. `r' (114) &
  77. \cname{RESTART}
  78. Restart the gateway, disconnecting all nodes. This is functionally equivalent to re-plugging it to the USB port.
  79. & \\
  80. `i' (105) &
  81. \cname{GET\_NET\_ID}
  82. Read the unique 4-byte network ID. This command has no side effects and may be used as ``ping'' to verify the USB connection. &
  83. \begin{cmdresp}
  84. \cfield{0x01}
  85. \cfield{u8[4]} network ID
  86. \end{cmdresp}
  87. \\
  88. `n' (110) &
  89. \cname{ADD\_NODES}
  90. Configure the gateway to listen for messages from the given nodes.
  91. Nodes may be removed using the RESTART command.
  92. &
  93. \begin{cmdreq}
  94. \cfield{u8} count
  95. \cfield{u8[]} node addresses
  96. \end{cmdreq}
  97. \\
  98. `m' (109)&
  99. \cname{SEND\_MSG}
  100. Send a binary message to one of the connected nodes. The message may span multiple 64-byte frames; the subsequent frames will contain only the payload bytes, or zero padding at the end of the last one.
  101. & \begin{cmdreq}
  102. \cfield{u8} node address
  103. \cfield{u16} length
  104. \cfield{u8} checksum (inverted XOR of all payload bytes)
  105. \cfield{u8[]} payload
  106. \end{cmdreq} \\
  107. 0x02 &
  108. \cname{INCOMING\_MSG}
  109. A message was received from one of the configured nodes. This is an event frame sent by the gateway to the host.
  110. & \begin{cmdpld}
  111. \cfield{u8} node address
  112. \cfield{u8} message length
  113. \cfield{u8[]} payload
  114. \end{cmdpld} \\
  115. \end{longtabu}
  116. }
  117. \subsection{Gateway Initialization Procedure}
  118. A host program connecting to a node or nodes through the gateway should follow the following procedure to initialize and configure the gateway:
  119. \begin{enumerate}
  120. \item Send the ``GET\_NET\_ID'' command to test if the gateway is connected (and obtain its network ID as a side effect)
  121. \item Restart the gateway using the ``RESTART'' command to clean any possible previous configuration; this is not needed when the gateway was restarted or freshly connected to the \gls{USB} port.
  122. \item Add the node address(es) using the ``ADD\_NODES'' command.
  123. \item Ping the connected node(s) through the GEX communication protocol to test the connection. Note that GEX will not use the radio module if \gls{USB} is connected and enumerated, as it has lower priority.
  124. \end{enumerate}