Possible CryptoHAL bug.



  • I have updated my temperature sensor sketch to MySensors 2.3.1. It's a Nodemanager Sketch and looks as follows:

    /*
    * 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-2017 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.
    */
    
    /**************************
    Template
    
    This sketch can be used as a template since containing the most relevant MySensors library configuration settings, 
    NodeManager's settings, all its the supported sensors commented out and a sketch structure fully functional to operate with
    NodeManager. Just uncomment the settings you need and the sensors you want to add and configure the sensors in before()
    */
    
    /**********************************
     * MySensors node configuration
     */
    
    // General settings
    #define SKETCH_NAME "SBM TempHum"
    #define SKETCH_VERSION "1.0"
    #define MY_NODE_ID 10
    
    // RFM69 radio settings
    #define MY_RADIO_RFM69
    #define MY_RFM69_FREQUENCY RFM69_433MHZ
    #define MY_IS_RFM69HW
    //#define MY_RFM69_NEW_DRIVER
    //#define MY_RFM69_ENABLE_ENCRYPTION
    #define MY_RFM69_NETWORKID 99
    //#define MY_DEBUG_VERBOSE_RFM69
    //#define MY_RF69_IRQ_PIN D1
    //#define MY_RF69_IRQ_NUM MY_RF69_IRQ_PIN
    //#define MY_RF69_SPI_CS D2
    //#define MY_RFM69_ATC_MODE_DISABLED
    
    // Message signing settings
    //#define MY_SIGNING_SOFT
    //#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7
    //#define MY_SIGNING_REQUEST_SIGNATURES
    #define MY_SIGNING_ATSHA204
    //#define MY_SIGNING_ATSHA204_PIN 4
    #define MY_SIGNING_REQUEST_SIGNATURES
    
    // OTA Firmware update settings
    #define MY_OTA_FIRMWARE_FEATURE
    #define OTA_WAIT_PERIOD 300
    #define FIRMWARE_MAX_REQUESTS 2
    #define MY_OTA_RETRY 2
    
    // OTA debug output
    //#define MY_DEBUG_OTA (0)
    //#define MY_OTA_LOG_SENDER_FEATURE
    //#define MY_OTA_LOG_RECEIVER_FEATURE
    //#define MY_DEBUG_OTA_DISABLE_ACK
    
    // Advanced settings
    #define MY_BAUD_RATE 115200
    //#define MY_SMART_SLEEP_WAIT_DURATION_MS 500
    #define MY_SPLASH_SCREEN_DISABLED
    //#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE
    //#define MY_SIGNAL_REPORT_ENABLED
    
    // Optimizations when running on 2032 Coin Cell. Also set nodeManager.setSleepBetweenSend(500) and run the board at 1Mhz
    #define MY_TRANSPORT_UPLINK_CHECK_DISABLED
    #define MY_TRANSPORT_WAIT_READY_MS  5000
    #define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 2000
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    /***********************************
     * NodeManager configuration
     */
    
    #define NODEMANAGER_DEBUG ON
    #define NODEMANAGER_SLEEP ON
    #define NODEMANAGER_CONDITIONAL_REPORT ON
    #define NODEMANAGER_OTA_CONFIGURATION OFF
    
    
    // import NodeManager library (a nodeManager object will be then made available)
    #include <MySensors_NodeManager.h>
    
    /***********************************
     * Add your sensors
     */
     
    #include <sensors/SensorBattery.h>
    SensorBattery battery;
    
    #include <sensors/SensorSI7021.h>
    SensorSI7021 si7021;
    
    /***********************************
     * Main Sketch
     */
    
    // before
    void before() {
    	
      /***********************************
       * Configure your sensors
       */
      nodeManager.setSmartSleep(true); 
      nodeManager.setReportIntervalMinutes(10);
      nodeManager.setSleepMinutes(10);
      nodeManager.setSleepBetweenSend(200);
      
      for (List<Child*>::iterator itr = si7021.children.begin(); itr != si7021.children.end(); ++itr) {
        Child* child = *itr;
        if (child->getType() == V_TEMP) child->setValueDelta(0.15);
        if (child->getType() == V_HUM) child->setValueDelta(2.0);
        child->setForceUpdateTimerValue(59);
      }
    
      battery.setMinVoltage(2.0);
      battery.setMaxVoltage(3.1);
      battery.setSendBatteryLevel(true);
        
      nodeManager.before();
    }
    
    // presentation
    void presentation() {
      // call NodeManager presentation routine
      nodeManager.presentation();
    }
    
    // setup
    void setup() {
      // call NodeManager setup routine
      nodeManager.setup();
    }
    
    // loop
    void loop() {
      // call NodeManager loop routine
      nodeManager.loop();
    }
    

    This works fine with MySensors 2.3.0. This is the log output:

    0 NM:INIT:VER=1.8
    0 NM:INIT:INO=SBM TempHum v1.0
    0 NM:INIT:LIB VER=2.3.0 CP=RRONAA-- 
    0 NM:INIT:RBT p=255
    2 NM:BFR:INIT
    1964 NM:BFR:OK
    3094 NM:PRES:BATTERY(201) p=30 t=38
    3559 NM:PRES:SI7021(1) p=6 t=0
    3823 NM:PRES:SI7021(2) p=7 t=1
    5468 NM:STP:ID=10 M=1
    5541 NM:STP:HW V=3271 F=8 M=310
    5617 NM:LOOP:BATTERY(201):SET t=38 v=3.27
    6762 NM:LOOP:SI7021(1):SET t=0 v=24.48
    6782 NM:LOOP:SI7021(2):SET t=1 v=53.00
    7712 NM:SLP:SLEEP s=600
    

    But with MySensors 2.3.1 there seems to be some problem at presentation. This is the log output:

    0 NM:INIT:VER=1.8
    0 NM:INIT:INO=SBM TempHum v1.0
    0 NM:INIT:LIB VER=2.3.1 CP=RRONAA-- 
    0 NM:INIT:RBT p=255
    2 NM:BFR:INIT
    1929 NM:BFR:OK
    3065 NM:PRES:BATTERY(201) p=30 t=38
    3530 NM:PRES:SI7021(1) p=6 t=0
    3792 NM:PRES:⸮5437 NM:STP:ID=10 M=1
    5515 NM:STP:HW V=3271 F=8 M=354
    5588 NM:LOOP:BATTERY(201):SET t=38 v=3.27
    6522 NM:LOOP:SI7021(1):SET t=0 v=24.64
    6987 NM:SLP:SLEEP s=600
    

    I have been reverting commits and found out that the problem started when "Introduce CryptoHAL, optimize crypto functions (#1178)" was merged. Also found out that disabling conditional report makes it work, which really doesn't make any sense.
    The same problem is happening on other node without conditional report but with an additional BH1750 sensor. Looks like a buffer overflow bug? 🤷‍♂️

    I'm quite lost at this point.
    Thanks.


  • Admin

    @gerator Looks like a stack overflow - how much RAM is free after compilation? Also, could you try with the latest development branch?



  • @tekka First of all thanks for your interest. The same happens with the latest development branch. This is the output after compilation:

    Sketch uses 28834 bytes (93%) of program storage space. Maximum is 30720 bytes. 
    Global variables use 1270 bytes (62%) of dynamic memory, leaving 778 bytes for local variables. Maximum is 2048 bytes.
    

    I have tried disabling OTA Flash (which has nothing to do with cryptohal nor presentation) and it seams to work.


  • Mod

    @gerator OTA Flash uses ram, so if the problem is due to insufficient ram it can still affect the rest of the code.



  • It seems you two are right. Thanks for your help.


Log in to reply
 

Suggested Topics

  • 33
  • 5
  • 6
  • 8
  • 2
  • 11

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts