Skip to content

Memory leak? #57

Open
Open
@TXswe

Description

@TXswe

I am not the most experienced coder, so i could have something wrong, but I have tried to minimize the code to replicate the issue. The code i do now is simple create a single modbus registry, and just re-add data to it.

I get less then 200 loops (often around 175), then the Arduino crashes.
If I modify to add more/less variables, just changes when it crashes.
If I use a mega, instead of an uno, it just takes longer as it has more memory, but same result.

#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>


//Modbus Registers Offsets (0-9999)
const int reg01CurXPos = 1;  // Current X Position

//ModbusIP object
ModbusIP mb;

//Variables
unsigned int looper = 0;


void setup() {
    Serial.begin(9600);
    // The media access control (ethernet hardware) address for the shield
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    // The IP address for the shield
    byte ip[] = { 192, 168, 1, 175};
    //Config Modbus IP
    mb.config(mac, ip);
    
    Serial.println("Setup done");
    delay(1000);
}

void loop() {
  mb.addHreg(reg01CurXPos, 1);
  delay(10);
  mb.task(); // Call update on registrys for Modbus.

  Serial.print("Loop - ");
  Serial.println(looper);
  looper++;

  delay(10);
}

Any ideas on what is going on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions