Design and Development of Micro-meteorological stations based on Raspberry Pi (Windows 10 IoT Core) and iotcore
Preface
Raspberry Pi (RPi) is designed specifically for Students' Computer Programming education. Only credit card-sized card-type computers can run Linux or Windows 10 IoT Core operating systems. This article uses 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:
- Two or three Raspberry Pi cards, one memory card with more than 8 GB, one card reader (or computer with SD card interface;
- Dht11 temperature and humidity sensor, a GY-68 BMP 180 pressure gauge;
- LY-69 soil hygrometer A, MQ-2 Smoke Gas Sensor A, raindrops Sensor;
- Several dubang cables for the male, one for the bread, one for the micro USB cable, and one for the power supply;
- One HDMI interface display (or HDMI to other interfaces ).
Development Section:
- Integrated Development Environment: Visual Studio 2017 (Community edition is recommended );
- Development language: C #;
- Development Platform: UWP;
- Communication Protocol: MQTT;
- Raspberry Pi OS: WIndows 10 IoT Core;
- Database: Sqlite
Download and install the operating system:
- Install the Windows 10 IoT Core Dashboard application and visit the Microsoft Developer Center https://developer.microsoft.com/en-us/windows/iot/GetStarted. select Raspberry Pi 3, Install onto my blank microSD card, Windows10 IoT core, click Next to go to the new page, click Download Dashboard to Download and Install.
- Burn the operating system to the MicroSD card. After installation is complete, select set new device items to go to the burn-in page. Select Raspberry Pi 2 & 3 as the device type. For OS, select Windows 10 IoT Core (15063) as the OS version. For the drive, select the inserted MicroSD card. Enter the device name, password, and password; select the WLAN Network Connection check box (If this option is selected, you can copy the WLAN information connected to the current computer to the operating system of the Raspberry Pi Development Board, saving the trouble of re-configuring). At this point, raspberry Pi has been installed on Windows 10 IoT.
For example:
Windows Device Portal:
Enter the IP address of Raspberry Pi in a browser in the same network environment. The port is 8080. Enter the user name and password. The default user name is Administrator, and the password is set when the operating system is burned. If you forget the password, you can only reinstall it. After logging on to the system, you will see the details of the current operating system of the Raspberry Pi Development Board, the application management interface, set the default program, and boot automatically.
Implementation
MQTT communication:
MQTT (Message Queuing Telemetry Transport, Message Queue Telemetry transmission) 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 has a large proportion in Android applications. As a communication protocol designed for IOT, MQTT works properly in a low-bandwidth, unstable network environment. Its message transmission has three modes:
For MQTT server construction can refer to: http://blog.csdn.net/yannanxiu/article/details/52703946
The use of MQTT in UWP can be referred to: http://www.cnblogs.com/Yixin-ran/archive/2016/10/21/mqtt.html
To use MQTT in UWP, you must install the nuget package m2mqtt.
Here I will paste 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 in UWP, you must first install the VS extension Sqlite for Universal Windows Platform and Nuget package SQLite. Net-PCL. For detailed use of sqlite reference: http://www.cnblogs.com/yanxiaodi/p/4941312.html
Below are the Database classes in the 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: https://github.com/yixinin/Yixin.Atom
This project is not complete yet. Please add and correct it!
If you have any questions, contact my Email: xingran1994@live.com.