虎符电竞官网

关注官方微信

en

EN.

chanpinzhongxin

产品中心

卓岚MQTT和JSON转Modbus网关用法

发布时间:2019-09-09 作者:上海卓岚 浏览量:11523
1.概述

benwenjieshaozhuolanzhichimqtthejsondeshebeideyongfa,zhichideshebeibaokuozlan5143、zlan8303-7、zlan1043、zlan7144deng。qizhongzlan5143、zlan8303-7、zlan1043degujianbanbenyaozai1.577jiyishang,zlan7144xuyaozai1.489jiyishang。xuyaohezlvircomde5.09banbenpeiheshiyong。

mqtthejsonkeyidandushiyongyekeyiheqilaishiyong。qizhongdejsonzhichimodbus rtugeshizhuanhuaweijsongeshi。

zhuyaotedianshi:

1.caiyongmqttweijichudexieyihefuwuqijianlilianjie,caiyongdingyuefabudexingshijinxingshujutongxun。

2.zhichimodbus rtujicunqidezizhushejihezidongcaiji。

3.zhichijiangtedingdemodbusjicunqineirongzhuanhuaweijsongeshidingshizhudongshangfa。

4.zhichizaijsongeshizhongjiarushebeiid,fangbianyunduanshibieshebei。

5.zhichiwufuhaoshujuheyoufuhaoshuju,zhichixiaoshudianbiaoshi,zhichi4zijiezhangdushuju。

6.suoyoupeizhidoukeyijiemianhuapeizhiwancheng,yonghuzizhupeizhiwuxudingzhi。

2.JSON
2.1.Modbus RTU转JSON

zhuolanmodbus rtuzhuanjsonkeyishixianmodbus rtubiaodezidongcaiji,binganzhaojsongeshizidongshangfajiyunduanfuwuqi。

zheiliwomentongguoyigejutideanlilaijiangjiezheigeyongfa。

2.2.Modbus表

jiashexianzaiyouyigegongnengmawei3,dizhiwei1demodbusbiao,qijicunqidizhihecanshumingruxia。qizhongzijiezhangduwei4debiaoshixuyaolianxudu2gejicunqi。

寄存器地址 参数名 字节长度 备注
0 当前总有功电能 4 无符号,保留2位小数
97 A相电压 2 无符号,保留1位小数
98 B相电压 2
99 C相电压 2
100 A相电流 2 无符号,保留2位小数
101 B相电流 2
102 C相电流 2
119 频率 2
356 A相有功功率 4 有符号,保留3位小数
358 B相有功功率 4
360 C相有功功率 4
362 总有功功率 4

suoweiyoufuhaoshizhi,2zijiehuozhe4zijiezuigaobitweifuhaowei,liru0xffffjiangbeirenweishi-1。baoliu2weixiaoshushizhijiangshujudangzuozhengxingzhuanhuazhihou,xiaoshudiancongzuiyoubianxiangzuoyidong2wei。

2.3.设备配置

womenanzhaoshebeizuoweikehuduandefangshijinxingpeizhi。

使用SocketDlgTest,在本地计算机1883端口监听一个TCP服务器。

Socket模拟服务器接收数据

shiyongzlvircomduishebeijinxingpeizhi。

设备配置

dianjixiugaipeizhi,keyirangshebeilianjieshangsocketdlgtestgongju。zaicijinrushebeibianjiduihuakuang。dianji“gujianhepeizhi”anniu。

下载界面

shouxiandianji“wangyemuluxiazai”jinrupeizhixiazaimoshi。ranhouxuanzeyigexindekongmulu,birumqtthttpdmulu。fangzhizhiqiandeshejiyoucanliu,qingxiandianji“qingchuquanbu”anniu,zheiyangkeyiqingkongzhiqiandeshejineirong。shejiwenjianjianghuibaocunzaizheigemulu,dengyixiakeyitongguodianji“xiazai”anniuxiazaidaoshebeineibu。

dianji“jsonpeizhi”anniu。

JSON配置主界面

zheilidecanshushuomingruxia:

1.shangfafuwuqishijian:morenjsonshujumeigeduoshaoshijianshangfadaofuwuqi,fuwuqijiushiganggangzaishebeipeizhijiemianshezhidemudeip,danweishihaomiao。

2.shifoushangfashebeiid:ruguoxuanze1zehuizaimeicishangfadejsonshujuzhongbaohanyoushebeideid,shebeiidjiushizaishebeibianjijiemianzuoshangjiaokandaodeshebeidemacdizhi。

3.iddejsonguanjiancishizijimingmingdeidduiyingdedejsonguanjianci,zheilixiemyid,zuizhangwei32zijie。zheiyangyihoujsongeshizhonghuizengjia”myid”:”2850002f0eec”deneirong。zheileisiyuzhucebao,youliyufuwuqishibieshinayitaishebeifalaideshuju。

4.tianjia/chakan:dianjihoukeyijinxingmodbusjicunqidesheji,yekeyichakanmuqianyijingneirong。

5.shanchuquanbu:shanchuyou“tianjia/chakan”anniushejidesuoyoudemodbusjicunqi,fangbianzhongxinkaishisheji。

6.baocunjsonshezhi:shejiwanchenghouzhiyoudianjizheigeanniucaikeyibaocunshujudaogangcaidexiazaimulu,zhihoukeyixiazaidaoshebeineibu。

xianzaidianji“tianjia/chakan”anniu。duiyuzhiqiandemodbusbiaodediyixing:

寄存器地址 参数名 字节长度 备注
0 当前总有功电能 4 无符号,保留2位小数

duiyingdepeizhiruxia:

寄存器设置

zheilidecanshushuomingruxia:

1.di1gejicunqi:zheilide1,biaoshixianzaideshejijiemianshipeizhidiyigejicunqi。

2.yijingtianjiaguo:ruguodagoushuomingshiyijingtianjiade,chakanyijingpeizhidexinxideshihouhuichuxiandagoudeqingkuang。

3.congzhandizhi:modbusdebiaodizhi。

4.modbusgongnengma:muqianzhichi03he04gongnengma。

5.jicunqidizhi:zheiliduiyingde0。

6.shujuzhangdu:zheiliduiyingshi4zijie。

7.shujugeshi:zheiliduiyingshiwufuhaozhengxing。

8.baoliuxiaoshudian:zheilibaoliu2wei。

9.chuankoulunxunshijian:zheilishewei100ms。shizhizheigejicunqihexiagejicunqidelunxundejiange,erbushizheitiaozhilingdelunxunjiange。

10.duiyingdejsonguanjianci:duiyingshangfadejsonzhongdekeyword。liru”currentw”:232.12。

11.shejixiayige:dianjihoujinruxiayigejicunqideshezhi。

12.baocunsheji:wanchengsheji,zhihoudianjishangyigejiemiande“baocunjsonpeizhi”jike。

13.quxiaosheji:quxiaodangqiandesuoyousheji,ruguoshichakanshejineirong,keyidianjizheigeanniutuichu。

zheilidianji“shejixiayige”anniujixushejimodbusbiaozhongdeqitajicunqi。quanbushejiwanbiaogezhongdejicunqihou,dianji“wanchengsheji”,ranhoudianji“baocunjsonpeizhi”houtuichu。ranhoudianji“xiazaiweb”yemiande“xiazaianniu”

下载

ranhoudianji“queding”,shebeihuizidongzhongqi。ruguomeiyouzhongqiqingshoudongzhongqi。

2.4.新建Modbus模拟表

zheilishiyongmodbus slavelaimoniyigebiao

测试结果

ceshijieguoxianshi,shiyongmodbus slavegongjumonideyibiaonenggoubeiwangguansuocaiji。tongshikeyidingshi,anzhaojsongeshishangfadaosocketdlgtestmonidefuwuqiruanjianduan。

3.MQTT

mqttkeyidandushiyongyekeyihejsongongnengpeiheshiyong。dangdandushiyongdeshihoumqttgongnengjiangchuankoushujutouchuanshangfamqttfuwuqi。yejiushijiangchuankoujieshoudeshujuzuoweimqttdezaihe。tongshimqttdezaihehuiyitouchuandefangshicongchuankoushuchu。shixianchuankouzhuanmqtt。

3.1.设备配置

MQTT配置1

dianji“gujianyupeizhi”,danchupeizhixiazaiheshejiduihuakuang:

MQTT配置2

zheilixuanze“wangyemuluxiazai”,ranhouxuanzeyigekongdemulu,birumqtthttpdmulu,ranhouxiandianji“qingchuquanbu”qingchuzhiqiandesheji(zhuyiruguozhiqiananyoujsonshejide,zebuyaoqingchuquanbu,fouzehuiqingchuzhiqiandejsonsheji)。ranhoudianjimqttpeizhi。

MQTT配置3

zheilipeizhishuomingruxia:

1.fuwuqiyuminghuoip:zheilitianxiedeshimqttfuwuqideip,zuizhangwei30gezifu。

2.yonghuming:shimqttfuwuqideyonghuming。

3.mima:shizheigeyonghudedenglumima。

4.kehuduanid:shimqttdeclient id。

5.dingyuezhuti:shizheigeshebeidingyuedezhuti,youqitashebeifabuzheigezhutideshihou,fuwuqihuixiafajizheigeshebei。ruguozhishifabu,yibanwuxutianxiezheigeziduan。

6.fabuzhuti:zheigeshebeichuankouzhuanmqttdeshihouxiangfuwuqifasongdeshujudezhuti。

7.mqttgaojicanshu:yongyupeizhigaojicanshu。

8.baocunmqttshezhi:shejiwanbidianjizheigeanniujinxingbaocun,ranhoudianjiwangyexiazaimulude“xiazaianniu”xiazai。

xianzaixiandianji“mqttgaojicanshu”(yibanwuxupeizhigaojicanshu):

MQTT高级参数配置

shuomingruxia:

1.xieyibanben:muqianzhuliudeshi3.1.1banben,ruguoxuyaoxuanze3.1banben,qingzaizheilixuanze。

2.baohuoshijian:mqttdexintiaoshijian,zuishaowei10miao,morenwei60miao。

3.fuwuqiqingchudingyue:kehuduanduanxianhoufuwuqishifouqingchudingyuexinxi。

4.shifouqiyongyiyuan:shifouyouyiyuan。

5.yiyuanzhuti:yiyuanzhuti。

6.yiyuanxinxi:yiyuandexinxi。

7.shifoubaocunyiyuan:fuwuqishifouxuyaobaochikehuduanyichanglixianshifasongjikehuduandeyiyuanxiaoxi。

8.yiyuanzhiliang:fuwuqifasongdeyiyuanxiaoxidejiaofuzhiliangjibie。

9.dingyuezhiliang:dingyuedejiaofuzhiliangjibie。

10.fabuzhiliang:kehuduanfabuxiaoxidejiaofuzhiliangjibie。

11.shifoubaocunfabu:fuwuqishifoubaochizuihouyitiaoxiaoxi(ruguoyouxindekehuduandingyuezefasongjikehuduan)。

womenzheilibuxiugaigaojicanshu。zhijiedianji“baocunmqttshezhi”。ranhoudianji“xiazai”

下载

xiazaiwanbidianjiqueding,cishihuihuidaoshebeiguanliduihuakuang,kandaoshebeidemudeip、gongzuomoshi、mudeduankouyijingzidongxiugaiweimqttdeshezhi:

自动修改

ruguomeiyouzidongxiugaizexuyaozaishebeibianjiduihuakuangxia,shezhimudeip、gongzuomoshi、mudeduankou。ranhoudianji“xiugaishezhi”。

IP配置

zheiyangpeizhijiuwanchengle。

3.2.数据测试

lianjiewanchenghoushebeidelinkdeng(yibanweizhongjiandelansedeng)bianliang。shuomingshebeizhengchanglianjieshangmqttfuwuqi。

xianzaidakaichuankougongju:

串口发送和接收

shiyongheshebeiyiyangdebotelvdakaichuankou,bingfasongshuju“dev send”,cihouzaijieshouchuangkoukandaofanhuideshuju“dev send”。zheishiyouyuwomenjiangdev sendzheigexinxiyizlansubdezhutifabujimqttfuwuqi。danshitongshiwomendeshebeiyedingyuelezlansubzheigezhuti,suoyifuwuqilikehuijiwomenfasongyigedingyuexinxi,dingyuexinxideneirongjiushidev send。zheigexinxizuoweimqttdezaihefasongxiazai,tongguotouchuandefangshicongchuankoushuchu。

ruguoqitashebeifabuxinxiguolai,zheigeshebeiyenenggoushoudaoshuju。

yibanlaishuo,yonghukeyizhijiejiangchuankouzhiling(birumodbus rtu)zhilingzhijietouchuanjimqttfuwuqi。lingwaiyekeyishiyongjsongongneng,caiyongzidongmodbus rtugeshicaiji,dingshijsongeshishangfadexingshi。lingwaiyekeyizhaoshanghaizhuolandingzhiyixiefeibiaodeyibiaoheshangweijixieyigeshi。

4.MQTT+JSON转Modbus RTU

jiangshangshudejsonhemqttxiangzuhekeyishixianruxiadegongneng:

1.caiyongmqttweijichudexieyihefuwuqijianlilianjie,caiyongdingyuefabudexingshijinxingshujutongxun。

2.zhichimodbus rtujicunqidezizhushejihezidongcaiji。

3.zhichijiangtedingdemodbusjicunqineirongzhuanhuaweijsongeshidingshizhudongshangfa。

4.zhichizaijsongeshizhongjiarushebeiid,fangbianyunduanshibieshebei。

ruguoxuyaomqtt+jsonzhuanmodbus rtugongnengde,keyifenbieshejimqtthejson,bufenxianhoucixu。shejiwanyizhongbuyaodianji“qingchusheji”anniu,lianggeshejiwan,yiqidianji“xiazai”anniuxiazaidaoshebeineirong。

yibankeyixiazaihoushoudongzhongqishebei,jiazaishezhi。