[英]Xively and Node-Red
I'm fairly new at all this but have muddled my way to getting my Arduino to post values to a Xively stream I've named "Lux and Temp." 我在这方面还算是新手,但是却迷惑了让Arduino将值发布到名为“ Lux and Temp”的Xively流中的方法。 Three values;
三个值; count, lux, and temperature.
计数,勒克斯和温度。
Now what I want to do is take those values and do something with them using Node-Red. 现在,我要做的就是获取这些值,并使用Node-Red对它们进行处理。 http://nodered.org
http://nodered.org
I have Node-Red up and running, but I'll be danged if I can figure out how to parse the data from the Xively API feed. 我已经启动并运行Node-Red,但是如果我想出了如何解析Xively API提要中的数据,我会感到很惊讶。 https://api.xively.com/v2/feeds/1823833592
https://api.xively.com/v2/feeds/1823833592
Sadly, I don't have enough reputation points to be able to actually post the data it returns to here, since it has more than 3 URLs embedded in the data. 可悲的是,我没有足够的信誉点来实际将返回的数据发布到此处,因为它在数据中嵌入了3个以上的URL。 It's a LONG string of data too.
这也是一个很长的数据字符串。 ;)
;)
I'm just stumped though as to how to write the function to extract the parts I want. 我只是为如何编写函数以提取所需部分而感到困惑。
My initial want is to make a simple Twitter feed out of it. 我最初的愿望是制作一个简单的Twitter提要。 Something like;
就像是;
"Count 40, Lux 30, Temp 78.3" “计数40,勒克斯30,温度78.3”
I'll eventually want to recycle the code for other things like making my RasPi do something; 我最终将要为其他事情回收代码,例如使RasPi做一些事情。 maybe a display or some LEDs.
可能是显示器或某些LED。 In either case I need to parse the data and build various messages with it.
无论哪种情况,我都需要解析数据并使用它构建各种消息。
Anybody have any experience with the Node-Red functions that can walk me through a solution? 是否有人对Node-Red功能有任何经验,可以带我逐步解决? The Node-Red site is pretty awesome, but I think it assumes I'm a MUCH more experienced user than I really am.
Node-Red站点非常棒,但是我认为它是我比实际拥有更多经验的用户。 It gives hints, but frankly about all I know is fairly basic Arduino and trivial level Python.
它给出了提示,但坦率地说,我所知道的只是相当基本的Arduino和普通级别的Python。
OK, it shouldn't be too tricky, but try putting this in a function block: 好的,它应该不会太棘手,但是请尝试将其放在功能块中:
var newPayload = "";
var count, lux, temp;
var data = msg.payload.datastreams;
for (var i = 0 ; i< data.length; i++) {
if (data[i].id === 'Count') {
count = data[i].current_value;
}else if (data[i].id === 'Lux') {
lux = data[i].current_value;
} else if (data[i].id === 'Temp') {
temp = data[i].current_value;
}
}
newPayload = util.format('Count: %s, Lux: %s, Temp: %s', count, lux, temp);
msg.payload = newPayload;
return msg;
You may need to add a msg.payload = JSON.parse(msg.payload); 您可能需要添加msg.payload = JSON.parse(msg.payload); to the start if however your getting the feed from xively is not already considered to be json.
然而,如果您尚未从xively获取提要,则应该从头开始。 [edit] You could also just run the flow through a JSON parse node.
[edit]您也可以只通过JSON解析节点运行流。 (I always forget the converter nodes)
(我总是忘记转换器节点)
You should be able to wire that to a twitter output node. 您应该能够将其连接到Twitter输出节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.