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
2
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.29 to 0.1.0

Dockerfile

1

flows/m2x_flow.json

@@ -1,2 +0,1 @@

<<<<<<< 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":[]}]
{
"name": "node-red-m2x",
"version": "0.0.29",
"version": "0.1.0",
"description": "A Node-RED node to AT&T M2X",
"dependencies": {
"m2x": "2.1.9",
"log-driver": "1.2.5",
"m2x": "4.0.0",
"async": "0.9.0"

@@ -14,3 +13,3 @@ },

},
"license": "Apache",
"license": "MIT",
"keywords": [

@@ -22,3 +21,4 @@ "node-red",

"nodes": {
"m2x": "m2x.js"
"m2x": "m2x/m2x.js",
"m2x feed": "m2x_feed/m2x_feed.js"
}

@@ -25,0 +25,0 @@ },

@@ -1,429 +0,86 @@

<img src="./md_images/logo.png"/>
Node-RED M2X Node
=================
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>.
![Logo](md_images/logo.png)
# Node-RED M2X Node
A [Node-RED](http://nodered.org) node used to store time-series data in [AT&T's M2X](https://m2x.att.com). This node is also included out-of-the-box with [AT&T's Flow Designer](http://flow.att.com).
[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
-------
## Installation
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:
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:
npm install node-red-m2x
```bash
npm install node-red-m2x
```
Usage
-----
## Usage
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 properties:
On its core, this node uses the [M2X NodeJS client library](https://github.com/attm2x/m2x-nodejs) and maps the `msg` properties to prototypes and methods of said library.
<ul>
<li><b>msg.topic</b> - (required)
<li><b>msg.sub_topic</b> - (optional)
<li><b>msg.payload</b> - (optional)
<li><b>msg.action</b> - (required)
<li><b>msg.topic_id</b> - (optional)
<li><b>msg.sub_topic_id</b> - (optional)
</ul>
<ul>
<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 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.
The accepted properties are:
- **msg.topic** (required) - The type of object to act on, it corresponds with the prototypes defined on the M2X NodeJS client libraries (collections, commands, devices, distributions, jobs, keys).
- **msg.action** (required) - An action to be applied for this type of object, corresponds with the methods defined for the entity specified in **msg.topic**.
- **msg.topic_id** (optional) - The unique identifier to be passed to the method defined on **msg.action**.
- **msg.sub_topic_id** (optional) - The unique identifier of an instance relative to the **msg.topic_id** (e.g.: msg.topic_id could be a device id and msg.sub_topic_id could be a stream or trigger id)
- **msg.payload** (optional) - A JSON object that will be the body of the request when applicable.
<ul>
<li><b>devices</b>
<ul>
<li>catalog
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Search-Public-Devices-Catalog"> Search Catalog </a>
<li> msg.payload - catalog parameters
</ul>
<li>create
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Create-Device"> Create new device </a>
<li> msg.payload - device parameters
</ul>
<li>createTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Create-Trigger"> Create a new trigger associated with the specified device.</a>
<li> msg.topic_id - The device id
<li> msg.payload
</ul>
<li>deleteDevice
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Delete-Device"> Delete an existing device</a>
<li> msg.topic_id - The device id
</ul>
<li>deleteStream
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Delete-Data-Stream"> Delete a stream</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
</ul>
<li>deleteStreamValues
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Delete-Data-Stream-Values"> Delete values from a stream by a date range</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
<li> msg.payload - parameters - time range
</ul>
<li>deleteTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Delete-Trigger"> Delete an existing trigger associated with a specific device.</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The trigger id
</ul>
<li>groups
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Device-Groups"> List Groups of devices</a>
</ul>
<li>keys
<ul>
<li> Returns a list of API keys associated with the device
<li> msg.topic_id - The device id
</ul>
<li>list
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Search-Devices"> List Devices </a>
<li> msg.payload - The device id
</ul>
<li>location
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Read-Device-Location"> View device current location</a>
<li> msg.topic_id - The device id
</ul>
<li>log
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#View-Request-Log"> Return a list of access log to the supplied device</a>
<li> msg.topic_id - The device id
</ul>
<li>postMultiple
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Post-Device-Updates--Multiple-Values-to-Multiple-Streams-"> Post multiple values to multiple streams</a>
<li> msg.topic_id - The device id
<li> msg.payload - parameters
</ul>
<li>postValues
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Post-Data-Stream-Values"> Post timestamped values to an existing stream</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
<li> msg.payload - parameters - the values -
<pre>[{ "timestamp": "timeStamp" "value": "value" },
{ "timestamp": "timeStamp","value": "value>"}]</pre>
</ul>
<li>sampleStreamValues
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Data-Stream-Sampling"> Sample values from an existing stream</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The Name of the stream
<li> msg.payload
</ul>
<li>setStreamValue
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Update-Data-Stream-Value"> Set the stream value</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
<li> msg.payload - parameters - the values
</ul>
<li>stream
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#View-Data-Stream"> View stream details </a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
<li> msg.payload
</ul>
<li>streamStats
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Data-Stream-Stats"> Stream Statistics </a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
<li> msg.payload
</ul>
<li>streamValues
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Data-Stream-Values"> List data stream values </a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The stream name
<li> msg.payload
</ul>
<li>streams
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Data-Streams"> Return list of associated streams</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The Name of the stream
<li> msg.payload
</ul>
<li>testTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Test-Trigger"> Test the specified trigger by firing it with a fake value.</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The trigger id
</ul>
<li>trigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#View-Trigger"> Get details of a specific trigger associated with an existing device</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The trigger ID
</ul>
<li>triggers
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Triggers"> Retrieve list of triggers associated with the specified device.</a>
<li> msg.topic_id - The device id
</ul>
<li>update
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Update-Device-Details"> Update a device </a>
<li> msg.topic_id - The device id
<li> msg.payload
</ul>
<li>updateLocation <ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Update-Device-Location"> Update a device location </a>
<li> msg.topic_id - The device id
<li> msg.payload
</ul>
<li>updateStream
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Create-Update-Data-Stream"> Update a data stream</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The Name of the stream
<li> msg.payload - parameters
</ul>
<li>updateStreams
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#Create-Update-Data-Stream"> Update a data stream</a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - Array of streams names
<li> msg.payload - parameters
</ul>
<li>updateTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#List-Data-Stream-Values">Update an existing trigger associated with the specified device. </a>
<li> msg.topic_id - The device id
<li> msg.sub_topic_id - The trigger name
<li> msg.payload - trigger parameters
</ul>
<li>view
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/device#View-Device-Details"> View device </a>
<li> msg.topic_id - The device id
</ul>
</ul>
</ul>
<ul>
<li><b>distribution</b>
<ul>
<li>addDevice
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Add-Device-to-an-existing-Distribution">Add a new device to an existing device distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The device id
</ul>
<li>create
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Create-Distribution">Create a new device distribution </a>
<li> msg.payload - Create parameters
</ul>
<li>createTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Create-Trigger">Create a new trigger associated with the distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.payload - trigger parameters
</ul>
<li>dataStream
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#View-Data-Stream">View information about a stream associated to the distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The stream name
</ul>
<li>datatStreams
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#List-Data-Streams">Retrieve a list of data streams associated with the distribution</a>
<li> msg.topic_id - The distribution id
</ul>
<li>deleteDataStream
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Delete-Data-Stream">Delete an existing data stream associated to distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The stream name
## Authentication
</ul>
<li>deleteDistribution
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Delete-Distribution">Delete an existing device distribution</a>
<li> msg.topic_id - The distribution id
</ul>
<li>deleteTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Delete-Trigger">Delete a trigger associated to the distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The trigger id
</ul>
<li>devices
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#List-Devices-from-an-existing-Distribution"> Retrieve a list of devices added to the a device distribution </a>
<li> msg.topic_id - The distribution id
</ul>
<li>list
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#List-Distributions">Retrieve a list of device distributions </a>
<li> msg.payload - List parameters
</ul>
<li>testTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Test-Trigger">Test a trigger by firing a fake value</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The trigger id
</ul>
<li>trigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#View-Trigger">Retrieve information about a trigger associated to a distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The trigger id
</ul>
<li>triggers
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#List-Triggers"> Retrieve list of triggers associated with the distribution </a>
<li> msg.topic_id - The distribution id
</ul>
<li>update
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Update-Distribution-Details">Update an existing device distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.payload - distribution parameters
</ul>
<li>updateDataStream
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Create-Update-Data-Stream">Create/Update a data stream associated with the distribution. </a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The stream name
<li> msg.payload - stream parameters
</ul>
<li>updateTrigger
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#Update-Trigger">Update an existing trigger associated with the distribution</a>
<li> msg.topic_id - The distribution id
<li> msg.sub_topic_id - The trigger id
<li> msg.payload - trigger parameters
</ul>
<li>view
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/distribution#View-Distribution-Details"> Retrieve information about an existing device distribution </a>
<li> msg.topic_id - The disribution id
</ul>
</ul>
</ul>
<ul>
<li><b>charts</b>
<ul>
<li>create
<ul>Get details of a chart
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#Create-Chart">Create a new chart</a>
<li> msg.payload - chart parameters
</ul>
<li>deleteChart
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#Delete-Chart">Delete an existing chart</a>
<li> msg.topic_id - The chart id
</ul>
<li>list
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#List-Charts">Retrieve a list of charts that belongs to the user </a>
</ul>
<li>render
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#Render-Chart">Retrieve a rendering of a given chart as image format</a>
<li>msg.topic_id - The chart id
<li>msg.sub_topic_id - the image format : "svg" or "png"
</ul>
<li>update
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#Update-Chart">Update an existing chart</a>
<li> msg.topic_id - The chart id
<li> msg.payload - chart parameters -<pre>{ series : [{device: "device-id", stream:"stream_name" }]}</pre>
</ul>
<li>view
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#View-Chart-Details">Get details of a chart</a>
<li> msg.topic_id - The chart id
</ul>
</ul>
</ul>
<ul>
<li><b>keys</b>
<ul>
<li>create
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/keys#Create-Key">Create a new API Key</a>
<li> msg.payload - key parameters
</ul>
<li>del
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/charts#Delete-Chart">Delete an existing chart</a>
<li> msg.topic_id - The key id
</ul>
<li>list
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/keys#List-Keys">List all the Master API Keys that belongs to the authenticated user</a>
</ul>
<li>regenerate
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/keys#Regenerate-Key">Regenerate an API Key token</a>
<li> msg.topic_id - The key id
</ul>
<li>update
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/keys#Update-Key">Update API Key properties</a>
<li> msg.topic_id - The key id
<li> msg.payload - key parameters
</ul>
<li>view
<ul>
<li><a href="https://m2x.att.com/developer/documentation/v2/keys#View-Key-Details">Return the details of the API Key supplied</a>
<li> msg.topic_id - The key id
</ul>
</ul>
</ul>
</ul>
<div>
<H3>Authentication</H3>
<p>There are two ways to pass authentication using the M2X Node:<p>
<ul>
<li>Use the node configuration and set the relevant X-M2X-KEY.
<li>Pass the X-M2X-KEY via msg.m2x_key.
</ul>
</div>
<div>
<img src="./md_images/m2x.png"/>
<H3> Examples </H3>
<H4> Create Trigger </H4>
<H5> Function Code </H5>
<pre>
msg.topic = "devices";<br>
msg.action = "createTrigger";<br>
msg.topic_id = "1b2f98cc3b31b527c27ba14fe46c615c";<br>
msg.payload = { "stream": "heat", <br>
"name": "Hightemperature3", <br>
"condition": ">", <br>
"value": 100, <br>
"callback_url": "http://example.com", <br>
"status": "enabled", <br>
"send_location": true }; <br>
</pre>
<H4> Show device Details<H4>
<H5> Function Code </H5>
<pre>
msg.topic = "devices";<br>
msg.action = "view";<br>
msg.topic_id = "1b2f98cc3b31b527c27ba14fe46c615c";<br>
return msg;<br>
</pre>
</div>
</div>
Use the `m2x feed` configuration node to set your M2X API Key
## Examples
### Listing devices:
```javascript
msg = {
topic: "devices",
action: "list"
}
```
### Viewing a device:
```javascript
msg = {
topic: "devices",
action: "view",
topic_id: "65b89448f954f49e42b746d73b385cbb"
}
```
### Viewing a stream of a device:
```javascript
msg = {
topic: "devices",
action: "stream",
topic_id: "65b89448f954f49e42b746d73b385cbb",
sub_topic_id: "temperature"
}
```
## Development
This repository includes a `Dockerfile` that makes it easier to launch a local instance of node-red and test the M2X node.
Make sure to have a running version of docker on your computer.
### Building the image
```bash
make build
```
### Creating the container
```bash
make create
```
After executing those steps, you will get a new container ready for development, you can see it by executing `docker ps -a` and start it with `docker start node-red`. Once the container is ready, node-red will be running and listening for connections on the port 1880 of your docker host.
## Helpful Resources ##

@@ -433,2 +90,3 @@

* [M2X API Documentation](https://m2x.att.com/developer/documentation/overview)
* [M2X NodeJS client library](https://github.com/attm2x/m2x-nodejs)
* [Get started with AT&T Flow Designer Account](https://flow.att.com/start)

@@ -435,0 +93,0 @@ * [Node-RED Documentation](http://nodered.org/docs/)

@@ -1,2 +0,2 @@

/*
/*
* To change this license header, choose License Headers in Project Properties.

@@ -10,5 +10,5 @@ * To change this template file, choose Tools | Templates

var flow = [{id:"m2xFeed", type:"m2x feed",apiKey:"YOUR_M2X_ACCOUNT_ID",name:"My M2x node"},
{id:"m2xn1", type:"m2x",feed:"m2xFeed", wires:[["m2xn2"]]},
{id:"m2xn1", type:"m2x",feed:"m2xFeed", wires:[["m2xn2"]]},
{id:"m2xn2", type:"helper"}];
return flow;
}

@@ -26,3 +26,3 @@ /**

});
afterEach(function() {

@@ -55,3 +55,3 @@ helper.unload();

});
n1.receive({payload:{ "q" : "m2x","limit" : "5"}, topic: "devices", action : "catalog"});
n1.receive({payload:{ "q" : "m2x","limit" : "5"}, topic: "devices", action : "catalog"});
});

@@ -67,3 +67,3 @@ });

"name" : "testing",
"description" : "A Testing device",
"description" : "A Testing device",
"visibility" : "private"

@@ -74,6 +74,6 @@ });

n1.receive({payload:{ "name" : "testing",
"description" : "A Testing device",
"visibility" : "private"},
"description" : "A Testing device",
"visibility" : "private"},
topic : "devices",
action : "create"});
action : "create"});
});

@@ -88,3 +88,3 @@ });

console.log(msg);
msg.payload.status.should.equals("204");
msg.payload.status.should.equals("204");
done();

@@ -94,6 +94,6 @@ });

action : "deleteDevice",
topic_id : "cae50230e5787523e14441a37defdbfd"});
topic_id : "cae50230e5787523e14441a37defdbfd"});
});
});
});
it('should post single stream values', function(done) {

@@ -106,3 +106,3 @@ var flow = flow_initer.build_flow();

console.log(msg);
msg.status.should.within(200,299);
msg.status.should.within(200,299);
done();

@@ -115,8 +115,8 @@ });

payload : [ {"timestamp" : new Date().toJSON(), "value" : "111"}]
});
});
});
});
});
it('delete stream values', function(done) {

@@ -129,3 +129,3 @@ var flow = flow_initer.build_flow();

console.log(msg);
msg.payload.status.should.equals("204");
msg.payload.status.should.equals("204");
done();

@@ -138,7 +138,7 @@ });

payload : { "from": "2014-09-09T19:15:00.624Z",
"end": "2015-09-09T20:15:00.522Z" }});
"end": "2015-09-09T20:15:00.522Z" }});
});
});
});
it('should create new trigger', function(done) {

@@ -167,8 +167,8 @@ var flow = flow_initer.build_flow();

"status": "enabled",
"send_location": true },
"send_location": true },
topic : "devices",
action : "createTrigger",
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
});
});
});
it('should view trigger', function(done) {

@@ -193,5 +193,5 @@ var flow = flow_initer.build_flow();

topic_id : "1b2f98cc3b31b527c27ba14fe46c615c",
sub_topic_id : "AUtGaZbkTjhBGEzH1DCo"});
sub_topic_id : "AUtGaZbkTjhBGEzH1DCo"});
});
});
});
it('should list trigger', function(done) {

@@ -208,5 +208,5 @@ var flow = flow_initer.build_flow();

action : "triggers",
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
});
});
});
it('should update trigger', function(done) {

@@ -225,5 +225,5 @@ var flow = flow_initer.build_flow();

sub_topic_id : "AUtpxLWkTjhBGEzH2Jli",
payload : {"value": 200}});
payload : {"value": 200}});
});
});
});
});

@@ -26,3 +26,3 @@ /**

});
afterEach(function() {

@@ -46,3 +46,3 @@ helper.unload();

n1.receive({topic : "distributions",
action : "create",
action : "create",
payload : { "name" : "test_distrib",

@@ -52,6 +52,6 @@ "description" : "m2x node red testing distrib",

"base_device" : "654f4684d54a88591c2b1f1da0fd621a"}
});
});
});
});
});
it('should create device', function(done) {

@@ -71,3 +71,3 @@ var flow = flow_initer.build_flow();

n1.receive({topic : "distributions",
action : "addDevice",
action : "addDevice",
topic_id : "1ee40764159d8b7bbc51e79916309e85",

@@ -79,5 +79,5 @@ sub_topic_id : "testing_distrib_device",

"base_device" : "654f4684d54a88591c2b1f1da0fd621a"}
});
});
});
});
});
});
//TODO: SHOULD Be run with -t 5000

@@ -105,10 +105,10 @@ it('should create trigger', function(done) {

"callback_url": "https://scrum-api-flow.att.io/sandbox/https/chenfli/in/flow",
"status": "enabled" },
"status": "enabled" },
topic : "distributions",
action : "createTrigger",
topic_id : "1ee40764159d8b7bbc51e79916309e85"});
topic_id : "1ee40764159d8b7bbc51e79916309e85"});
});
});
it('should delete trigger', function(done) {

@@ -127,6 +127,6 @@ var flow = flow_initer.build_flow();

topic_id : "1ee40764159d8b7bbc51e79916309e85",
sub_topic_id :"AUtanUPpTjhBGEzH1rnX" });
sub_topic_id :"AUtanUPpTjhBGEzH1rnX" });
});
});
it('should delete distribution', function(done) {

@@ -144,6 +144,6 @@ var flow = flow_initer.build_flow();

action : "deleteDistribution",
topic_id : "c145918984bf63dfcd6c94d2b0e07dc4"});
topic_id : "c145918984bf63dfcd6c94d2b0e07dc4"});
});
});
});
it('should delete a data stream', function(done) {

@@ -162,5 +162,5 @@ var flow = flow_initer.build_flow();

topic_id : "3d6ecf7f2e3561dfc1a6bea16182a29f",
sub_topic_id : "Thermo"});
sub_topic_id : "Thermo"});
});
});
});
});

@@ -31,3 +31,3 @@ /**

});
afterEach(function() {

@@ -49,3 +49,3 @@ helper.unload();

});
n1.receive({payload:{ "q" : "m2x","limit" : "5"}, topic: "devices", action : "catalog"});
n1.receive({payload:{ "q" : "m2x","limit" : "5"}, topic: "devices", action : "catalog"});
});

@@ -61,3 +61,3 @@ });

"name" : "testing",
"description" : "A Testing device",
"description" : "A Testing device",
"visibility" : "private"

@@ -68,6 +68,6 @@ });

n1.receive({payload:{ "name" : "testing",
"description" : "A Testing device",
"visibility" : "private"},
"description" : "A Testing device",
"visibility" : "private"},
topic : "devices",
action : "create"});
action : "create"});
});

@@ -98,8 +98,8 @@ });

"status": "enabled",
"send_location": true },
"send_location": true },
topic : "devices",
action : "createTrigger",
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
});
});
});
it('should view trigger', function(done) {

@@ -124,5 +124,5 @@ var flow = flow_initer.build_flow();

topic_id : "1b2f98cc3b31b527c27ba14fe46c615c",
sub_topic_id : "AUtGaZbkTjhBGEzH1DCo"});
sub_topic_id : "AUtGaZbkTjhBGEzH1DCo"});
});
});
});
it('should list trigger', function(done) {

@@ -139,5 +139,5 @@ var flow = flow_initer.build_flow();

action : "triggers",
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
topic_id : "1b2f98cc3b31b527c27ba14fe46c615c"});
});
});
});
it('should update trigger', function(done) {

@@ -156,5 +156,5 @@ var flow = flow_initer.build_flow();

sub_topic_id : "AUtpxLWkTjhBGEzH2Jli",
payload : {"value": 200}});
payload : {"value": 200}});
});
});
});
it('should test trigger', function(done) {

@@ -172,6 +172,6 @@ var flow = flow_initer.build_flow();

topic_id : "1b2f98cc3b31b527c27ba14fe46c615c",
sub_topic_id : "hot"});
sub_topic_id : "hot"});
});
});
});
});
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