FLIRS ISSUE

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: FLIRS ISSUE

Post by petergebruers »

PoltoS wrote:
03 Sep 2017 00:28
Z-Uno software 2.1.0 is released with support for FLiRS capable channels: Siren and Valve control
Do you have example code for Siren or Valve?
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: FLIRS ISSUE

Post by petergebruers »

Thanks. I came up with this piece of code. I can control the on-board LED if I use always awake mode and remove zunoSendDeviceToSleep. If I change to "frequently awake", the device indeed goes to sleep but does not respond to remote commands. Power supply is 5 V USB.

I must be missing something obvious, but I can't see what. I'm still learning...

Controller is RaZberry 2.3.5.
I always exclude, upload sketch, include when I change something.
Expert mode tells me I have 0 FLiRS.
;
EDIT: code removed, I'll make a new sketch with better initialization from NZRAM.
FLiRS inclusion issue solved: I included from 'rescue' mode, not from user mode. In rescue mode, the device is always of type "mains".
Last edited by petergebruers on 06 Sep 2017 17:56, edited 1 time in total.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: FLIRS ISSUE

Post by petergebruers »

Next problem. When I load this sketch, the device always reports 0 (checked with a Z-Sniffer). If I comment out the zunoSendDeviceToSleep(); function, the device reports 1 as expected. What am I missing here? The reference manual says: "Functions getter should return 0 for Off and any non-zero value for On".

Code: Select all

// 2.1.0 FLiRS example by user "petergebruers"
// FLiRS capable channels: Siren and Valve control only!

ZUNO_SETUP_CHANNELS(ZUNO_SIREN(getter, setter));
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);

void setup() {
}

void loop() {
  zunoSendDeviceToSleep();
}

void setter(BYTE value) {
}

BYTE getter() {
  return 1;
}
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: FLIRS ISSUE

Post by PoltoS »

Hi

We found the problem. This happens because zunoSendDevoceIntoSleep is called too early. As a fix, call this function on the second loop only.
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: FLIRS ISSUE

Post by p0lyg0n1 »

This have to work. Tested it with security enabled.

Code: Select all

// LED pin number
// 13 pin - user LED of Z-Uno board
#define LED_PIN 13
#include <EEPROM.h>
#define STATE_ADDR 1
#define MAGIC_ADDR 2

ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));
// next macro sets up the sleeping mode
// device will wake up by user request and regulary listening for packets
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);

// Just a trick to keep device ready for some loops
byte g_loop_count = 100;

byte state_changed = false;
byte current_val;

// the setup routine runs once when you press reset:
void setup() {
  pinMode(LED_PIN, OUTPUT); // setup pin as output
  if( NZRAM.read(MAGIC_ADDR) != 0x42) // Check a magic value (if memory was initialized value have to be correct)
  {
       NZRAM.write(STATE_ADDR, 0); // Switched of by default
       NZRAM.write(MAGIC_ADDR, 0x42);
       Serial0.println("Reinit");
  }
  current_val = NZRAM.read(STATE_ADDR);
  // We have to reinitialize the pin state every wake up
  digitalWrite(LED_PIN, current_val);
}


// the loop routine runs over and over again forever:
void loop() {
  if(state_changed)
  {
       
      if (current_val > 0) {           // if greater then zero
          digitalWrite (LED_PIN, HIGH); //turn the LED on (HIGH is the voltage level)
      } else {                         // if equals zero
          digitalWrite(LED_PIN, LOW);   //turn the LED off by making the voltage LOW
      }
      NZRAM.write(STATE_ADDR, current_val);
      state_changed = false;
  }
  g_loop_count--;
  if(!g_loop_count)
  {
    // this function sends the device into sleep
    zunoSendDeviceToSleep();
  }
  delay(20);
}
void setter(byte value) {
  // Here we just store new state and tell the main logic that state was changed
  current_val = value;
  state_changed = true;
}

byte getter() {
  return current_val;
}
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: FLIRS ISSUE

Post by petergebruers »

Thanks. New issue. Probably again missing some info. See code below. If you run this minimal sketch, you'll notice the LED turns off when the Z-Uno receives a command from the controller. My code never turns off the LED, so it has to be the Z-Uno runtime. Is there any way to avoid this? I'm guessing the state is correctly maintained during sleep, but some code after waking from sleep turns off the LED.

The low period is about 0.08 seconds.

Code: Select all

// 2.1.0 FLiRS example by user "petergebruers"
// FLiRS capable channels: Siren and Valve control only!
#include "EEPROM.h"

ZUNO_SETUP_CHANNELS(ZUNO_SIREN(getter, setter));
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);

// LED pin number 13 = white user LED of Z-Uno board
#define LED_PIN LED_BUILTIN

// loopcounter counts number of loop calls and
// is used to send device to slaap after 2 rounds
// to avoid "getter issues"

BYTE loopcounter;

void setup() {
  loopcounter = 0;
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
}

void loop() {
  loopcounter++;
  if (loopcounter == 2)
    zunoSendDeviceToSleep();
}

void setter(BYTE value) {
}

BYTE getter() {
  return 42;
}
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: FLIRS ISSUE

Post by PoltoS »

This is a know issue - when the chip boots up, it sets all to INPUT and then only in setup() values are restored. We are working on this problem
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: FLIRS ISSUE

Post by petergebruers »

PoltoS wrote:
07 Sep 2017 18:33
This is a know issue - when the chip boots up, it sets all to INPUT and then only in setup() values are restored. We are working on this problem
Thank you for confirming this. I will continue my work on a nice working example when the known issues have been resolved. Please contact me if you want me to beta test something.

Related to this issue: when working on a breadboard or prototype, all unused pins will float. In my code, I set *all* pins to output when testing FLIRS to make sure no input draws excessive power. It is a habit I got from working with other micro-controllers, it is important if they have pure digital inputs and somewhat less important if they have analog inputs. With the 2.1.0 the pins will still float for 80 ms at each wake-up but I do not think this is a big deal.
Post Reply