gw.request - how is it done?



  • Hejda,

    I'm trying to get my power meter sensor running. The final piece that is missing is the
    feature to get the last known value from domoticz. In theory it should be something like:

    gw.begin(incomingMessage, NODE_ID, true);
    gw.present(CHILD_ID, V_VAR1);

    And after that I should be able to retrieve the value by using:

    gw.request(CHILD_ID, V_VAR1);

    I'd have to provide the routine for incoming of course:

    void incomingMessage(const MyMessage &message){}

    But this routine is never ever entered.
    Now, has anyone here a code example for me which successfully requests a variable
    from the domoticz server?
    I have of course tried the examples from MySensors but without success.

    I'm using Domoticz 2.3488 beta on a RaspberryPi and MySensors 1.5.

    So far I had just hard coded the value for the energy meter counter at the time of startup into my
    firmware and hoped I would never have to reboot.
    But today I had a power failure and I'm back to my problem again. And I'd reeeeeaally like to get this
    solved 🙂

    Thanks for any help!

    Christoph


  • Admin

    Can't help much when we don't see the Domoticz/GW/Node logs.

    Does the req-message reach Domoticz? Is it issuing an answer?



  • @hek said:

    Can't help much when we don't see the Domoticz/GW/Node logs.

    Does the req-message reach Domoticz? Is it issuing an answer?

    Where do I have to look for those logs? All I'm aware of is the log tab in
    the setup page of my Domoticz server homepage. But I don't get any
    details there, just which sensor sent anything at all:


    2015-10-29 20:41:52.312 Hardware Monitor: Fetching data (System sensors)
    2015-10-29 20:42:04.279 (Pyramid) Temp (Temp_Dach_Fien)
    2015-10-29 20:42:06.155 (Pyramid) Temp (TempTest_03)
    2015-10-29 20:42:06.173 (Pyramid) Temp (BattVoltage)

    and so on.

    So, where are thos logs You mentioned?

    Oh, and I had another power failure today. It was my wife's flat iron
    😉

    Thanks,
    Christoph


  • Admin

    Hook up the sensor to Arduino IDE and look in serial monitor.



  • Okay. Did that already, of course. 🙂
    Let's start from something known. I've used the demo code for
    the EnergyMeterPulseSensor Example. All I changed is the Node_ID
    (to 123). Did this in:

    gw.begin(incomingMessage, NODE_ID, false);

    And I am sending a demo value to V_VAR1:

    gw.send(pcMsg.set(123456));
    This does get sent obviously. In the Domoticz.db file I can find that value
    in the "MySensorsVar" table. After having sent the value I remove this line.

    And this is what I get (b.t.w.: how do I decipher those messages? This is
    not the format that is used in the MySensors SerialProtocol document):

    send: 123-123-0-0 s=255,c=0,t=17,pt=0,l=3,sg=0,st=ok:1.5
    send: 123-123-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    sensor started, id=123, parent=0, distance=1
    send: 123-123-0-0 s=255,c=3,t=11,pt=0,l=12,sg=0,st=ok:Energy Meter
    send: 123-123-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 123-123-0-0 s=0,c=0,t=13,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    read: 12-13-0 s=0,c=1,t=1,pt=7,l=5,sg=0:46.6
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    send: 123-123-0-0 s=0,c=2,t=24,pt=0,l=0,sg=0,st=ok:

    and so on.
    Some of this I understand (I think). What about the lonesome "read" line?
    As I already wrote: it doesn't look like the routine...

    void incomingMessage(const MyMessage &message)

    ... is ever entered.

    What else can I tell You?

    Christoph


  • Admin

    Ok, guess you have to ask someone over at Domoticz forum if it even supports REQ/VARx.



  • Okay, will do.
    But apart from that: really nobody here with Domoticz who successfully worked with
    "request"? Can't believe that...

    Thanks,
    Christoph



  • Hi,

    this is my workaround for my problem:
    Ive added a 1F goldcap capacitor as an emergency power supply.
    If my powersupply voltage drops a routine is called which stores
    the current counter value via gw.setState() and then enters an
    endless loop. And an LED is switched on to empty the capacitor.
    Next time the sensor boots up, first thing it'll do is to retrieve the
    old value for the pulsecount from the EEPROM.

    With this I can use the setstate function in case it's necessary
    but I don't have to write to the EEPROM continuously which
    wouldn't work for long (100k write cycle limit).

    It's probably not failsafe. For example: what happens if there
    are multiple reboots because the brownout watchdog "barks"
    and the final power cut happens while the EEPROM is written to?

    But for now it seems to work. Dah!

    🙂
    Christoph



  • Interesting workaround!

    Could you please share your sketch?


  • Hardware Contributor

    I have made a sketch requesting VVAR1 from Domoticz. It didnt work with the stable version but better with the beta.
    But as i wrote in this post im still having issues with getting the request back: http://forum.mysensors.org/topic/2116/hard-to-grab-time-and-value-sent-from-controller

    The sketch is in the link, but its a rain gauge.



  • @Mediacj sure. It's not cleaned up. And a hack of various sources.
    I guess You won't mind 😉
    EnergyMeterPulseSensorGrace.ino

    The fun stuff happens in the void graceful() routine.

    First of all You'll have to run this line once to set Your startup value:
    pulseCount = ((1912810 * PULSE_FACTOR / 10) + 5) / 10; graceful();

    After that You can comment this out and hopefully won't ever need it again 🙂
    With the next booting of the sensor the value will be read from the EEPROM:

    pulseCount = 0;
    pulseCount += gw.loadState(GRACE + 3); // get highest byte
    pulseCount *= 256;
    pulseCount += gw.loadState(GRACE + 2);
    pulseCount *= 256;
    (and so on).

    If the pre-voltage-regulator voltage drops the gold cap will still hold enough power
    to save the current value to the EEPROM.

    Still. I'd much prefer the software solution ...

    Christoph



  • @sundberg84 I'll have a look at that.
    I've just tried the TimeAwareSensor example mentioned and it doesn't work.
    But I DO get some reads, as far as I could see I got them from those
    sensors that are repeater enabled.
    But NEVER anything from "GW". WHat's it's address anyway?

    Christoph



  • @Mediacj

    You guessed it:

    pulseCount = ((1912810 * PULSE_FACTOR / 10) + 5) / 10; graceful();
    You don't use the number 1912810 of course: that's just my kWh at the time I started, MULTIPLYED BY 100!

    Christoph



  • Thanks for sharing!!

    Yes it would be better to have a stable software solution but your solution is good also and even safer when there is a power failure!



  • Gizmocuz has a working sketch example

    I have successfully used it.


Log in to reply
 

Suggested Topics

  • 5
  • 5
  • 8
  • 4
  • 1
  • 4

53
Online

11.4k
Users

11.1k
Topics

112.7k
Posts