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();
            }
            }
    
    }
  • 相关阅读:
    Linux mail命令详解
    Linux 硬件RAID详解系统功能图
    Linux 下Discuz论坛的搭建
    Linux 下Wordpress博客搭建
    运维监控---企业级Zabbix详解_【all】
    Linux下的Mysql的双向同步
    Linux下的Mysql的主从备份
    实参时丢弃了类型 discards qualifiers discards qualifiers问题
    Qt::ConnectionType(信号与槽的传递方式)
    Qt多线程编程总结(一)
  • 原文地址:https://www.cnblogs.com/dXIOT/p/9999892.html
Copyright © 2011-2022 走看看