Please, need help getting RPi controller working with MQTT



  • I'm just starting out with MySensors and home automation in general. Been trying to get Home Assistant working with this gateway and an irrigation node. Had the gateway and node working fine using RPi ethernet build but could not get Home Assistant to recognize any nodes. After much trial and tribulation I decided to try out MQTT on the RPi (through GPIO, sans Arduino) using the config:

    ./configure --my-rf24-irq-pin=15 --my-leds-err-pin=12 --my-leds-rx-pin=16 --my-leds-tx-pin=18 --my-leds-blinking-inverse --my-rf24-channel=69 --my-rf24-pa-level=RF24_PA_LOW --my-gateway=mqtt --my-controller-ip-address=127.0.0.1 --my-mqtt-publish-topic-prefix=mysensors-out --my-mqtt-subscribe-topic-prefix=mysensors-in --my-mqtt-client-id=mygateway1
    

    I "sudo make" it and run "sudo ./bin/mysgw -d" and get the following output:

    mysgw: Starting gateway...
    mysgw: Protocol version - 2.2.0-beta
    mysgw: MCO:BGN:INIT GW,CP=RNNG--Q-,VER=2.2.0-beta
    mysgw: TSF:LRT:OK
    mysgw: TSM:INIT
    mysgw: TSF:WUR:MS=0
    mysgw: TSM:INIT:TSP OK
    mysgw: TSM:INIT:GW MODE
    mysgw: TSM:READY:ID=0,PAR=0,DIS=0
    mysgw: MCO:REG:NOT NEEDED
    mysgw: MCO:BGN:STP
    mysgw: MCO:BGN:INIT OK,TSP=1
    mysgw: Attempting MQTT connection...
    mysgw: connected to 127.0.0.1
    mysgw: MQTT connected
    mysgw: Sending message on topic: mysensors-out/0/255/0/0/18
    mysgw: TSF:SAN:OK
    

    Perfect. "sudo make install", enable service and start it. I move over to the sensor with the arduino and load the attached (though much pared down) sketch.

    // Enable debug print
    #define MY_DEBUG
    #define DEBUG_ON   // comment out to supress serial monitor output
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    //#define MY_NODE_ID 1  // Set this to fix your Radio ID or use Auto
    
    #include <Wire.h>
    #include <Timezone.h>
    #include <TimeLib.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <LiquidCrystal.h>
    #include <LiquidCrystal_I2C.h>
    
    #define NUMBER_OF_PROGRAMS 2 //no idea if there is enough memory to store these.
    #define NUMBER_OF_VALVES 15  // Change this to set your valve count up to 16. I use one of my 16 relays to control the pump start relay for my system, which comes on anytime any of the valves is activated.
    #define TOTAL_SENSORS NUMBER_OF_PROGRAMS+NUMBER_OF_VALVES+1 
    #define VALVE_RESET_TIME 7500UL   // Change this (in milliseconds) for the time you need your valves to hydraulically reset and change state
    #define PROGRAM_ZONE_NAMES_RELOAD 1200000UL  // Change this (in milliseconds) for how often to update all valves data from the controller (Loops at value/(number of programs + number of valves)) 1200000=10mins
                                         // ie: 1200000 for 15 valves+all zones + 2 programs produces requests 66.6666 seconds with all valves updated every 20mins 
    #define VALVE_ON 1
    #define VALVE_OFF 0
    
    //Assign Pins
    #define ledPin 5
    #define menuButtonPin 3
    
    //Shift Register Pins
    #define latchPin 8
    #define clockPin 4
    #define dataPin  7
    #define outputEnablePin 6
    
    #define MAX_LCD_CHARS 20
    #define MAX_LCD_LINES 4
    
    #define DEBOUNCE_DELAY 200
    
    #define SKETCH_NAME "MySprinkler Beta"
    #define SKETCH_VERSION "0.1"
    
    #define CHILD_ID_SPRINKLER 0
    
    #define BITSHIFT_VALVE_NUMBER ~((1U << (valveNumber))+1) //this was adjusted because of the need for the main valve relay, which is the 1st 
    #define ALL_VALVES_OFF 0xFFFF //all high, for active low relays 
    //
    #ifdef DEBUG_ON
    #define DEBUG_PRINT(x)   Serial.print(x)
    #define DEBUG_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_PRINT(x)
    #define DEBUG_PRINTLN(x)
    #define SERIAL_START(x)
    #endif
    
    typedef enum {
      STANDBY_ALL_OFF, RUN_SINGLE_ZONE, RUN_ALL_ZONES, RUN_PROGRAM, CYCLE_COMPLETE, ACTION_SELECT_MENU
    } SprinklerStates;
    SprinklerStates state = STANDBY_ALL_OFF;
    SprinklerStates lastState, lastStateRun;
    
    bool receivedInitialValue = false;
    bool inSetup = true;
    byte currentValveProgramUpdating = 0;
    byte menuState = 0;
    byte valveNumber;
    byte requestedProgram;
    byte lastValve;
    bool buttonPushed = false;
    char *programNames[] = {"Program A", "Program B"}; //default program names
    char *zoneNames[] = {"Zone 1", "Zone 2", "Zone 3", "Zone 4", "Zone 5", "Zone 6", "Zone 7", "Zone 8", "Zone 9", "Zone 10", "Zone 11", "Zone 12", "Zone 13", "Zone 14", "Zone 15", "All Zones"};
    byte programValveRunTimes[NUMBER_OF_VALVES] = {0};
    char lcdBuffer[21];
    byte lastMenuState = -1;
    
    //time variables
    unsigned long menuTimer;
    byte countDownTime = 10;
    time_t startMillis, nowMillis; //used to store zone run start time
    time_t lastTimeRun;
    bool clockUpdating = false;
    bool recentUpdate = true;
    int totalTimeRun, customRunTime = 0;
    const char *dayOfWeek[] = {
      "Null", "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "
    };
    
    MyMessage msg1valve(CHILD_ID_SPRINKLER, V_STATUS); //updated from V_LIGHT to V_STATUS, same function
    
    // Set the pins on the I2C chip used for LCD connections:
    //                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address to 0x27
    
    void setup(){
      //Presentation  
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      /*
       * First sensors are for individual zones up to NUMBER_OF_VALVES
       * Next sensor after NUMBER_OF_VALVES is for All Zones
       * Any Sensors after all zones are for programs
       */
      for (byte i = 0; i <= NUMBER_OF_PROGRAMS + NUMBER_OF_VALVES; i++){
        present(i, S_CUSTOM);
      }
    }
    

    I'll omit the remainder of the code, as I don't THINK it's important for this issue (correct me if I'm wrong) and I don't want to make you guys waste your time crawling through a lot of unnecessaries. Here is the output that I get from the serial monitor. The gateway/controller is running about 2 ft away from the node.

    0 MCO:BGN:INIT NODE,CP=RNNNA---,VER=2.2.0-beta
    4 TSM:INIT
    5 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSM:FPAR
    15 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2023 !TSM:FPAR:NO REPLY
    2025 TSM:FPAR
    2027 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4035 !TSM:FPAR:NO REPLY
    4037 TSM:FPAR
    4039 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6047 !TSM:FPAR:NO REPLY
    6049 TSM:FPAR
    6051 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8060 !TSM:FPAR:FAIL
    8061 TSM:FAIL:CNT=1
    8064 TSM:FAIL:DIS
    8066 TSF:TDI:TSL
    18068 TSM:FAIL:RE-INIT
    18070 TSM:INIT
    18077 TSM:INIT:TSP OK
    18079 TSM:FPAR
    18081 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    20089 !TSM:FPAR:NO REPLY
    20091 TSM:FPAR
    20093 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    22102 !TSM:FPAR:NO REPLY
    22104 TSM:FPAR
    22106 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    24114 !TSM:FPAR:NO REPLY
    24116 TSM:FPAR
    24118 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    26126 !TSM:FPAR:FAIL
    26127 TSM:FAIL:CNT=2
    26129 TSM:FAIL:DIS
    26131 TSF:TDI:TSL
    

    And on and on and on. Any ideas why I can't get this to connect to the parent? I had no problem with this part using the basic ethernet (non-mqtt) build. Thanks for looking! Yay first post.



  • Forgot to mention:
    I'm using an Arduino Nano.
    I'm using the development branch for MySensors Arduino library
    1.8.3 Arduino IDE
    The nrf module on the Pi is regulated using one of these:
    http://www.ebay.com/itm/5Pcs-DC-DC-4-5V-7V-to-3-3V-AMS1117-3-3V-Power-Supply-Module-Volt-Regulator-N24/401258780242?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649
    modulated to 3.3V. These come equipped with SMD capacitors, so didn't think there would be a need for an electrolytic one as well.
    The nrf on the Arduino gets power from the 3v3 out and has a 104 ceramic cap on the power and ground.

    Can't think of any other important details for now..


  • Hardware Contributor

    These come equipped with SMD capacitors, so didn't think there would be a need for an electrolytic one as well.

    @Ethan-Kalebaugh - NO REPLY indicates the radios can not find eachother or find the route to eachother. I would never skip the 4.7uF capacitor on the nrf module even though I have a 0.1 and 10uF cap helping the voltage regulator.



  • Alright I've soldered a 4.7uf cap across each nrf power and ground, but I am still getting the exact same behavior. Any more suggestions?


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts