Hassbian initial configuration on Raspberry Pi MQTT gateway



  • Hello,

    I am struggling to make the initial setup of MySensors with Hassbian. I am running both on same Raspberry Pi 3.

    I installed MySensor gateway on the RPi with following configuration

    ./configure --my-transport=rf24 --my-rf24-ce-pin=18 --my-rf24-cs-pin=24 --my-gateway=mqtt --my-controller-ip-address=127.0.0.1 --my-mqtt-publish-topic-prefix=mygateway1-out --my-mqtt-subscribe-topic-prefix=mygateway1-in --my-mqtt-client-id=mygateway1
    

    In Hassbian I installed Mosquitto and this is how my configuration.yaml file look like:

    # MQTT gateway
    mqtt:
      broker: 127.0.0.1
      client_id: mygateway1
      username: pi
      password: raspberry
    
    # MySensor
    mysensors:
      gateways:
        - device: mqtt
          persistence_file: '/home/homeassistant/.homeassistant/mysensors.json'
          topic_in_prefix: 'mygateway1-out'
          topic_out_prefix: 'mygateway1-in'
      optimistic: false
      persistence: true
      retain: true
      version: '2.3.1'
    
    
    # Debug logger
    logger:
      default: info
      logs:
        homeassistant.components.mysensors: debug
        mysensors: debug
    

    I followed the instructions from Home Assistant page and made a dummy sensor node with following code:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <MySensors.h>
    
    #define CHILD_ID 1
    #define MY_NODE_ID 1
    
    bool initialValueSent = false;
    bool state = false;
    
    MyMessage msg(CHILD_ID, V_LIGHT);
    
    void setup() { }
    
    void presentation()  {
      sendSketchInfo("Relay+button", "1.0");
      present(CHILD_ID, S_LIGHT);
    }
    
    void loop()
    {
      // Need to send initial values for Home Assistant
      if (!initialValueSent) {
        Serial.println("Sending initial value");
        send(msg.set(state));
    
        Serial.println("Requesting initial value from controller");
        request(CHILD_ID, V_LIGHT);
        wait(2000, C_SET, V_LIGHT);
      }
      
    }
    
    void receive(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
        // We got initial values from Home Assistant
        if (!initialValueSent) {
          Serial.println("Receiving initial value from controller");
          initialValueSent = true;
        }
        
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    I make sure that I send the sensor S_TYPE in the presentation and that I also send an initial value out.

    The Arduino console output is the following:

    16 MCO:BGN:INIT REPEATER,CP=RNNRA---,REL=255,VER=2.3.1
    26 TSM:INIT
    27 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=1
    37 TSM:FPAR
    74 TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2081 !TSM:FPAR:NO REPLY
    2083 TSM:FPAR
    2119 TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4127 !TSM:FPAR:NO REPLY
    4129 TSM:FPAR
    4165 TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6173 !TSM:FPAR:NO REPLY
    6175 TSM:FPAR
    6211 TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8219 !TSM:FPAR:FAIL
    8220 TSM:FAIL:CNT=1
    8222 TSM:FAIL:DIS
    8224 TSF:TDI:TSL
    18226 TSM:FAIL:RE-INIT
    

    I tried using MySensor log parser and if I understand correctly the node does not get answer from the gateway.

    On the Raspberry Pi, I checked the logs from Home Assistant and they seem fine.

    2019-09-12 07:39:12 DEBUG (SyncWorker_17) [mysensors.persistence] Loading sensors from persistence file /home/homeassistant/.homeassistant/mysensors.json
    2019-09-12 07:39:12 DEBUG (SyncWorker_6) [mysensors.persistence] Saving sensors to persistence file /home/homeassistant/.homeassistant/mysensors.json
    2019-09-12 07:39:12 INFO (MainThread) [mysensors.gateway_mqtt] Setting up initial MQTT topic subscription
    2019-09-12 07:39:12 DEBUG (MainThread) [mysensors.gateway_mqtt] Subscribing to: mygateway1-out/+/+/0/+/+, qos: 0
    2019-09-12 07:39:12 DEBUG (MainThread) [mysensors.gateway_mqtt] Subscribing to: mygateway1-out/+/+/3/+/+, qos: 0
    2019-09-12 07:39:12 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to mygateway1-out/+/+/0/+/+
    2019-09-12 07:39:12 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to mygateway1-out/+/+/3/+/+
    

    So then I stopped MySensor gateway service and run it myself using the command

    cd MySensors
    sudo ./bin/msgw
    

    This is what I have as output

    pi@hassbian:~/MySensors $ sudo ./bin/mysgw
    Sep 12 10:12:32 INFO  Starting gateway...
    Sep 12 10:12:32 INFO  Protocol version - 2.3.1
    Sep 12 10:12:32 DEBUG MCO:BGN:INIT GW,CP=RNNGL---,REL=255,VER=2.3.1
    Sep 12 10:12:32 DEBUG TSF:LRT:OK
    Sep 12 10:12:32 DEBUG TSM:INIT
    Sep 12 10:12:32 DEBUG TSF:WUR:MS=0
    Sep 12 10:12:32 DEBUG TSM:INIT:TSP OK
    Sep 12 10:12:32 DEBUG TSM:INIT:GW MODE
    Sep 12 10:12:32 DEBUG TSM:READY:ID=0,PAR=0,DIS=0
    Sep 12 10:12:32 DEBUG MCO:REG:NOT NEEDED
    Sep 12 10:12:32 DEBUG MCO:BGN:STP
    Sep 12 10:12:32 DEBUG MCO:BGN:INIT OK,TSP=1
    Sep 12 10:12:32 DEBUG GWT:RMQ:MQTT RECONNECT
    Sep 12 10:12:32 DEBUG connected to 127.0.0.1
    Sep 12 10:12:32 DEBUG TSM:READY:NWD REQ
    Sep 12 10:12:32 DEBUG TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    Sep 12 10:12:32 DEBUG GWT:RMQ:MQTT RECONNECT
    Sep 12 10:12:32 DEBUG connected to 127.0.0.1
    Sep 12 10:12:32 DEBUG GWT:RMQ:MQTT RECONNECT
    Sep 12 10:12:32 DEBUG connected to 127.0.0.1
    ...
    (infinite amount of reconnect message)
    ...
    Sep 12 10:12:32 DEBUG GWT:RMQ:MQTT RECONNECT
    Sep 12 10:12:32 DEBUG connected to 127.0.0.1
    Sep 12 10:12:32 DEBUG GWT:RMQ:MQTT RECONNECT
    Sep 12 10:12:32 DEBUG connected to 127.0.0.1
    Sep 12 10:12:32 DEBUG TSF:MSG:READ,1-1-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    Sep 12 10:12:32 DEBUG TSF:MSG:BC
    Sep 12 10:12:32 DEBUG TSF:MSG:FPAR REQ,ID=1
    Sep 12 10:12:32 DEBUG TSF:CKU:OK,FCTRL
    Sep 12 10:12:32 DEBUG TSF:MSG:GWL OK
    Sep 12 10:12:33 DEBUG !TSF:MSG:SEND,0-0-1-1,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0
    Sep 12 10:12:33 DEBUG GWT:RMQ:MQTT RECONNECT
    Sep 12 10:12:33 DEBUG connected to 127.0.0.1
    ...
    

    I would assume the problem comes from the gateway that do not stay connected and constantly reconnect but I am out of clues of what I am doing wrong.

    Any idea is appreciated, thanks!



  • I made some more tests and I think it doesn't work because when I setup Mosquitto, I created a user/password but didn't do it when building MySensor gateway.

    I looked at the list of options from this page and added the next 2 configuration options:

    --my-mqtt-user=pi
    --my-mqtt-password=raspberry
    

    (pi / raspberry being the same user / password I set my Mosquitto user during the installation)

    But when I configure the MySensor gateway I see this in the console:

    [WARNING] Unknown option detected:--my-mqtt-user=pi, ignored
    [WARNING] Unknown option detected:--my-mqtt-password=raspberry, ignored
    

    Is there any other way I could try to build the gateway with user/password than this? Or is this a bug? Those 2 options are clearly written in the configuration options page for the Raspberry Pi gateway.


  • Mod

    @meach that's strange. Which version of MySensors are you using?

    If you are unsure of the version, delete the MySensors folder and download latest stable by following the instructions on https://www.mysensors.org/build/raspberry from the top



  • @meach Configure is not seeing the = in your command line properly - so I'm assuming a cut+paste issue with character strings.

    Ie. It's seeing the configuration option --my-mqtt-user=pi instead of --my-mqtt-user and a value of pi.

    Try to retype that part of the command line manually and try it again.

    A

    EDIT: As an aside, I usually put my configure command line into a script and then just run the script. Handy when you come back to it 6-8 months later and wonder what configure options you used the last time you ran it.


  • Mod

    This is what the configure command looks like on my system. The username and passwords work

    pi@raspberrypi:~/MySensors $ ./configure --my-mqtt-user=pi --my-mqtt-password=raspberry
    [SECTION] Detecting target machine.
      [OK] machine detected: SoC=BCM2836, Type=rpi2, CPU=armv7l.
    [SECTION] Detecting SPI driver.
      [OK] SPI driver detected:BCM.
    [SECTION] Gateway configuration.
      [OK] Type: ethernet.
      [OK] Transport: rf24.
      [OK] Signing: Disabled.
      [OK] Encryption: Disabled.
      [OK] CPPFLAGS: -DMY_RADIO_RF24 -DMY_GATEWAY_LINUX -DMY_DEBUG -DLINUX_SPI_BCM -DLINUX_ARCH_RASPBERRYPI -DMY_MQTT_PASSWORD="raspberry" -DMY_MQTT_USER="pi"
    [SECTION] Detecting init system.
      [OK] Init system detected: systemd.
    [SECTION] Saving configuration.
      [OK] Saved.
    [SECTION] Cleaning previous builds.
      [OK] Finished.
    


  • What I had noticed and was trying to point out was that the error was:

    [WARNING] Unknown option detected: --my-mqtt-user=pi, ignored
    

    not:

    [WARNING] Unknown option detected: --my-mqtt-user, ignored
    


  • You were right, there was a character problem when copy/pasting the command to the terminal.
    Now I can build MySensor with username and password and it works fine.

    Thanks for the help!


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 1
  • 8
  • 3

13
Online

11.4k
Users

11.1k
Topics

112.7k
Posts