如何在Node-red

时间:2018-04-30 05:07:26

标签: iot node-red

我使用Node red创建了一个设备模拟。基本上,设备每秒发送UDP数据包,直到收到确认。我已经成功地完成了这项工作

问题是我试图模拟10000个这样的设备。因此,我需要自动化设备创建/注册过程。有没有办法在Node-red

中实现这一点

下面的json显示了一个设备应该如何表现。它将UDP数据包发送到服务器并等待ACK。如果在一段时间内未收到ACK,则重新发送该数据包。

这是一个设备的节点红色JSON。

[{" ID":" a53cc152.31f27""类型":"评价"" Z&#34 ;:" d51aa60c.64d028""名称":"监听""信息":"",& #34; X":106," Y" 134"电线":[]},{" ID":" a972f44d。 eaa9e8""类型":"评价"" Z":" d51aa60c.64d028""名称&#34 ;:"发件人""信息":""" X" 136" Y":332 "电线":[]},{" ID":" ff1376ae.e08a58""类型":"功能&# 34;," z":" d51aa60c.64d028"," name":" stringToBytes"," func" :" // var binary = msg.payload.toString(2); \ n // 6因为它基于零的计数\ n // var bit7 = binary.charAt(6); \ n / /msg.payload = bit7; \ n //返回msg; \ n str = msg.payload \ n var ch,st,re = []; \ n for(var i = 0; i< str.length; i ++ ){\ n ch = str.charCodeAt(i); // get char \ n st = []; //设置\" stack \" \ n做{\ n st.push(ch& 0xFF); //将字节推送到堆栈\ n ch = ch>> 8; //将值向下移1个字节\ n} \ n而(ch); \ n //将堆栈内容添加到结果\ n //完成因为字符有\"错误\" endianness \ n re = re.concat(st.reverse()); \ n} \ n msg.payload = re \ n //返回一个字节数组\ n返回msg; \ n \ n",&# 34;输出":1," noerr仅":0," X":566," Y" 381"电线" :[[" 98c6c5a8.aaf1c8"]]},{" ID":" 85d26758.5ee0f8""类型":&#34 ;功能"" Z":" d51aa60c.64d028""名称":" ConfigMessge"" FUNC&# 34;:" msg.payload =' 830546613660520101010201225A8622475A862247E96665D15684EF030000242D0000000000E308000001FFA94F0A1F00FF0B08000000000000002E50000000000000000000000000000000000000000000000000    MSG;""输出":1," noerr仅":0," X":353," Y":375 "电线":[[" ff1376ae.e08a58"]]},{" ID":" c83f781f.ae3428"&#34 ;类型":"调试"" Z":" d51aa60c.64d028""名称":"&# 34;,"有源":真," tosidebar":真,"控制台":FAL SE," tostatus":假,"完整":"真"" X" 919" Y" :632,"电线":[]},{" ID":" 98c6c5a8.aaf1c8""类型":" http请求"," z":" d51aa60c.64d028","名称":" ParserAPIRequest","方法&# 34;:" GET""保留":" TXT"" URL":" HTTP:/ API" " TLS":""" X":590," Y":529,"电线&#34 ;: [[" eac23a48.b479d8"" 66759bdf.7fd864"]]},{" ID":" 4a724471.e5158c"&# 34;类型":"注入"" Z":" d51aa60c.64d028""名称":" TimerTrigger& #34;"主题":"""有效载荷":"""的payloadType":& #34;日期""重复":""" crontab的":"""一次&# 34;:假," onceDelay":0.1" X" 148" Y":377,"电线":[[] ]},{" id":" eac23a48.b479d8","输入":" http响应"," z&#34 ;:" d51aa60c.64d 028""名称":" ParserAPIResponse""的StatusCode":" 200""头&#34 ;: {"内容类型":"应用/ JSON"}" X":602," Y":614,"导线":[]},{" ID":" 66759bdf.7fd864""类型":"功能"&# 34; Z":" d51aa60c.64d028""名称":" CheckForAck"" FUNC":&#34 ; //循环函数\ n \ ncontext.loops = context.loops || 0; \ nmsg \ nif(context.loops!== 0)\ n {\ n \ n \ ncontext.ACK = 0 \ ncontext.ACK = flow.get(' ACK')|| 0; \ n // msg.payload = context.ACK \ nif(context.ACK === 1)\ n {\ n // \ n //返回消息; \ n返回[null,null]; \ n} \ nelse \ n {\ n // msg.payload ='没有ACK触发&+ 39; + context.ACK \ n context.loops = context.loops + 1 \ n \ n} \ n \ n \ n} \ n返回[msg,msg]; \ n","输出":" 2"," noerr":0," x&# 34; 857" Y":364,"电线":[[" faa8c055.7dd7d"" f8eb8444.61e8f8",& #34; a3286965.3120d8"],[]]},{" ID":" a3286965.3120d8""类型":" udp out"," z":" d51aa60c.64d028"," name":" Resend Packet"," addr& #34;:" 127.0.0.1"" IFACE":"""端口":"&#34 ;," IPV":" udp4""外港":" 13500"" BASE64":假,& #34;多播":"假"" X":1116," Y":230,"电线":[] },{" ID":" faa8c055.7dd7d""类型":"调试"" Z&#34 ;: " d51aa60c.64d028""名称" :" CONSOLE.LOG""有源":真," tosidebar":真,"控制台":假," tostatus& #34;:假,"完整":"有效载荷"" X":1095," Y":494,"导线":[]},{" ID":" f8eb8444.61e8f8""类型":"延迟"&# 34; Z":" d51aa60c.64d028""名称":""" pauseType":"延迟& #34;"超时":" 5"" timeoutUnits":"秒""速率":& #34; 1"" nbRateUnits":" 1"" rateUnits":"第二"" randomFirst&# 34;:" 1"" randomLast":" 5"" randomUnits":"秒"&# 34;降":假," X":848," Y":420,"电线":[[" 66759bdf.7fd864&# 34;]]},{" id":" 637d9a4c.1182d4","输入":" udp in"," ž":" d51aa60c.64d028""名称":" RecieveAck"" IFACE":"&#34 ;,"端口":" 13501"" IPV":" udp4"" multic AST":"假""组":"""数据类型":" UTF8&#34 ;, " X":173," Y":177,"电线":[[" 8b85adf3.38d6d"]]},{&# 34; ID":" 8b85adf3.38d6d""类型":"开关"" Z":" d51aa60c .64d028""名称":" AssignAck""属性":"有效载荷""属性类型" :" MSG""规则":[{" T":"当量"" v":&# 34;' ACK'"" VT":" STR"}]," checkall":"真&# 34;,"修复":假,"输出":1," X":384," Y" 193&#34 ;电线":[[" 1d63307c.82e67"]]},{" ID":" 66ffd66c.b3c118""类型&#34 ;:"功能"" Z":" d51aa60c.64d028""名称":" StoreAckInContext",& #34; FUNC":" context.ACK = 0 \ nflow.set(' ACK',1); \ nmsg.payload = flow.get(' ACK&#39 ;)\ n \ nreturn msg;","输出":1," noerr":0," x":717," ý":178,"&电线#34;:[[" be667fba.f6701"]]},{" ID":" be667fba.f6701""类型&#34 ;: "调试"" Z":" d51aa60c.64d028""名称":" CONSOLE.LOG",& #34;有源":真," tosidebar":真,"控制台":假," tostatus":假,"完整&#34 ;:"有效载荷"" X" 909" Y" 155"电线":[]},{&#34 ; ID":" 1d63307c.82e67""类型":"变更"" Z":" d51aa60c。 64d028""名称":"复位""规则":[{" T":"设置&#34 ;," p":" ACK"" PT":"流速""至":&#34 ; 0"" TOT":" STR"}],"动作":"""属性&# 34;:"""从":"""至":""&# 34; REG":假," X":510," Y" 165"电线":[[" 66ffd66c.b3c118&# 34;]]},{" ID":" 68ded0.44db513""类型":"状态"" Z& #34;:" d51aa60c.64d028""名称":"&#34 ;, "范围":[" 66759bdf.7fd864&#34]," X":667," Y" 282"电线&# 34;:[[" a3286965.3120d8"]]}]

0 个答案:

没有答案