Home > Article > Backend Development > Detailed introduction to Raspberry Pi (RPi)
Preface
## The Raspberry Pi (RPi) is specially designed for students’ computer programming education. It is only a credit card-sized card. Computer, can run Linux or Windows 10 IoT Core operating system. This article will use Raspberry Pi and UWP (Universal Windows Platform) development technology to build a weather station system that can be monitored in real time.
Hardware and related technologies
Hardware part:
Implementation
MQTT communication:
MQTT (Message Queuing Telemetry Transport) is an instant messaging protocol developed by IBM. After years of development, MQTT has been widely used in various fields. It can be used as a message push tool for mobile clients and accounts for a large proportion of Android applications. As a communication protocol specially designed for the Internet of Things, MQTT has the characteristics of working normally in low-bandwidth and unstable network environments. Its message delivery has three modes:At least once to ensure the message can arrive, but duplication may occur.
For the construction of MQTT server, please refer to:
For the use of MQTT under UWP, please refer to:
To use MQTT under UWP, you need to install the nuget package m2mqtt
Here I will post the MQTT connection code:
public class Mqtt : MqttClient {public Mqtt(string host) : base(host, 61613, false, MqttSslProtocols.None) { Connect(Guid.NewGuid().ToString(), "admin", "password"); Subscribe(new string[] { "atmo" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); // PostData("Hello World!"); } public void RequestData(string msg) { Publish("atmo", Encoding.UTF8.GetBytes(msg)); }public void PostData(string msg) { Publish("atmo", Encoding.UTF8.GetBytes(msg)); } }Sqlite implementation: To use Sqlite under UWP, you need to first install the VS extension Sqlite for Universal Windows Platform and the Nuget package SQLite .Net-PCL. For detailed usage of sqlite, please refer to: The following is the Database class in this system:
public class DataBase : SQLiteConnection {public static string path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "atmo.db");public DataBase() : base(new SQLitePlatformWinRT(), path) { CreateTable<DataModel>(); } }INotifyPropertyChanged interface implementation
public class ViewModelBase : INotifyPropertyChanged {public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged([CallerMemberName]string name = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } }
Raspberry Pi GPIO diagram
Hardware connection diagram:
Sensor pin diagram:
Project address:
This project is not yet complete, everyone is welcome Supplements and corrections!
The above is the detailed content of Detailed introduction to Raspberry Pi (RPi). For more information, please follow other related articles on the PHP Chinese website!