[SOLVED] RFM95 Node with gateway no parents found (But looks like messages are being sent)



  • Hello MySensor Friends!

    I got myself a new challange. Wiring up an RFM95 gateway so I can reflash my buggy LORA Soil Sensors with RFM95 radio's and put it to work in my trusty MySensors environment.

    Everything is being built with the latest Mysensor branch (2.3.2).

    Gateway Sketch is straight forward, just like the Node sketch.

    Now what is the problem. The Node sends out a parent request (PARENT_REQUEST) The gateway even responds to this request (To Node ID). But the node is not getting that message at all. It looks like there is one way traffic. Or None.

    What did I do?

    On the gateway I enabled the following options (extra)

    #define MY_RADIO_RFM95
    #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
    #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
    #define MY_RFM95_ATC_MODE_DISABLED
    #define MY_RFM95_TX_POWER_DBM (13)
    #define MY_TRANSPORT_STATE_TIMEOUT_MS (3*1000ul)
    #define RFM95_RETRY_TIMEOUT_MS (5000ul)
    #define MY_DEBUG_VERBOSE_RFM95
    
    

    And on the node I did the following

    #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
    #define MY_TRANSPORT_STATE_TIMEOUT_MS (3*1000ul)
    #define RFM95_RETRY_TIMEOUT_MS (5000ul)
    #define MY_DEBUG_VERBOSE_RFM95
    

    If I collect al the different logs and put them in the Log Parser I can see that the Node request is recieved by the gateway. The gateway then send a response. But the node is not getting it.

    I'm out of ideas. Moved the node arround the house. Looked at the schematics.
    It is a busy spectrum here at 868mhz. I still have an RFM69 mysensors gateway, a lora gateway and Z-Wave all fighting over 868mhz.

    The stuff I'm using
    Gateway:
    A Wemos D1 Mini with an RFM Shield from Diycon (https://diycon.nl/product/d1-rfm-shield-pcb301-for-rfm-and-wemos-d1/) I soldered an extra 10 uF capacitator on the shield for stable 3.3 volts

    Node
    A Makerfab soil sensor with RFM95 radio (v2) (https://www.makerfabs.com/lora-soil-moisture-sensor-v2.html)

    If anybode has an idea. Please let me know.

    Complete Sketches:

    Node

    #include <Arduino.h>
    #include <AHT10.h>
    
    #define MY_DEBUG
    
    
    //Batterij
    const int BatHighValue = 3050;   //you need to replace this value with Value_1
    const int BatLowValue = 2650;  //you need to replace this value with Value_2
    
    int batterypercent=0;
    int batterypercentage=0;
    
    
    
    // sensors pin mapping
    int sensorPin = A2;         // select the input pin for the potentiometer
    int sensorPowerCtrlPin = 5; // select control pin for switching VCC (sensors)
    
    uint8_t readStatus = 0;
    
    AHT10             myAHT10(AHT10_ADDRESS_0X38);
    
    // Enable and select radio type attached
    #define MY_RADIO_RFM95
    #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
    #define MY_RFM95_IRQ_PIN 2
    #define MY_RFM95_CS_PIN 10
    #define MY_RFM95_RST_PIN 4
    #define MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
    #define MY_TRANSPORT_STATE_TIMEOUT_MS (3*1000ul)
    #define RFM95_RETRY_TIMEOUT_MS (5000ul)
    #define MY_DEBUG_VERBOSE_RFM95
    #define MY_SOFT_SPI_SCK_PIN 13
    #define MY_SOFT_SPI_MISO_PIN 12
    #define MY_SOFT_SPI_MOSI_PIN 11
    
    // AANPASSEN ANDERS DIKKE PROBLEMEN!!
    #define MY_NODE_ID 100
    //#define MY_PARENT_NODE_ID 0
    //#define MY_PARENT_NODE_IS_STATIC
    
    #define MY_BAUD_RATE 115200
    
    #define MY_SPLASH_SCREEN_DISABLED //Spaart 120 bytes uit
    
    
    
    #define MY_SMART_SLEEP_WAIT_DURATION_MS 120000
    
    
    #include <MySensors.h>
    
    
    #define TEMP_CHILD 1
    #define HUM_CHILD 2
    #define SOIL_CHILD 3
    
    MyMessage tempMsg(TEMP_CHILD, V_TEMP);
    MyMessage humMsg(HUM_CHILD, V_HUM);
    MyMessage soilMsg(SOIL_CHILD, V_LEVEL);
    
    float lastSoil = -1;
    float lastHum = -1;
    float lastTemp = -1;
    
    
    
    uint32_t SLEEP_TIME = 900000;  // sleep time between reads (seconds * 1000 milliseconds)
    
    int oldbatterypercentage = 0;
    
    float   temperature=0.0;        //temperature
    float   humidity=0.0;           //humidity
    int     soilmoisturepercent=0;  //spoil moisture humidity
    int     AirValue = 850;         //capacitive sensor in the value (maximum value)
    int     WaterValue = 520;       //capacitive sensor in water value (minimum value)
    int     sensorValue = 0;        //capacitive sensor
    int     x = 0;
    
    
    // switch VCC on (sensors on)
    void sensorPowerOn(void)
    {
      digitalWrite(sensorPowerCtrlPin, HIGH);//Sensor power on 
    }
    
    // switch VCC off (sensor off)
    void sensorPowerOff(void)
    {
      digitalWrite(sensorPowerCtrlPin, LOW);//Sensor power on 
    }
    
    
    void setup()
    {
    #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
    #else
      analogReference(INTERNAL);
    #endif
    /* AHT10 connection check */
      while (myAHT10.begin() != true)
      {
        Serial.print("AHT10 not connected or fail to load calibration coefficient");
        delay(5000);
      }
    
    }
    
    void presentation()
    {
    	sendSketchInfo("Soilsensor01", "HNSSV2-1.0");
    	present(TEMP_CHILD, S_TEMP);
      present(HUM_CHILD, S_HUM);
      present(SOIL_CHILD, S_MOISTURE);
    }
    
    void loop()
    {
    
    
        // read capacitive sensor value
        sensorPowerOn();//
        wait(100);
        sensorValue = analogRead(sensorPin);
        wait(200);
    
    readStatus = myAHT10.readRawData(); 
    
    if (readStatus != AHT10_ERROR)
      {
        temperature = myAHT10.readTemperature(AHT10_USE_READ_DATA);
        humidity = myAHT10.readHumidity(AHT10_USE_READ_DATA);
      }
      else
      {
        Serial.print("i2c error");
      } 
    
    soilmoisturepercent = map(sensorValue, AirValue, WaterValue, 0, 100);
        if(soilmoisturepercent >= 100)
        {
         soilmoisturepercent=100;
        }
        else if(soilmoisturepercent <=0)
        {
          soilmoisturepercent=0;
        }
    
    // measure voltage by band gap voltage
      unsigned int getVDD = 0;
    
      
      // set the reference to Vcc and the measurement to the internal 1.1V reference
      while (((getVDD == 0)&&(x<=10)) ||  isnan(getVDD)){
      x++;
      ADMUX = (1<<REFS0) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1);
      delay(50);                        // Wait for Vref to settle
      ADCSRA |= (1<<ADSC);              // Start conversion
      while (bit_is_set(ADCSRA,ADSC));  // wait until done
      getVDD = ADC;                     // Vcc in millivolts
      // mcu dependend calibration
      }
      getVDD = 1122475UL / (unsigned long)getVDD; //1126400 = 1.1*1024*1000
    
      batterypercent = map(getVDD, BatLowValue, BatHighValue, 0, 100);
                if(batterypercent >= 100)
                {
                batterypercentage = 100;
                }
                else if(batterypercent <=0)
                {
                batterypercentage = 0;
                }
                else if(batterypercent >0 && batterypercent < 100)
                {
                batterypercentage = batterypercent;
                }
      
    
    #ifdef MY_DEBUG
    
      Serial.print("Battery percent: ");
      Serial.print(batterypercentage);
      Serial.println(" %");
    #endif
    
      
      if (lastTemp != temperature) {
        send(tempMsg.set(temperature, 1));
        lastTemp = temperature;
      }
    
        if (lastHum != humidity) {
        send(humMsg.set(humidity, 1));
        lastHum = humidity;
      }
    
        if (lastSoil != soilmoisturepercent) {
        send(soilMsg.set(soilmoisturepercent, 1));
        lastSoil = soilmoisturepercent;
      }
    
      if (oldbatterypercentage != batterypercentage) {
        sendBatteryLevel(batterypercentage);
        oldbatterypercentage = batterypercentage;
      }
    
      Serial.print(F(" Nu Slapen "));
        sensorPowerOff();
        wait(100);
      smartSleep(SLEEP_TIME);
    }
    

    Gateway

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 115200
    
    //Nieuw
    #define MY_RADIO_RFM95
    #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
    #define MY_RFM95_IRQ_PIN D1 //DIO0
    #define MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    #define MY_RFM95_CS_PIN D8 // NSS
    #define MY_DEBUG_VERBOSE_RFM95
    #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128
    #define RFM95_RETRY_TIMEOUT_MS  (3000ul)
    #define MY_RFM95_ATC_MODE_DISABLED
    #define MY_RFM95_TX_POWER_DBM (13)
    #define MY_TRANSPORT_STATE_TIMEOUT_MS (3*1000ul)
    #define RFM95_RETRY_TIMEOUT_MS (5000ul)
    #define MY_SOFT_SPI_SCK_PIN D5
    #define MY_SOFT_SPI_MISO_PIN D6
    #define MY_SOFT_SPI_MOSI_PIN D7
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mysensors02-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mysensors02-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "removed"
    
    // Enable these if your MQTT broker requires username/password
    #define MY_MQTT_USER "removed"
    #define MY_MQTT_PASSWORD "removed"
    
    // Set WIFI SSID and password
    #define MY_WIFI_SSID "removed"
    #define MY_WIFI_PASSWORD "removed"
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    #define MY_HOSTNAME "removed"
    // MQTT broker ip address.
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 7
    
    //MQTT broker if using URL instead of ip address.
    //#define MY_CONTROLLER_URL_ADDRESS "removed"
    
    // The MQTT broker port to to open
    #define MY_PORT 1883
    
    
    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    #define MY_DEFAULT_ERR_LED_PIN D0  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  D4  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  D4  // the PCB, on board LED
    
    #include <ESP8266WiFi.h>
    #include <MySensors.h>
    
    void setup()
    {
    	// Setup locally attached sensors
    }
    
    void presentation()
    {
    	// Present locally attached sensors here
    }
    
    void loop()
    {
    	// Send locally attached sensors data here
    }
    


  • Shouldn't this define

    #define MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    

    Be

    #define MY_RFM95_IRQ_NUM digitalPinToInterrupt(MY_RFM95_IRQ_PIN)
    

    Now the interrupt isn't handled and the received message isn't noticed.



  • @electrik OMG, this was a quick fix! It runs very good.

    Thank you all for the help als reading. Very nice!


  • Mod

    @VonJoost Do you have any recollection of where you got the code from (assuming it is something you copied and pasted)? I double-checked the MySensors documentation (link) and it looks good. If there is bad code somewhere, I would like to try to get it corrected.



  • @mfalkvidd It was code from my ESP RFM69 gateway. Runs on NodeMCUV3. But that works perfect. But I may reflash that one with the good define code.

    But the example in your link seems wrong.

    #define MY_RFM95_IRQ_PIN DEFAULT_RFM95_IRQ_PIN
    

    Should be

    #define MY_RFM95_IRQ_NUM digitalPinToInterrupt(MY_RFM95_IRQ_PIN)
    

    To make it working on an ESP8266 Wemos D1 Mini with RFM95 radio.


  • Mod

    @VonJoost are you sure? One defines the irq pin, the other defines the irq number?



  • @mfalkvidd Yes you are correct. The point was that digitalPinToInterrupt(MY_RFM95_IRQ_PIN) makes everything works on the D1. Leaving digitalPinToInterrupt() out will break the gateway.


  • Mod

    @VonJoost Yes, naturally. Bad code will result in bad result.

    I'm trying to understand where the bad code came from.


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts