New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-red-m2x

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-m2x - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

md_images/logo.png

0

flows/m2x_flow.json
<<<<<<< HEAD
[{"type":"tab","id":"d8a3e781.275c18","label":"Sheet 1"},{"id":"704442f7.8fbbbc","type":"m2x feed","apiKey":"YOUR ACCOUNT KEY HERE","name":"My M2x node"},{"id":"ceb4b7d1.314b48","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":1324.0000305175781,"y":257,"z":"d8a3e781.275c18","wires":[["2d3546eb.d2caba","dc56a763.23a958"]]},{"id":"be6c5781.4193a8","type":"function","name":"Create Trigger for > 200 Degrees","func":"msg.topic = \"devices\";\n\nmsg.action = \"createTrigger\";\n\nmsg.topic_id = \"1b2f98cc3b31b527c27ba14fe46c615c\";\n\nmsg.payload = { \"stream\": \"temperature\", \n\n \"name\": \"high temp\", \n\n \"condition\": \">\", \n\n \"value\": 200, \n\n \"callback_url\": \"http://localhost:1880/high\", \n\n \"status\": \"enabled\", \n\n \"send_location\": true }; \nreturn msg;","outputs":1,"x":1088.0001525878906,"y":258,"z":"d8a3e781.275c18","wires":[["ceb4b7d1.314b48"]]},{"id":"6d5fb737.92a048","type":"http request","name":"> 200 ","method":"GET","url":"/hot","x":100,"y":565.0000305175781,"z":"d8a3e781.275c18","wires":[["4daf277b.b250d8"]]},{"id":"2d3546eb.d2caba","type":"debug","name":"","active":true,"console":"true","complete":"false","x":1425.0000915527344,"y":189,"z":"d8a3e781.275c18","wires":[]},{"id":"4966ba86.b69944","type":"function","name":"Delete Trigger for > 200 Degrees if exists","func":"console.log(msg.payload);\n\nmsg.topic = \"devices\";\nmsg.action = \"deleteTrigger\";\nmsg.topic_id = \"1b2f98cc3b31b527c27ba14fe46c615c\";\nmsg.sub_topic_id = msg.payload;\nmsg.payload = {};\nreturn msg;","outputs":1,"x":1068.0000305175781,"y":120,"z":"d8a3e781.275c18","wires":[["4ddcb92a.b22348"]]},{"id":"e969d087.16963","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":473,"y":192,"z":"d8a3e781.275c18","wires":[["2a706e23.d58f92"]]},{"id":"37b9ce.ffc84632","type":"function","name":"Get All Triggers","func":"msg.topic = \"devices\";\nmsg.action = \"triggers\";\nmsg.topic_id = \"1b2f98cc3b31b527c27ba14fe46c615c\";\nmsg.payload = {};\nreturn msg;","outputs":1,"x":301,"y":194,"z":"d8a3e781.275c18","wires":[["e969d087.16963"]]},{"id":"2a706e23.d58f92","type":"function","name":"Find the if high tempe trigger exists","func":"if (!msg.payload) {\n\tconsole.log(\"No Payload quit flow\");\n\tmsg.payload = -1;\n} else {\n\tif (!msg.payload.triggers) {\n\t\tconsole.log(\"No Triggers found\");\n\t\tmsg.payload = -1;\n\t} \n\telse \n\t{\n\t\tvar triggers = msg.payload.triggers;\n\t\tfor(var trigger in msg.payload.triggers) {\n\t\t console.log(triggers[trigger].name);\n\t\t\tif (typeof (triggers[trigger].name) === 'string' && triggers[trigger].name === \"high temp\") {\t\t\t\t\n\t\t\tconsole.log(\"High temp Trigger found \"+ triggers[trigger].id);\n\t\t\tmsg.payload = triggers[trigger].id;\t\n\t\t\treturn msg;\n\t\t\t} \n\t\t}\n\t}\n}\nmsg.payload = -1;\nconsole.log(\"Counldn't find high temp trigger, go directly to create it\");\nreturn msg;","outputs":"1","x":687.0000305175781,"y":190,"z":"d8a3e781.275c18","wires":[["81deccc4.7e213"]]},{"id":"81deccc4.7e213","type":"switch","name":"","property":"payload","rules":[{"t":"neq","v":-1,"v2":0},{"t":"else"}],"checkall":"true","outputs":2,"x":915.0001525878906,"y":194,"z":"d8a3e781.275c18","wires":[["4966ba86.b69944"],["be6c5781.4193a8"]]},{"id":"4ddcb92a.b22348","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":1327.0000305175781,"y":119,"z":"d8a3e781.275c18","wires":[["be6c5781.4193a8"]]},{"id":"d0cbca4d.2f3438","type":"function","name":"Create relevant Out Message","func":"msg.topic=\"charts\";\nmsg.action=\"render\";\nmsg.topic_id=\"f149a94a715fa12455c9ad53f7b18e42\";\nmsg.sub_topic_id=\"svg\";\nreturn msg;","outputs":1,"x":310,"y":743.0000915527344,"z":"d8a3e781.275c18","wires":[["8b7e8fbf.74817"]]},{"id":"8b7e8fbf.74817","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":542.0000305175781,"y":744.0000915527344,"z":"d8a3e781.275c18","wires":[["6fc363d1.903c9c"]]},{"id":"6fc363d1.903c9c","type":"function","name":"Extract Graph Data","func":"msg.payload = msg.payload.raw;\n\nreturn msg;","outputs":1,"x":718.0000305175781,"y":749.0001525878906,"z":"d8a3e781.275c18","wires":[["2c3fc26c.d3c03e"]]},{"id":"2c3fc26c.d3c03e","type":"template","name":"Create the HTML","field":"payload","template":"<html>\n<head/>\n<body>\n<img src=\"data:image/svg+xml;,{{payload}}\" hieght=\"600\" width=\"800\"/>\n</body>\n</html","x":897.0000305175781,"y":748.0000915527344,"z":"d8a3e781.275c18","wires":[["2c51ec4d.d3ae14"]]},{"id":"dc388f81.23c77","type":"http in","name":"","url":"/graph","method":"get","x":95,"y":743.0000305175781,"z":"d8a3e781.275c18","wires":[["d0cbca4d.2f3438"]]},{"id":"2c51ec4d.d3ae14","type":"http response","name":"","x":1072.0002746582031,"y":752.0002746582031,"z":"d8a3e781.275c18","wires":[]},{"id":"d7396ed3.28c69","type":"comment","name":"Display Stream Graph","info":"","x":152.88888549804688,"y":667.8888854980469,"z":"d8a3e781.275c18","wires":[]},{"id":"271fafa5.d8e05","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":110.88888549804688,"y":435.8888854980469,"z":"d8a3e781.275c18","wires":[["84881931.7b77e8"]]},{"id":"84881931.7b77e8","type":"function","name":"Inject Random Temperature between 195 and 204","func":"var temp = Math.random()*10+ 195;\nmsg.topic = \"devices\";\nmsg.action = \"setStreamValue\";\nmsg.topic_id = \"1b2f98cc3b31b527c27ba14fe46c615c\";\nmsg.sub_topic_id = \"temperature\";\nmsg.payload = { \"at\": new Date().toJSON(), \"value\": temp}\nreturn msg;","outputs":1,"x":424.8888854980469,"y":434.8888854980469,"z":"d8a3e781.275c18","wires":[["2d33482e.d2ccb8"]]},{"id":"2d33482e.d2ccb8","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":747.8889465332031,"y":436.8888854980469,"z":"d8a3e781.275c18","wires":[["51afa1eb.ae506"]]},{"id":"51afa1eb.ae506","type":"debug","name":"","active":false,"console":"false","complete":"false","x":952.8889465332031,"y":410.8888854980469,"z":"d8a3e781.275c18","wires":[]},{"id":"c363ddcc.3c9c2","type":"comment","name":"Create Trigger for 200 degrees erase the previous one if exists first","info":"","x":255.88888549804688,"y":59.888885498046875,"z":"d8a3e781.275c18","wires":[]},{"id":"1a42bf38.e5bd41","type":"comment","name":"Inject temperature reading every 10 seconds","info":"","x":212.88888549804688,"y":331.8888854980469,"z":"d8a3e781.275c18","wires":[]},{"id":"8a1d6b15.75e298","type":"debug","name":"","active":true,"console":"false","complete":"false","x":468.8888854980469,"y":560.8889465332031,"z":"d8a3e781.275c18","wires":[]},{"id":"4daf277b.b250d8","type":"function","name":"Write log Message","func":"msg.payload = \"200 Limit was reached - \"+ msg.value + \" was recorded.\"\nreturn msg;","outputs":1,"x":278.8888854980469,"y":569.8888854980469,"z":"d8a3e781.275c18","wires":[["8a1d6b15.75e298"]]},{"id":"3e6d0518.c192fa","type":"comment","name":"Trigger critiria was met","info":"","x":127.88888549804688,"y":508.8888854980469,"z":"d8a3e781.275c18","wires":[]},{"id":"bb93efe4.446c1","type":"http in","name":"","url":"/create_trigger","method":"get","x":109.88888549804688,"y":195.88888549804688,"z":"d8a3e781.275c18","wires":[["37b9ce.ffc84632"]]},{"id":"dc56a763.23a958","type":"http response","name":"","x":1487.8889465332031,"y":258.8888854980469,"z":"d8a3e781.275c18","wires":[]},{"id":"d74083f6.28bf8","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":1387.8890686035156,"y":984.8889541625977,"z":"d8a3e781.275c18","wires":[["65891d8e.9a76e4","2d0a145.fd2f5ec"]]},{"id":"383105a6.c7cefa","type":"function","name":"Create m2x_node_red_distrib distribution","func":"msg.topic = \"distributions\";\nmsg.action = \"create\";\nmsg.payload = { \"name\" : \"m2x_node_red_distrib\",\"description\" : \"m2x ndoe red testing\", \"visibility\" : \"private\", \"base_device\" : \"1b2f98cc3b31b527c27ba14fe46c615c\"};\nreturn msg;","outputs":1,"x":1144.8890075683594,"y":989.8889350891113,"z":"d8a3e781.275c18","wires":[["d74083f6.28bf8"]]},{"id":"65891d8e.9a76e4","type":"debug","name":"","active":true,"console":"false","complete":"false","x":1567.8890686035156,"y":905.8889713287354,"z":"d8a3e781.275c18","wires":[]},{"id":"ddaeac57.22515","type":"comment","name":"Create m2x_node_red distribution and erase the previous one if exists first","info":"","x":310.8888854980469,"y":820.4444885253906,"z":"d8a3e781.275c18","wires":[]},{"id":"1a7ec325.e5813d","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":515.8889465332031,"y":904.6667060852051,"z":"d8a3e781.275c18","wires":[["45780a19.ba87f4"]]},{"id":"13213b64.ecdec5","type":"function","name":"Get All Distribution","func":"msg.topic = \"distributions\";\nmsg.action = \"list\";\nmsg.payload = {};\nreturn msg;","outputs":1,"x":326.8888854980469,"y":900.6667060852051,"z":"d8a3e781.275c18","wires":[["1a7ec325.e5813d"]]},{"id":"45780a19.ba87f4","type":"function","name":"Find the if m2x_node_red_distrib exists","func":"if (!msg.payload) {\n\tconsole.log(\"No Payload quit flow\");\n\tmsg.payload = -1;\n} else {\n\tif (!msg.payload.distributions) {\n\t\tconsole.log(\"No distributions found\");\n\t\tmsg.payload = -1;\n\t} \n\telse \n\t{\n\t\tvar distribs = msg.payload.distributions;\n\t\tfor(var distrib in distribs) {\n\t\t console.log(distribs[distrib].name);\n\t\t\tif (typeof (distribs[distrib].name) === 'string' && distribs[distrib].name === \"m2x_node_red_distrib\") {\t\t\t\t\n\t\t\tconsole.log(\"Distribution m2x_node_red_distrib found \"+ distribs[distrib].id);\n\t\t\tmsg.payload = distribs[distrib].id;\t\n\t\t\treturn msg;\n\t\t\t} \n\t\t}\n\t}\n}\nmsg.payload = -1;\nconsole.log(\"Counldn't find m2x_node_red_distrib distribution, go directly to create it\");\nreturn msg;","outputs":"1","x":778.8889465332031,"y":901.6667060852051,"z":"d8a3e781.275c18","wires":[["aed355c2.512ca8"]]},{"id":"aed355c2.512ca8","type":"switch","name":"","property":"payload","rules":[{"t":"neq","v":-1,"v2":0},{"t":"else"}],"checkall":"true","outputs":2,"x":1021.8890686035156,"y":904.6667175292969,"z":"d8a3e781.275c18","wires":[["332c2e44.ccd3d2"],["383105a6.c7cefa"]]},{"id":"e3c65244.1c39b","type":"http in","name":"","url":"/create_distribution","method":"get","x":109.77777099609375,"y":902.5555725097656,"z":"d8a3e781.275c18","wires":[["13213b64.ecdec5"]]},{"id":"332c2e44.ccd3d2","type":"function","name":"Delete m2x_node_red_distribution if exists","func":"console.log(msg.payload);\n\nmsg.topic = \"distributions\";\nmsg.action = \"deleteDistribution\";\nmsg.topic_id = msg.payload;\nmsg.payload = {};\nreturn msg;","outputs":1,"x":1186.8889465332031,"y":825.8889465332031,"z":"d8a3e781.275c18","wires":[["4392684c.bc6d98"]]},{"id":"4392684c.bc6d98","type":"m2x","feed":"704442f7.8fbbbc","name":"","x":1449.888916015625,"y":826.888916015625,"z":"d8a3e781.275c18","wires":[["383105a6.c7cefa"]]},{"id":"2d0a145.fd2f5ec","type":"http response","name":"","x":1581.888916015625,"y":984.7777709960938,"z":"d8a3e781.275c18","wires":[]}]
module.exports = function (RED) {
var m2x = require('m2x');
var log = require('log-driver').logger;
var async = require('async');
var M2X_API_SERVER = "https://api-m2x.att.com/";

@@ -92,14 +94,39 @@ // CF - General Error code in case of error

var arguments = getParamNames(_this.m2xClient[topic][msg.action]);
var parameters = [];
// Iterate on all arguments and attach the relevnt parameters
//
for (var i = 0; i < arguments.length; i++) {
switch (arguments[i]) {
log.debug(arguments);
// Iterate on all arguments and attach the relevnt parameters
async.map( arguments,
function(item, callback){
try {
var parameter = parse_argument(item, msg);
log.debug("PARAMETER "+ parameter);
callback(null, parameter);
} catch (e){
log.debug("ERROR "+ e);
callback(e, null);
}
},
function(err, result) {
if(!err) {
call_m2x(result ,msg);
} else {
log.error("Could not invoke call to m2x since " +
"incoming node request could not be parsed, flow continued. [" +err + "]");
var err_msg = {};
err_msg.statusCode = INPUT_ERROR_CODE;
err_msg.payload = err;
_this.node.send(err_msg);
}
}
);
function parse_argument(item, msg) {
switch (item) {
case "id":
case "key":
set_parameter(msg, msg.topic_id, i, parameters, "msg.topic_id is empty for " + msg.action);
return set_parameter(msg, msg.topic_id, "msg.topic_id is empty for " + msg.action);
break;
case 'params' :
case 'values':
set_parameter(msg, msg.payload, i, parameters, "msg.payoad is empty for " + msg.action);
return set_parameter(msg, msg.payload, "msg.payoad is empty for " + msg.action);
break;

@@ -113,6 +140,6 @@ case 'name' :

case 'serial':
set_parameter(msg, msg.sub_topic_id, i, parameters, "msg.sub_topic_id is empty for " + msg.action);
return set_parameter(msg, msg.sub_topic_id, "msg.sub_topic_id is empty for " + msg.action);
break;
case 'callback':
parameters[i] = function (error, response) {
return function (error, response) {
_this.handle_msg_response(msg, error, response);

@@ -122,13 +149,31 @@ };

}
_this.m2xClient[topic][msg.action].apply(_this.m2xClient[topic], parameters);
function call_m2x(parameters, msg){
log.debug("TOPIC [" + topic + "] ACTIONS [" +msg.action + "]");
_this.m2xClient[topic][msg.action].apply(_this.m2xClient[topic], parameters, function(msg, response) {
if(response && response.json) {
try{
log.debug("FINAL OUTPUT " +JSON.stringify(response.json));
var res_msg = {};
res_msg.payload = response.json;
res_msg.statusCode = response.status;
} catch(e) {
log.error("Failed to parse "+response + " As JSON, will return error instead");
res_msg.statusCode = OUTPUT_PARSE_ERROR;
res_msg.payload = "Cannot extract M2X output";
}
}
_this.node.send(res_msg);
});
};
});
function set_parameter(msg, msg_field, i, parameters, error_msg) {
function set_parameter(msg, msg_field, error_msg) {
if (typeof (msg_field) === 'undefined') {
_this.handle_msg_failure(msg, INPUT_ERROR_CODE, error_msg);
throw "Cannot find message field " + error_msg;
} else {
parameters[i] = msg_field;
return msg_field;
}
}
function validate_msg(msg, msg_field, regex, error_code, error_msg) {

@@ -135,0 +180,0 @@ if (typeof (msg_field) === 'undefined') {

2

package.json
{
"name": "node-red-m2x",
"version": "0.0.21",
"version": "0.0.22",
"description": "A Node-RED node to AT&T M2X",

@@ -5,0 +5,0 @@ "dependencies": {

@@ -1,9 +0,12 @@

node-red-m2x
<img src="./md_images/logo.png"/>
Node-RED M2X Node
=================
A <a href="http://nodered.org" target="_new">Node-RED</a> node to store in <a href="http://m2x.att.com" target="_new">M2X</a>.
A <a href="http://nodered.org" target="_new">Node-RED</a> node used to store time-series data in <a href="https://m2x.att.com" target="_new">AT&T M2X</a>. This node is also included out-of-the-box with <a href="http://flow.att.com">AT&T Flow Designer</a>.
Install
[AT&T M2X](http://m2x.att.com) is a cloud-based fully managed time-series data storage service for network connected machine-to-machine (M2M) devices and the Internet of Things (IoT).
Installation
-------
Run the following command in the root directory of your Node-RED Directory
This node is available as an npm package (https://www.npmjs.com/package/node-red-m2x). Run the following command in the root directory of your Node-RED Directory:

@@ -14,5 +17,6 @@ npm install node-red-m2x

-----
Use node-red-m2x to store time-series data from anything in [AT&T M2X](http://m2x.att.com) and manage your M2X devices.
<div>
The user will set the following message proprties:
The user will set the following message properties:

@@ -28,7 +32,7 @@ <ul>

<ul>
<li> msg.topic - The type of object to act on - distribution,device,chart.key.
<li> msg.topic - The type of object to act on - distribution, device, chart, key.
<li> msg.action - An action to be applied for this type of object - The second level entry in the below list. (catalog for example)
<li> msg.payload - A json that represent the body for the rest API, only if such is defiend.
<li> msg.topic_id - a unique id for either device,distribution,key or chart
<li> msg.sub_topic_id - define the a unique instance of sub topic such as distributon's device.
<li> msg.payload - A json that represents the body for the rest API, only if such is defiend.
<li> msg.topic_id - A unique id for either device, distribution, key or chart
<li> msg.sub_topic_id - Defines the unique instance of sub topic such as distributon's device.

@@ -392,5 +396,5 @@ <ul>

<H3>Authentication</H3>
There are 2 ways to pass authentication using the flow designer M2X Node.
<p>There are two ways to pass authentication using the M2X Node:<p>
<ul>
<li>Used the node configuration and set the relevant X-M2X-KEY.
<li>Use the node configuration and set the relevant X-M2X-KEY.
<li>Pass the X-M2X-KEY via msg.m2x_key.

@@ -415,4 +419,4 @@ </ul>

"send_location": true }; <br>
</pre>
<H4> Show device Details<H4>

@@ -428,1 +432,13 @@ <H5> Function Code </H5>

</div>
## Helpful Resources ##
* [Signup for an AT&T M2X Account](https://m2x.att.com/signup)
* [M2X API Documentation](https://m2x.att.com/developer/documentation/overview)
* [Get started with AT&T Flow Designer Account](https://flow.att.com/start)
* [Node-RED Documentation](http://nodered.org/docs/)
* [Running Node-Red](http://nodered.org/docs/getting-started/running.html)
## License ##
This software is provided under the MIT license. See [LICENSE](LICENSE) for applicable terms.

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /*

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc