• 通过domoticz restful接口更新数据 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;
    
    namespace Tlink_Send
    {
        class Program
        {
    
            static void Main(string[] args)
            {
                Console.WriteLine("江苏xx电气公司OPC-domoticz转发工具");
                System.Timers.Timer maxTimer = new System.Timers.Timer();
                maxTimer.Elapsed += new ElapsedEventHandler(Tmr_Elapsed);
                maxTimer.Interval = 1000;
                maxTimer.Enabled = true;
                System.Threading.Thread.Sleep(1000);
                Console.ReadKey();
    
            }
    
            //idx 为设备id
            //svalue 为变量值
    
            static void Tmr_Elapsed(object sender, ElapsedEventArgs e)
            {
                GetWebClient("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=" + "1" + "&nvalue=0&svalue=" + (System.DateTime.Now.Millisecond - 666).ToString());
                Console.WriteLine("成功转发");
                Console.ReadKey();
            }
    
            public static string GetWebClient(string url)
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
                request.Method = "GET";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Credentials = CredentialCache.DefaultCredentials;
                //获得用户名密码的Base64编码
                string code = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "admin", "admin")));
                //添加Authorization到HTTP头
                request.Headers.Add("Authorization", "Basic " + code);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string content = reader.ReadToEnd();
                return content;
            }
        }
    }

     2020年3月10日

    下面可以做一些灵活对接的工具,方便做项目。

  • 相关阅读:
    如何在EasyDSS内调用的iframe地址设置自动播放?
    雏鹰训练营第一次作业
    211806152 蔡钰玲 http://www.cnblogs.com/211806152Erika/ https://github.com/ErikaSakii
    Python05:while循环
    Python04:简单if逻辑判断
    Python03:用户交互输入格式输出
    Python02:变量
    Python01:HelloWorld
    课后作业(一)
    软工假期预先作业
  • 原文地址:https://www.cnblogs.com/dXIOT/p/9999858.html
Copyright © 2020-2023  润新知