Very strange bugs. 2.3. RFM69.


  • Contest Winner

    Today I've tried to solve very simple task using my nodes. I've tried to use new 2.3 core. Unfortunately I bumped with very strange bugs and put off my task to investigate mysensors behaviour a little. I think I bumped with big software problems and I try to described it very detailed.

    Network topology is very simple. I tried two variants:

    1. Vell tested PIR node + basic RFM serial gateway.
    2. Pir node (exactly the same board) + basic ESP8266 to MQTT gateway.
      Nodes uses RFM69 868Mhz radio. I'm sure hardware works propery.

    I used basic mysensors configuration without any changes (I've downloaded it today to the clear virtual machine).

    Code of the SERIAL gateway:

    /**
    * 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-2015 Sensnology AB
    * Full contributor list: https://github.com/mysensors/Arduino/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.
    *
    *******************************
    *
    * DESCRIPTION
    * The ArduinoGateway prints data received from sensors on the serial link.
    * The gateway accepts input on serial which will be sent out on radio network.
    *
    * The GW code is designed for Arduino Nano 328p / 16MHz
    *
    * Wire connections (OPTIONAL):
    * - Inclusion button should be connected between digital pin 3 and GND
    * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
    *
    * LEDs (OPTIONAL):
    * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs
    * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
    * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
    * - ERR (red) - fast blink on error during transmission error or receive crc error
    *
    */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_NRF5_ESB
    #define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level.
    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    #define MY_RFM69_FREQUENCY RFM69_868MHZ
    //#define MY_RFM69_FREQUENCY RFM69_433MHZ
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    #if F_CPU == 8000000L
    #define MY_BAUD_RATE 38400
    #endif
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Inverses the behavior of leds
    //#define MY_WITH_LEDS_BLINKING_INVERSE
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <MySensors.h>
    
    void setup()
    {
    	// Setup locally attached sensors
    }
    
    void presentation()
    {
    	// Present locally attached sensors
    }
    
    void loop()
    {
    	// Send locally attached sensor data here
    }
    

    Code of the ESP8266 MQTT gateway

    /**
     * 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-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/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 - Henrik Ekblad
     *
     * DESCRIPTION
     * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
     * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
     *
     * LED purposes:
     * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs in your sketch
     * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or receive crc error
     *
     * See https://www.mysensors.org/build/connect_radio for wiring instructions.
     *
     * If you are using a "barebone" ESP8266, see
     * https://www.mysensors.org/build/esp8266_gateway#wiring-for-barebone-esp8266
     *
     * Inclusion mode button:
     * - Connect GPIO5 (=D1) via switch to GND ('inclusion switch')
     *
     * Hardware SHA204 signing is currently not supported!
     *
     * Make sure to fill in your ssid and WiFi password below for ssid & pass.
     */
    
    // 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 9600
    
    // Enables and select radio type (if attached)
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #define MY_RFM69_FREQUENCY RFM69_868MHZ  // Define for frequency setting. Needed if you're radio module isn't 868Mhz (868Mhz is default in lib)
    //#define MY_IS_RFM69HW  // Mandatory if you radio module is the high power version (RFM69HW and RFM69HCW), Comment it if it's not the case
    
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Enable these if your MQTT broker requires username/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    // Set WIFI SSID and password
    #define MY_WIFI_SSID "iceberg"
    #define MY_WIFI_PASSWORD "ochkarik"
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    // #define MY_HOSTNAME "mqtt-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192,168,178,87
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // MQTT broker ip address.
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 171
    
    //MQTT broker if using URL instead of ip address.
    // #define MY_CONTROLLER_URL_ADDRESS "test.mosquitto.org"
    
    // The MQTT broker port to to open
    #define MY_PORT 1883
    
    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN D1
    
    // Set blinking period
    //#define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  16  // 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
    }
    

    And code of the SENSOR NODE. Please pay attention to the //TEST STRING/. I've changed this value during tests. Also please pay attention - BH1750 level sends in any case without any conditionals.

    /**
     * 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-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/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.
     *
    **/
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    //#include <MemoryFree.h>
    #include <avr/wdt.h>
    #ifdef __AVR__
      #include <avr/power.h>
    #endif
    
    // Enable and select radio type attached
    #define MY_RADIO_RFM69
    //#define MY_RFM69_FREQUENCY   RFM69_433MHZ
    #define MY_RFM69_FREQUENCY   RFM69_868MHZ
    //#define MY_RFM69_NEW_DRIVER
    
    //#define MY_RADIO_NRF24
    
    // Comment it out for CW  version radio.
    //#define MY_IS_RFM69HW
    
    // Comment it out for Auto Node ID #
    #define MY_NODE_ID 0x90
    
    
    // Avoid battery drain if Gateway disconnected and the node sends more than MY_TRANSPORT_STATE_RETRIES times message.
    #define MY_TRANSPORT_UPLINK_CHECK_DISABLED
    #define MY_PARENT_NODE_IS_STATIC
    #define MY_PARENT_NODE_ID 0
    
    
    //Enable OTA feature
    #define MY_OTA_FIRMWARE_FEATURE
    #define MY_OTA_FLASH_JDECID 0x0//0x2020
    
    //Enable Crypto Authentication to secure the node
    //#define MY_SIGNING_ATSHA204
    //#define  MY_SIGNING_REQUEST_SIGNATURES
    
    #include <Wire.h>
    
    // Written by Christopher Laws, March, 2013.
    #include <BH1750.h>
    BH1750 lightMeter;
    
    #include "SparkFun_Si7021_Breakout_Library.h"
    //Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor
    Weather sensor;
    
    #include <MySensors.h>
    
    // Redefining write codes for JDEC FLASH used in the node
    // These two defines should always be after #include <MySensors.h> declaration
    #define SPIFLASH_BLOCKERASE_32K   0xD8
    #define SPIFLASH_CHIPERASE        0x60
    
    #include <stdlib.h>
    
    
    #define BUTTONS_INTERUPT_PIN 3
    #define RED_LED_PIN 6
    #define YELLOW_LED_PIN 5
    
    
    
    // Assign numbers for all sensors we will report to gateway\controller (they will be created as child devices)
    #define SW_sensor 1
    #define HUM_sensor 2
    #define TEMP_sensor 3
    #define VIS_sensor 4
    #define UV_sensor 5
    
    // Create MyMessage Instance for sending readins from sensors to gateway\controller (they will be created as child devices)
    
    MyMessage msg_sw(SW_sensor, V_LIGHT);
    MyMessage msg_hum(HUM_sensor, V_HUM);
    MyMessage msg_temp(TEMP_sensor, V_TEMP);
    MyMessage msg_vis(VIS_sensor, V_LEVEL);
    MyMessage msg_uv(UV_sensor, V_UV);
    
    unsigned long wdiDelay2  = 0;
    
    int BATTERY_SENSE_PIN = A6;  // select the input pin for the battery sense point
    
    
    
    static int32_t oldLux = 0, lux;
    static int16_t oldHumdty = 0, humdty;
    static int16_t oldTemp = 0, temp;
    
    void swarm_report()
    {
      static int oldBatteryPcnt = 0;
      char humiditySi7021[10];
      char tempSi7021[10];
      char visBH1750[10];
    
    
      lightMeter.begin(); // need for correct wake up
      lux = lightMeter.readLightLevel();// Get Lux value
      // dtostrf(); converts float into string
      long d = (long)(lux - oldLux);
      //Serial.print("abs(lux - oldLux)="); Serial.print(abs(d)); Serial.print(" lux ="); Serial.print(lux); Serial.print(" oldLux ="); Serial.println(oldLux); 
      dtostrf(lux,0,0,visBH1750);
      //if ( abs(d) > 50 ) send(msg_vis.set(visBH1750), true); // Send LIGHT BH1750     sensor readings
    
      send(msg_vis.set(visBH1750), true);
      
      oldLux = lux;
      wait(100);
    
      // Measure Relative Humidity from the Si7021
      humdty = sensor.getRH();
      dtostrf(humdty,0,2,humiditySi7021);  
      if (humdty != oldHumdty) send(msg_hum.set(humiditySi7021), true); // Send humiditySi7021     sensor readings
      oldHumdty = humdty; 
      wait(100);
      
      // Measure Temperature from the Si7021
      // Temperature is measured every time RH is requested.
      // It is faster, therefore, to read it from previous RH
      // measurement with getTemp() instead with readTemp()
      temp = sensor.getTemp();
      dtostrf(temp,0,2,tempSi7021);
      if (temp != oldTemp) send(msg_temp.set(tempSi7021), true); // Send tempSi7021 temp sensor readings
      oldTemp = temp;
      wait(100);
    
      // Get the battery Voltage
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      // 1M, 470K divider across battery and using internal ADC ref of 1.1V1
      // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      /* The MySensors Lib uses internal ADC ref of 1.1V which means analogRead of the pin connected to 470kOhms Battery Devider reaches  
       * 1023 when voltage on the divider is around 3.44 Volts. 2.5 volts is equal to 750. 2 volts is equal to 600. 
       * RFM 69 CW works stable up to 2 volts. Assume 2.5 V is 0% and 1023 is 100% battery charge    
       * RFM 69 HCW works stable up to 2.5 volts (sometimes it can work up to 2.0V). Assume 2.5 V is 0% and 1023 is 100% battery charge  
       * 3.3V ~ 1023
       * 3.0V ~ 900
       * 2.5V ~ 750 
       * 2.0V ~ 600
       */
    
    #ifdef  MY_IS_RFM69HW
      int batteryPcnt = (sensorValue - 750)  / 1.5;
    #else
      int batteryPcnt = (sensorValue - 600)  / 3;
    #endif
      
      batteryPcnt = batteryPcnt > 0 ? batteryPcnt:0; // Cut down negative values. Just in case the battery goes below 2V (2.5V) and the node still working. 
      batteryPcnt = batteryPcnt < 100 ? batteryPcnt:100; // Cut down more than "100%" values. In case of ADC fluctuations. 
    
      if (oldBatteryPcnt != batteryPcnt ) {
        sendBatteryLevel(batteryPcnt);
        wait(100);
        oldBatteryPcnt = batteryPcnt;
      }
    }
    
    void before() {
        //No need watch dog enabled in case of battery power.
        //wdt_enable(WDTO_4S);
        wdt_disable();
      
        
        noInterrupts();
        _flash.initialize();
        interrupts();
    
        #ifdef  MY_RADIO_RFM69
          /*  RFM reset pin is 9
           *  A manual reset of the RFM69HCW\CW is possible even for applications in which VDD cannot be physically disconnected.
           *  Pin RESET should be pulled high for a hundred microseconds, and then released. The user should then wait for 5 ms
           *  before using the module.
           */
          pinMode(9, OUTPUT);
          //reset RFM module
          digitalWrite(9, 1);
          delay(1);
          // set Pin 9 to high impedance
          pinMode(9, INPUT);
          delay(10);
        #endif
        
        pinMode(A2, INPUT);
        
        pinMode(RED_LED_PIN, OUTPUT);
        digitalWrite(RED_LED_PIN,0);
        pinMode(YELLOW_LED_PIN, OUTPUT);
        digitalWrite(YELLOW_LED_PIN,0);
    }
    
    void setup() {
    }
    
    void presentation() 
    {  
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("PIR node", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(SW_sensor, V_LIGHT);
      present(HUM_sensor, S_HUM);
      present(TEMP_sensor, S_TEMP);
      present(VIS_sensor, S_LIGHT_LEVEL);
    }
    
    unsigned long wdiDelay  = 0;
    
    void loop()
    {
      digitalWrite(RED_LED_PIN,1);
      wait(300);
      digitalWrite(RED_LED_PIN,0);
      
      noInterrupts();
      _flash.wakeup();
      interrupts();
      
      //No need watch dog in case of battery power.
      //wdt_reset();
    
    
      //If NACK received retry to send as many as uint8_t rty; times
      uint8_t rty=5;
      static boolean  value = false;
      if ( digitalRead(BUTTONS_INTERUPT_PIN) == HIGH )  while (!send(msg_sw.set(!value), true) && (rty > 0))  rty--;
    
      wait(100);  //TEST STRING/
    
      if (!rty) {
        for  (int i = 5;i;i--){
          // failure to get ACK from controller - 4 Blinks in Yellow
          digitalWrite(YELLOW_LED_PIN,1);
          wait(30);
          digitalWrite(YELLOW_LED_PIN,0);
          wait(30);
          }
        }
      
      value = !value;
      lightMeter.begin();
      swarm_report();      
      lightMeter.write8(BH1750_POWER_DOWN);
     
     // Go sleep for some milliseconds
      noInterrupts();
      _flash.sleep();
      interrupts();
      
      //sleep(180000);
      sleep(BUTTONS_INTERUPT_PIN - 2, RISING,0);  //, 300000
    }
    

    Now I will describe the scenarios and results with logs. In all cases log shows only ONE pir event. I repeated all tests many times and results was the same.

    //////////////////////////////////////////////////////////////////////////////////////////////////
    TEST STRING - wait (100ms)

    Node is connected to serial gateway:
    Node log:

    45551 MCO:SLP:WUP=1
    45555 TSF:TRI:TSB
    45864 TSF:MSG:SEND,144-144-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
    45899 TSF:MSG:READ,0-0-144,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    45905 TSF:MSG:ACK
    45953 TSF:MSG:SEND,144-144-0-0,s=4,c=1,t=37,pt=0,l=3,sg=0,ft=0,st=OK:174
    45989 TSF:MSG:READ,0-0-144,s=4,c=1,t=37,pt=0,l=3,sg=0:174
    45996 TSF:MSG:ACK
    46170 TSF:MSG:SEND,144-144-0-0,s=2,c=1,t=1,pt=0,l=5,sg=0,ft=0,st=OK:30.00
    46206 TSF:MSG:READ,0-0-144,s=2,c=1,t=1,pt=0,l=5,sg=0:30.00
    46213 TSF:MSG:ACK
    46479 MCO:SLP:MS=0,SMS=0,I1=1,M1=3,I2=255,M2=255
    46483 TSF:TDI:TSL
    

    Serial Gateway log:

    0;255;3;0;9;46831 TSF:MSG:READ,144-144-0,s=1,c=1,t=2,pt=1,l=1,sg=0:1
    0;255;3;0;9;46850 TSF:MSG:ACK REQ
    0;255;3;0;9;46866 TSF:MSG:SEND,0-0-144-144,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
    144;1;1;0;2;1
    0;255;3;0;9;46964 TSF:MSG:READ,144-144-0,s=4,c=1,t=37,pt=0,l=3,sg=0:319
    0;255;3;0;9;46983 TSF:MSG:ACK REQ
    0;255;3;0;9;46999 TSF:MSG:SEND,0-0-144-144,s=4,c=1,t=37,pt=0,l=3,sg=0,ft=0,st=OK:319
    144;4;1;0;37;319
    0;255;3;0;9;47173 TSF:MSG:READ,144-144-0,s=2,c=1,t=1,pt=0,l=5,sg=0:34.00
    0;255;3;0;9;47194 TSF:MSG:ACK REQ
    0;255;3;0;9;47210 TSF:MSG:SEND,0-0-144-144,s=2,c=1,t=1,pt=0,l=5,sg=0,ft=0,st=OK:34.00
    144;2;1;0;1;34.00
    

    So everything is OK.

    Node is connected to ESP8266 MQTT gateway:
    ESP gateway log:

    11162 TSF:MSG:READ,144-144-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    11221 TSF:MSG:ACK REQ
    11252 TSF:MSG:SEND,0-0-144-144,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
    11325 GWT:TPS:TOPIC=mygateway1-out/144/1/1/0/2,MSG SENT
    11495 TSF:MSG:READ,144-144-0,s=4,c=1,t=37,pt=0,l=3,sg=0:454
    11558 TSF:MSG:ACK REQ
    11589 TSF:MSG:SEND,0-0-144-144,s=4,c=1,t=37,pt=0,l=3,sg=0,ft=0,st=OK:454
    11665 GWT:TPS:TOPIC=mygateway1-out/144/4/1/0/37,MSG SENT
    

    Sensor log is the same in this case.

    So everything is OK too.

    ////////////////////////////////////////////////////////////////////////////////////////
    TEST STRING - wait (50ms)

    Node is connected to serial gateway:
    In this case everything is ok too, logs are identical

    Node is connected to ESP8266 MQTT gateway:
    ESP gateway log:

    185600 TSF:MSG:READ,144-144-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    185661 TSF:MSG:ACK REQ
    186904 !TSF:MSG:SEND,0-0-144-144,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=NACK:0
    186981 GWT:TPS:TOPIC=mygateway1-out/144/1/1/0/2,MSG SENT
    

    Node log:

    8153 MCO:SLP:WUP=1
    8155 TSF:TRI:TSB
    8466 TSF:MSG:SEND,144-144-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
    9762 !TSF:MSG:SEND,144-144-0-0,s=4,c=1,t=37,pt=0,l=3,sg=0,ft=0,st=NACK:220
    10272 MCO:SLP:MS=0,SMS=0,I1=1,M1=3,I2=255,M2=255
    10276 TSF:TDI:TSL
    

    So only switch message was sended, light sensor message was omitted in this case.

    ////////////////////////////////////////////////////////////////////////////////////////
    TEST STRING - wait (0ms)

    Node is connected to serial gateway:
    Serial Gateway log:

    0;255;3;0;9;260765 TSF:MSG:READ,144-144-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    0;255;3;0;9;260786 TSF:MSG:ACK REQ
    0;255;3;0;9;262012 !TSF:MSG:SEND,0-0-144-144,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=NACK:0
    144;1;1;0;2;0
    

    Node log:

    15908 MCO:SLP:WUP=1
    15910 TSF:TRI:TSB
    16222 TSF:MSG:SEND,144-144-0-0,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=1,st=OK:0
    17682 !TSF:MSG:SEND,144-144-0-0,s=4,c=1,t=37,pt=0,l=3,sg=0,ft=0,st=NACK:467
    18192 MCO:SLP:MS=0,SMS=0,I1=1,M1=3,I2=255,M2=255
    18196 TSF:TDI:TSL
    

    So only switch message was sended, light sensor message was omitted in this case too.

    Node is connected to ESP8266 MQTT gateway:
    ESP gateway log:

    60501 TSF:MSG:READ,144-144-0,s=1,c=1,t=2,pt=1,l=1,sg=0:0
    60561 TSF:MSG:ACK REQ
    61803 !TSF:MSG:SEND,0-0-144-144,s=1,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=NACK:0
    61879 GWT:TPS:TOPIC=mygateway1-out/144/1/1/0/2,MSG SENT
    

    Node log:
    Log is identical to 50ms esp8266 gateway case.

    So a small summary:
    wait(0ms) after the first message - next message is ommited with both gateways.
    wait(50ms) after the first message - next message is ommited with ESP8266 gateway.
    wait(100ms) after the first message - next message is sent with both gateways

    Many thanks for any ideas.



  • I don't know if it affecting your case, but according to the source code for the BH1750 library you need to set the mode:
    Source code for bh1750 library
    Note that the begin() function needs a mode parameter, and that is used in configure, it if is not provided it is an invalid mode,

    void BH1750::begin(uint8_t mode) {
    
      Wire.begin();
      //write8(mode);
      configure(mode);
    }
    
    
    void BH1750::configure(uint8_t mode) {
    
        switch (mode) {
            case BH1750_CONTINUOUS_HIGH_RES_MODE:
            case BH1750_CONTINUOUS_HIGH_RES_MODE_2:
            case BH1750_CONTINUOUS_LOW_RES_MODE:
            case BH1750_ONE_TIME_HIGH_RES_MODE:
            case BH1750_ONE_TIME_HIGH_RES_MODE_2:
            case BH1750_ONE_TIME_LOW_RES_MODE:
                // apply a valid mode change
                write8(mode);
                _delay_ms(10);
                break;
            default:
                // Invalid measurement mode
                #if BH1750_DEBUG == 1
                Serial.println("Invalid measurement mode");
                #endif
                break;
        }
    }```


  • @mickecarlsson said in Very strange bugs. 2.3. RFM69.:

    Note that the begin() function needs a mode parameter, and that is used in configure

    Should be this one lightMeter.begin(BH1750::ONE_TIME_LOW_RES_MODE); but Koresh was asking radio related question...



  • @yury @Koresh I am not sure it is radio related question. However, something is not letting the node to transfer messages if delay is less than 100ms.

    @Koresh Can you try to do a simple node sending say 5 messages to the GW within 5ms?
    I am trying to understand if this is your code or something is wrong elsewhere. In 2.2.0 no issues?

    @tekka any ideas please?


  • Hardware Contributor

    Hello.

    Like I said in this other thread https://forum.mysensors.org/post/91188 ,
    we heard you, and we will try to fix issue if there is one in 2.3 as soon as we get time (can't tell you about 2.3, I'm using customized code atm).

    Regarding sketch, yes it's always easier for debugging to use a sketch with no external lib. A simple counter sender for example (often using it for this purpose), etc.

    So in the meantime, you can wait and use 2.2 if you don't need something special in 2.3, or feel free to fix this issue 😉



  • @alexsh1
    I was trying the same code on bare RFM69 board without any external libs,
    just mysesnsors2.0 and 2.2 and 2.3 old drivers. 2.0 need 30ms waits 2.2-2.3 - up to 100ms for stable ACK's and sends

    @scalz
    NRF24 works fine without waits.... may be you know some direction where to dig in RFM driver for gold?



  • @yury I've never used Mysensors but looking at the latest RFM69 driver it's clear that it waits minimum MY_RFM69_CSMA_TIMEOUT_MS (default 500ms) before sending a frame.
    https://github.com/mysensors/MySensors/blob/master/drivers/RFM69/new/RFM69_new.cpp line 378

    I suppose it does it to respect the regulations.


  • Contest Winner

    @bakcsa Excuse me... Do you understand what CSMA means? 🙂 The air in all tests was absolutely avaliable. So we have a bugs in ideal conditions (dot to dot connection without cramps).


  • Contest Winner

    Yury and I have been digging deep into the new RFM69 driver and MySensors 2.3 for the past two days. I think it needs a lot of work so far. But good results have already been achieved 😄
    Now I can send lots of messages which requested ACK one by one without any wait between them (we tested 200 messages) and not a single NACK has ever appeared.
    Will share results soon.


  • Mod

    That fantastic news @koresh, great work!


  • Contest Winner


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts