zoukankan      html  css  js  c++  java
  • 中国移动物联网平台数据转发 c# 控制台程序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;
    using System.Timers;
    using System.Data;
    using Newtonsoft;
    using System.Threading.Tasks;
    using System.Net.Sockets;
    using OneNET.Api;
    using OneNET.Api.Entity;
    using OneNET.Api.Request;
    
    namespace Tlink_Send
    {
        class Program
        {
    
            private const string url = "api.heclouds.com";
            private const string appkey = "xxxxxxxxxx";//您在OneNET平台的APIKey
    
            static void Main(string[] args)
            {
                Console.WriteLine("江苏xx电气公司OPC-中国移动物联网平台转发工具");
                //Console.ReadKey();
                System.Timers.Timer maxTimer = new System.Timers.Timer();
                maxTimer.Elapsed += new ElapsedEventHandler(Tmr_Elapsed);
                // 设置引发时间的时间间隔 此处设置为1秒(1000毫秒)
                maxTimer.Interval = 1000;
                maxTimer.Enabled = true;
    
    
                //Console.WriteLine(album.ToString());
                System.Threading.Thread.Sleep(3000);
                Console.ReadKey();
                
    
            }
    
            static void Tmr_Elapsed(object sender, ElapsedEventArgs e)
            {
                string value1 = (System.DateTime.Now.Millisecond - 100).ToString();
                string value2 = (System.DateTime.Now.Millisecond - 10).ToString();
                string value3 = (System.DateTime.Now.Millisecond ).ToString();
                string message="";
    
                var client = new DefaultOneNETClient(url, appkey, "");
                var streams = new List<DataStreamSimple>
                              {
                                  new DataStreamSimple
                                  {
                                      ID = "1#污水PH值",//你在平台的数据流id
                                      Datapoints = new List<DataPointSimple>
                                                   {
                                                       new DataPointSimple {Value = value1}
                                                   }
                                  },
                                  new DataStreamSimple
                                  {
                                      ID = "2#污水电导率",//你在平台的数据流id
                                      Datapoints = new List<DataPointSimple>{
                                          new DataPointSimple
                                                   {
                                                       Value = new {yyy = value1, zzz = value2, aaa = value3}
                                                   }
                                      }
                                  }
                              };
    
                var data = new NewDataPointData { DataStreams = streams };
                var req = new NewDataPointRequest { DeviceID = 40066497, Data = data };//你在平台的设备id
                var rsp = client.Execute(req);
    
                Console.WriteLine("上传成功,上传值为" + value1 + " " + value2 + " " + value3);
                Console.ReadKey();
            }
            }
    
    }
  • 相关阅读:
    前后端交互, 安装drf, restful接口规范, pycharm断点调试
    django中文设置, axios, CORS, 全局js配置, Vue配置jq + bs
    js原型, Vue项目环境搭建, Vue项目目录结构, Vue项目生命周期, 小组件使用, 全局样式, 路由跳转, 组件的生命周期钩子, 路由传参
    Vue组件
    Vue表单指令, 条件指令, 循环指令, 成员
    question1 赋值运算操作符
    CH15 面向对象程序设计
    CH12 动态内存
    CH11 关联容器
    CH10 泛型算法
  • 原文地址:https://www.cnblogs.com/dXIOT/p/9999892.html
Copyright © 2011-2022 走看看