1. 程式人生 > >中國移動物聯網平臺數據轉發 c# 控制檯程式

中國移動物聯網平臺數據轉發 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(); } } }