incomingMessage is not initiated on relay sensor



  • Hi!

    I'm struggling to get any kind of relay sensor to work. I'm using framework 1.5 for nr24 sensors and serial USB gateway. My other DHT22 sensor is working just fine but the relay sensor must of course also receive messages and I guess somewhere around here lies the problem.

    I'm using Openhab as the controller on my RPi2 but while debugging this I've also tried MYSController on my Win7 PC as a way of narrowing this problem down. While troubleshooting on the RPi I also tried to sniff the serial communication so at least I've added that tool (jpnevulator) to my toolbox.

    Here's some code I've tried:

    /*  RF433Mhz Transmitter node:
        This sketch allows On-Off-Keying (OOK) control of four 433Mhz relay outlets
        which utilize the common PT2262 encoding chip for signal transmission. The sketch could
        be easily expanded to include additional outlets.  The sensor node consists of a nano 
        connected to a NRF24L01 and a 433Mhz transmitter connected to pin 3, 5V and Gnd.  The 
        transmitter can run off of 3.3V as well. 
        
        The sketch is based on the MySensors project (http://www.mysensors.org). 
        Submitted by Dwalt.
    
        Thanks to https://forum.mysensors.org/user/jribera!
    */ 
    
    //  Include related libraries
    #include <MySensor.h>
    #include <SPI.h>  
    //#include <RF24.h> //wouldn't compile => comment, NickBuilder
    #include <RCSwitch.h>
    
    //  Define Constants
    #define RF433_CHILD_ID 0
    #define NUMBER_OF_OUTLETS 1 // Each outlet will have 2 OOK codes
    //#define SEND_DATA 3 //defined in call to function, NickBuilder
    
    #define CODE_1On 1394007
    #define CODE_1Off 1394004
    
    MySensor gw;
    
    RCSwitch mySwitch = RCSwitch();
    
    void setup() 
    {
        mySwitch.enableTransmit(3); //transmit pin
      
        Serial.begin(115200); // already defined in config, NickBuilder
    
        //  The node is mains powered, so why not make it a repeater.
       gw.begin(incomingMessage, AUTO, true); //node-id=50, NickBuilder
     
        // Send the sketch version information to gateway
        gw.sendSketchInfo("RF433", "1.1");
     
        // Register outlets to gw (they will be created as child devices)
        for(int i=0; i<NUMBER_OF_OUTLETS;i++) {
            gw.present(i+1, S_LIGHT);
        }
    
        Serial.println("RF433MHz is awake!");
        
    }//setup
    
    void loop() {
        gw.process();
    }
    
    void incomingMessage(const MyMessage &message) {
          Serial.print("Outlet #: "); //added these 4 lines for debug, NickBuilder
          Serial.println(message.sensor);
          Serial.print("Command: ");
          Serial.println(message.getBool());
          
      if (message.type==V_LIGHT) {
          int incomingLightState =  message.getBool(); 
          int incomingOutlet = message.sensor;
          
          Serial.print("Outlet #: ");
          Serial.println(message.sensor);
          Serial.print("Command: ");
          Serial.println(message.getBool());
     
          if (incomingOutlet==1) {
              if (incomingLightState==1) {
                  // Turn on  socket 1
                  Serial.println("Turn on Socket 1");
                  mySwitch.send(CODE_1On, 24); // These codes are unique to each outlet
                  delay(50); 
              }
              if (incomingLightState==0)  {
                  // Turn off socket 1
                  Serial.println("Turn off Socket 1");
                  mySwitch.send(CODE_1Off, 24);
                  delay(50); 
              }
          }//==1      
            
      }//if message.type==V_LIGHT
     
      delay(50);
    }//incomingMessage
    

    For some reason I can't initiate the incomingMessage function because if I had then I would have gotten som serial feedback, right?

    I've tried sending commands both through the Openhab binding (on runtime 1.8.3) and also though the MYSController but without any sign of feedback in the serial monitor.

    Arduino seriel monitor:
    send: 50-50-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0
    send: 50-50-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=ok:1.5.4
    send: 50-50-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    repeater started, id=50, parent=0, distance=1
    send: 50-50-0-0 s=255,c=3,t=11,pt=0,l=5,sg=0,st=ok:RF433
    send: 50-50-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.1
    send: 50-50-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 50-50-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 50-50-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 50-50-0-0 s=4,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    RF433MHz is awake!

    MYSController Debug:
    2016-07-14 00:38:18 SIGNING Node 50 does not require signing
    2016-07-14 00:38:18 SIGNING MYSController is not signing
    2016-07-14 00:38:18 TX 50;255;3;0;15;0
    2016-07-14 00:38:18 RX 50;255;3;0;15;0
    2016-07-14 00:38:18 DEBUG Update child id=255, type=ARDUINO_RELAY
    2016-07-14 00:38:18 RX 50;255;0;0;18;1.5.4
    2016-07-14 00:38:18 TX 50;255;3;0;6;M
    2016-07-14 00:38:18 RX 50;255;3;0;6;0
    2016-07-14 00:38:20 RX 50;255;3;0;11;RF433
    2016-07-14 00:38:20 RX 50;255;3;0;12;1.1
    2016-07-14 00:38:20 DEBUG Update child id=1, type=LIGHT
    2016-07-14 00:38:20 RX 50;1;0;0;3;
    2016-07-14 00:38:20 DEBUG Update child id=2, type=LIGHT
    2016-07-14 00:38:20 RX 50;2;0;0;3;
    2016-07-14 00:38:20 DEBUG Update child id=3, type=LIGHT
    2016-07-14 00:38:20 RX 50;3;0;0;3;
    2016-07-14 00:38:20 DEBUG Update child id=4, type=LIGHT
    2016-07-14 00:38:20 RX 50;4;0;0;3;

    If I follow the link in the header to the referenced project @jribera mentions that version 1.4 of the API was used while I'm using 1.5, could this be the cause?

    I'm new to MySensors so I might be missing something quite fundamental.

    Assistance would be much appreciated, I'm at road's end.



  • So now I've been through some additional forum threads trying and find something similar. I stumbled upon this one:
    https://forum.mysensors.org/topic/3904/node-are-not-receiving-messages-from-domoticz

    Luckily I've already tried most of the debugging suggestions on my own initiative. 🙂

    The comment by @ToniA seems rather important and quite fundamental if you choose an Arduino with a frequnecy other than 16 MHz..

    @ToniA said:

    8 MHz Arduinos absolutely need to use lower baud rate than 115200. The baud rate is generated from the internal clock, and at 8 MHz 38400 bps is the highest baud rate close enough to the standard.

    This isn't obvious to someone who isn't that experienced. The examples assumes the standard 5V 16MHz Arduino but the 3V3 8Mhz is almost as common a choice. This fact is also confirmed if you do some BAUD callculations at: http://wormfood.net/avrbaudcalc.php

    I'll try 38.4 kbps for my sensor network and come back with the outcome. This might improve communications in general.

    A thought is then how to incorporate my 5V Arduinos in the same network but I guess I can divide the frequency somehow...


  • Hardware Contributor

    Hello.

    about the baudrate problem, that could be a problem for your GW but not for the node.
    Even if I'm aware about the rules of bauds/voltage/freq, sometimes i forget it during debug and most of the time it works well with few garbage chars (even with 8mhz internal rc which is more timing critical lol!). But it's better adjusted, and to know about this of course.
    The fact is, on a radio node you don't transmit serial data so no problem, but from a Serial GW view, which transmits serial data, of course if baudrate is not well adjusted you could have garbage and bad transmission to controllers.

    • What is your hardware. 8Mhz gateway like arduino mini 3v? if so, yes you can tweak a bit the baudrate. The beginning of your logs seems ok but who knows.
    • at the end of myscontroller debug, I don't see any send "relay=1" to your node. Did you try to send from MYSController?? strange!
    • to be sure, what you could try is :
      on your computer, open a serial monitor for your GW and another one for your node. Then from your GW serial monitor try to send a command to your node and see if you receive it on the other side. Then show logs if you can.
    • do you know about the new mysensors 2.0 🙂 If you have very few nodes, I would suggest you try it and convert the few sketch you have.


  • Hi @scalz!

    Thank you for answering!

    Yhea regarding the serial communication between the nodes of course you are right, I forgot about the nrf24 link. 🙂 And I know for a fact that the repeater function for the relay node works as I received debug serial information regarding this.

    Yes the hardware is mostly 3V3 8 MHz pro minis but I have a couple of Uno clones as well. I'll adjust the baudrate for the serial gateway at least to make sure its more reliable.

    Sorry I didn't include that debug information from MYSController but believe me I tried. I tried all sorts of message types and payloads with and without the ack-bit. The gw LED blinked for each transmission but the serial monitoring of the relay sensor was silent. What would be the message to send to the node and can I send it in ASCII or do I need to format it in some way?

    I would be wise to move to the new API, especially as I haven't gotten that far yet. But it would be nice to taste some success before moving on to new challenges. I can only handle that many nights of debugging before losing it.


  • Hardware Contributor

    @NickBuilder
    you will find how it is formatted and some examples here for 1.5
    https://www.mysensors.org/download/serial_api_15
    the last example for instance. change it for your node id etc and you can send it by serial to gw. you should see your GW sending. I mean debug messages (if enabled) and what happens then at node side. a read (so it receives)? nothing? or if ack enabled, does it send back ack then etc...



  • The experience I have is from running the serial gateway on Sensebender (which is a 8MHz device, running on 3.3V). It just didn't work at all, and as soon as changed the serial speed to 38400 everything was just fine.

    http://wormfood.net/avrbaudcalc.php?bitrate=300%2C600%2C1200%2C2400%2C4800%2C9600%2C14.4k%2C19.2k%2C28.8k%2C38.4k%2C57.6k%2C76.8k%2C115.2k%2C230.4k%2C250k%2C.5m%2C1m&clock=8&databits=8

    It also doesn't matter whether you connect through USB or RS-232, it's still the same problem. Another 'nice' finding was that Arduino Nano has a hardware problem, it's not discovered as a USB device when Raspberry boots up. I had really interesting times when trying to use it as the serial gateway, works fine when plugged in when Raspberry is running, but it's lost on every boot.

    https://ketturi.kapsi.fi/2014/04/how-to-fix-moody-arduino-nano/



  • After migrating my few sketches to 2.0 and adjusting my baud rate to 38.4 kbps everything works!

    Thank you @scalz for pushing me to 2.0 and @ToniA for pointing out the poor choice of baud rate for the 8 Mhz Arduino.

    The recommended baud rate is now hard to miss in the 2.0 serial gateway example sketch. So moving to the latest API would possibly have solved my problems anyhow.

    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    

    Moving on to new challenges.


Log in to reply
 

Suggested Topics

  • 3
  • 1
  • 5
  • 6
  • 2

73
Online

11.4k
Users

11.1k
Topics

112.7k
Posts