mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Automatic detection of csv and json call and simplified help text
This commit is contained in:
		@@ -19,10 +19,6 @@
 | 
			
		||||
        <label for="node-input-emonServer"><i class="icon-globe"></i> Emoncms server</label>
 | 
			
		||||
        <input type="text" id="node-input-emonServer">
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="form-row">
 | 
			
		||||
        <label for="node-input-topic"><i class="icon-tasks"></i> Key</label>
 | 
			
		||||
        <input type="text" id="node-input-topic" placeholder="">
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="form-row">
 | 
			
		||||
        <label for="node-input-nodegroup"><i class="icon-tag"></i> Node</label>
 | 
			
		||||
        <input type="text" id="node-input-nodegroup" placeholder="">
 | 
			
		||||
@@ -31,22 +27,13 @@
 | 
			
		||||
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
 | 
			
		||||
        <input type="text" id="node-input-name" placeholder="Emoncms">
 | 
			
		||||
    </div>
 | 
			
		||||
		<div class="form-tips">If <b>msg.payload</b> holds comma separated values (csv), Key and <b>msg.topic</b> is ignored and the key will
 | 
			
		||||
 		be automatically generated by Emoncms. If <b>msg.payload</b> holds a single value and Key and <b>msg.topic</b> is not specified, <b>msg.payload</b>
 | 
			
		||||
		will be treated as a csv otherwise it will be treated as a json payload and the key value can be manually or programmatically set.</br></br>
 | 
			
		||||
		Key is not mandatory, if Key is left blank <b>msg.topic</b> will used. Key overrides <b>msg.topic</b>, it will be ignored if <b>msg.payload</b> is holding csv</br></br>
 | 
			
		||||
		Node (numeric) is not mandatory, if Node is left blank <b>msg.nodegrpup</b> will used. Node over rides <b>msg.nodegroup</b>.
 | 
			
		||||
		</div>
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<script type="text/x-red" data-help-name="emoncms">
 | 
			
		||||
    <p>Performs post to Emoncms.</p>
 | 
			
		||||
    <p>If <b>msg.payload</b> holds comma separated values (csv), Key and <b>msg.topic</b> is ignored. 
 | 
			
		||||
	If <b>msg.payload</b> holds a single value and Key and <b>msg.topic</b> is not specified, <b>msg.payload</b>
 | 
			
		||||
	will be treated as a csv otherwise it will be treated as a json payload</p>
 | 
			
		||||
    <p>If Key is left blank <b>msg.topic</b> will used, ignored if <b>msg.payload</b> holds csv.</p>
 | 
			
		||||
    <p>Emoncms post.</p>
 | 
			
		||||
    <p>The <b>msg.payload</b> can contain either a comma separated list of name value pairs ex. name:value,... or a comma separated list of values ex. 1,2,.. . 
 | 
			
		||||
    <p>If Node is left blank <b>msg.nodegrpup</b> will used.</p>
 | 
			
		||||
    <p>Insertion time can be manipulated by setting <b>msg.time</b>.</p>
 | 
			
		||||
    <p>Insertion time can be manipulated by setting <b>msg.time</b>.</p>		
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
@@ -56,8 +43,6 @@
 | 
			
		||||
        defaults: {
 | 
			
		||||
            name: {value:"Emoncms"},
 | 
			
		||||
            emonServer: {type:"emoncms-server", required:true},
 | 
			
		||||
            payloadType: {value:"json"},
 | 
			
		||||
            topic: {value:""},
 | 
			
		||||
            nodegroup: {value:""}
 | 
			
		||||
        },
 | 
			
		||||
        inputs:1,
 | 
			
		||||
 
 | 
			
		||||
@@ -71,18 +71,16 @@ function Emoncms(n) {
 | 
			
		||||
    this.baseurl = sc.server;
 | 
			
		||||
    this.apikey = sc.apikey;
 | 
			
		||||
 | 
			
		||||
    this.topic = n.topic ||"";
 | 
			
		||||
    this.nodegroup = n.nodegroup || "";
 | 
			
		||||
    var node = this;
 | 
			
		||||
    if (this.baseurl.substring(0,5) === "https") { var http = require("https"); }
 | 
			
		||||
    else { var http = require("http"); }
 | 
			
		||||
    this.on("input", function(msg) {
 | 
			
		||||
        this.url = this.baseurl + '/input/post.json?';
 | 
			
		||||
        var topic = this.topic || msg.topic;
 | 
			
		||||
        if(msg.payload.indexOf(',') > -1 || topic.trim() == ''){
 | 
			
		||||
        	this.url += 'csv='+msg.payload;
 | 
			
		||||
        if(msg.payload.indexOf(':') > -1){
 | 
			
		||||
        	this.url += 'json={' + msg.payload + '}';
 | 
			
		||||
        } else {
 | 
			
		||||
        	this.url += 'json={' + topic + ':' + msg.payload+'}';
 | 
			
		||||
        	this.url += 'csv='+msg.payload;
 | 
			
		||||
        }
 | 
			
		||||
        this.url += '&apikey='+this.apikey;
 | 
			
		||||
        var nodegroup = this.nodegroup || msg.nodegroup;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user