ThingSpeak™ TV White Space Monitor with RTL-SDR Radio on Raspberry Pi
This example shows how to use an RTL-SDR radio connected to a Raspberry Pi hardware with Simulink® and Communications Toolbox® to monitor TV white space signal levels and publish the data to the Internet using ThingSpeak. To run this example, you need to install Communications Toolbox Support Package for RTL-SDR Radio and Simulink Support Package for Raspberry Pi Hardware. You can view the published data in TV White Space Monitor Channel of ThingSpeak.
Simulink Support Package for Raspberry Pi Hardware enables you to create and run Simulink models on Raspberry Pi hardware. Communications Toolbox Support Package for RTL-SDR Radio enables you to receive radio signals from the RTL-SDR radio. You can use these two support packages together to receive RF signals in a given bandwidth in the TV white space on the Raspberry Pi hardware.
In this example you will learn how to run the TV White Space Monitor Simulink model on Raspberry Pi hardware and publish the estimated received signal strength value to the Internet using the ThingSpeak Write block. ThingSpeak is a web service for Internet of Things applications. It provides real-time data collection, data processing, visualizations, apps, and plugins. You need to connect your Raspberry Pi directly to the Internet for this example to publish results to the ThingSpeak channel.
To run this example, you will need the following hardware:
- Raspberry Pi hardware (connected to the Internet)
- RTL-SDR radio
TV White Space Monitor
The following shows the TV white space monitor model. The model uses the RTL-SDR receiver block to receive RF signals and sends them to the signal strength estimator subsystem.
The signal strength estimator block estimates the signal power in a given band. You can vary the center frequency and signal bandwidth.
Configure and Run the Model as a Standalone Application
In this task, you will configure your model to run on Raspberry Pi hardware. You will then run your model on Raspberry Pi hardware in External mode. When you are prototyping and developing an algorithm, it is useful to monitor and tune the algorithm while it runs on hardware. The External mode feature in Simulink enables this capability.
1. Make sure that your Raspberry Pi hardware is connected to the Internet.
2. In the model, set simulation stop time to 'inf' to run the simulation until you explicitly pause or stop the model.
3. In the Simulink model, click Tools > Run on Target Hardware> Options....
4. When the Configuration Parameters page opens up, set the Target hardware parameter to Raspberry Pi. Review the other parameters on that page. If you performed a Firmware Update, Board information will be automatically populated with the IP address, user name and password of your Raspberry Pi hardware. Also, notice the TCP/IP port edit box under Signal monitoring and parameter tuning. The default value of TCP/IP port is 17725. Simulink uses this TCP/IP port to communicate with Raspberry Pi hardware. Leave the TCP/IP port parameter to its default value. Click OK when you are done.
5. In the Simulink model, click the Deploy to Hardware button on the toolbar or press Ctrl+B.
6. The model will now run on the Raspberry Pi hardware. A system command window will open that shows the messages coming from the model running on Raspberry Pi hardware:
7. Open the TV White Space Monitor Channel of ThingSpeak. Observe the estimated signal strength values as they are sent to the ThingSpeak channel by the Raspberry Pi.
Running and Stopping the Model on Raspberry Pi Hardware
Simulink Support Package for Raspberry Pi Hardware generates a Linux executable for each Simulink model you run on the Raspberry Pi hardware.
1. To run/stop a Simulink model, you use the run and stop methods of the raspberrypi communication object. First, create a communication object to the Raspberry Pi hardware:
rpi = raspberrypi;
This command generates a Raspberry Pi object that is your gateway to communicating with your Raspberry Pi hardware from MATLAB command line.
2. Execute the following on the MATLAB command line to stop the Simulink model you ran in previous section:
3. To run a previously built Simulink model on your board, you use run method. In order to run the sdrrFMMonoRaspberryPiExample model, execute the following on the MATLAB command line:
You can also run this model in Simulink's External Mode, as described in TV White Space Monitor with RTL-SDR Radio on Raspberry Pi 2 Hardware. As you vary the center frequency, bandwidth, and gain values, the data in the ThingSpeak channel will reflect these changes.
This example introduced the workflow for receiving RF signals with an RTL-SDR radio, processing the received signals, and publishing the results to ThingSpeak using a Simulink model running on Raspberry Pi hardware.