1)阿里云物联网
1)首先在VS2019创建控制台.net core应用程序
2)在依赖项中添加Mqtt和CZGL_AliloTClient两个包
3)在progress.cs中编写连接秘钥
在这里插入代 static void Main(string[] args)
{
client = new AliIoTClientJson(new DeviceOptions
{
ProductKey = "a1Ga*****",
DeviceName = "te***8",
DeviceSecret = "bce138fdf854dac********",
RegionId = "cn-shanghai"
});
//设置要订阅的Topic、运行要接收内容的Topic
string[] topics = new string[] { client.CombineHeadTopic("get") };
//使用默认事件
client.UseDefaultEventHandler();
//连接服务器
client.ConnectIoT(topics, null, 60);
//定时上传数据
//while (true)
//{
// ToServer();
// Thread.Sleep(1000);
//}
Console.ReadKey();
}码片
测试结果如下:

版权声明:本文为ruoyu8836原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。