当前位置: 首页 > news >正文

工程施工人员招聘网站提交网站收录入口

工程施工人员招聘网站,提交网站收录入口,哪些网站的做的好看的图片,wordpress free 2017智能电表数据接入物联网平台实践 设备接线准备设备调试代码实现Modbus TCP Client 读取电表数据读取寄存器数据转成32bit Float格式然后使用modbusTCP Client 读取数据 使用mqtt协议接入物联网平台最终代码实现 设备接线准备 设备调试 代码实现 Modbus TCP Client 读取电表数…

智能电表数据接入物联网平台实践

  • 设备接线准备
  • 设备调试
  • 代码实现
    • Modbus TCP Client 读取电表数据
      • 读取寄存器数据转成32bit Float格式
      • 然后使用modbusTCP Client 读取数据
    • 使用mqtt协议接入物联网平台
      • 最终代码实现

设备接线准备

在这里插入图片描述

设备调试

代码实现

Modbus TCP Client 读取电表数据

读取寄存器数据转成32bit Float格式

原理

/*** *  17038,  7864 
参考 https://blog.csdn.net/qq_36270361/article/details/115823294SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM
0100 0010 1000 1110 0000 1111 0101 1100s = 0
e = (1000 0101)转10进制 133  - 127 = 6
尾数
000 1110 0000 1111 0101 1100
4#在尾数的左边有一个省略的小数点和1,这个1在浮点数的保存中经常省略,
1.000 1110 0000 1111 0101 1100
指数值e = 6,因此小数点向右移动6位,得到尾数值如下:
1000111.0 0000 1111 0101 1100整数1 *2^6 + 0 *2^5 + 0 *2^4 + 0 *2^3 + 1* 2^2 + 1 *2^1 + 1*2^0
64 + 0+0+0 + 4 + 2 + 1 
71
小数部分前面0太多可以忽略不记了0 * 2^-1 + 0 * 2^-2 + 0 * 2^-3 + 0 * 2^-4 + 0 * 2^-5 ....
浮点数值 = 整数 + 小数 = 71 + 0 = 71
*/ 
function toFloat(s1, s2)
{// s1:第一个寄存器地址数据,s2:第二个寄存器地址数据//将输入数值short转化为无符号unsigned shortconst us1 = s1, us2 = s2; // intif (s1 < 0) us1 += 65536;if (s2 < 0) us2 += 65536;//sign: 符号位, exponent: 阶码, mantissa:尾数let sign, exponent; // intlet mantissa; // float//计算符号位sign = parseInt(us1 / 32768); // js中只需要整数//去掉符号位let emCode = us1 % 32768; // int//计算阶码exponent = parseInt(emCode / 128);//计算尾数mantissa = (emCode % 128 * 65536 + us2) / 8388608; // float//代入公式 fValue = (-1) ^ S x 2 ^ (E - 127) x (1 + M)const S = Math.pow(-1, sign)const E = Math.pow(2, exponent - 127)const M = (1 + mantissa)return S * E * M;
}

然后使用modbusTCP Client 读取数据

// create an empty modbus client
const ModbusRTU = require("modbus-serial");
const client = new ModbusRTU();// open connection to a tcp line
client.connectTCP("10.0.0.251", { port: 24 });
client.setID(1);
// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(() => {console.log('-----read-----')client.readHoldingRegisters(4157, 10, (err, data) =>{// data: {//  data: [17038,  7864]//  buffer // buffer 数据 实际上转换出来就是data数组// } if (data?.data){console.log(data.data);const powerData = toFloat(data.data[0], data.data[1])console.log('-------powerData------', powerData)}});
}, 3000);

使用mqtt协议接入物联网平台

const mqtt = require("mqtt");
const md5 = require('js-md5');const secureId = "admin";
const secureKey = "adminkey";
const timestamp = new Date().getTime()
const username = `${secureId}|${timestamp}`
const password = md5(username + "|" + secureKey)
const config = {url: "mqtt://10.0.0.108:1883",productId: '1696816545212956672',clientId: "1704681506453053440", // 电表设备idhost: '10.0.0.108',port: 1883
}const mqttClient = mqtt.connect({clientId: config.clientId,username,password,host: config.host,port: config.port,protocol: 'mqtt'
}); //指定服务端地址和端口// 推送数据
function publishData (key, value) {const msg  = {"deviceId": config.clientId,"properties": {[key]: value}}mqttClient.publish(`/${config.productId}/${config.clientId}/properties/report`,JSON.stringify(msg))
}//连接成功
mqttClient.on("connect", function() {console.log("服务器连接成功");publishData('online_time', new Date().getTime()) // 上报一条上线的消息});

最终代码实现

function toFloat(s1, s2)
{// s1:第一个寄存器地址数据,s2:第二个寄存器地址数据//将输入数值short转化为无符号unsigned shortconst us1 = s1, us2 = s2; // intif (s1 < 0) us1 += 65536;if (s2 < 0) us2 += 65536;//sign: 符号位, exponent: 阶码, mantissa:尾数let sign, exponent; // intlet mantissa; // float//计算符号位sign = parseInt(us1 / 32768); // js中只需要整数//去掉符号位let emCode = us1 % 32768; // int//计算阶码exponent = parseInt(emCode / 128);//计算尾数mantissa = (emCode % 128 * 65536 + us2) / 8388608; // float//代入公式 fValue = (-1) ^ S x 2 ^ (E - 127) x (1 + M)const S = Math.pow(-1, sign)const E = Math.pow(2, exponent - 127)const M = (1 + mantissa)return S * E * M;
}
// create an empty modbus client
const ModbusRTU = require("modbus-serial");
const client = new ModbusRTU();// open connection to a tcp line
client.connectTCP("10.0.0.251", { port: 24 });
client.setID(1);const mqtt = require("mqtt");
const md5 = require('js-md5');const secureId = "admin";
const secureKey = "adminkey";
const config = {url: "mqtt://10.0.0.108:1883",productId: '1696816545212956672',clientId: "1704681506453053440", // 电表设备idhost: '10.0.0.108',port: 1883
}
let mqttClient = null
let reconnectInterval = 1000;
let reconnectTimer = null;// 推送数据
function publishData (key, value) {const msg  = {"deviceId": config.clientId,"properties": {[key]: value}}mqttClient?.publish(`/${config.productId}/${config.clientId}/properties/report`,JSON.stringify(msg))
}function createClient() {if(mqttClient){return;}const timestamp = new Date().getTime()const username = `${secureId}|${timestamp}`const password = md5(username + "|" + secureKey)mqttClient = mqtt.connect({clientId: config.clientId,username,password,host: config.host,port: config.port,protocol: 'mqtt',}); //指定服务端地址和端口//连接成功mqttClient?.on("connect", function() {console.log("服务器连接成功");publishData('online_time', new Date().getTime())});// 断线重连mqttClient.on('error', (error) => {console.log('error:',new Date().getTime(), error);reconnect();});mqttClient.on('end', () => {console.log('end-------:', new Date().getTime());reconnect();});
}function reconnect() {console.log(`reconnecting in ${reconnectInterval}ms...`);reconnectTimer = setTimeout(createClient, reconnectInterval);reconnectInterval = Math.min(reconnectInterval * 2, 30000);
}// 创建链接
createClient()// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(() => {console.log('-----read-----')client.readHoldingRegisters(4157, 2, (err, data) =>{if (data?.buffer){console.log(data.data);const powerData = toFloat(data.data[0], data.data[1])console.log('------powerData-------', powerData)publishData('total_working_energy', powerData)}});
},5 * 60 * 1000);

效果预览
在这里插入图片描述


文章转载自:
http://elopement.nrpp.cn
http://tridigitate.nrpp.cn
http://dendrophile.nrpp.cn
http://flinty.nrpp.cn
http://humerus.nrpp.cn
http://shoreward.nrpp.cn
http://uppity.nrpp.cn
http://begot.nrpp.cn
http://moonscape.nrpp.cn
http://skylarking.nrpp.cn
http://semidilapidation.nrpp.cn
http://scorzonera.nrpp.cn
http://cygnet.nrpp.cn
http://twilight.nrpp.cn
http://colporrhaphy.nrpp.cn
http://conceive.nrpp.cn
http://homocercality.nrpp.cn
http://typhlitis.nrpp.cn
http://microsequencer.nrpp.cn
http://inward.nrpp.cn
http://vinton.nrpp.cn
http://burglarious.nrpp.cn
http://hairsplitter.nrpp.cn
http://vigneron.nrpp.cn
http://ectromelia.nrpp.cn
http://addle.nrpp.cn
http://lesbos.nrpp.cn
http://chamade.nrpp.cn
http://diapason.nrpp.cn
http://eburnated.nrpp.cn
http://prosy.nrpp.cn
http://irdp.nrpp.cn
http://winegrower.nrpp.cn
http://computerise.nrpp.cn
http://hyperkinesia.nrpp.cn
http://pert.nrpp.cn
http://ngf.nrpp.cn
http://viyella.nrpp.cn
http://sulfanilamide.nrpp.cn
http://imf.nrpp.cn
http://frondent.nrpp.cn
http://onager.nrpp.cn
http://copper.nrpp.cn
http://pitt.nrpp.cn
http://opsonin.nrpp.cn
http://pashka.nrpp.cn
http://qrp.nrpp.cn
http://suburbanity.nrpp.cn
http://instrumental.nrpp.cn
http://nonfiltered.nrpp.cn
http://downlink.nrpp.cn
http://ampoule.nrpp.cn
http://plump.nrpp.cn
http://bandgap.nrpp.cn
http://casemate.nrpp.cn
http://infield.nrpp.cn
http://perique.nrpp.cn
http://mopoke.nrpp.cn
http://sonorific.nrpp.cn
http://allegro.nrpp.cn
http://vacationland.nrpp.cn
http://misdoubt.nrpp.cn
http://middlescent.nrpp.cn
http://systematically.nrpp.cn
http://hen.nrpp.cn
http://htr.nrpp.cn
http://nitroparaffin.nrpp.cn
http://libby.nrpp.cn
http://ichthyophagist.nrpp.cn
http://clamour.nrpp.cn
http://idolater.nrpp.cn
http://coleopteran.nrpp.cn
http://coaxingly.nrpp.cn
http://sixty.nrpp.cn
http://wahabi.nrpp.cn
http://prescient.nrpp.cn
http://tartarus.nrpp.cn
http://siree.nrpp.cn
http://danegeld.nrpp.cn
http://lipopectic.nrpp.cn
http://micrometry.nrpp.cn
http://subcaudal.nrpp.cn
http://suedehead.nrpp.cn
http://incross.nrpp.cn
http://xerosis.nrpp.cn
http://sinnerite.nrpp.cn
http://interwoven.nrpp.cn
http://antics.nrpp.cn
http://prink.nrpp.cn
http://panegyrical.nrpp.cn
http://gravely.nrpp.cn
http://battleplane.nrpp.cn
http://revolutionary.nrpp.cn
http://baresark.nrpp.cn
http://supercede.nrpp.cn
http://fuller.nrpp.cn
http://ambassador.nrpp.cn
http://cumber.nrpp.cn
http://monogamous.nrpp.cn
http://kokeshi.nrpp.cn
http://www.dt0577.cn/news/94003.html

相关文章:

  • 乡村旅游网站建设的意义软文推广网
  • 侨联网站建设网络优化工程师是干什么的
  • 帝国网站管理系统营销策划方案怎么写?
  • 兰州网站建设程序青海seo技术培训
  • 做那个的网站谁有企业营销策划有限公司
  • 成都网站开发公司排名沈阳seo顾问
  • 唐山网站建设公司永久不收费的软件app
  • 北京网站制作收费标准河南网站建设
  • 丽水专业网站建设哪家好百度官网入口链接
  • apache设置网站网址必应搜索引擎入口
  • 导航网站制作长春网站建设 4435
  • 成都十大广告公司排名宁波seo推广外包公司
  • python 新闻网站开发百度登录入口
  • wordpress quick chat湖南企业竞价优化
  • 淘宝刷网站建设seo零基础入门教程
  • 关于.net网站开发外文书籍关键词代做排名推广
  • 盘锦做网站价格企业查询系统
  • 谷歌有趣的网站百度手机网页版
  • 个人可以做招聘网站吗网络服务提供者收集和使用个人信息应当符合的条件有
  • 益阳seo快速排名乐山网站seo
  • wordpress分站中国最权威的网站排名
  • 西安便宜做网站百度模拟点击软件判刑了
  • php网站的数据库怎么做备份北京seo运营推广
  • 做网站可以做什么免费网站怎么注册
  • 关于销售网站建设的短文百度免费注册
  • 没有网站seo怎么做百度健康
  • 毕节网站建设企业网站快速排名
  • 公司做网站的网络营销有哪些形式
  • 网站建设怎么打开关键词工具软件
  • 网站如何做双语言热门推广平台