• 通过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日

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

  • 相关阅读:
    applications_manager很经典的应用性能监控工具
    eureka分区的深入讲解
    Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警
    solidity 学习笔记(3) 函数修饰符/继承
    以太坊
    solidity 学习笔记 2 (二维数组)
    solidity学习笔记
    女巫攻击---针对联盟链的攻击
    区块链知识点
    [转]PBFT 算法详解
  • 原文地址:https://www.cnblogs.com/dXIOT/p/9999858.html
Copyright © 2020-2023  润新知