Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
A

Alphalove

@Alphalove
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Itead RBoard and RMini Example Sketch
    A Alphalove

    Hello All,
    I've been using an Iteadstudio RBoard and RMini for MySensor nodes. These boards are perfect for MySensors as they are cheap and comes with nRF24 socket. I'm not sure why there isn't more mention of them here!

    Anyway, here is a simple sketch I put together for both boards, it follows the same basic pattern as the standard 'Relay With Button Actuator' example.

    I tested this with MyController.org and it all worked as expect, however I am a coding novice, so any suggested improvements would be most welcome.

    Cheers!

    /**
     * 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Alex Scott
     * 
     * DESCRIPTION
     * Example MySensor sketch for both the Itead RBoard and RMini
     * 
     * The code sends and receives commands from the GW unit.
     * This unit does the following.
     *     - Receives incoming commands to turn on or off the relays
     *     - Local input switches sends change to GW
     *     - Switch's ACK back from GW sets the corresponding relay i.e.
     *       if GW is down, local relay will not turn on.
     *       This can be good as you know your connected to
     *       the GW... However if you want the swtich-to-relay
     *       to be linked even if the GW is down, then change the
     *       enable the #define below
     *     - Option to save / restore relay states from EEPROM
     *     - Also a MySensors repeater node
     *
     */ 
    
    /*** Set Itead board type  ***/
    //#define RBOARD 1
    #define RMINI 1
    
    /*** Set direct switch-to-relay link if desired ***/
    //#define DIRECT_SW_TO_R
    
    /*** Set to save / restore relay sate from EEPROM  ***/
    //#define USE_EEPROM
    
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <MyTransportNRF24.h>
    #include <Bounce2.h>
    
    #define SKETCH_VER        "1.0"                 // Sketch version
    #define NODE_ID           AUTO                  // Set number if static node ID if not assigned by HA
    #define NODE_REPEATER     true                  // Set true if a repeater node (i.e. always turned on)
    #define CHILD_NAME        "Switch & Relay"      // Optional child sensor name
    #define MSG_NO_ACK        false
    #define MSG_ACK           true
    
    #ifdef RBOARD
      #define SKETCH_NAME   "RBoard"
      #define NRF24_CE      8                       // RBoard nRF24 CE pin
      #define NRF24_CS      9                       // RBoard nRF24 CS pin
      byte switchInputs[] = {14, 15, 16, 17};       // input switches A0 - A3
      byte relayOutput[]  = {4, 5, 6, 7};           // relay output D4 - D7
    #elif RMINI
      #define SKETCH_NAME   "RMini"
      #define NRF24_CE      9                       // RMini nRF24 CE pin
      #define NRF24_CS      10                      // RMini nRF24 CS pin
      byte switchInputs[] = {A0};                   // input switche A0
      byte relayOutput[]  = {4};                    // relay output D4
    #endif
      
    #define DEBOUNCE_TIME   5
    #define NUM_SWITCHES    sizeof(switchInputs)/sizeof(switchInputs[0])  // Number of input switches
    #define NUM_RELAYS      sizeof(relayOutput)/sizeof(relayOutput[0])    // Number of relay channels
    
    char childName[] = "Relay  ";                                         // Send child sensor name, leave space on end for No.
    Bounce *switchDebounce;                                               // Create pointer to bouncer object
    MyTransportNRF24 transport(NRF24_CE, NRF24_CS, RF24_PA_LEVEL);        // Set non-default CE and CS pins for RBoard
    MySensor gw(transport);
    
    
    
    // ************* Setup ***************
    
    void setup(void) {
      for (byte i = 0; i < NUM_SWITCHES; i++) {                           // Configure switch inputs
        pinMode(switchInputs[i], INPUT_PULLUP);                           // Set internal pullup resistor
      }
    
      for (byte i = 0; i < NUM_RELAYS; i++) {                             // Configure outputs to relays
        pinMode(relayOutput[i], OUTPUT);
    #ifdef USE_EEPROM
        digitalWrite(relayOutput[i], gw.loadState(i));                    // Set output to state in EEPROM
    #else
        digitalWrite(relayOutput[i], LOW);                                // Just set relay off
    #endif
      }
      
      switchDebounce = (Bounce *) malloc(sizeof(Bounce) * NUM_SWITCHES);  // Allocated memory for bouncer objects
      
      for (byte i = 0; i < NUM_SWITCHES; i++) {                           // Attach switches to bouncer objects
        switchDebounce[i].attach(switchInputs[i]);
        switchDebounce[i].interval(DEBOUNCE_TIME);
      }
    
      gw.begin(incomingMessage, NODE_ID, NODE_REPEATER);                  // RX message handler, node ID, node repeater
      gw.sendSketchInfo(SKETCH_NAME, SKETCH_VER);                         // Send sketch info
    
      for (byte i = 0; i < NUM_SWITCHES; i++) {                           // Present the switch / relay child sensors to the GW
        childName[(sizeof(childName))-2] = '0'+i;                         // Insert switch / relay number into end of child sensor char array
        gw.present(i, S_LIGHT, childName);
      }  
    }
    
    
    // ************* Main Loop ***************
    
    void loop(void) {
      gw.process();                                                       // Pump the MySensor network
    
      for(int i = 0; i < NUM_SWITCHES; i++) {                             // Check for debounce switch changes
        if(switchDebounce[i].update()) {                                  // Cycle through debounce objects looking for switch change
          bool state = switchDebounce[i].read();
          MyMessage tmpMsg;                                               // Build a new message and send switch state to GW
          tmpMsg.setSensor(i);
          tmpMsg.setType(V_LIGHT);
          tmpMsg.set(state);
    #ifdef DIRECT_SW_TO_R
          digitalWrite(relayOutput[i], state);                            // Set corresponding relay, no via GW ACK message
          gw.send(tmpMsg, MSG_NO_ACK);                                    // Send message, no ACK
      #ifdef USE_EEPROM
          gw.saveState(i, state);
      #endif
    #else
          gw.send(tmpMsg, MSG_ACK);                                       // Send message, ask for ACK, which in turn will set the relay
    #endif                                                                // No EEPROM saving here as we haven't changed to relay state
        }
      }
    }
    
    
    // ********* Handle Incoming MySensor Messages ********
    
    void incomingMessage(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
        int relayNum = message.sensor;                                    // get child / sensor ID from received message
        if (relayNum >= 0 && relayNum < NUM_RELAYS) {                     // Valid Relay Number?
          digitalWrite(relayOutput[relayNum], message.getBool());         // Set relay output to the received status
    #ifdef USE_EEPROM
          gw.saveState(relayNum, message.getBool());                      // Save relay state to EEPROM
    #endif
         }
      }
    }
    
    Development itead actuator rmini rboard relay

  • Minimal design thoughts
    A Alphalove

    Hello, I'd be in for at least 5 assembled boards.

    Hardware

  • Ethernet Gateway "Inclusion started by Button" messages...when no button connected.
    A Alphalove

    Hello,
    Firstly thanks for such a wonderful Arduino ecosystem, the effort you've put in is amazing.

    Just got my Vera Lite today. Had been playing around with MySenosrs and FHEM for a week then gave in and bought the Vera.

    I have an identical setup to gregl (modified iboard gateway, UI7 I think, no idea what I'm doing in Vera at the moment) and was getting the same 'inclusion' message every time the gateway received a remote node message.

    Implemented the changes in Mygateway.cpp and the error went away.

    Didn't seem to matter which pin I chose for the inclusion input.

    Thanks again,

    alex

    Troubleshooting
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular