Missing data for some sensors when define MY_DEBUG is disabled [SOLVED]



  • Hello,

    I noticed that when I remove define MY_DEBUG from Passive node sketch data for some node sensors are not send/received.

    This is sketch I am using and only line I am changing is line 30.

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - tekka
     *
     * DESCRIPTION
     * Passive node example: This is a passive & independent reporting node
     *
     */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable passive mode
    #define MY_PASSIVE_NODE
    
    // Passive mode requires static node ID
    #define MY_NODE_ID 100
    
    // Enable and select radio type attached
    //#define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    #define MY_RADIO_RFM95
    
    #define MY_DEBUG_VERBOSE_RFM95
    #define MY_RFM95_FREQUENCY (RFM95_868MHZ)
    //#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW31_25CR48SF512
    #define MY_RFM95_CS_PIN 8
    #define MY_RFM95_IRQ_PIN 2
    
    #include <MySensors.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <Adafruit_Sensor.h>
    #include "Adafruit_BME680.h"
    
    #define BME_SCK 13
    #define BME_MISO 12
    #define BME_MOSI 11
    #define BME_CS 10
    
    #define SEALEVELPRESSURE_HPA (1013.25)
    
    // Initialize general message
    MyMessage msgTemp( 1, V_TEMP );
    MyMessage msgPres( 2, V_PRESSURE );
    MyMessage msgHumi( 3, V_HUM );
    MyMessage msgPosi( 4, V_POSITION );
    
    //Adafruit_BME680 bme; // I2C
    Adafruit_BME680 bme(BME_CS); // hardware SPI
    //Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);
    
    void setup()
    {
    
      if (!bme.begin()) {
        Serial.println("Could not find a valid BME680 sensor, check wiring!");
        while (1);
      }
      // Set up oversampling and filter initialization
      bme.setTemperatureOversampling(BME680_OS_8X);
      bme.setPressureOversampling(BME680_OS_4X);
      bme.setHumidityOversampling(BME680_OS_2X);
      bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
      //bme.setGasHeater(320, 150); // 320*C for 150 ms
    
      delay(2000);
      
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and controller
    	sendSketchInfo("Passive node", "1.0");
    
    	// Register all sensors to gw (they will be created as child devices)
    	present( 1, S_TEMP );
      present( 2, S_BARO );
      present( 3, S_HUM );
      present( 4, S_GPS );
    }
    
    void loop()
    {
    	// generate some random data
    	//send(msg.set(25.0+random(0,30)/10.0,2));
    
      if (! bme.performReading()) {
        Serial.println("Failed to perform reading :(");
        return;
      }
      
      float temp = bme.temperature; //C
      send(msgTemp.set(temp,2));
    
      float pres = bme.pressure/100.00; //hPa
      send(msgPres.set(pres,2));
    
      float humi = bme.humidity; //%
      send(msgHumi.set(humi,2));
    
      float alti = bme.readAltitude(SEALEVELPRESSURE_HPA);
      send(msgPosi.set(alti,2));
        
    /*
      Serial.print("Pressure = ");
      Serial.print(bme.pressure / 100.0);
      Serial.println(" hPa");
    
      Serial.print("Humidity = ");
      Serial.print(bme.humidity);
      Serial.println(" %");
    
      Serial.print("Gas = ");
      Serial.print(bme.gas_resistance / 1000.0);
      Serial.println(" KOhms");
    
      Serial.print("Approx. Altitude = ");
      Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      Serial.println(" m");
      */
      
    	sleep(10000);
    }
    

    When define MY_DEBUG is UNcommented. Everything works as expected - I receive data for all 4 sensors in MQTT broker.

    13:20:30.390 ->  
    13:20:30.390 ->  __  __       ____
    13:20:30.390 -> |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    13:20:30.390 -> | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    13:20:30.390 -> | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    13:20:30.390 -> |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
    13:20:30.390 ->         |___/                      2.3.2
    13:20:30.424 -> 
    13:20:30.424 -> 16 MCO:BGN:INIT NODE,CP=RLNPA---,FQ=8,REL=255,VER=2.3.2
    13:20:30.424 -> 28 TSM:INIT
    13:20:30.424 -> 28 TSF:WUR:MS=0
    13:20:30.424 -> 30 RFM95:INIT
    13:20:30.424 -> 32 RFM95:INIT:PIN,CS=8,IQP=2,IQN=0
    13:20:30.424 -> 47 RFM95:PTX:LEVEL=13
    13:20:30.424 -> 49 TSM:INIT:TSP OK
    13:20:30.424 -> 51 TSM:INIT:TSP PSM
    13:20:30.424 -> 53 TSM:INIT:STATID=100
    13:20:30.424 -> 55 TSF:SID:OK,ID=100
    13:20:30.457 -> 57 TSM:FPAR
    13:20:30.457 -> 59 TSM:FPAR:STATP=255
    13:20:30.457 -> 61 TSM:ID
    13:20:30.457 -> 61 TSM:ID:OK
    13:20:30.457 -> 63 TSM:UPL:DISABLED
    13:20:30.457 -> 65 TSM:READY:ID=100,PAR=255,DIS=1
    13:20:30.457 -> 69 RFM95:SWR:SEND,TO=255,SEQ=0,RETRY=0
    13:20:30.523 -> 122 ?TSF:MSG:SEND,100-100-255-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    13:20:30.590 -> 184 RFM95:SAC:SEND ACK,TO=0,SEQ=243,RSSI=-64,SNR=9
    13:20:30.623 -> 233 TSF:MSG:READ,0-0-100,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    13:20:30.623 -> 241 RFM95:SWR:SEND,TO=255,SEQ=2,RETRY=0
    13:20:30.689 -> 299 ?TSF:MSG:SEND,100-100-255-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
    13:20:30.689 -> 307 RFM95:SWR:SEND,TO=255,SEQ=3,RETRY=0
    13:20:30.756 -> 360 ?TSF:MSG:SEND,100-100-255-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:255
    13:20:32.779 -> 2369 RFM95:SWR:SEND,TO=255,SEQ=4,RETRY=0
    13:20:32.849 -> 2437 ?TSF:MSG:SEND,100-100-255-0,s=255,c=3,t=11,pt=0,l=12,sg=0,ft=0,st=OK:Passive node
    13:20:32.849 -> 2447 RFM95:SWR:SEND,TO=255,SEQ=5,RETRY=0
    13:20:32.915 -> 2504 ?TSF:MSG:SEND,100-100-255-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
    13:20:32.915 -> 2512 RFM95:SWR:SEND,TO=255,SEQ=6,RETRY=0
    13:20:32.981 -> 2566 ?TSF:MSG:SEND,100-100-255-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
    13:20:32.981 -> 2574 RFM95:SWR:SEND,TO=255,SEQ=7,RETRY=0
    13:20:33.014 -> 2627 ?TSF:MSG:SEND,100-100-255-0,s=2,c=0,t=8,pt=0,l=0,sg=0,ft=0,st=OK:
    13:20:33.014 -> 2635 RFM95:SWR:SEND,TO=255,SEQ=8,RETRY=0
    13:20:33.081 -> 2686 ?TSF:MSG:SEND,100-100-255-0,s=3,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    13:20:33.081 -> 2695 RFM95:SWR:SEND,TO=255,SEQ=9,RETRY=0
    13:20:33.147 -> 2748 ?TSF:MSG:SEND,100-100-255-0,s=4,c=0,t=38,pt=0,l=0,sg=0,ft=0,st=OK:
    13:20:33.147 -> 2756 MCO:REG:NOT NEEDED
    13:20:33.147 -> 2758 MCO:BGN:STP
    13:20:35.170 -> 4773 MCO:BGN:INIT OK,TSP=1
    13:20:35.535 -> 5144 RFM95:SWR:SEND,TO=255,SEQ=10,RETRY=0
    13:20:35.601 -> 5203 ?TSF:MSG:SEND,100-100-255-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:21.32
    13:20:35.601 -> 5212 RFM95:SWR:SEND,TO=255,SEQ=11,RETRY=0
    13:20:35.667 -> 5271 ?TSF:MSG:SEND,100-100-255-0,s=2,c=1,t=4,pt=7,l=5,sg=0,ft=0,st=OK:947.89
    13:20:35.701 -> 5279 RFM95:SWR:SEND,TO=255,SEQ=12,RETRY=0
    13:20:35.734 -> 5337 ?TSF:MSG:SEND,100-100-255-0,s=3,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:56.07
    13:20:36.132 -> 5715 RFM95:SWR:SEND,TO=255,SEQ=13,RETRY=0
    13:20:36.198 -> 5775 ?TSF:MSG:SEND,100-100-255-0,s=4,c=1,t=49,pt=7,l=5,sg=0,ft=0,st=OK:558.78
    13:20:36.198 -> 5783 MCO:SLP:MS=10000,SMS=0,I1=255,M1=255,I2=255,M2=255
    13:20:36.198 -> 5789 TSF:TDI:TSL
    13:20:36.198 -> 5791 RFM95:RSL
    
    mosquitto_sub -v -h 192.168.1.227 -t "868-out/#"
    868-out/100/1/1/0/0 21.50
    868-out/100/2/1/0/4 947.91
    868-out/100/3/1/0/1 55.92
    868-out/100/4/1/0/49 558.78
    868-out/100/255/0/0/17 2.3.2
    868-out/100/255/3/0/6 255
    868-out/100/255/3/0/11 Passive node
    868-out/100/255/3/0/12 1.0
    868-out/100/1/0/0/6 (null)
    868-out/100/2/0/0/8 (null)
    868-out/100/3/0/0/7 (null)
    868-out/100/4/0/0/38 (null)
    868-out/100/1/1/0/0 21.32
    868-out/100/2/1/0/4 947.89
    868-out/100/3/1/0/1 56.07
    868-out/100/4/1/0/49 558.78
    868-out/100/1/1/0/0 21.38
    868-out/100/2/1/0/4 947.89
    868-out/100/3/1/0/1 56.10
    868-out/100/4/1/0/49 558.78
    

    When comment OUT line 30 as //define MY_DEBUG - I only receive data for some sensors - I am missing data for sensor id 2.

    13:22:04.062 ->  
    13:22:04.062 ->  __  __       ____
    13:22:04.062 -> |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    13:22:04.062 -> | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    13:22:04.095 -> | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    13:22:04.095 -> |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
    13:22:04.095 ->         |___/                      2.3.2
    13:22:04.095 -> 
    13:22:04.095 -> 16 RFM95:INIT
    13:22:04.095 -> 24 RFM95:INIT:PIN,CS=8,IQP=2,IQN=0
    13:22:04.128 -> 38 RFM95:PTX:LEVEL=13
    13:22:04.128 -> 40 RFM95:SWR:SEND,TO=255,SEQ=0,RETRY=0
    13:22:04.228 -> 157 RFM95:SAC:SEND ACK,TO=0,SEQ=244,RSSI=-65,SNR=12
    13:22:04.294 -> 206 RFM95:SWR:SEND,TO=255,SEQ=2,RETRY=0
    13:22:04.327 -> 264 RFM95:SWR:SEND,TO=255,SEQ=3,RETRY=0
    13:22:06.384 -> 2318 RFM95:SWR:SEND,TO=255,SEQ=4,RETRY=0
    13:22:06.483 -> 2385 RFM95:SWR:SEND,TO=255,SEQ=5,RETRY=0
    13:22:06.517 -> 2443 RFM95:SWR:SEND,TO=255,SEQ=6,RETRY=0
    13:22:06.583 -> 2496 RFM95:SWR:SEND,TO=255,SEQ=7,RETRY=0
    13:22:06.649 -> 2549 RFM95:SWR:SEND,TO=255,SEQ=8,RETRY=0
    13:22:06.682 -> 2603 RFM95:SWR:SEND,TO=255,SEQ=9,RETRY=0
    13:22:09.136 -> 5038 RFM95:SWR:SEND,TO=255,SEQ=10,RETRY=0
    13:22:09.202 -> 5095 RFM95:SWR:SEND,TO=255,SEQ=11,RETRY=0
    13:22:09.235 -> 5154 RFM95:SWR:SEND,TO=255,SEQ=12,RETRY=0
    13:22:09.667 -> 5582 RFM95:SWR:SEND,TO=255,SEQ=13,RETRY=0
    13:22:09.733 -> 5640 RFM95:RSL
    
    mosquitto_sub -v -h 192.168.1.227 -t "868-out/#"
    868-out/100/255/0/0/17 2.3.2
    868-out/100/255/3/0/11 Passive node
    868-out/100/1/0/0/6 (null)
    868-out/100/3/0/0/7 (null)
    868-out/100/1/1/0/0 21.39
    868-out/100/3/1/0/1 56.28
    868-out/100/4/1/0/49 559.49
    868-out/100/1/1/0/0 21.45
    868-out/100/3/1/0/1 56.22
    868-out/100/4/1/0/49 559.31
    

    Am I doing something wrong?


  • Mod

    @tssk try adding a wait(100); before each send.
    Sending multiple messages in quick succession can strain the power supply. Waiting a bit lets the power supply recover.

    If that works, you can experiment with adding capacitors to help the power supply. You can also experiment with how long the device needs to wait to have reliable communication, and you can see if sleep() instead of wait() works (to potentially save power but it could be that a quick sleep + wakeup uses more power than just using wait).



  • @mfalkvidd Thanks adding wait like this helped!

    float temp = bme.temperature; //C
    wait(100);
    send(msgTemp.set(temp,2));
    

    But the node is currently powered from the USB cable from computer using USBtoTTL. How this could "stress" the power supply? USB2TTL->ARDUINO VCC->SX1276


  • Mod

    Nice work @tssk

    Drawing power stresses the power supply. The radio draws power when it is sending.



  • @mfalkvidd Sorry for the stupid question - I would understand that for battery but I thought computer as power supply is "strong" enough...?


  • Mod

    @tssk there are multiple components between the computer's USB power and the radio. The USB cable and the regulator on the Arduino are the main ones. So even if the computer can deliver stable power (which it might not), the power might not be stable when it reaches the radio.

    We're talking very quick fluctuations - obviously less than 1/10 of a second since the 100 millisecond wait helps. There is no way you can see those changes on a voltmeter. But if you hook up an oscilloscope you could probably see what is going on.



  • @mfalkvidd OK, oscilloscope is out of my electronics skills league 🙂 But thank you very much for the explanation!



  • @mfalkvidd In addition, since the later sensors are seeing it, it's probably just that the power supply is drooping before the voltage regulation on it can catch up. They kind of have 'inertia' and can take a bit to respond, and of course every power supply is different, based on how it's built.

    So likely the capacitors are helping it ride through the first transmission, and then the power supply 'catches up' for the later ones, but the second one gets garbled with the lower power, and the receiving radio chucks it as a bad packet.


Log in to reply
 

Suggested Topics

154
Online

9.7k
Users

10.3k
Topics

106.5k
Posts