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();
            }
            }
    
    }
  • 相关阅读:
    姚班
    xxx
    1358B
    1368A
    莫烦Tensorflow 建造自己的NN
    莫烦Tensorflow 入门
    linux服务器安装Apache (Centos)
    C++ 获取Linux 服务器CPU占用率+内存空闲率(亲测绝对可以运行)
    MySQL主键从初始值自增
    基础练习 矩阵乘法
  • 原文地址:https://www.cnblogs.com/dXIOT/p/9999892.html
Copyright © 2011-2022 走看看