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();
        }
        }

}