RFM69 BinarySwitchSleepSensor not working.



  • Im runnig a BinarySwitchSleepSensor.ino file with some edits to make it work with a RFM69 but alas im not getting what i want

    Here is the code im using (on a Uno with the level adjuster to get 3.3V)

    /**
     * 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.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Interrupt driven binary switch example with dual interrupts
     * Author: Patrick 'Anticimex' Fallberg
     * Connect one button or door/window reed switch between
     * digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
     * one in similar fashion on digital I/O pin 2.
     * This example is designed to fit Arduino Nano/Pro Mini
     *
     */
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    #define RF69_IRQ_PIN 4
    #define MY_RFM69_FREQUENCY   RF69_868MHZ
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #define SKETCH_NAME "Wall switch"
    #define SKETCH_MAJOR_VER "0"
    #define SKETCH_MINOR_VER "1"
    
    #define PRIMARY_CHILD_ID 3
    #define SECONDARY_CHILD_ID 4
    
    #define PRIMARY_BUTTON_PIN 2   // Arduino Digital I/O pin for button/reed switch
    #define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
    
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(PRIMARY_CHILD_ID, V_LIGHT);
    MyMessage msg2(SECONDARY_CHILD_ID, V_LIGHT);
    
    void setup()
    {
      // Setup the buttons
      pinMode(PRIMARY_BUTTON_PIN, INPUT);
      pinMode(SECONDARY_BUTTON_PIN, INPUT);
    
      // Activate internal pull-ups
      digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
      digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
    }
    
    void presentation() {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
    
      // Register binary input sensor to sensor_node (they will be created as child devices)
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(PRIMARY_CHILD_ID, S_LIGHT);
      present(SECONDARY_CHILD_ID, S_LIGHT);
    }
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop()
    {
      uint8_t value;
      uint8_t value2;
      static uint8_t sentValue=2;
      static uint8_t sentValue2=2;
    
      // Short delay to allow buttons to properly settle
      sleep(5);
    
      Serial.println("Im Awake!");
    
      value = digitalRead(PRIMARY_BUTTON_PIN);
    
      if (value != sentValue) {
         // Value has changed from last transmission, send the updated value
         Serial.println(value);
         send(msg.set(value==HIGH ? 1 : 0));
         sentValue = value;
      }
    
      value2 = digitalRead(SECONDARY_BUTTON_PIN);
    
      if (value2 != sentValue2) {
         // Value has changed from last transmission, send the updated value
         Serial.println(value2);
         send(msg2.set(value2==HIGH ? 1 : 0));
         sentValue2 = value2;
      }
    
      // Sleep until something happens with the sensor
      Serial.println("Going to sleep until buttons are pressed");
      sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
    }
    
    

    When i run this i get this from the Serial monitor, this is including me pressing the buttons connected to pin 2 -> GND and 3 -> GND.

    ti�G�Starting sensor (RRNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    

    Anyone got an idea on how to fix this?


  • Hardware Contributor

    Hello.

    For the moment you have no communication.

    In your define you set RF69_IRQ = D4, but you can't. you need to use D2 or D3, native INT0/1 of Arduino which are compatible with Mysensors.
    So, interruption is not fired and then you cannot get any ACK etc..no parent node etc..

    So comment the line for D2 default, or use D3, should fix your problem i hope.



  • aah. Then I will have to run it from a 3.3V pro micro 🙂 need 3 interupt pins for this sketch 🙂

    Thank you for the answer!


Log in to reply
 

Suggested Topics

  • 3
  • 6
  • 5
  • 8
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts