阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:4.1 上报位置信息

文档目录:


阿里云物联网的位置服务,并不是完全独立的功能。位置信息包含 二维、三维,位置数据来源于属性的上传。

1)添加二维位置数据

打开 数据分析 -> 空间数据可视化 -> 二维数据 -> 添加,为上面演示的设备添加位置,刷新时间为1秒。 在产品功能中,打开功能定义 ,在 标准功能 里,添加功能。
选择 其它类型 ,里面搜索 位置 ,在出现的列表中选一个(前面那几个都可以)。
笔者选择的是:

标识符:GeoLocation 适用类别:CuttingMachine

位置上传要设置的信息:

输入图片说明

注意注意,如果选择的标准属性跟上图的类型定义不一样,需要手动修改。要把上面的位置属性按上图来改,有一个地方不同,都会失败。 当然,也可以一开始就按图手动创建。

输入图片说明


2)基础代码

上传位置数据,不需要做什么大操作,按照属性的上传方法上传即可。模型代码参考:

        public class TestModel
        {
            public string id { get { return DateTime.Now.Ticks.ToString(); } set { } } public string version { get { return "1.0"; } set { } } public Params @params { get; set; } public TestModel() { @params = new Params(); } public class Params { public geoLocation GeoLocation { get; set; } public class geoLocation { public Value value { get; set; } public long time { get { return AliIoTClientJson.GetUnixTime(); } set { } } public geoLocation() { value = new Value(); } public class Value { public double Longitude { get; set; } public double Latitude { get; set; } public double Altitude { get; set; } public int CoordinateSystem { get; set; } } } public Params() { GeoLocation = new geoLocation(); } } public string method { get { return "thing.event.property.post"; } set { } } } 

整体代码参考: 定义位置模型 -> 设置位置数据 -> 上传位置数据

    class Program
    {
        static AliIoTClientJson client;
        static void Main(string[] args) { // 创建客户端 client = new AliIoTClientJson(new DeviceOptions { ProductKey = "a1A6VVt72pD", DeviceName = "json", DeviceSecret = "7QrjTptQYCdepjbQvSoqkuygic2051zM", RegionId = "cn-shanghai" }); client.OpenPropertyDownPost(); // 设置要订阅的Topic、运行接收内容的Topic string[] topics = new string[] { client.CombineHeadTopic("get") }; // 使用默认事件 client.UseDefaultEventHandler(); // 连接服务器 client.ConnectIoT(topics, null, 60); while (true) { ToServer(); Thread.Sleep(1000); } Console.ReadKey(); } public static void ToServer() { // 实例化模型 TestModel model = new TestModel(); // 设置属性值 // 经度 model.@params.GeoLocation.value.Longitude = 113.952981; // 纬度 model.@params.GeoLocation.value.Latitude = 22.539843; // 海拔 model.@params.GeoLocation.value.Altitude = 56; // 坐标系类型 model.@params.GeoLocation.value.CoordinateSystem = 2; // 上传属性数据 client.Thing_Property_Post<TestModel>(model, false); } public class TestModel { public string id { get { return DateTime.Now.Ticks.ToString(); } set { } } public string version { get { return "1.0"; } set { } } public Params @params { get; set; } public TestModel() { @params = new Params(); } public class Params { public geoLocation GeoLocation { get; set; } public class geoLocation { public Value value { get; set; } public long time { get { return AliIoTClientJson.GetUnixTime(); } set { } } public geoLocation() { value = new Value(); } public class Value { public double Longitude { get; set; } public double Latitude { get; set; } public double Altitude { get; set; } public int CoordinateSystem { get; set; } } } public Params() { GeoLocation = new geoLocation(); } } public string method { get { return "thing.event.property.post"; } set { } } } 

上面使用的是模拟位置数据,请实际情况设置位置数据。

打开阿里云物联网控制台 -> 数据分析 -> 空间数据可视化 -> 二维数据 -> 演示产品

扫描二维码关注公众号,回复: 6385557 查看本文章

会看到定位到了深圳阿里云大厦(高新园地铁站附近)~~~

猜你喜欢

转载自www.cnblogs.com/whuanle/p/10994696.html