Ali cloud Things .NET Core Client | CZGL.AliIoTClient: 4.1 reporting location information

Documents directory:


 

Ali cloud service position of things, not entirely separate functions. Location information contains a two-dimensional, three-dimensional position data uploaded from the property.

1) Adding the two-dimensional location data

> Spatial Data Visualization - -> two-dimensional data -> added, as demonstrated above, the position of the device is added, the refresh time is 1 second to open the data analysis. Product features, open the functions defined in the standard functions, the added functionality.
Choose other types, search inside  位置 , a (in front of those few are) selected in the list that appears.
I chose:

标识符:GeoLocation 适用类别:CuttingMachine

Location upload information to be set:

Enter Caption

Note Note, if the selected standard attribute FIG keep different type definitions need to be manually modified. The above properties make the position change according to the map, there is a different place, it will fail. Of course, you can start to create a map by hand.

Enter Caption


2) the underlying code

Upload location data, you do not need to do any major operation, you can upload upload method in accordance with the property. Reference model code:

        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 { } } } 

Overall code reference: Model defined position -> position data set -> location data upload

    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 { } } } 

Used above is simulation position data, actual position data set.

Open Ali cloud Things Console -> Data Analysis -> Spatial Data Visualization -> two-dimensional data -> Presentation Products

You see targeted to the (high-tech garden near the rail station) Shenzhen Ali cloud building ~~~

Guess you like

Origin www.cnblogs.com/whuanle/p/10994696.html