mycontroller-org / mycontroller-v1-legacy

The Open Source Controller
http://www.MyController.org
Apache License 2.0
148 stars 90 forks source link

[Bug] SmartSleep with Payload forwarding not working? #400

Closed cimba007 closed 7 years ago

cimba007 commented 7 years ago

Hello,

I have the following setup:

Node A = A node with temperature + humidity Sensor Node B = A Node with a display

Now I want to forward temperature and humidity from Node A to Node B with the "Forward payload" feature which is btw. REALLY REALLY NEAT!!! very good feature.

Node B is sleeping most of the time with smartsleep .. but due to smart sleep misses the forwarded payloads. Is there maybe a bug with smartsleep?

I have enabled smart sleep on Node B:

image

As I see this correctly the controller might forward the values despite Node B not beeing "online"??

image

This function is not called when I use smartsleep

void receive(const MyMessage &message) { printmsg(message); }

If I comment it out it is working as expected.

PS: I am running 2.2.0-beta on my gateway and Node B I am using Built on 2017-05-08T08:27:47+0530 image

/**
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
**/

#define MY_NODE_ID 50

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95

#define MY_RF24_CE_PIN 8
#define MY_RF24_CS_PIN 9

#define MY_SMART_SLEEP_WAIT_DURATION_MS 500

#include <MySensors.h>

MyMessage msg_temp(0, V_TEMP);
MyMessage msg_hum(1, V_HUM);

void before()
{

}

void setup()
{
  //send(msg_temp.set(0));
  //send(msg_hum.set(0));
}

void presentation()
{
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("Dummy show", "1.0");
  present(0, S_TEMP);
  present(1, S_HUM);
}

void loop()
{
  smartSleep(4000);
}

void receive(const MyMessage &message)
{
    printmsg(message);
}

PS: This is my current project:

img_20171001_010015

I tried this too but the list stays empty:

https://forum.mycontroller.org/topic/128/send-payload-but-nack/7

cimba007 commented 7 years ago

I solved the issue by:

  smartSleep(5000);
  Serial.print("."); Serial.flush();
  sendHeartbeat();
  delay(500);

Will check why this is not included in smartSleep ?!

Update:

PreSleep From my understanding this happens in mysensors sleep function:

    if (smartSleep) {
        // notify controller about going to sleep, payload indicates smartsleep waiting time in MS
        (void)_sendRoute(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL,
                               I_PRE_SLEEP_NOTIFICATION).set((uint32_t)MY_SMART_SLEEP_WAIT_DURATION_MS));
        wait(MY_SMART_SLEEP_WAIT_DURATION_MS);      // listen for incoming messages
    }

PostSleep

    if (smartSleep) {
        // notify controller about waking up, payload indicates sleeping time in MS
        (void)_sendRoute(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL,
                               I_POST_SLEEP_NOTIFICATION).set(sleepingTimeMS));
    }

I think mycontroller only listens to heartbeat messages and should listen to I_POST_SLEEP_NOTIFICATION and I_PRE_SLEEP_NOTIFICATION too and send queued messages accordingly.

jkandasa commented 7 years ago

@cimba007 Sure, I will add this.

jkandasa commented 7 years ago

@cimba007 fix is available in SNAPSHOT build

cimba007 commented 7 years ago

Somehow I can't get the fix to work. I see that mycontroller is sending the messages but the node is unable to receive them .. investigating.

I like the idea of:

+                //Check still do we have duration on receiver side
 +                if (sleepWaitDuration != null && (System.currentTimeMillis() <= (startTime + sleepWaitDuration))) {
 +                    break;
 +                }

But it seems this is a bit too optimistic. There are various delays that might make the time shorter as it seems.

Delay Node -> Gateway Delay Gateway -> MQTT Delay MQTT -> Mycontroller

..

Still no clue why it is not working. I tried to do the "old" behavior of sleep() and then sending heartbeat and wait() .. but I only get once message at a time.

Any way to check/modifie txDelay of gateway?

Thread.sleep(McObjectManager.getGateway(mcMessage.getGatewayId()).getGateway().getTxDelay(),333333);

Maybe this value got mixed up.

Same problem with smartSleep

image

You can see that only the "oldest" value gets sent.

cimba007 commented 7 years ago

Found the mistake I guess:

After the first cycle

System.currentTimeMillis() <= (startTime + sleepWaitDuration

will evaluate to "true" and break the loop so only one message gets send.

+                //Check still do we have duration on receiver side
 +                if (sleepWaitDuration != null && (System.currentTimeMillis() <= (startTime + sleepWaitDuration))) {
 +                    break;
 +                }
jkandasa commented 7 years ago

@cimba007 Thank you for the findings. I have fixed and updated the SNAPSHOT build. Could you please check it there?

I like this display. Where did you buy? any link? img_20171001_010015

cimba007 commented 7 years ago

I would recommend to get one from waveshare as they already got the required electronic parts (mostly capacitors):

https://www.ebay.de/sch/i.html?_from=R40&_sacat=0&_nkw=waveshare%20e-ink&rt=nc&LH_PrefLoc=2&_trksid=p2045573.m1684