Endlessly rebooting node



  • I finally got bootloader and upload issues done, but now one sketch/node is killing me. I have tried different AtMega328Ps but the symptom remains.
    The node: SlimNode, constant power (step down to 3.3V from alarm system 12V battery), non-PA NRF24, DHT11. Extra LED to blink at start-up, extra cap 100yF at power input. Pins/connections verified once extra.

    Serial:

    
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.1
    
    34 MCO:BGN:INIT REPEATER,CP=RNNRASQ-,REL=255,VER=2.3.1
    55 MCO:BGN:BFR
    2093 TSM:INIT
    2097 TSF:WUR:MS=0
    2105 TSM:INIT:TSP OK
    2109 TSM:INIT:STATID=3
    2113 TSF:SID:OK,ID=3
    2117 TSM:FPAR
    2154 TSF:MSG:SEND,3-3-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    3115 TSF:MSG:READ,0-0-3,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    3125 TSF:MSG:FPAR OK,ID=0,D=1
    4167 TSM:FPAR:OK
    4169 TSM:ID
    4171 TSM:ID:OK
    4175 TSM:UPL
    4182 TSF:MSG:SEND,3-3-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    4194 TSF:MSG:READ,0-0-3,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    4204 TSF:MSG:PONG RECV,HP=1
    4208 TSM:UPL:OK
    4212 TSM:READY:ID=3,PAR=0,DIS=1
    4222 TSF:MSG:SEND,3-3-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0101
    4235 TSF:MSG:READ,0-0-3,s=255,c=3,t=15,pt=6,l=2,sg=0:0101
    4249 TSF:MSG:SEND,3-3-0-0,s=255,c=3,t=16,pt=0,l=0,sg=0,ft=0,st=OK:
    4263 TSF:MSG:READ,0-0-3,s=255,c=3,t=17,pt=6,l=25,sg=0:<NONCE>
    4329 TSF:MSG:SEND,3-3-0-0,s=255,c=0,t=18,pt=0,l=5,sg=1,ft=1,st=OK:2.3.1
    4341 !TSF:RTE:FPAR ACTIVE
     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.1
    
    36 MCO:BGN:INIT REPEATER,CP=RNNRASQ-,REL=255,VER=2.3.1
    57 MCO:BGN:BFR
    

    ...and this keeps repeating

    Code:

    /**
     *
     * DESCRIPTION
     * Temp Sensor and repeater / Slim node
     *
     */
    
    #define MY_DEBUG
    #define MY_RADIO_RF24
    #define MY_REPEATER_FEATURE   // Enable repeater functionality for this node
    #define MY_SIGNING_SIMPLE_PASSWD "XXXXXXXXXX"
    #define MY_RF24_IRQ_PIN 2
    #define MY_RX_MESSAGE_BUFFER_FEATURE
    #define MY_NODE_ID 3
    #define MY_BAUD_RATE 57600
    
    #define DHT_DATA_PIN 4
    #define SENSOR_TEMP_OFFSET 0
    #define HUM 1
    #define TEMP 2
    
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    
    #include <SPI.h>
    #include <DHT.h>
    #include <MySensors.h>
    
    MyMessage msgHum(HUM, V_HUM);
    MyMessage msgTemp(TEMP, V_TEMP);
    DHT dht;
    
    void before()
    {
      pinMode(7, OUTPUT);
      int i = 0;
      for(i=0; i < 5; i++) {
        digitalWrite(7, HIGH);
        delay(100);
        digitalWrite(7, LOW);
        delay(300);
    }
    }
    
    void setup()
    {
      delay(100);  // Let power settle
      dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
      wait(2000);
    }
    
    void presentation()  
    { 
      sendSketchInfo("Temp Sensor & Repeater", "v06012019");
      present(HUM, S_HUM);
      present(TEMP, S_TEMP);
      metric = getControllerConfig().isMetric;
    }
    
    void loop()
    {
       // Force reading sensor, so it works also after sleep()
      dht.readSensor(true);
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        temperature += SENSOR_TEMP_OFFSET;
        send(msgTemp.set(temperature, 1));
    
        #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
        #endif
      } else {
        // Increase no update counter if the temperature stayed the same
        nNoUpdatesTemp++;
      }
    
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        // Reset no updates counter
        nNoUpdatesHum = 0;
        send(msgHum.set(humidity, 1));
    
        #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
        #endif
      } else {
        // Increase no update counter if the humidity stayed the same
        nNoUpdatesHum++;
      }
    
      // Sleep for a while to save energy
      //sleep(UPDATE_INTERVAL); 
    //}
    wait(120000);
    }
    

    I dont think it's a power issue but what else could it be? Behavior is the same with DHT11 unplugged. Also same if powering from FTDI.


  • Contest Winner

    @masmat atmega328p with software signing and encryption will probably mean you are low on ram. Perhaps stack issues cause the reboots?


  • Mod

    Good point @anticimex
    I tried the sketch and it displays the following output on my system

    Global variables use 1655 bytes (80%) of dynamic memory, leaving 393 bytes for local variables. Maximum is 2048 bytes.
    Low memory available, stability problems may occur.
    

    @MasMat you'll need to save some ram or switch to a mcu with more ram. https://www.mysensors.org/apidocs/group__memorysavings.html might be useful but will probably be insufficient.


  • Contest Winner

    @masmat correction; you don't use encryption. But as @mfalkvidd says, you are probably in the grey zone of operations so stability much depend on execution paths.


  • Mod

    By

    • Turning off MY_DEBUG (yes, you'll be blind but there isn't much to do if you want the signing feature)
    • Turning off MY_REPEATER_FEATURE (can't cram all features into an atmega328)
    • Adding #ifdef MY_DEBUG around the two serial prints that didn't have any rules
    • Changing sendsketchinfo to use the F macro

    I get the following result:

    Sketch uses 13902 bytes (45%) of program storage space. Maximum is 30720 bytes.
    Global variables use 1456 bytes (71%) of dynamic memory, leaving 592 bytes for local variables. Maximum is 2048 bytes.
    

    Not sure if that will be sufficient to avoid crashing, but maybe.



  • @mfalkvidd Yeah, it became stable after I did the same. I will have to simplify the tasks for my bare bones nodes.
    Since I'm getting wrong (no warnings) memory messages uploading, do you think I should edit boards.txt?

    atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)
    
    atmega328bb.upload.protocol=arduino
    atmega328bb.upload.maximum_size=30720
    atmega328bb.upload.speed=57600
    
    atmega328bb.bootloader.low_fuses=0xE2
    atmega328bb.bootloader.high_fuses=0xDA
    atmega328bb.bootloader.extended_fuses=0xfd
    
    atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
    atmega328bb.bootloader.unlock_bits=0x3F
    atmega328bb.bootloader.lock_bits=0x0F
    
    atmega328bb.build.mcu=atmega328p
    atmega328bb.build.f_cpu=8000000L
    atmega328bb.build.core=arduino:arduino
    atmega328bb.build.variant=arduino:standard
    
    
    atmega328bb.bootloader.tool=arduino:avrdude
    atmega328bb.upload.tool=arduino:avrdude```

  • Mod

    @masmat I have never messed with boards.txt, but it seems like your file is missing maximum_data_size. See https://github.com/arduino/arduino-flash-tools/blob/443c0534131d2beb95d0825b6afee3fb123f3f77/hardware/avr/boards.txt#L641


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 5
  • 8
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts