How to get power feedback?

92 views
Skip to first unread message

husa550

unread,
Jan 12, 2014, 1:05:50 PM1/12/14
to comman...@googlegroups.com
Hi

I have an electrical power meter that is connected to an online service.
I get this in the browser window: {"createddate":"2014-01-12T18:08:58","power":9575.0}
"power":9575.0 is the actual power used at that moment.
My question is, how can i get the number after "power" to iViewer and realtime update?

Jarrod Bell

unread,
Jan 12, 2014, 5:29:58 PM1/12/14
to comman...@googlegroups.com
CF.request("https://my.eliq.se/api/datanow?accesstoken=783b7e1af70b4b57ac9fa3c014f9xxxx", function(status, header, body) {
    if (status == 200) {
        var returnedData = JSON.parse(body);
        CF.setJoin("s10", returnedData.power);
    }
});

Add this script to your project, it will set the power value to serial join 10.

You could make the whole script one line and attach it to a button, or create a separate .js file in a text editor and add it to your project like this:

function requestPower() {
    CF.request("https://my.eliq.se/api/datanow?accesstoken=783b7e1af70b4b57ac9fa3c014f9xxxx", function(status, header, body) {
        if (status == 200) {
            var returnedData = JSON.parse(body);
            CF.setJoin("s10", returnedData.power);
        }
    });
}

Then you simply add this script to your button: requestPower();

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

husa550

unread,
Jan 12, 2014, 10:07:59 PM1/12/14
to comman...@googlegroups.com
Hi and Thank's Jarrod!

I made a scriptfile called Power_script.js and put this in it:

function requestPower() {
    CF.request("https://my.eliq.se/api/datanow?accesstoken=783b7e1af70b4b57ac9fa3c014f9xxxx", function(status, header, body) {
        if (status == 200) {
            var returnedData = JSON.parse(body);
            CF.setJoin("s10", returnedData.power);
        }
    });

The xxxx in the end of command is replaced with the correct numbers
Changed serial join to 500, my s10 was already used.
Made a button with this: requestPower();

And finaly i made a textfield with serial join 500

Sorry to say but nothing happends when i push the "Power" button.

Jarrod Bell

unread,
Jan 12, 2014, 10:31:37 PM1/12/14
to comman...@googlegroups.com
You should run the debugger to check for any syntax errors:
http://commandfusion.com/docs/scripting/debug.html

Also, note that the CF.request function will only work if you are using a licensed device. So make sure you have a valid license in your GUI project before uploading it to your device.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


Guillaume Vigneron

unread,
Jan 13, 2014, 1:14:13 AM1/13/14
to comman...@googlegroups.com, jar...@commandfusion.com
Are you sure the "access token" still remain valid after few minutes/hours? It looks like one of these bridge accesses via an online platform, am I right? Can't you access the equipment directly on it's IP address from you network?

husa550

unread,
Jan 13, 2014, 3:44:26 PM1/13/14
to comman...@googlegroups.com
Hi and sorry for late reply.
I wrote the first text just before i hade to go to work and did not have time to look at it again untill now.

I have a valid license so that will not be the problem.
I run the debugger and that can't find any syntax error.
The acces token is valid for ever or untill i change it my self.

The only thing that happen in debugger when i push the button is:

Pusched  = d0 = 1
Released = d0 = 0

husa550

unread,
Jan 13, 2014, 3:47:32 PM1/13/14
to comman...@googlegroups.com

This is the complete command with the right acces token.


It works if i type it in a browser and reply:

{"createddate":"2014-01-13T21:42:52","power":2835.0}
 
Feel fre to test :-)

thechad

unread,
Jan 13, 2014, 5:36:43 PM1/13/14
to comman...@googlegroups.com
Hi,

You first need to understand where the error actually is...ie. Do you know if the button press is even calling the function you defined?

Let's start from the start.

I assume you have this script in a file in the same folder as the gui (say called main.js) added the script to the gui using Script Manager as per here? http://www.commandfusion.com/wiki2/software/gui-designer/script-manager

If so, add some debugging output to the script using cf.log and cf.logobject to see what is happening (http://www.commandfusion.com/docs/scripting/util.html#cF.log) and post script and debug.

Once you know where the issue is (ie. not calling script at all, error in json response, error in cf.request etc) I suggest you post the full script (eg. main.js) to pastebin and post a link here so we can see it.

cheers.

Reply all
Reply to author
Forward
0 new messages