MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Subforum for the 'MySensors' project.
http://www.mysensors.org/
piokuc
Posts: 289
Joined: Sunday 07 February 2016 14:31
Target OS: Raspberry Pi
Domoticz version: 3.6328
Contact:

Re: MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Post by piokuc » Monday 22 January 2018 20:41

Ok but serial should also be fixed.

piokuc
Posts: 289
Joined: Sunday 07 February 2016 14:31
Target OS: Raspberry Pi
Domoticz version: 3.6328
Contact:

Re: MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Post by piokuc » Sunday 28 January 2018 18:22

HI
Finally i update FW on RPI3 to version 4.14.15 (this is new FW from branch name NEXT). Then i compile and build MySensors Gateway with connection Serial on my RPI3 and it start working ok. Now i dont have info about port closed.

Code: Select all

./configure --my-transport=rfm69 --my-rfm69-frequency=868 --my-is-rfm69hw --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyUSB30

Code: Select all

make

Code: Select all

sudo make install

Code: Select all

sudo systemctl enable mysgw.service
Then i programm my node on Arduino Mini Pro with radio RFM69HW with this sketch. I use on gateway and sketch library MySensors 2.2.0. But after programm node is found on my gateway but not show switch relay from node. Only show repeater. Look:

SKETCH

Code: Select all

/*
   Relay with button sketch
   modified to work with no uplink
   to gateway and try to maintain sync to controller
*/


#define MY_DEBUG                               // Enable debug prints to serial monitor

#define MY_RADIO_RFM69
#define MY_IS_RFM69HW
#define RFM69_868MH
#define MY_RFM69_NEW_DRIVER

//#define MY_NODE_ID 203                       // Node id defaults to AUTO (tries to fetch id from controller) 

#define MY_TRANSPORT_WAIT_READY_MS 5000        //set how long to wait for transport ready in milliseconds

#define MY_REPEATER_FEATURE                    // Enabled repeater feature for this node

#include <MySensors.h>
#include <Bounce2.h>

#define RELAY_PIN  5      // Arduino Digital I/O pin number for relay 
#define BUTTON_PIN  3     // Arduino Digital I/O pin number for button 
#define CHILD_ID 1        // Id of the sensor child
#define RELAY_ON 1
#define RELAY_OFF 0

Bounce debouncer = Bounce();
int oldValue = 0;
bool uplinkAvailable = true;
bool state = false;
bool requestState;
bool firstStart = true;
unsigned long uplinkCheckTime ;                // holder for uplink checks
unsigned long uplinkCheckPeriod = 30*1000;     // time between checks for uplink in milliseconds
unsigned long returnWait = 1000;               // how long to wait for return from controller in milliseconds.. adjust as needed
unsigned long oldTime = 0;
unsigned long newTime = 0;
MyMessage msg(CHILD_ID, V_STATUS);

void setup(){
  pinMode(BUTTON_PIN, INPUT_PULLUP);           // Setup the button pin, Activate internal pull-up
  
  debouncer.attach(BUTTON_PIN);                // After setting up the button, setup debouncer
  debouncer.interval(5);

  pinMode(RELAY_PIN, OUTPUT);                 // set relay pin in output mode
  digitalWrite(RELAY_PIN, RELAY_OFF);         // Make sure relay is off when starting up
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("1xRelay & Button", "2.2.0");

  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID, S_BINARY);
}


void loop(){
  if (firstStart) {                            // this code is only run once at startup
    Serial.println("First run started");
    requestTime();                             // get time from controller
    wait (returnWait);                         // delay to allow time to return
    if (oldTime == 0){                         // check to see if there was a return from the time request
      Serial.println("uplink not available");
      uplinkAvailable = false;                 // no uplink established
      uplinkCheckTime = millis();
    }
     else{
      Serial.println("uplink available");
      request( CHILD_ID, V_STATUS);            // get status of switch on controller
      wait (returnWait);                       //wait needed to allow request to return from controller
      Serial.print("controller state --- ");
      Serial.println(requestState);
      if (requestState != state) {             // check that controller is corectly showing the current relay state
        send(msg.set(state), false);           // notify controller of current state
      } 
     }   
  firstStart = false;                                          // set firstStart flag false to prevent code from running again
 }

  debouncer.update();
  int value = debouncer.read();                               // Get the update value
  if (value != oldValue && value == 0) {                      // check for new button push
    state =  !state;                                          // Toggle the state
    digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF);    // switch the relay to the new state
    requestTime();
    wait (returnWait);                                               // delay to allow time to return
    if (oldTime != newTime){                                  // if times are different then uplink is available
      send(msg.set(state), false);
      oldTime = newTime;
    }
    else{                                                    // if times are the same no uplink is available
     Serial.println("uplink not available");
      uplinkAvailable = false;                                // no uplink available, set flag false
      uplinkCheckTime = millis();                             // start the timer from now
    }

  }
  oldValue = value;
 
  if (!uplinkAvailable && (millis() - uplinkCheckTime > uplinkCheckPeriod) ) {       // test to see if function should be called
    uplinkCheck();                                                                  // call uplink checking function
  }

}

/*-------------------start of functions--------------------------*/

void receive(const MyMessage &message) {
  if (message.type == V_STATUS) {                                   // check to see if incoming message is for a switch
    switch (message.getCommand()) {                                 // message.getCommand will give us the command type of the incomming message
      case C_SET:                                                   //message is a set command  from controller to update relay state
        state = message.getBool();                                  // get the new state
        digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF);      // switch relay to new state
        uplinkAvailable = true;                                     //  uplink established
        /*---- Write some debug info----*/
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
        break;
      case C_REQ:                                               // message is a returning request from controller
        requestState = message.getBool();                       // update requestState with returning state
        break;
    }
  }
}

void uplinkCheck() {
    requestTime();
    wait (returnWait);                       // wait for time return.. this may need to be varied for your system
   if (oldTime != newTime){
     Serial.println("uplink re-established");
     request( CHILD_ID, V_STATUS);
     wait (returnWait);                        //wait needed to allow request to return from controller
    if (requestState != state) {              // check that controller is corectly showing the current relay state
      send(msg.set(state), false);            // notify controller of current state no ack
      uplinkAvailable = true;                 //  uplink established
      oldTime = newTime;
    }
  }
  uplinkCheckTime = millis();                // reset the checktime
  Serial.println("uplinkchecktime reset");
}


void receiveTime(unsigned long time)
{
  if (firstStart){
    oldTime = time;
    newTime = time;
  }
  else{
  newTime = time;
}
  Serial.print("time received---- " );
  Serial.println(time);
}
node.jpg
node.jpg (210.79 KiB) Viewed 153 times

SweetPants
Posts: 1767
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V3.8922
Location: The Netherlands
Contact:

Re: MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Post by SweetPants » Sunday 28 January 2018 19:06

Tried to "Enable New Hardware" in domoticz settings menu? ChildID 255 is your gateway. So you never learned a node yet
Ubuntu 16.04.3 LTS on Intel NUC, MySensors 2.2.1, Pro Mini 3.3 8M RFM69, ESP8266 (SDK2.1.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

piokuc
Posts: 289
Joined: Sunday 07 February 2016 14:31
Target OS: Raspberry Pi
Domoticz version: 3.6328
Contact:

Re: MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Post by piokuc » Sunday 28 January 2018 22:27

Enable New Hardware nothing change...

SweetPants
Posts: 1767
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V3.8922
Location: The Netherlands
Contact:

Re: MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Post by SweetPants » Monday 29 January 2018 13:34

piokuc wrote:
Sunday 28 January 2018 22:27
Enable New Hardware nothing change...
Hmm, That's weird, i'm running the same MySensors GW on RPI 2 version 2.2.1-alpha (used to run 2.2.0-rc2), and nodes 2.2.0-beta and 2.2.0-rc2 without any issues. After enabeling hardware you have to trigger a message from the node before Domoticz pick's it up.
MySensors-Nodes.png
MySensors-Nodes.png (107.25 KiB) Viewed 137 times
Ubuntu 16.04.3 LTS on Intel NUC, MySensors 2.2.1, Pro Mini 3.3 8M RFM69, ESP8266 (SDK2.1.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

piokuc
Posts: 289
Joined: Sunday 07 February 2016 14:31
Target OS: Raspberry Pi
Domoticz version: 3.6328
Contact:

Re: MySensors Gateway on GPIO RPi 3 with RFM69HW-Problem

Post by piokuc » Monday 29 January 2018 16:05

Can you send me your sketch for node and how you connect radio to RPI2 ?(what pinout)

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests