Problems with sending emails

Hi!

I am a new Arduino user and this is my first Project.

I have multiple smokedetectors in my house and they are connected via a 2-wire cable. They are not connected to an Alarm-Station or wathever - just private usage - and I know what I am doing with the detectors :-)

Function: If one Smokedetector detects an alarm it will put a 9 Volt Signal on the 2-wire cable. All other detectors are detecting this signal and also sending out an alarm. If now all smokedetectors are in ALARM-State it is hard to check, which Detector detected the smoke or detected a false alarm. Therefor you can put a shortcut between the 2 wires, which will suspend all detectors, except the one which detected the Alarm.

So, what do I want to do with the Arduino: 1) By pressing a Maintenance Button on the Arduino or pushing a button on a Webfrontend putting a shortcut on the wires. 2) Check if there is an alarm on the wire and swith on an alarm led 3) Sending an email when there is an active alarm

I was able to finish #1 and #2, but I have troubles with number #3. If I use the code for Email-only (no web), then I can send out an email via my SMTP Rely. When I load the whole config, then my program stops working.

If I comment out line 255 until end, then everything is working again (except email of course). If this lines are active, then the programm somehow stops working. The last message I am getting on the console is "SUCCESS - SD card initialized", which can be found at line 57.

Could it be because I am trying to run the Ethernet Shield in Server and Client mode at the same time?

Attached the Code:

Rauchmelder_with_Ethernet_and_Email.ino (10.3 KB)

Could it be because I am trying to run the Ethernet Shield in Server and Client mode at the same time?

You don't say which Arduino you have, but using client and server code at the same time is not likely to be the problem. Running out of memory is far more likely.

A 328-based Arduino has 2K of SRAM. The SD class uses more than 1/4 of that. EthernetServer, EthernetClient, and Serial all need some.

http://playground.arduino.cc/Code/AvailableMemory

Oh, forgot that...

Its an UNO.

BR, Johannes

You would do yourself a huge favor by adding the F() macro to all of your client prints.

client.println("Content-Type: text/xml");

to

client.println(F("Content-Type: text/xml"));

Hi!

What is the reason for this change?

Br, Johannes

Because strings like that in quotes are constant character arrays, which never change. They get copied to RAM before being used, so they burn up a lot of the precious 2K of RAM you have.

The F() macro keeps the character array in PROGMEM (it's there already), only using up 1 byte at a time. http://www.baldengineer.com/blog/2013/11/20/arduino-f-macro/

PaulS:

Could it be because I am trying to run the Ethernet Shield in Server and Client mode at the same time?

You don't say which Arduino you have, but using client and server code at the same time is not likely to be the problem. Running out of memory is far more likely.

A 328-based Arduino has 2K of SRAM. The SD class uses more than 1/4 of that. EthernetServer, EthernetClient, and Serial all need some.

http://playground.arduino.cc/Code/AvailableMemory

The FreeMem-Sketch shows me 1821 byte.

How do I know how much Memory a Sketch needs?

[quote author=James C4S link=topic=207133.msg1524914#msg1524914 date=1388343075] Because strings like that in quotes are constant character arrays, which never change. They get copied to RAM before being used, so they burn up a lot of the precious 2K of RAM you have.

The F() macro keeps the character array in PROGMEM (it's there already), only using up 1 byte at a time. http://www.baldengineer.com/blog/2013/11/20/arduino-f-macro/ [/quote]

Perfect, I added the F() function to all Serial.println and client.println.

Now the sketch is working without issues...

Still interested on how I can verify how much MEM my sketch is using...

I added the FreeMem() to my working Sketch. It shows me 446 byte free with the adopted code.

The FreeMem-Sketch shows me 1821 byte.

I find that hard to believe, given that you say you are using the SD library, which allocates a buffer of 512 bytes, leaving you with no more than 1536 bytes.

I added the FreeMem() to my working Sketch. It shows me 446 byte free with the adopted code.

What this suggests to me is that the original value was complete non-sense, since you actually had no memory available, having used more than all of it. Having gotten rid of a lot of SRAM usage, by using the F() macro, you now have enough memory to operate with.

Of course, this is pure speculation, because you have made code changes BUT NOT POSTED YOUR CODE!

If this is an Uno, you are out of SRAM. It may not show zero or a negative number, but an unrealistic value, and this is an unrealistic value. There is no way you can use the ethernet library and use only 200 bytes of SRAM.

ebnerjoh: The FreeMem-Sketch shows me 1821 byte.

ebnerjoh: The FreeMem-Sketch shows me 1821 byte.

This is why I cringe when people suggest these memory check functions. The ATmega328 does not have a memory controller and so these functions that check free-memory are guesses at best.

Sometimes, they're wrong. Unfortunately, they are usually wrong when RAM has already been exhausted, which is what you're seeing.

The proper way to manage memory is for the programmer to be mindful of what resources their program is using and when.

With the 1.5-release of the IDE, you'll at least this get a report from avr-size that tells you how much static memory will need to be allocated. This is a pretty basic evaluation of variables and constants, but at least a start.

PaulS:

The FreeMem-Sketch shows me 1821 byte.

I find that hard to believe, given that you say you are using the SD library, which allocates a buffer of 512 bytes, leaving you with no more than 1536 bytes.

I added the FreeMem() to my working Sketch. It shows me 446 byte free with the adopted code.

What this suggests to me is that the original value was complete non-sense, since you actually had no memory available, having used more than all of it. Having gotten rid of a lot of SRAM usage, by using the F() macro, you now have enough memory to operate with.

Of course, this is pure speculation, because you have made code changes BUT NOT POSTED YOUR CODE!

My mistake again: I run this FreeMem() without any other code. So this should be the FreeMem with only FreMem() in the Memory.