Webserver not running anymore

Hi,

I have an Arduino Uno Project, where I am monitoring smoke detectors and send an email on an alarm.
In addition to that I have implemented a webserver to query the status, but also to suspend alarms.

This sketch was running fine for 3 years now, but I had to change the IP Adress of the Arduino.
I just changed the IPs of the Arduino, the Gateway and the SMTP Server and uploaded again.

Before doing that I had to install the new IDE, because I changed my PC in the meantime.

Everything works fine, but I am only getting a blank page when accessing the Webserver.

This is attached.

Here are the warnings I am getting:

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino: In function 'void loop()':

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:105:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

                     if (StrContains(HTTP_req, "ajax_inputs")) {

                                                            ^

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino: In function 'void SetLEDs()':

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:216:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (StrContains(HTTP_req, "LED4=1")) {

                                     ^

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:221:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (StrContains(HTTP_req, "LED3=1")) {

                                     ^

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:226:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (StrContains(HTTP_req, "LED1=1")) {

                                     ^

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:231:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (StrContains(HTTP_req, "LED1=0")) {

                                     ^

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:236:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (StrContains(HTTP_req, "LED2=1")) {

                                     ^

C:\UserData\ebnerjoh\Nextcloud\Privat\Arduino\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2\Rauchmelder_with_Ethernet_and_Email_SMS_LAN_V2.ino:241:37: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

   if (StrContains(HTTP_req, "LED2=0")) {

                                     ^

Sketch uses 21478 bytes (66%) of program storage space. Maximum is 32256 bytes.
Global variables use 1785 bytes (87%) of dynamic memory, leaving 263 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

Best Regards,
Johannes

sketch.txt (13.1 KB)

BTW:

The serial monitor shows the following, when I try to access the webserver:

Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index4.htm file.
Ready
GET / HTTP/1.1
Host: 192.168.1.22
Upgrade-Insecure-RequesGET /favicon.ico HTTP/1.1
Host: 192.168.1.22
Connection:

Two possibilities

As the compiler told you "Low memory available, stability problems may occur."

Looks that you are being notified as well that it would be better to move to secure http (Upgrade-Insecure-RequesGET /favicon.ico) . Did you change server too?

Hi,

No, I only changed the SMTP-Server, the IP-Address and the Default Gateway. Nothing more.

Of course I changed the compiler. The last time I compiled the programme somewhen in 2014. Now, after the cahnges, I have compiled it with the latest IDE.

All other fuctions are working without any issues, Only the webserver part is causing issues.

Br,
Johannes

try to address the compiler warning first to ensure coherence

for example you have:


char req_index = 0;

which you use as an index in an array… this should not be a char but a byte if you want only indexes less than 255 or an unsigned int
→ suggest you replace with

byte req_index = 0;       // index into HTTP_req buffer

you define your string comparison function as

char StrContains(char *str, char *sfind)

but the second element you pass is a constant so write it

char StrContains(char *str, const char *sfind)

and because you actually want to return a truth statement, instead of returning a char (which you don’t do, you return 0 or 1 at the moment) return a boolean so write it as

boolean StrContains(char *str, const char *sfind)

and return true and false instead of 0 and 1


The way you handle time comparison will cause problems

long lastMillis = 0;
long currentMillis = 0;
long previousMillis = 0;
long blinkMillis = 0;

should all be unsigned long → change to

unsigned long lastMillis = 0;
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
unsigned long blinkMillis = 0;
unsigned long blinkInterval = 1000ul; // should that be const ??

That test will cause problem over time when millis() rolls over

if ( millis() < lastMillis + 540000) {

should be written

   if ( millis() - lastMillis < 540000ul) {

similarily change the other one to

   else if ( (millis() > blinkMillis) && (millis() - blinkMillis < 60000ul)) {

When you do this:

 char len;

  len = strlen(str);

you use again a char to hold a size. the whole function should be rewritten to have the right types, suggest you use

boolean StrContains(char *str, const char *sfind)
{
  unsigned int found = 0;
  unsigned int index = 0;
  unsigned int len;

  len = strlen(str);

  if (strlen(sfind) > len) {
    return false;
  }

  while (index < len) {
    if (str[index] == sfind[found]) {
      found++;
      if (strlen(sfind) == found) {
        return true;
      }
    }  else {
      found = 0;
    }
    index++;
  }
  return false;
}

Note that you have just reinvented a common c function strstr()


in the function sendEmail() the variables thisByte and respCode are unused, get rid of them


the sendEmail() functions actually returns a truth value, so you should honor that and return true or false and declare it as returning a boolean. Same for eRcv()

the way you handle asynchronous communication is weak, you are not guaranteed to get all the buffer with the way you handle the reading


There are many places where you print constant strings without using the F() macro or use write whereas you could use print and the F macro. since you are running low on memory, I suggest you fix those too.


follow up form previous post #4

So with all those changes (and changing pins number from int to byte) you should get that code (attached as too big to fit in) which would compile without error nor warnings and drops to 67% of RAM usage which will give you some more room for your memory but you are still dangerously close to the max. Give it a try

Last but not least, I would also recommend to switch to the SDFat library instead of SD. I let you do those changes and of course make sure your SD card and SD Shields are still in good conditions after 4 years… → check the SD card works fine

(I’ve not tested the code nor looked for bugs since you said that was working OK)

modified.ino (12.2 KB)

J-M-L:
follow up form previous post #4

So with all those changes (and changing pins number from int to byte) you should get that code (attached as too big to fit in) which would compile without error nor warnings and drops to 67% of RAM usage which will give you some more room for your memory but you are still dangerously close to the max. Give it a try

Last but not least, I would also recommend to switch to the SDFat library instead of SD. I let you do those changes and of course make sure your SD card and SD Shields are still in good conditions after 4 years.. --> check the SD card works fine

(I've not tested the code nor looked for bugs since you said that was working OK)

Many thanks, working perfectly.

Br,
Johannes

Good news!!