CF Iviewer - No output command

Forum about Domotiga Open Source Home Automation for Linux.

Moderator: RDNZL

CF Iviewer - No output command

Postby Pik » Wed May 07, 2014 8:17 pm

Hello,

I created a simple GUI with CF Viewer in order to train on this interface.
I have 5 PIR (X10 devices MS13), 4 lamps, 2 Oregon sensors with temperature text display and also a graph coming from Domotiga.
I have also as in tuto on Youtube to check if Domotiga Online or not.
Reading = no trouble. each time a sensor see a movement, I can see a change on screen (Android Mobile phone); same nice function for lamps.

I created a button to switch On/Off a lamp but I can't switch ON !!!
Of course, I created a main.js file (a copy from wiki) and I changed my IP to "http://192.168.1.31:9090/"
In this main.js, I have also a Callback function for DomotiGa System status change. So I confirm my js file is working well as my status button on my interface change if Domotiga connected or not.
here's code for main.js :

Code: Select all
// Callback function for DomotiGa System status change
function onDomotiGaSystemConnectionStatusChange(system, connected, remote) {
    if (connected) {
        CF.log(system + " System is CONNECTED to " + remote); //Print a status message to the debug log
        CF.setJoin("d" + joinDomotiga, 1);                                        //Set the DomotiGa icon to "on" (coulored icon)
        CF.send(system, "SendDeviceStatusAll\x03");                    //Send a command to DomotiGa CF iViewer interface, requesting it so send curent status of all (active) devices.
    }
    else {
        CF.setJoin("d" + joinDomotiga, 0);
        CF.log(system + " System not connected");
    }
}

// This function disconnects and reconnects to a system.
// I have attached it to a button on the gui so i can manually force a re-connect attempt (to DomotiGa)
// It addresses an issue in the current version if iViewer where iViewer times out and stops trying to connect to an "Always On" system and so may look like it's connected when it is not.
function DisconnectReconnect(system) {
    CF.setSystemProperties(system, {enabled: false});
    CF.setSystemProperties(system, {enabled: true});
}

CF.userMain = function () {

    joinDomotiga = 1;        // <---CHANGE THIS to digital join number for the icon indicating a connection to DomotiGa

    // Watch for important system connects and disconnects
    // IMPORTANT:  If you named your domotiga system something other than "DomotiGa", you'll need to change the text "DomotiGa"
    // =========   in following line to match the system name in System manager.
    //
    CF.watch(CF.ConnectionStatusChangeEvent, "DomotiGa", onDomotiGaSystemConnectionStatusChange, true);  // <--- CHANGE THIS to match the DomotiGa system name defined in System manager
};


// This is called by pressing a button in the GUI - eg. to toggle a light on or off depending upon the button's current state.
//
// This function checks the current state of the button, and passes either paramValueOnCommand or paramValueOffCommand to SendJsonCommandToDomotiGa depending upon the current state of the button
// You would call this from a button in the gui by putting something like the following in the Basic Action/Javascript field
//       SendCommandToDomotiGaByButtonState({"jsonrpc": "2.0", "method": "device.set", "params": {"device_id": 41, "value": "On" }, "id": 1},{"jsonrpc": "2.0", "method": "device.set", "params": {"device_id": 41, "value": "Off" }, "id": 1},[join])
//
// The [join] parameter is evaluated when the button is pressed, and sends the join type&number of the button (eg. "d2") if the button was assigned Digital Join 2
// If (in this example) "d2" was off (ie =0), then we send the On parameter to DomotiGa otherwise we send the Off one.
//
// The current state of the buttons is set by a feedback rule (defined through guidesigner) and is updated via DomotiGa iViewer sending status updates to connected devices.
//      ie.  you would see something like this in in the DomotiGa logs when the light is set to on (100%).
//           2013/10/04 12:55:59 [iViewer] SendUpdateDevice: Study_Light_value :100
//
function SendCommandToDomotiGaByButtonState(paramValueOnCommand, paramValueOffCommand, buttonJoin) {
    CF.getJoin(String(buttonJoin), function (join, value, tokens) {
        // regardless of the join type, the value is always a string
        // if we want a number, we need to use parseInt() or parseFloat()
        if (value == 0) {
            SendJsonCommandToDomotiGa(paramValueOnCommand)
        } else {
            SendJsonCommandToDomotiGa(paramValueOffCommand)
        }
    });
}

// Set Send an JSON-RPC command to DomotiGa server
function SendJsonCommandToDomotiGa(rBody) {
    CF.log("SendJsonCommandToDomotiGa: rBody : ");
    CF.logObject(rBody);
    try {
        var Parameters = {"Content-Type": "application/json"};

        var host = "http://192.168.1.31:9090/";
        CF.request(host, "POST", Parameters, JSON.stringify(rBody), function (status, headers, body) {
            try {
                if (status == 200) {
                    var data = JSON.parse(body);
                    if (data.error !== undefined) {
                        self.lastError = data.error;
                        CF.log("ERROR REPLY ---------");
                        CF.logObject(self.lastError);
                    } else {
                        Object.keys(data).forEach(function (keyTag) {
                            CF.log("Domotiga Returned Data..." + keyTag + ":" + data[keyTag]);
                        });
                    }
                } else {
                    self.lastError = (typeof(body) == "string" && body.length > 0) ? body : "HTTP status: " + status;
                    CF.log("ERROR REPLY ---------");
                    CF.logObject(self.lastError);
                }
            } catch (e) {
                CF.log("Exception caught while processing response from SendJsonCommandToDomotiGa: " + e);
            }
        });
    } catch (e) {
        CF.log("Exception caught in SendJsonCommandToDomotiGa: " + e);
    }
}



In my script button, I have :
Code: Select all
SendJsonCommandToDomotiGa({"jsonrpc": "2.0", "method": "device.set", "params": {"device_id": 5, "value": "On" }, "id": 1})

device 5 is a lamp device (reading status is working fine)

With terminal on Raspberry, If I use this command
Code: Select all
curl -sS -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "device.set","params": {"device_id": 5,"value": "On"}, "id": 1}' localhost:9090
This switch On my lamp...


In CF GUI Designer, my system properties are (see attached file)

Using this command in terminal to see DomotiGa Status :
Code: Select all
sudo /etc/init.d/domotigaserver3 status
[ ok ] DomotiGaServer3.gambas is running.



Using this command in terminal :
Code: Select all
sudo netstat -nap|grep 9090
tcp        0      0 0.0.0.0:9090            0.0.0.0:*               LISTEN      2801/gbr3


So, it seems Domotiga Well running in Server mode with port 9090 open...

Since 2 days now, I try to understand why no function and I can't solve my trouble... any idea ?

Thanks in advance for your comment...
Attachments
Clip_8.jpg
Clip_8.jpg (83.25 KiB) Viewed 3607 times
Pik
Starting Member
Starting Member
 
Posts: 33
Joined: April 2014

Re: CF Iviewer - No output command

Postby Pik » Fri May 09, 2014 6:39 pm

Hello,

Please forget this post... I just discovered CF Iviewer for Android is not free.
I cancel the use of this soft.

Post closed.
Pik
Starting Member
Starting Member
 
Posts: 33
Joined: April 2014


Return to DomotiGa Forum

Who is online

Users browsing this forum: No registered users and 1 guest